mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 13:01:10 +02:00
drivers: Support special QSPI direct-read protocol.
This is useful for interfaces that stay in memory-mapped mode by default. They can implement this method with a simple `memcpy()`. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -46,6 +46,7 @@ typedef struct _mp_qspi_proto_t {
|
||||
int (*write_cmd_addr_data)(void *self, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src);
|
||||
int (*read_cmd)(void *self, uint8_t cmd, size_t len, uint32_t *dest);
|
||||
int (*read_cmd_qaddr_qdata)(void *self, uint8_t cmd, uint32_t addr, uint8_t num_dummy, size_t len, uint8_t *dest);
|
||||
int (*direct_read)(void *self, uint32_t addr, size_t len, uint8_t *dest); // can be NULL if direct read not supported
|
||||
} mp_qspi_proto_t;
|
||||
|
||||
typedef struct _mp_soft_qspi_obj_t {
|
||||
|
@@ -197,6 +197,10 @@ void mp_spiflash_init(mp_spiflash_t *self) {
|
||||
} else {
|
||||
uint8_t num_dummy = MICROPY_HW_SPIFLASH_QREAD_NUM_DUMMY(self);
|
||||
self->config->bus.u_qspi.proto->ioctl(self->config->bus.u_qspi.data, MP_QSPI_IOCTL_INIT, num_dummy);
|
||||
if (self->config->bus.u_qspi.proto->direct_read != NULL) {
|
||||
// A bus with a custom read function should not have any further initialisation done.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mp_spiflash_acquire_bus(self);
|
||||
@@ -318,6 +322,10 @@ int mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *de
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
const mp_spiflash_config_t *c = self->config;
|
||||
if (c->bus_kind == MP_SPIFLASH_BUS_QSPI && c->bus.u_qspi.proto->direct_read != NULL) {
|
||||
return c->bus.u_qspi.proto->direct_read(c->bus.u_qspi.data, addr, len, dest);
|
||||
}
|
||||
mp_spiflash_acquire_bus(self);
|
||||
int ret = mp_spiflash_read_data(self, addr, len, dest);
|
||||
mp_spiflash_release_bus(self);
|
||||
|
Reference in New Issue
Block a user