2019-05-22 07:02:00 +00:00
|
|
|
#ifndef BB_SPI_H_
|
|
|
|
#define BB_SPI_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
enum spi_state {
|
|
|
|
SS_UNCONFIGURED = 0,
|
|
|
|
SS_SINGLE,
|
|
|
|
SS_DUAL_RX,
|
|
|
|
SS_DUAL_TX,
|
|
|
|
SS_QUAD_RX,
|
|
|
|
SS_QUAD_TX,
|
|
|
|
SS_HARDWARE,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum spi_type {
|
|
|
|
ST_UNCONFIGURED,
|
|
|
|
ST_SINGLE,
|
|
|
|
ST_DUAL,
|
|
|
|
ST_QUAD,
|
|
|
|
ST_QPI,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum spi_pin {
|
|
|
|
SP_MOSI,
|
|
|
|
SP_MISO,
|
|
|
|
SP_HOLD,
|
|
|
|
SP_WP,
|
|
|
|
SP_CS,
|
|
|
|
SP_CLK,
|
|
|
|
SP_D0,
|
|
|
|
SP_D1,
|
|
|
|
SP_D2,
|
|
|
|
SP_D3,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct spi_id {
|
|
|
|
uint8_t manufacturer_id; // Result from 0x90
|
|
|
|
uint8_t device_id; // Result from 0x90
|
|
|
|
uint8_t _manufacturer_id; // Result from 0x9f
|
|
|
|
uint8_t memory_type; // Result from 0x9f
|
|
|
|
uint8_t memory_size; // Result from 0x9f
|
|
|
|
uint8_t signature; // Result from 0xab
|
|
|
|
uint8_t serial[4]; // Result from 0x4b
|
|
|
|
int bytes; // -1 if unknown
|
|
|
|
const char *manufacturer;
|
|
|
|
const char *model;
|
|
|
|
const char *capacity;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ff_spi;
|
|
|
|
|
2019-05-23 01:51:45 +00:00
|
|
|
void spiPause(void);
|
|
|
|
void spiBegin(void);
|
|
|
|
void spiEnd(void);
|
2019-05-22 07:02:00 +00:00
|
|
|
|
2019-05-23 01:51:45 +00:00
|
|
|
//void spiSingleTx(uint8_t out);
|
|
|
|
//uint8_t spiSingleRx(void);
|
|
|
|
//void spiDualTx(uint8_t out);
|
|
|
|
//void spiQuadTx(uint8_t out);
|
|
|
|
void spiCommand(uint8_t cmd);
|
|
|
|
//uint8_t spiDualRx(void);
|
|
|
|
//uint8_t spiQuadRx(void);
|
|
|
|
int spiTx(uint8_t word);
|
|
|
|
uint8_t spiRx(void);
|
|
|
|
uint8_t spiReadStatus(uint8_t sr);
|
|
|
|
void spiWriteStatus(uint8_t sr, uint8_t val);
|
|
|
|
void spiReadSecurity(uint8_t sr, uint8_t security[256]);
|
|
|
|
void spiWriteSecurity(uint8_t sr, uint8_t security[256]);
|
|
|
|
int spiSetType(enum spi_type type);
|
|
|
|
int spiRead(uint32_t addr, uint8_t *data, unsigned int count);
|
|
|
|
int spiIsBusy(void);
|
|
|
|
int spiBeginErase32(uint32_t erase_addr);
|
|
|
|
int spiBeginErase64(uint32_t erase_addr);
|
|
|
|
int spiBeginWrite(uint32_t addr, const void *data, unsigned int count);
|
2019-05-22 07:02:00 +00:00
|
|
|
void spiEnableQuad(void);
|
|
|
|
|
2019-05-23 01:51:45 +00:00
|
|
|
struct spi_id spiId(void);
|
|
|
|
void spiOverrideSize(uint32_t new_size);
|
2019-05-22 07:02:00 +00:00
|
|
|
|
2019-05-23 01:51:45 +00:00
|
|
|
int spiWrite(uint32_t addr, const uint8_t *data, unsigned int count);
|
|
|
|
uint8_t spiReset(void);
|
|
|
|
int spi_init(void);
|
2019-05-22 07:02:00 +00:00
|
|
|
|
2019-05-23 01:51:45 +00:00
|
|
|
void spiHold(void);
|
|
|
|
void spiUnhold(void);
|
|
|
|
void spiSwapTxRx(void);
|
2019-05-22 07:02:00 +00:00
|
|
|
|
2019-05-23 01:51:45 +00:00
|
|
|
void spiSetPin(enum spi_pin pin, int val);
|
2019-05-22 07:02:00 +00:00
|
|
|
void spiFree(void);
|
|
|
|
|
|
|
|
#endif /* BB_SPI_H_ */
|