Skip to content

Commit 173328f

Browse files
committed
fixes build error
1 parent 563361d commit 173328f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

micropy_updates/esp32/machine_hw_spi.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct _machine_hw_spi_bus_obj_t {
106106
int8_t sck;
107107
int8_t mosi;
108108
int8_t miso;
109-
uint8_t active_devices;
109+
int16_t active_devices;
110110
enum {
111111
MACHINE_HW_SPI_STATE_NONE,
112112
MACHINE_HW_SPI_STATE_INIT,
@@ -299,7 +299,7 @@ STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_
299299

300300
mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
301301

302-
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso ARG_cs};
302+
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso, ARG_cs};
303303
static const mp_arg_t allowed_args[] = {
304304
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = -1} },
305305
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 500000} },
@@ -327,6 +327,7 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
327327
default_pins = &machine_hw_spi_default_pins[spi_id - 1];
328328
} else {
329329
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), spi_id);
330+
return mp_const_none;
330331
}
331332

332333
self->base.type = &machine_spi_type;
@@ -366,15 +367,18 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
366367
cs = machine_pin_get_id(args[ARG_cs].u_obj);
367368
}
368369

370+
esp_err_t ret;
371+
369372
if (self->spi_bus->state == MACHINE_HW_SPI_STATE_INIT) {
370373
if (self->spi_bus->sck != sck || self->spi_bus->miso != miso || self->spi_bus->mosi != mosi) {
371374
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("bus already initilized using different pins"));
375+
return mp_const_none;
372376
}
373377
} else {
374-
self->spi_bus->host = args[ARG_id].u_int
375-
self->spi_bus->miso = miso
376-
self->spi_bus->mosi = mosi
377-
self->spi_bus->sck = sck
378+
self->spi_bus->host = args[ARG_id].u_int;
379+
self->spi_bus->miso = miso;
380+
self->spi_bus->mosi = mosi;
381+
self->spi_bus->sck = sck;
378382

379383
spi_bus_config_t buscfg = {
380384
.miso_io_num = miso,
@@ -400,7 +404,7 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
400404
switch (ret) {
401405
case ESP_ERR_INVALID_ARG:
402406
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration"));
403-
return;
407+
return mp_const_none;
404408

405409
case ESP_ERR_INVALID_STATE:
406410
break;
@@ -429,15 +433,15 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
429433
switch (ret) {
430434
case ESP_ERR_INVALID_ARG:
431435
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration"));
432-
return;
436+
return mp_const_none;
433437

434438
case ESP_ERR_NO_MEM:
435439
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("out of memory"));
436-
return;
440+
return mp_const_none;
437441

438442
case ESP_ERR_NOT_FOUND:
439443
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("no free slots"));
440-
return;
444+
return mp_const_none;
441445
}
442446

443447
self->spi_bus->active_devices++;

0 commit comments

Comments
 (0)