diff options
| author | Damien George <damien@micropython.org> | 2022-08-10 00:52:03 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-08-10 14:05:02 +1000 |
| commit | f72d3cec2338e88b9aa6e28d345f0007042d692b (patch) | |
| tree | 177d767655ce109ed79a902b3b489f18edbc513f | |
| parent | af6d2845fad4fde2d36f220efce876a4b1facdaa (diff) | |
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>
| -rw-r--r-- | ports/rp2/machine_spi.c | 23 | ||||
| -rw-r--r-- | ports/rp2/mphalport.h | 2 |
2 files changed, 16 insertions, 9 deletions
diff --git a/ports/rp2/machine_spi.c b/ports/rp2/machine_spi.c index 742a3cfdd..42998664a 100644 --- a/ports/rp2/machine_spi.c +++ b/ports/rp2/machine_spi.c @@ -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")); + } +} diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index 88683d936..31bedf338 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -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, |
