spi: add function to read various id codes
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
cddbe4c90c
commit
a9af9820be
66
spi.c
66
spi.c
@ -203,13 +203,6 @@ static void spiQuadTx(struct ff_spi *spi, uint8_t out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spiCommand(struct ff_spi *spi, uint8_t cmd) {
|
|
||||||
if (spi->type == ST_QPI)
|
|
||||||
spiQuadTx(spi, cmd);
|
|
||||||
else
|
|
||||||
spiSingleTx(spi, cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t spiDualRx(struct ff_spi *spi) {
|
static uint8_t spiDualRx(struct ff_spi *spi) {
|
||||||
int bit;
|
int bit;
|
||||||
uint8_t in = 0;
|
uint8_t in = 0;
|
||||||
@ -276,6 +269,20 @@ uint8_t spiRx(struct ff_spi *spi) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void spiCommand(struct ff_spi *spi, uint8_t cmd) {
|
||||||
|
if (spi->type == ST_QPI)
|
||||||
|
spiQuadTx(spi, cmd);
|
||||||
|
else
|
||||||
|
spiSingleTx(spi, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t spiCommandRx(struct ff_spi *spi) {
|
||||||
|
if (spi->type == ST_QPI)
|
||||||
|
return spiQuadRx(spi);
|
||||||
|
else
|
||||||
|
return spiSingleRx(spi);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t spiReadSr(struct ff_spi *spi, int sr) {
|
uint8_t spiReadSr(struct ff_spi *spi, int sr) {
|
||||||
uint8_t val = 0xff;
|
uint8_t val = 0xff;
|
||||||
|
|
||||||
@ -350,6 +357,51 @@ void spiWriteSr(struct ff_spi *spi, int sr, uint8_t val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct spi_id spiId(struct ff_spi *spi) {
|
||||||
|
struct spi_id id;
|
||||||
|
memset(&id, 0xff, sizeof(id));
|
||||||
|
|
||||||
|
spiBegin(spi);
|
||||||
|
spiCommand(spi, 0x90); // Read manufacturer ID
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 1
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 2
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 3
|
||||||
|
id.manufacturer_id = spiCommandRx(spi);
|
||||||
|
id.device_id = spiCommandRx(spi);
|
||||||
|
spiEnd(spi);
|
||||||
|
|
||||||
|
spiBegin(spi);
|
||||||
|
spiCommand(spi, 0x9f); // Read device id
|
||||||
|
id._manufacturer_id = spiCommandRx(spi);
|
||||||
|
id.memory_type = spiCommandRx(spi);
|
||||||
|
id.memory_size = spiCommandRx(spi);
|
||||||
|
spiEnd(spi);
|
||||||
|
|
||||||
|
spiBegin(spi);
|
||||||
|
spiCommand(spi, 0xab); // Read electronic signature
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 1
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 2
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 3
|
||||||
|
id.signature = spiCommandRx(spi);
|
||||||
|
spiEnd(spi);
|
||||||
|
|
||||||
|
spiBegin(spi);
|
||||||
|
spiCommand(spi, 0x4b); // Read unique ID
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 1
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 2
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 3
|
||||||
|
spiCommand(spi, 0x00); // Dummy byte 4
|
||||||
|
id.serial[0] = spiCommandRx(spi);
|
||||||
|
id.serial[1] = spiCommandRx(spi);
|
||||||
|
id.serial[2] = spiCommandRx(spi);
|
||||||
|
id.serial[3] = spiCommandRx(spi);
|
||||||
|
spiEnd(spi);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t spiJedecId(struct ff_spi *spi);
|
||||||
|
|
||||||
int spiSetType(struct ff_spi *spi, enum spi_type type) {
|
int spiSetType(struct ff_spi *spi, enum spi_type type) {
|
||||||
|
|
||||||
if (spi->type == type)
|
if (spi->type == type)
|
||||||
|
11
spi.h
11
spi.h
@ -34,6 +34,16 @@ enum spi_pin {
|
|||||||
SP_D3,
|
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
|
||||||
|
};
|
||||||
|
|
||||||
struct ff_spi;
|
struct ff_spi;
|
||||||
|
|
||||||
void spiPause(struct ff_spi *spi);
|
void spiPause(struct ff_spi *spi);
|
||||||
@ -53,6 +63,7 @@ uint8_t spiReadSr(struct ff_spi *spi, int sr);
|
|||||||
void spiWriteSr(struct ff_spi *spi, int sr, uint8_t val);
|
void spiWriteSr(struct ff_spi *spi, int sr, uint8_t val);
|
||||||
int spiSetType(struct ff_spi *spi, enum spi_type type);
|
int spiSetType(struct ff_spi *spi, enum spi_type type);
|
||||||
int spiRead(struct ff_spi *spi, uint32_t addr, uint8_t *data, unsigned int count);
|
int spiRead(struct ff_spi *spi, uint32_t addr, uint8_t *data, unsigned int count);
|
||||||
|
struct spi_id spiId(struct ff_spi *spi);
|
||||||
//int spi_wait_for_not_busy(struct ff_spi *spi);
|
//int spi_wait_for_not_busy(struct ff_spi *spi);
|
||||||
int spiWrite(struct ff_spi *spi, uint32_t addr, const uint8_t *data, unsigned int count);
|
int spiWrite(struct ff_spi *spi, uint32_t addr, const uint8_t *data, unsigned int count);
|
||||||
uint8_t spiReset(struct ff_spi *spi);
|
uint8_t spiReset(struct ff_spi *spi);
|
||||||
|
Loading…
Reference in New Issue
Block a user