Skip to content

Commit

Permalink
ports/psoc6: Single SPI init helper.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Jun 21, 2024
1 parent 0051976 commit b00e746
Showing 1 changed file with 0 additions and 67 deletions.
67 changes: 0 additions & 67 deletions ports/psoc6/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down

0 comments on commit b00e746

Please sign in to comment.