rp2/machine_spi: Add mp_hal_get_spi_obj helper function.

And remove the now-obsolete spi_from_mp_obj() function.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-08-10 00:52:03 +10:00
parent af6d2845fa
commit f72d3cec23
2 changed files with 16 additions and 9 deletions

View File

@ -269,15 +269,6 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
}
}
machine_spi_obj_t *spi_from_mp_obj(mp_obj_t o) {
if (mp_obj_is_type(o, &machine_spi_type)) {
machine_spi_obj_t *self = MP_OBJ_TO_PTR(o);
return self;
} else {
mp_raise_TypeError(MP_ERROR_TEXT("expecting an SPI object"));
}
}
STATIC const mp_machine_spi_p_t machine_spi_p = {
.init = machine_spi_init,
.transfer = machine_spi_transfer,
@ -291,3 +282,17 @@ const mp_obj_type_t machine_spi_type = {
.protocol = &machine_spi_p,
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
};
mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t o) {
if (mp_obj_is_type(o, &machine_spi_type)) {
return MP_OBJ_TO_PTR(o);
}
#if MICROPY_PY_MACHINE_SOFTSPI
else if (mp_obj_is_type(o, &mp_machine_soft_spi_type)) {
return MP_OBJ_TO_PTR(o);
}
#endif
else {
mp_raise_TypeError(MP_ERROR_TEXT("expecting an SPI object"));
}
}

View File

@ -148,6 +148,8 @@ enum mp_hal_pin_interrupt_trigger {
void mp_hal_pin_interrupt(mp_hal_pin_obj_t pin, mp_obj_t handler, mp_uint_t trigger, bool hard);
mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t spi_in);
enum {
MP_HAL_MAC_WLAN0 = 0,
MP_HAL_MAC_BDADDR,