Skip to content

Commit

Permalink
samd/machine_spi: Implement spi.deinit() and simplify sercom_deinit_all.
Browse files Browse the repository at this point in the history
The sercom_deinit_all() function does not need the object pointers.
  • Loading branch information
robert-hh authored and dpgeorge committed Oct 25, 2022
1 parent 9c2bc37 commit d74215a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ports/samd/machine_spi.c
Expand Up @@ -254,17 +254,23 @@ STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, s
return self;
}

STATIC void machine_sercom_deinit(mp_obj_base_t *self_in) {
machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
Sercom *spi = sercom_instance[self->id];
// Disable interrupts (if any)
spi->SPI.INTENCLR.reg = 0xff;
sercom_enable(spi, 0);
// clear table entry of spi
sercom_table[self->id] = NULL;
}

void sercom_deinit_all(void) {
for (int i = 0; i < SERCOM_INST_NUM; i++) {
if (sercom_table[i] != NULL) {
machine_spi_obj_t *self = sercom_table[i];
Sercom *spi = sercom_instance[self->id];
// Disable interrupts (if any)
spi->SPI.INTENCLR.reg = 0xff;
// clear table entry of spi
sercom_table[i] = NULL;
sercom_enable(spi, 0);
}
Sercom *spi = sercom_instance[i];
spi->SPI.INTENCLR.reg = 0xff;
sercom_register_irq(i, NULL);
sercom_enable(spi, 0);
sercom_table[i] = NULL;
}
}

Expand Down Expand Up @@ -316,6 +322,7 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8

STATIC const mp_machine_spi_p_t machine_spi_p = {
.init = machine_spi_init,
.deinit = machine_sercom_deinit,
.transfer = machine_spi_transfer,
};

Expand Down

0 comments on commit d74215a

Please sign in to comment.