samd/machine_spi: Implement spi.deinit() and simplify sercom_deinit_all.
The sercom_deinit_all() function does not need the object pointers.
This commit is contained in:
parent
9c2bc379f1
commit
d74215a313
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user