46
46
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
47
47
//| It doesn't handle display initialization.
48
48
//|
49
- //| .. class:: FourWire(spi_bus, *, command, chip_select, reset=None, baudrate=24000000)
49
+ //| .. class:: FourWire(spi_bus, *, command, chip_select, reset=None, baudrate=24000000, polarity=0,
50
+ //| phase=0)
50
51
//|
51
52
//| Create a FourWire object associated with the given pins.
52
53
//|
60
61
//| :param microcontroller.Pin chip_select: Chip select pin
61
62
//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used
62
63
//| :param int baudrate: Maximum baudrate in Hz for the display on the bus
64
+ //| :param int polarity: the base state of the clock line (0 or 1)
65
+ //| :param int phase: the edge of the clock that data is captured. First (0)
66
+ //| or second (1). Rising or falling depends on clock polarity.
63
67
//|
64
68
STATIC mp_obj_t displayio_fourwire_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
65
- enum { ARG_spi_bus , ARG_command , ARG_chip_select , ARG_reset , ARG_baudrate };
69
+ enum { ARG_spi_bus , ARG_command , ARG_chip_select , ARG_reset , ARG_baudrate , ARG_polarity , ARG_phase };
66
70
static const mp_arg_t allowed_args [] = {
67
71
{ MP_QSTR_spi_bus , MP_ARG_REQUIRED | MP_ARG_OBJ },
68
72
{ MP_QSTR_command , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
69
73
{ MP_QSTR_chip_select , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
70
74
{ MP_QSTR_reset , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
71
75
{ MP_QSTR_baudrate , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 24000000 } },
76
+ { MP_QSTR_polarity , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
77
+ { MP_QSTR_phase , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
72
78
};
73
79
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
74
80
mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -91,8 +97,17 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
91
97
mp_raise_RuntimeError (translate ("Too many display busses" ));
92
98
}
93
99
100
+ uint8_t polarity = args [ARG_polarity ].u_int ;
101
+ if (polarity != 0 && polarity != 1 ) {
102
+ mp_raise_ValueError (translate ("Invalid polarity" ));
103
+ }
104
+ uint8_t phase = args [ARG_phase ].u_int ;
105
+ if (phase != 0 && phase != 1 ) {
106
+ mp_raise_ValueError (translate ("Invalid phase" ));
107
+ }
108
+
94
109
common_hal_displayio_fourwire_construct (self ,
95
- MP_OBJ_TO_PTR (spi ), command , chip_select , reset , args [ARG_baudrate ].u_int );
110
+ MP_OBJ_TO_PTR (spi ), command , chip_select , reset , args [ARG_baudrate ].u_int , polarity , phase );
96
111
return self ;
97
112
}
98
113
0 commit comments