Skip to content

Commit 62a674c

Browse files
committed
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>
1 parent eaffbac commit 62a674c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

drivers/bus/qspi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct _mp_qspi_proto_t {
4646
int (*write_cmd_addr_data)(void *self, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src);
4747
int (*read_cmd)(void *self, uint8_t cmd, size_t len, uint32_t *dest);
4848
int (*read_cmd_qaddr_qdata)(void *self, uint8_t cmd, uint32_t addr, uint8_t num_dummy, size_t len, uint8_t *dest);
49+
int (*direct_read)(void *self, uint32_t addr, size_t len, uint8_t *dest); // can be NULL if direct read not supported
4950
} mp_qspi_proto_t;
5051

5152
typedef struct _mp_soft_qspi_obj_t {

drivers/memory/spiflash.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ void mp_spiflash_init(mp_spiflash_t *self) {
197197
} else {
198198
uint8_t num_dummy = MICROPY_HW_SPIFLASH_QREAD_NUM_DUMMY(self);
199199
self->config->bus.u_qspi.proto->ioctl(self->config->bus.u_qspi.data, MP_QSPI_IOCTL_INIT, num_dummy);
200+
if (self->config->bus.u_qspi.proto->direct_read != NULL) {
201+
// A bus with a custom read function should not have any further initialisation done.
202+
return;
203+
}
200204
}
201205

202206
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
318322
if (len == 0) {
319323
return 0;
320324
}
325+
const mp_spiflash_config_t *c = self->config;
326+
if (c->bus_kind == MP_SPIFLASH_BUS_QSPI && c->bus.u_qspi.proto->direct_read != NULL) {
327+
return c->bus.u_qspi.proto->direct_read(c->bus.u_qspi.data, addr, len, dest);
328+
}
321329
mp_spiflash_acquire_bus(self);
322330
int ret = mp_spiflash_read_data(self, addr, len, dest);
323331
mp_spiflash_release_bus(self);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy