Skip to content

Commit c29ed7d

Browse files
committed
PimoroniBus: Support machine.Pin.
1 parent bc241e7 commit c29ed7d

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

micropython/modules/pimoroni_bus/pimoroni_bus.cpp

+26-25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using namespace pimoroni;
77
extern "C" {
88
#include "pimoroni_bus.h"
99
#include "py/mperrno.h"
10+
#include "machine_pin.h"
1011

1112

1213
void PimoroniBus_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@@ -37,12 +38,12 @@ void PimoroniBus_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
3738
mp_obj_t SPIPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
3839
enum { ARG_cs, ARG_dc, ARG_sck, ARG_mosi, ARG_miso, ARG_bl };
3940
static const mp_arg_t allowed_args[] = {
40-
{ MP_QSTR_cs, MP_ARG_INT, {.u_int = SPI_BG_FRONT_CS} },
41-
{ MP_QSTR_dc, MP_ARG_INT, {.u_int = SPI_DEFAULT_MISO} },
42-
{ MP_QSTR_sck, MP_ARG_INT, {.u_int = SPI_DEFAULT_SCK} },
43-
{ MP_QSTR_mosi, MP_ARG_INT, {.u_int = SPI_DEFAULT_MOSI} },
44-
{ MP_QSTR_miso, MP_ARG_INT, {.u_int = PIN_UNUSED} },
45-
{ MP_QSTR_bl, MP_ARG_INT, {.u_int = PIN_UNUSED} },
41+
{ MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_BG_FRONT_CS)} },
42+
{ MP_QSTR_dc, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_DEFAULT_MISO)} },
43+
{ MP_QSTR_sck, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_DEFAULT_SCK)} },
44+
{ MP_QSTR_mosi, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_DEFAULT_MOSI)} },
45+
{ MP_QSTR_miso, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(PIN_UNUSED)} },
46+
{ MP_QSTR_bl, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(PIN_UNUSED)} },
4647
};
4748

4849
// Parse args.
@@ -51,13 +52,13 @@ mp_obj_t SPIPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
5152

5253
_PimoroniBus_obj_t *self = mp_obj_malloc(_PimoroniBus_obj_t, &SPIPins_type);
5354
self->pins = new(m_new(SPIPins, 1)) SPIPins{
54-
((args[ARG_sck].u_int >> 3) & 0b1) == 0 ? spi0 : spi1,
55-
(uint)args[ARG_cs].u_int,
56-
(uint)args[ARG_sck].u_int,
57-
(uint)args[ARG_mosi].u_int,
58-
(uint)args[ARG_miso].u_int,
59-
(uint)args[ARG_dc].u_int,
60-
(uint)args[ARG_bl].u_int
55+
((mp_hal_get_pin_obj(args[ARG_sck].u_obj) >> 3) & 0b1) == 0 ? spi0 : spi1,
56+
mp_hal_get_pin_obj(args[ARG_cs].u_obj),
57+
mp_hal_get_pin_obj(args[ARG_sck].u_obj),
58+
mp_hal_get_pin_obj(args[ARG_mosi].u_obj),
59+
mp_hal_get_pin_obj(args[ARG_miso].u_obj),
60+
mp_hal_get_pin_obj(args[ARG_dc].u_obj),
61+
mp_hal_get_pin_obj(args[ARG_bl].u_obj)
6162
};
6263

6364
return MP_OBJ_FROM_PTR(self);
@@ -80,12 +81,12 @@ mp_obj_t SPISlot(mp_obj_t slot_in) {
8081
mp_obj_t ParallelPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
8182
enum { ARG_cs, ARG_dc, ARG_wr_sck, ARG_rd_sck, ARG_d0, ARG_bl };
8283
static const mp_arg_t allowed_args[] = {
83-
{ MP_QSTR_cs, MP_ARG_INT, {.u_int = 10} },
84-
{ MP_QSTR_dc, MP_ARG_INT, {.u_int = 11} },
85-
{ MP_QSTR_wr_sck, MP_ARG_INT, {.u_int = 12} },
86-
{ MP_QSTR_rd_sck, MP_ARG_INT, {.u_int = 13} },
87-
{ MP_QSTR_d0, MP_ARG_INT, {.u_int = 14} },
88-
{ MP_QSTR_bl, MP_ARG_INT, {.u_int = 2} },
84+
{ MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(10)} },
85+
{ MP_QSTR_dc, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(11)} },
86+
{ MP_QSTR_wr_sck, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(12)} },
87+
{ MP_QSTR_rd_sck, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(13)} },
88+
{ MP_QSTR_d0, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(14)} },
89+
{ MP_QSTR_bl, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(2)} },
8990
};
9091

9192
// Parse args.
@@ -94,12 +95,12 @@ mp_obj_t ParallelPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t
9495

9596
_PimoroniBus_obj_t *self = mp_obj_malloc(_PimoroniBus_obj_t, &ParallelPins_type);
9697
self->pins = new(m_new(ParallelPins, 1)) ParallelPins{
97-
(uint)args[ARG_cs].u_int,
98-
(uint)args[ARG_dc].u_int,
99-
(uint)args[ARG_wr_sck].u_int,
100-
(uint)args[ARG_rd_sck].u_int,
101-
(uint)args[ARG_d0].u_int,
102-
args[ARG_bl].u_int == -1 ? PIN_UNUSED : (uint)args[ARG_bl].u_int
98+
mp_hal_get_pin_obj(args[ARG_cs].u_obj),
99+
mp_hal_get_pin_obj(args[ARG_dc].u_obj),
100+
mp_hal_get_pin_obj(args[ARG_wr_sck].u_obj),
101+
mp_hal_get_pin_obj(args[ARG_rd_sck].u_obj),
102+
mp_hal_get_pin_obj(args[ARG_d0].u_obj),
103+
args[ARG_bl].u_obj == mp_const_none ? PIN_UNUSED : mp_hal_get_pin_obj(args[ARG_bl].u_obj)
103104
};
104105

105106
return MP_OBJ_FROM_PTR(self);

0 commit comments

Comments
 (0)