Improvements thanks to danh's review

This commit is contained in:
Scott Shawcroft 2019-01-18 16:37:06 -08:00
parent ae52c964c2
commit edc8383e22
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
6 changed files with 26 additions and 20 deletions

View File

@ -39,7 +39,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {
uint8_t data_pin = data0->number;
if (data_pin % 8 != 0 || data_pin % 32 >= 24) {
if (data_pin % 8 != 0) {
mp_raise_ValueError(translate("Data 0 pin must be byte aligned"));
}
for (uint8_t i = 0; i < 8; i++) {
@ -49,6 +49,13 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
}
PortGroup *const g = &PORT->Group[data0->number / 32];
g->DIRSET.reg = 0xff << (data_pin % 32);
uint32_t wrconfig = PORT_WRCONFIG_WRPINCFG | PORT_WRCONFIG_DRVSTR;
if (data_pin % 32 > 15) {
wrconfig |= PORT_WRCONFIG_HWSEL | (0xff << ((data_pin % 32) - 16));
} else {
wrconfig |= 0xff << (data_pin % 32);
}
g->WRCONFIG.reg = wrconfig;
self->bus = ((uint8_t*) &g->OUT.reg) + (data0->number % 32 / 8);
self->command.base.type = &digitalio_digitalinout_type;

View File

@ -39,7 +39,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {
uint8_t data_pin = data0->number;
if (data_pin % 8 != 0 || data_pin % 32 >= 24) {
if (data_pin % 8 != 0) {
mp_raise_ValueError(translate("Data 0 pin must be byte aligned"));
}
for (uint8_t i = 0; i < 8; i++) {
@ -57,6 +57,9 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
num_pins_in_port = P1_PIN_NUM;
}
g->DIRSET = 0xff << (data_pin % num_pins_in_port);
for (uint8_t i = 0; i < 8; i++) {
g->PIN_CNF[data_pin + i] |= NRF_GPIO_PIN_S0S1 << GPIO_PIN_CNF_DRIVE_Pos;
}
self->bus = ((uint8_t*) &g->OUT) + (data0->number % num_pins_in_port / 8);
self->command.base.type = &digitalio_digitalinout_type;

View File

@ -90,8 +90,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
{ MP_QSTR_colstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_rowstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ 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
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Display limit reached"));
mp_raise_RuntimeError(translate("Too many displays"));
}
self->base.type = &displayio_display_type;
common_hal_displayio_display_construct(self,

View File

@ -61,8 +61,8 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_spi_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@ -70,9 +70,6 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
mp_obj_t command = args[ARG_command].u_obj;
mp_obj_t chip_select = args[ARG_chip_select].u_obj;
if (command == mp_const_none || chip_select == mp_const_none) {
mp_raise_ValueError(translate("Command and chip_select required"));
}
assert_pin_free(command);
assert_pin_free(chip_select);
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_
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Display bus limit reached"));
mp_raise_RuntimeError(translate("Too many display busses"));
}
common_hal_displayio_fourwire_construct(self,

View File

@ -62,11 +62,11 @@
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) {
enum { ARG_data0, ARG_command, ARG_chip_select, ARG_write, ARG_read, ARG_reset };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_write, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_read, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_write, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_read, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
};
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
mp_obj_t write = args[ARG_write].u_obj;
mp_obj_t read = args[ARG_read].u_obj;
mp_obj_t reset = args[ARG_reset].u_obj;
if (data0 == mp_const_none || command == mp_const_none || chip_select == mp_const_none || write == mp_const_none || read == mp_const_none) {
mp_raise_ValueError(translate("Data0, command, chip_select, write and read required"));
}
assert_pin_free(data0);
assert_pin_free(command);
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
}
}
if (self == NULL) {
mp_raise_RuntimeError(translate("Display bus limit reached"));
mp_raise_RuntimeError(translate("Too many display busses"));
}
common_hal_displayio_parallelbus_construct(self, data0, command, chip_select, write, read, reset);

View File

@ -66,6 +66,8 @@ mp_obj_t board_i2c(void) {
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
#if BOARD_SPI
// Statically allocate the SPI object so it can live past the end of the heap and into the next VM.
// That way it can be used by built-in FourWire displays and be accessible through board.SPI().
STATIC busio_spi_obj_t spi_obj;
STATIC mp_obj_t spi_singleton = NULL;