Skip to content

Commit 54e8c63

Browse files
authored
Merge pull request #2730 from tannewt/fix_fourwire_phase_polarity
Add polarity and phase to FourWire.
2 parents eeca3b1 + b043384 commit 54e8c63

File tree

16 files changed

+63
-21
lines changed

16 files changed

+63
-21
lines changed

ports/atmel-samd/boards/hallowing_m0_express/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ void board_init(void) {
7979
&pin_PA28, // Command or data
8080
&pin_PA01, // Chip select
8181
&pin_PA27, // Reset
82-
12000000);
82+
12000000, // Baudrate
83+
0, // Polarity
84+
0); // Phase
8385

8486
displayio_display_obj_t* display = &displays[0].display;
8587
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/hallowing_m4_express/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ void board_init(void) {
5959
&pin_PB31, // TFT_DC Command or data
6060
&pin_PA27, // TFT_CS Chip select
6161
&pin_PB30, // TFT_RST Reset
62-
60000000);
62+
60000000, // Baudrate
63+
0, // Polarity
64+
0); // Phase
6365

6466
displayio_display_obj_t* display = &displays[0].display;
6567
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/monster_m4sk/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void board_init(void) {
6060
&pin_PA07, // TFT_DC Command or data
6161
&pin_PA06, // TFT_CS Chip select
6262
&pin_PA04, // TFT_RST Reset
63-
60000000);
63+
60000000, // Baudrate
64+
0, // Polarity
65+
0); // Phase
6466

6567
displayio_display_obj_t* display = &displays[0].display;
6668
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/openbook_m4/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ void board_init(void) {
6565
&pin_PB05, // EPD_DC Command or data
6666
&pin_PB07, // EPD_CS Chip select
6767
&pin_PA00, // EPD_RST Reset
68-
1000000);
68+
1000000, // Baudrate
69+
0, // Polarity
70+
0); // Phase
6971

7072
displayio_epaperdisplay_obj_t* display = &displays[0].epaper_display;
7173
display->base.type = &displayio_epaperdisplay_type;

ports/atmel-samd/boards/pewpew_m4/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ void board_init(void) {
107107
&pin_PA16, // TFT_DC Command or data
108108
&pin_PA11, // TFT_CS Chip select
109109
&pin_PA17, // TFT_RST Reset
110-
60000000);
110+
60000000, // Baudrate
111+
0, // Polarity
112+
0); // Phase
111113

112114
uint32_t cfg0 = lookupCfg(CFG_DISPLAY_CFG0, 0x000000);
113115
uint32_t offX = (cfg0 >> 8) & 0xff;

ports/atmel-samd/boards/pybadge/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ void board_init(void) {
8282
&pin_PB05, // TFT_DC Command or data
8383
&pin_PB07, // TFT_CS Chip select
8484
&pin_PA00, // TFT_RST Reset
85-
60000000);
85+
60000000, // Baudrate
86+
0, // Polarity
87+
0); // Phase
8688

8789
displayio_display_obj_t* display = &displays[0].display;
8890
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/pybadge_airlift/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void board_init(void) {
6060
&pin_PB05, // TFT_DC Command or data
6161
&pin_PB06, // TFT_CS Chip select
6262
&pin_PB07, // TFT_RST Reset
63-
60000000);
63+
60000000, // Baudrate
64+
0, // Polarity
65+
0); // Phase
6466

6567
displayio_display_obj_t* display = &displays[0].display;
6668
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/pygamer/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ void board_init(void) {
8282
&pin_PB05, // TFT_DC Command or data
8383
&pin_PB12, // TFT_CS Chip select
8484
&pin_PA00, // TFT_RST Reset
85-
60000000);
85+
60000000, // Baudrate
86+
0, // Polarity
87+
0); // Phase
8688

8789
displayio_display_obj_t* display = &displays[0].display;
8890
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/pygamer_advance/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void board_init(void) {
6060
&pin_PA00, // TFT_DC Command or data
6161
&pin_PB15, // TFT_CS Chip select
6262
&pin_PB05, // TFT_RST Reset
63-
60000000);
63+
60000000, // Baudrate
64+
0, // Polarity
65+
0); // Phase
6466

6567
displayio_display_obj_t* display = &displays[0].display;
6668
display->base.type = &displayio_display_type;

ports/atmel-samd/boards/ugame10/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ void board_init(void) {
7979
&pin_PA09, // Command or data
8080
&pin_PA08, // Chip select
8181
NULL, // Reset
82-
24000000);
82+
24000000, // Baudrate
83+
0, // Polarity
84+
0); // Phase
8385

8486
displayio_display_obj_t* display = &displays[0].display;
8587
display->base.type = &displayio_display_type;

ports/nrf/boards/clue_nrf52840_express/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ void board_init(void) {
5959
&pin_P0_13, // TFT_DC Command or data
6060
&pin_P0_12, // TFT_CS Chip select
6161
&pin_P1_03, // TFT_RST Reset
62-
60000000);
62+
60000000, // Baudrate
63+
0, // Polarity
64+
0); // Phase
6365

6466
displayio_display_obj_t* display = &displays[0].display;
6567
display->base.type = &displayio_display_type;

ports/nrf/boards/ohs2020_badge/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ void board_init(void) {
5959
&pin_P0_08, // TFT_DC Command or data
6060
&pin_P0_14, // TFT_CS Chip select
6161
&pin_P0_13, // TFT_RST Reset
62-
60000000);
62+
60000000, // Baudrate
63+
0, // Polarity
64+
0); // Phase
6365

6466
displayio_display_obj_t* display = &displays[0].display;
6567
display->base.type = &displayio_display_type;

ports/stm/boards/meowbit_v121/board.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ uint8_t display_init_sequence[] = {
6161
0x3a, 1, 0x05, // COLMOD - 16bit color
6262
0xe0, 0x10, 0x02, 0x1c, 0x07, 0x12,
6363
0x37, 0x32, 0x29, 0x2d,
64-
0x29, 0x25, 0x2B, 0x39,
64+
0x29, 0x25, 0x2B, 0x39,
6565
0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
6666
0xe1, 0x10, 0x03, 0x1d, 0x07, 0x06,
6767
0x2E, 0x2C, 0x29, 0x2D,
@@ -80,7 +80,9 @@ void board_init(void) {
8080
&pin_PA08, // Command or data
8181
&pin_PB12, // Chip select
8282
&pin_PB10, // Reset
83-
24000000);
83+
24000000, // Baudrate
84+
0, // Polarity
85+
0); // Phase
8486

8587
displayio_display_obj_t* display = &displays[0].display;
8688
display->base.type = &displayio_display_type;

shared-bindings/displayio/FourWire.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
4747
//| It doesn't handle display initialization.
4848
//|
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, phase=0)
5050
//|
5151
//| Create a FourWire object associated with the given pins.
5252
//|
@@ -60,15 +60,20 @@
6060
//| :param microcontroller.Pin chip_select: Chip select pin
6161
//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used
6262
//| :param int baudrate: Maximum baudrate in Hz for the display on the bus
63+
//| :param int polarity: the base state of the clock line (0 or 1)
64+
//| :param int phase: the edge of the clock that data is captured. First (0)
65+
//| or second (1). Rising or falling depends on clock polarity.
6366
//|
6467
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 };
68+
enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset, ARG_baudrate, ARG_polarity, ARG_phase };
6669
static const mp_arg_t allowed_args[] = {
6770
{ MP_QSTR_spi_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
6871
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
6972
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
7073
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
7174
{ MP_QSTR_baudrate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 24000000} },
75+
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
76+
{ MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
7277
};
7378
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
7479
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -91,8 +96,17 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
9196
mp_raise_RuntimeError(translate("Too many display busses"));
9297
}
9398

99+
uint8_t polarity = args[ARG_polarity].u_int;
100+
if (polarity != 0 && polarity != 1) {
101+
mp_raise_ValueError(translate("Invalid polarity"));
102+
}
103+
uint8_t phase = args[ARG_phase].u_int;
104+
if (phase != 0 && phase != 1) {
105+
mp_raise_ValueError(translate("Invalid phase"));
106+
}
107+
94108
common_hal_displayio_fourwire_construct(self,
95-
MP_OBJ_TO_PTR(spi), command, chip_select, reset, args[ARG_baudrate].u_int);
109+
MP_OBJ_TO_PTR(spi), command, chip_select, reset, args[ARG_baudrate].u_int, polarity, phase);
96110
return self;
97111
}
98112

shared-bindings/displayio/FourWire.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ extern const mp_obj_type_t displayio_fourwire_type;
3838

3939
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
4040
busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
41-
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate);
41+
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate,
42+
uint8_t polarity, uint8_t phase);
4243

4344
void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self);
4445

shared-module/displayio/FourWire.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040

4141
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
4242
busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
43-
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate) {
43+
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate,
44+
uint8_t polarity, uint8_t phase) {
4445

4546
self->bus = spi;
4647
common_hal_busio_spi_never_reset(self->bus);
@@ -49,8 +50,8 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
4950
gc_never_free(self->bus);
5051

5152
self->frequency = baudrate;
52-
self->polarity = 0;
53-
self->phase = 0;
53+
self->polarity = polarity;
54+
self->phase = phase;
5455

5556
common_hal_digitalio_digitalinout_construct(&self->command, command);
5657
common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL);

0 commit comments

Comments
 (0)