diff options
| author | Damien George | 2018-02-05 13:51:27 +1100 |
|---|---|---|
| committer | Damien George | 2018-02-05 14:32:56 +1100 |
| commit | 20f5de9b397e9b9dac7070598685f24e8e9636a2 (patch) | |
| tree | d5eb0e1ecc88edfd32c2fb4083ba1f7629a542df | |
| parent | 93d5c9e1c4cb2850dc04abc0fa78e9b4c159747c (diff) | |
stm32/spi: Accept machine.SPI object in spi_from_mp_obj() function.
Also, change ValueError to TypeError if the argument to this function is
not of an SPI type.
| -rw-r--r-- | ports/stm32/spi.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c index bb35a042b..48df9288e 100644 --- a/ports/stm32/spi.c +++ b/ports/stm32/spi.c @@ -561,14 +561,6 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = { {{&pyb_spi_type}, &spi_obj[5]}, }; -const spi_t *spi_from_mp_obj(mp_obj_t o) { - if (!MP_OBJ_IS_TYPE(o, &pyb_spi_type)) { - mp_raise_ValueError("expecting an SPI object"); - } - pyb_spi_obj_t *self = o; - return self->spi; -} - STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_spi_obj_t *self = self_in; spi_print(print, self->spi, true); @@ -985,3 +977,15 @@ const mp_obj_type_t machine_hard_spi_type = { .protocol = &machine_hard_spi_p, .locals_dict = (mp_obj_t)&mp_machine_spi_locals_dict, }; + +const spi_t *spi_from_mp_obj(mp_obj_t o) { + if (MP_OBJ_IS_TYPE(o, &pyb_spi_type)) { + pyb_spi_obj_t *self = o; + return self->spi; + } else if (MP_OBJ_IS_TYPE(o, &machine_hard_spi_type)) { + machine_hard_spi_obj_t *self = o;; + return self->spi; + } else { + mp_raise_TypeError("expecting an SPI object"); + } +} |
