stm32/mphalport: Add mp_hal_get_spi_obj() helper function.

The function spi_from_mp_obj() is kept since it is used by the cc3k driver.
This commit is contained in:
robert-hh 2022-08-10 11:04:09 +02:00 committed by Damien George
parent c3305c49e4
commit 54eaa8c8a6
2 changed files with 17 additions and 0 deletions

View File

@ -110,6 +110,8 @@ bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, u
void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed);
void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t spi_in);
enum {
MP_HAL_MAC_WLAN0 = 0,
MP_HAL_MAC_WLAN1,

View File

@ -30,6 +30,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "spi.h"
#include "extmod/machine_spi.h"
// Possible DMA configurations for SPI buses:
// SPI1_TX: DMA2_Stream3.CHANNEL_3 or DMA2_Stream5.CHANNEL_3
@ -685,6 +686,20 @@ const spi_t *spi_from_mp_obj(mp_obj_t o) {
}
}
mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t o) {
if (mp_obj_is_type(o, &machine_hard_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"));
}
}
/******************************************************************************/
// Implementation of low-level SPI C protocol