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 <damien@micropython.org>
This commit is contained in:
parent
aaed33896b
commit
9e0533b9e1
@ -41,28 +41,6 @@
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
// MicroPython bindings for generic machine.SPI
|
// MicroPython bindings for generic machine.SPI
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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) {
|
|
||||||
// check the id argument, if given
|
|
||||||
if (n_args > 0) {
|
|
||||||
if (args[0] != MP_OBJ_NEW_SMALL_INT(-1)) {
|
|
||||||
#if defined(MICROPY_PY_MACHINE_SPI_MAKE_NEW)
|
|
||||||
// dispatch to port-specific constructor
|
|
||||||
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);
|
|
||||||
return MICROPY_PY_MACHINE_SPI_MAKE_NEW(type, n_args, n_kw, args);
|
|
||||||
#else
|
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid SPI peripheral"));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
--n_args;
|
|
||||||
++args;
|
|
||||||
}
|
|
||||||
|
|
||||||
// software SPI
|
|
||||||
return mp_machine_soft_spi_make_new(type, n_args, n_kw, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
|
||||||
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)s->type->protocol;
|
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 = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_SoftSPI,
|
.name = MP_QSTR_SoftSPI,
|
||||||
.print = mp_machine_soft_spi_print,
|
.print = mp_machine_soft_spi_print,
|
||||||
.make_new = mp_machine_spi_make_new, // delegate to master constructor
|
.make_new = mp_machine_soft_spi_make_new,
|
||||||
.protocol = &mp_machine_soft_spi_p,
|
.protocol = &mp_machine_soft_spi_p,
|
||||||
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
||||||
};
|
};
|
||||||
|
@ -148,7 +148,6 @@
|
|||||||
#define MICROPY_PY_MACHINE_SPI (1)
|
#define MICROPY_PY_MACHINE_SPI (1)
|
||||||
#define MICROPY_PY_MACHINE_SPI_MSB (0)
|
#define MICROPY_PY_MACHINE_SPI_MSB (0)
|
||||||
#define MICROPY_PY_MACHINE_SPI_LSB (1)
|
#define MICROPY_PY_MACHINE_SPI_LSB (1)
|
||||||
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hw_spi_make_new
|
|
||||||
#define MICROPY_HW_ENABLE_SDCARD (1)
|
#define MICROPY_HW_ENABLE_SDCARD (1)
|
||||||
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
|
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
|
||||||
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly
|
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly
|
||||||
|
@ -178,7 +178,7 @@ const mp_obj_type_t machine_hspi_type = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_HSPI,
|
.name = MP_QSTR_HSPI,
|
||||||
.print = machine_hspi_print,
|
.print = machine_hspi_print,
|
||||||
.make_new = mp_machine_spi_make_new, // delegate to master constructor
|
.make_new = machine_hspi_make_new,
|
||||||
.protocol = &machine_hspi_p,
|
.protocol = &machine_hspi_p,
|
||||||
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
||||||
};
|
};
|
||||||
|
@ -80,7 +80,6 @@
|
|||||||
#define MICROPY_PY_MACHINE_PULSE (1)
|
#define MICROPY_PY_MACHINE_PULSE (1)
|
||||||
#define MICROPY_PY_MACHINE_I2C (1)
|
#define MICROPY_PY_MACHINE_I2C (1)
|
||||||
#define MICROPY_PY_MACHINE_SPI (1)
|
#define MICROPY_PY_MACHINE_SPI (1)
|
||||||
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hspi_make_new
|
|
||||||
#define MICROPY_PY_UWEBSOCKET (1)
|
#define MICROPY_PY_UWEBSOCKET (1)
|
||||||
#define MICROPY_PY_WEBREPL (1)
|
#define MICROPY_PY_WEBREPL (1)
|
||||||
#define MICROPY_PY_WEBREPL_DELAY (20)
|
#define MICROPY_PY_WEBREPL_DELAY (20)
|
||||||
|
@ -48,7 +48,7 @@ STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp
|
|||||||
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) {
|
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) {
|
||||||
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso };
|
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} },
|
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 500000} },
|
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 500000} },
|
||||||
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||||
{ MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
{ 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 = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_SPI,
|
.name = MP_QSTR_SPI,
|
||||||
.print = machine_hard_spi_print,
|
.print = machine_hard_spi_print,
|
||||||
.make_new = mp_machine_spi_make_new, // delegate to master constructor
|
.make_new = machine_hard_spi_make_new,
|
||||||
.protocol = &machine_hard_spi_p,
|
.protocol = &machine_hard_spi_p,
|
||||||
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
|
||||||
};
|
};
|
||||||
|
@ -186,7 +186,6 @@
|
|||||||
#define MICROPY_PY_MACHINE_SPI (1)
|
#define MICROPY_PY_MACHINE_SPI (1)
|
||||||
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
|
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
|
||||||
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
|
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
|
||||||
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hard_spi_make_new
|
|
||||||
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
|
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
|
||||||
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48)
|
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48)
|
||||||
#define MICROPY_PY_UWEBSOCKET (MICROPY_PY_LWIP)
|
#define MICROPY_PY_UWEBSOCKET (MICROPY_PY_LWIP)
|
||||||
|
Loading…
Reference in New Issue
Block a user