Correctly handle no backlight pin.

This commit is contained in:
Scott Shawcroft 2019-01-31 11:00:12 -08:00
parent 2c069a5685
commit 354a26963b
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
2 changed files with 10 additions and 3 deletions

View File

@ -109,8 +109,13 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_init_sequence].u_obj, &bufinfo, MP_BUFFER_READ);
mp_obj_t backlight_pin = args[ARG_backlight_pin].u_obj;
mp_obj_t backlight_pin_obj = args[ARG_backlight_pin].u_obj;
assert_pin(backlight_pin_obj, true);
const mcu_pin_obj_t* backlight_pin = NULL;
if (backlight_pin_obj != NULL && backlight_pin_obj != mp_const_none) {
backlight_pin = MP_OBJ_TO_PTR(backlight_pin_obj);
assert_pin_free(backlight_pin);
}
displayio_display_obj_t *self = NULL;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
@ -127,7 +132,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
common_hal_displayio_display_construct(self,
display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int,
args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int,
args[ARG_write_ram_command].u_int, bufinfo.buf, bufinfo.len, backlight_pin);
args[ARG_write_ram_command].u_int, bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin));
return self;
}

View File

@ -100,6 +100,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->refresh = true;
self->current_group = &circuitpython_splash;
// Always set the backlight type in case we're reusing memory.
self->backlight_inout.base.type = &mp_type_NoneType;
if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) {
pwmout_result_t result = common_hal_pulseio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 5000, false);
if (result != PWMOUT_OK) {