diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-09-04 20:33:11 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-09-04 20:33:11 +0300 |
commit | dba40afa706a1ac4b102dceba217844dc1540ce7 (patch) | |
tree | 5f423c2d7a4a1c3245a8d0654d26f61babd5238e /esp8266/modpybhspi.c | |
parent | 7ddd1a58f6ec90a35e2ca815f62358acfb801c52 (diff) | |
download | micropython-dba40afa706a1ac4b102dceba217844dc1540ce7.tar.gz micropython-dba40afa706a1ac4b102dceba217844dc1540ce7.zip |
esp8266/modmachine: Simplify SPI class implementation multiplexing.
modpybhspi now does the needed multiplexing, calling out to modpybspi
(bitbanging SPI) for suitable peripheral ID's. modmachinespi (previous
multiplexer class) thus not needed and removed.
modpybhspi also updated to following standard SPI peripheral naming:
SPI0 is used for FlashROM and thus not supported so far. SPI1 is available
for users, and thus needs to be instantiated as:
spi = machine.SPI(1, ...)
Diffstat (limited to 'esp8266/modpybhspi.c')
-rw-r--r-- | esp8266/modpybhspi.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/esp8266/modpybhspi.c b/esp8266/modpybhspi.c index c4d4dcee8d..c1cd7f662d 100644 --- a/esp8266/modpybhspi.c +++ b/esp8266/modpybhspi.c @@ -39,6 +39,8 @@ #include "hspi.h" +mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, + size_t n_kw, const mp_obj_t *args); typedef struct _pyb_hspi_obj_t { mp_obj_base_t base; @@ -105,13 +107,14 @@ STATIC void hspi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t STATIC void pyb_hspi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_hspi_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "HSPI(baudrate=%u, polarity=%u, phase=%u)", + mp_printf(print, "HSPI(id=1, baudrate=%u, polarity=%u, phase=%u)", self->baudrate, self->polarity, self->phase); } STATIC void pyb_hspi_init_helper(pyb_hspi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_baudrate, ARG_polarity, ARG_phase }; + enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase }; static const mp_arg_t allowed_args[] = { + { MP_QSTR_id, MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_polarity, MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_phase, MP_ARG_INT, {.u_int = -1} }, @@ -160,7 +163,25 @@ STATIC void pyb_hspi_init_helper(pyb_hspi_obj_t *self, size_t n_args, const mp_o } mp_obj_t pyb_hspi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true); + mp_arg_check_num(n_args, n_kw, 0, 1, true); + mp_int_t id = -1; + if (n_args > 0) { + id = mp_obj_get_int(args[0]); + } + + if (id == -1) { + // Multiplex to bitbanging SPI + if (n_args > 0) { + args++; + } + return pyb_spi_make_new(type, 0, n_kw, args); + } + + if (id != 1) { + // FlashROM is on SPI0, so far we don't support its usage + mp_raise_ValueError(""); + } + pyb_hspi_obj_t *self = m_new_obj(pyb_hspi_obj_t); self->base.type = &pyb_hspi_type; // set defaults |