drivers/memory/spiflash: Change from hard-coded soft SPI to generic SPI.
The SPI flash driver now supports using an arbitrary SPI object to communicate with the flash chip, and in particular can use a hardware SPI peripheral.
This commit is contained in:
parent
d5336ba136
commit
613510bce8
@ -49,10 +49,8 @@ STATIC uint8_t buf[SECTOR_SIZE];
|
|||||||
void mp_spiflash_init(mp_spiflash_t *self) {
|
void mp_spiflash_init(mp_spiflash_t *self) {
|
||||||
mp_hal_pin_write(self->cs, 1);
|
mp_hal_pin_write(self->cs, 1);
|
||||||
mp_hal_pin_output(self->cs);
|
mp_hal_pin_output(self->cs);
|
||||||
mp_hal_pin_write(self->spi.sck, 0);
|
const mp_machine_spi_p_t *protocol = self->spi->type->protocol;
|
||||||
mp_hal_pin_output(self->spi.sck);
|
protocol->init(self->spi, 0, NULL, (mp_map_t*)&mp_const_empty_map);
|
||||||
mp_hal_pin_output(self->spi.mosi);
|
|
||||||
mp_hal_pin_input(self->spi.miso);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mp_spiflash_acquire_bus(mp_spiflash_t *self) {
|
STATIC void mp_spiflash_acquire_bus(mp_spiflash_t *self) {
|
||||||
@ -66,7 +64,8 @@ STATIC void mp_spiflash_release_bus(mp_spiflash_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mp_spiflash_transfer(mp_spiflash_t *self, size_t len, const uint8_t *src, uint8_t *dest) {
|
STATIC void mp_spiflash_transfer(mp_spiflash_t *self, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||||
mp_machine_soft_spi_transfer(&self->spi.base, len, src, dest);
|
const mp_machine_spi_p_t *protocol = self->spi->type->protocol;
|
||||||
|
protocol->transfer(self->spi, len, src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) {
|
STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) {
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
|
|
||||||
typedef struct _mp_spiflash_t {
|
typedef struct _mp_spiflash_t {
|
||||||
mp_hal_pin_obj_t cs;
|
mp_hal_pin_obj_t cs;
|
||||||
// TODO replace with generic SPI object
|
mp_obj_base_t *spi; // object must have protocol pointing to mp_machine_spi_p_t struct
|
||||||
mp_machine_soft_spi_obj_t spi;
|
|
||||||
} mp_spiflash_t;
|
} mp_spiflash_t;
|
||||||
|
|
||||||
void mp_spiflash_init(mp_spiflash_t *self);
|
void mp_spiflash_init(mp_spiflash_t *self);
|
||||||
|
@ -176,17 +176,19 @@ static uint8_t *flash_cache_get_addr_for_read(uint32_t flash_addr) {
|
|||||||
|
|
||||||
static bool flash_is_initialised = false;
|
static bool flash_is_initialised = false;
|
||||||
|
|
||||||
|
STATIC const mp_machine_soft_spi_obj_t spiflash_spi_bus = {
|
||||||
|
.base = {&mp_machine_soft_spi_type},
|
||||||
|
.delay_half = MICROPY_PY_MACHINE_SPI_MIN_DELAY,
|
||||||
|
.polarity = 0,
|
||||||
|
.phase = 0,
|
||||||
|
.sck = &MICROPY_HW_SPIFLASH_SCK,
|
||||||
|
.mosi = &MICROPY_HW_SPIFLASH_MOSI,
|
||||||
|
.miso = &MICROPY_HW_SPIFLASH_MISO,
|
||||||
|
};
|
||||||
|
|
||||||
STATIC const mp_spiflash_t spiflash = {
|
STATIC const mp_spiflash_t spiflash = {
|
||||||
.cs = &MICROPY_HW_SPIFLASH_CS,
|
.cs = &MICROPY_HW_SPIFLASH_CS,
|
||||||
.spi = {
|
.spi = (mp_obj_base_t*)&spiflash_spi_bus.base,
|
||||||
.base = {&mp_machine_soft_spi_type},
|
|
||||||
.delay_half = MICROPY_PY_MACHINE_SPI_MIN_DELAY,
|
|
||||||
.polarity = 0,
|
|
||||||
.phase = 0,
|
|
||||||
.sck = &MICROPY_HW_SPIFLASH_SCK,
|
|
||||||
.mosi = &MICROPY_HW_SPIFLASH_MOSI,
|
|
||||||
.miso = &MICROPY_HW_SPIFLASH_MISO,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user