Skip to content

Commit edc8383

Browse files
committed
Improvements thanks to danh's review
1 parent ae52c96 commit edc8383

6 files changed

Lines changed: 26 additions & 20 deletions

File tree

ports/atmel-samd/common-hal/displayio/ParallelBus.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
3939
const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {
4040

4141
uint8_t data_pin = data0->number;
42-
if (data_pin % 8 != 0 || data_pin % 32 >= 24) {
42+
if (data_pin % 8 != 0) {
4343
mp_raise_ValueError(translate("Data 0 pin must be byte aligned"));
4444
}
4545
for (uint8_t i = 0; i < 8; i++) {
@@ -49,6 +49,13 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
4949
}
5050
PortGroup *const g = &PORT->Group[data0->number / 32];
5151
g->DIRSET.reg = 0xff << (data_pin % 32);
52+
uint32_t wrconfig = PORT_WRCONFIG_WRPINCFG | PORT_WRCONFIG_DRVSTR;
53+
if (data_pin % 32 > 15) {
54+
wrconfig |= PORT_WRCONFIG_HWSEL | (0xff << ((data_pin % 32) - 16));
55+
} else {
56+
wrconfig |= 0xff << (data_pin % 32);
57+
}
58+
g->WRCONFIG.reg = wrconfig;
5259
self->bus = ((uint8_t*) &g->OUT.reg) + (data0->number % 32 / 8);
5360

5461
self->command.base.type = &digitalio_digitalinout_type;

ports/nrf/common-hal/displayio/ParallelBus.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
3939
const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {
4040

4141
uint8_t data_pin = data0->number;
42-
if (data_pin % 8 != 0 || data_pin % 32 >= 24) {
42+
if (data_pin % 8 != 0) {
4343
mp_raise_ValueError(translate("Data 0 pin must be byte aligned"));
4444
}
4545
for (uint8_t i = 0; i < 8; i++) {
@@ -57,6 +57,9 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
5757
num_pins_in_port = P1_PIN_NUM;
5858
}
5959
g->DIRSET = 0xff << (data_pin % num_pins_in_port);
60+
for (uint8_t i = 0; i < 8; i++) {
61+
g->PIN_CNF[data_pin + i] |= NRF_GPIO_PIN_S0S1 << GPIO_PIN_CNF_DRIVE_Pos;
62+
}
6063
self->bus = ((uint8_t*) &g->OUT) + (data0->number % num_pins_in_port / 8);
6164

6265
self->command.base.type = &digitalio_digitalinout_type;

shared-bindings/displayio/Display.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
9090
static const mp_arg_t allowed_args[] = {
9191
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
9292
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
93-
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
94-
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
93+
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
94+
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
9595
{ MP_QSTR_colstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
9696
{ MP_QSTR_rowstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
9797
{ MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} },
@@ -121,7 +121,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
121121
}
122122
}
123123
if (self == NULL) {
124-
mp_raise_RuntimeError(translate("Display limit reached"));
124+
mp_raise_RuntimeError(translate("Too many displays"));
125125
}
126126
self->base.type = &displayio_display_type;
127127
common_hal_displayio_display_construct(self,

shared-bindings/displayio/FourWire.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
6161
enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset };
6262
static const mp_arg_t allowed_args[] = {
6363
{ MP_QSTR_spi_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
64-
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
65-
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
64+
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
65+
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
6666
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
6767
};
6868
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
6969
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7070

7171
mp_obj_t command = args[ARG_command].u_obj;
7272
mp_obj_t chip_select = args[ARG_chip_select].u_obj;
73-
if (command == mp_const_none || chip_select == mp_const_none) {
74-
mp_raise_ValueError(translate("Command and chip_select required"));
75-
}
7673
assert_pin_free(command);
7774
assert_pin_free(chip_select);
7875
mp_obj_t reset = args[ARG_reset].u_obj;
@@ -93,7 +90,7 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
9390
}
9491
}
9592
if (self == NULL) {
96-
mp_raise_RuntimeError(translate("Display bus limit reached"));
93+
mp_raise_RuntimeError(translate("Too many display busses"));
9794
}
9895

9996
common_hal_displayio_fourwire_construct(self,

shared-bindings/displayio/ParallelBus.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262
STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6363
enum { ARG_data0, ARG_command, ARG_chip_select, ARG_write, ARG_read, ARG_reset };
6464
static const mp_arg_t allowed_args[] = {
65-
{ MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
66-
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
67-
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
68-
{ MP_QSTR_write, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
69-
{ MP_QSTR_read, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
65+
{ MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
66+
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
67+
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
68+
{ MP_QSTR_write, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
69+
{ MP_QSTR_read, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
7070
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
7171
};
7272
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -78,9 +78,6 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
7878
mp_obj_t write = args[ARG_write].u_obj;
7979
mp_obj_t read = args[ARG_read].u_obj;
8080
mp_obj_t reset = args[ARG_reset].u_obj;
81-
if (data0 == mp_const_none || command == mp_const_none || chip_select == mp_const_none || write == mp_const_none || read == mp_const_none) {
82-
mp_raise_ValueError(translate("Data0, command, chip_select, write and read required"));
83-
}
8481
assert_pin_free(data0);
8582
assert_pin_free(command);
8683
assert_pin_free(chip_select);
@@ -98,7 +95,7 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
9895
}
9996
}
10097
if (self == NULL) {
101-
mp_raise_RuntimeError(translate("Display bus limit reached"));
98+
mp_raise_RuntimeError(translate("Too many display busses"));
10299
}
103100

104101
common_hal_displayio_parallelbus_construct(self, data0, command, chip_select, write, read, reset);

supervisor/shared/board_busses.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ mp_obj_t board_i2c(void) {
6666
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
6767

6868
#if BOARD_SPI
69+
// Statically allocate the SPI object so it can live past the end of the heap and into the next VM.
70+
// That way it can be used by built-in FourWire displays and be accessible through board.SPI().
6971
STATIC busio_spi_obj_t spi_obj;
7072
STATIC mp_obj_t spi_singleton = NULL;
7173

0 commit comments

Comments
 (0)