Skip to content
Snippets Groups Projects
Commit da72bb68 authored by Damien George's avatar Damien George
Browse files

esp32/machine_hw_spi: Make HW SPI objects statically allocated.

This aligns more closely with the hardware, that there are two, fixed HW
SPI peripherals.  And it allows to recreate the HW SPI objects without
error, as well as create them again after a soft reset.

Fixes issue #4103.
parent d82f344f
Branches
No related tags found
No related merge requests found
...@@ -58,6 +58,9 @@ typedef struct _machine_hw_spi_obj_t { ...@@ -58,6 +58,9 @@ typedef struct _machine_hw_spi_obj_t {
} state; } state;
} machine_hw_spi_obj_t; } machine_hw_spi_obj_t;
// Static objects mapping to HSPI and VSPI hardware peripherals
STATIC machine_hw_spi_obj_t machine_hw_spi_obj[2];
STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) { STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) {
switch (spi_bus_remove_device(self->spi)) { switch (spi_bus_remove_device(self->spi)) {
case ESP_ERR_INVALID_ARG: case ESP_ERR_INVALID_ARG:
...@@ -363,7 +366,12 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_ ...@@ -363,7 +366,12 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; 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); mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
machine_hw_spi_obj_t *self = m_new_obj(machine_hw_spi_obj_t); machine_hw_spi_obj_t *self;
if (args[ARG_id].u_int == HSPI_HOST) {
self = &machine_hw_spi_obj[0];
} else {
self = &machine_hw_spi_obj[1];
}
self->base.type = &machine_hw_spi_type; self->base.type = &machine_hw_spi_type;
machine_hw_spi_init_internal( machine_hw_spi_init_internal(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment