Skip to content

Commit 9e0533b

Browse files
committed
extmod/machine_spi: Remove "id" arg in SoftSPI constructor.
The SoftSPI constructor is now used soley to create SoftSPI instances, it can no longer delegate to create a hardware-based SPI instance. Signed-off-by: Damien George <[email protected]>
1 parent aaed338 commit 9e0533b

File tree

6 files changed

+4
-29
lines changed

6 files changed

+4
-29
lines changed

extmod/machine_spi.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,6 @@
4141
/******************************************************************************/
4242
// MicroPython bindings for generic machine.SPI
4343

44-
STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
45-
46-
mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
47-
// check the id argument, if given
48-
if (n_args > 0) {
49-
if (args[0] != MP_OBJ_NEW_SMALL_INT(-1)) {
50-
#if defined(MICROPY_PY_MACHINE_SPI_MAKE_NEW)
51-
// dispatch to port-specific constructor
52-
extern mp_obj_t MICROPY_PY_MACHINE_SPI_MAKE_NEW(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
53-
return MICROPY_PY_MACHINE_SPI_MAKE_NEW(type, n_args, n_kw, args);
54-
#else
55-
mp_raise_ValueError(MP_ERROR_TEXT("invalid SPI peripheral"));
56-
#endif
57-
}
58-
--n_args;
59-
++args;
60-
}
61-
62-
// software SPI
63-
return mp_machine_soft_spi_make_new(type, n_args, n_kw, args);
64-
}
65-
6644
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
6745
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
6846
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)s->type->protocol;
@@ -275,7 +253,7 @@ const mp_obj_type_t mp_machine_soft_spi_type = {
275253
{ &mp_type_type },
276254
.name = MP_QSTR_SoftSPI,
277255
.print = mp_machine_soft_spi_print,
278-
.make_new = mp_machine_spi_make_new, // delegate to master constructor
256+
.make_new = mp_machine_soft_spi_make_new,
279257
.protocol = &mp_machine_soft_spi_p,
280258
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
281259
};

ports/esp32/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
#define MICROPY_PY_MACHINE_SPI (1)
149149
#define MICROPY_PY_MACHINE_SPI_MSB (0)
150150
#define MICROPY_PY_MACHINE_SPI_LSB (1)
151-
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hw_spi_make_new
152151
#define MICROPY_HW_ENABLE_SDCARD (1)
153152
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
154153
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly

ports/esp8266/machine_hspi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const mp_obj_type_t machine_hspi_type = {
178178
{ &mp_type_type },
179179
.name = MP_QSTR_HSPI,
180180
.print = machine_hspi_print,
181-
.make_new = mp_machine_spi_make_new, // delegate to master constructor
181+
.make_new = machine_hspi_make_new,
182182
.protocol = &machine_hspi_p,
183183
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
184184
};

ports/esp8266/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#define MICROPY_PY_MACHINE_PULSE (1)
8181
#define MICROPY_PY_MACHINE_I2C (1)
8282
#define MICROPY_PY_MACHINE_SPI (1)
83-
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hspi_make_new
8483
#define MICROPY_PY_UWEBSOCKET (1)
8584
#define MICROPY_PY_WEBREPL (1)
8685
#define MICROPY_PY_WEBREPL_DELAY (20)

ports/stm32/machine_spi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp
4848
mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
4949
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso };
5050
static const mp_arg_t allowed_args[] = {
51-
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} },
51+
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ },
5252
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 500000} },
5353
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
5454
{ MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
@@ -137,7 +137,7 @@ const mp_obj_type_t machine_hard_spi_type = {
137137
{ &mp_type_type },
138138
.name = MP_QSTR_SPI,
139139
.print = machine_hard_spi_print,
140-
.make_new = mp_machine_spi_make_new, // delegate to master constructor
140+
.make_new = machine_hard_spi_make_new,
141141
.protocol = &machine_hard_spi_p,
142142
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
143143
};

ports/stm32/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
#define MICROPY_PY_MACHINE_SPI (1)
187187
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
188188
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
189-
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hard_spi_make_new
190189
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
191190
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48)
192191
#define MICROPY_PY_UWEBSOCKET (MICROPY_PY_LWIP)

0 commit comments

Comments
 (0)