From b00e746f09642e436f2bb9e0597e15c497b741b8 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Fri, 21 Jun 2024 17:35:01 +0530 Subject: [PATCH] ports/psoc6: Single SPI init helper. Signed-off-by: NikhitaR-IFX --- ports/psoc6/machine_spi.c | 67 --------------------------------------- 1 file changed, 67 deletions(-) diff --git a/ports/psoc6/machine_spi.c b/ports/psoc6/machine_spi.c index e039f8818be4..ff6eb29c518a 100644 --- a/ports/psoc6/machine_spi.c +++ b/ports/psoc6/machine_spi.c @@ -181,73 +181,6 @@ static void machine_spi_slave_print(const mp_print_t *print, mp_obj_t self_in, m self->ssel->addr, self->sck->addr, self->mosi->addr, self->miso->addr); } -mp_obj_t machine_spi_master_init_helper(machine_spi_obj_t *self, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = DEFAULT_SPI_BAUDRATE} }, - { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPI_POLARITY} }, - { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPI_PHASE} }, - { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPI_BITS} }, - { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPI_FIRSTBIT} }, - { MP_QSTR_sck, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_mosi, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_miso, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - }; - // Parse the arguments. - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - // set baudrate if provided - if (args[ARG_baudrate].u_int != -1) { - self->baudrate = args[ARG_baudrate].u_int; - } - - // set polarity(CPOL) if provided - if (args[ARG_polarity].u_int != -1) { - self->polarity = args[ARG_polarity].u_int; - } - - // set phase(CPHA) if provided - if (args[ARG_phase].u_int != -1) { - self->phase = args[ARG_phase].u_int; - } - - // set bits if provided - if (args[ARG_bits].u_int != -1) { - self->bits = args[ARG_bits].u_int; - } - - // set firstbit if provided(LSB or MSB first) - if (args[ARG_firstbit].u_int != -1) { - self->firstbit = args[ARG_firstbit].u_int; - } - - spi_ssel_alloc(self, MP_ROM_QSTR(MP_QSTR_NC)); - - if (args[ARG_sck].u_obj != mp_const_none) { - spi_sck_alloc(self, args[ARG_sck].u_obj); - } else { - mp_raise_TypeError(MP_ERROR_TEXT("SCK pin must be provided")); - } - - if (args[ARG_mosi].u_obj != mp_const_none) { - spi_mosi_alloc(self, args[ARG_mosi].u_obj); - } else { - mp_raise_TypeError(MP_ERROR_TEXT("MOSI pin must be provided")); - } - - if (args[ARG_miso].u_obj != mp_const_none) { - spi_miso_alloc(self, args[ARG_miso].u_obj); - } else { - mp_raise_TypeError(MP_ERROR_TEXT("MISO pin must be provided")); - } - - if (n_args > 1 || n_kw > 0) { - spi_init(self, MASTER_MODE); - } - return MP_OBJ_FROM_PTR(self); -} - mp_obj_t machine_spi_init_helper(machine_spi_obj_t *self, int spi_mode, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_ssel, ARG_sck, ARG_mosi, ARG_miso }; static const mp_arg_t allowed_args[] = {