Add reset() to display busses to detect whether it works

crypto-aes
Scott Shawcroft 4 years ago
parent 24b30965c4
commit 3a98de1236
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E

@ -12,6 +12,9 @@ EXTERNAL_FLASH_DEVICE_COUNT = 2
EXTERNAL_FLASH_DEVICES = "W25Q16FW, GD25Q16C"
LONGINT_IMPL = MPZ
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_RTC = 0
CFLAGS_INLINE_LIMIT = 60
SUPEROPT_GC = 0

@ -79,6 +79,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
self->write_group = &PORT->Group[write->number / 32];
self->write_mask = 1 << (write->number % 32);
self->reset.base.type = &mp_type_NoneType;
if (reset != NULL) {
self->reset.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
@ -108,12 +109,16 @@ void common_hal_displayio_parallelbus_deinit(displayio_parallelbus_obj_t* self)
reset_pin_number(self->reset.pin->number);
}
void common_hal_displayio_parallelbus_reset(mp_obj_t obj) {
bool common_hal_displayio_parallelbus_reset(mp_obj_t obj) {
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
if (self->reset.base.type == &mp_type_NoneType) {
return false;
}
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
common_hal_mcu_delay_us(4);
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
return true;
}
bool common_hal_displayio_parallelbus_bus_free(mp_obj_t obj) {

@ -103,6 +103,21 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
return self;
}
//| .. method:: reset()
//|
//| Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
//| is available.
//|
STATIC mp_obj_t displayio_fourwire_obj_reset(mp_obj_t self_in) {
displayio_fourwire_obj_t *self = self_in;
if (!common_hal_displayio_fourwire_reset(self)) {
mp_raise_RuntimeError(translate("no reset pin available"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_reset_obj, displayio_fourwire_obj_reset);
//| .. method:: send(command, data, *, toggle_every_byte=False)
//|
//| Sends the given command value followed by the full set of data. Display state, such as
@ -140,6 +155,7 @@ STATIC mp_obj_t displayio_fourwire_obj_send(size_t n_args, const mp_obj_t *pos_a
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_fourwire_send_obj, 3, displayio_fourwire_obj_send);
STATIC const mp_rom_map_elem_t displayio_fourwire_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&displayio_fourwire_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_fourwire_send_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_fourwire_locals_dict, displayio_fourwire_locals_dict_table);

@ -40,7 +40,7 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self);
void common_hal_displayio_fourwire_reset(mp_obj_t self);
bool common_hal_displayio_fourwire_reset(mp_obj_t self);
bool common_hal_displayio_fourwire_bus_free(mp_obj_t self);
bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t self);

@ -95,6 +95,21 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t
return self;
}
//| .. method:: reset()
//|
//| Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
//| is available.
//|
STATIC mp_obj_t displayio_i2cdisplay_obj_reset(mp_obj_t self_in) {
displayio_i2cdisplay_obj_t *self = self_in;
if (!common_hal_displayio_i2cdisplay_reset(self)) {
mp_raise_RuntimeError(translate("no reset pin available"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_i2cdisplay_reset_obj, displayio_i2cdisplay_obj_reset);
//| .. method:: send(command, data)
//|
//| Sends the given command value followed by the full set of data. Display state, such as
@ -124,6 +139,7 @@ STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_ob
MP_DEFINE_CONST_FUN_OBJ_3(displayio_i2cdisplay_send_obj, displayio_i2cdisplay_obj_send);
STATIC const mp_rom_map_elem_t displayio_i2cdisplay_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&displayio_i2cdisplay_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_i2cdisplay_send_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_i2cdisplay_locals_dict, displayio_i2cdisplay_locals_dict_table);

@ -37,7 +37,7 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self);
void common_hal_displayio_i2cdisplay_reset(mp_obj_t self);
bool common_hal_displayio_i2cdisplay_reset(mp_obj_t self);
bool common_hal_displayio_i2cdisplay_bus_free(mp_obj_t self);
bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t self);

@ -106,6 +106,21 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
return self;
}
//| .. method:: reset()
//|
//| Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
//| is available.
//|
STATIC mp_obj_t displayio_parallelbus_obj_reset(mp_obj_t self_in) {
displayio_parallelbus_obj_t *self = self_in;
if (!common_hal_displayio_parallelbus_reset(self)) {
mp_raise_RuntimeError(translate("no reset pin available"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_parallelbus_reset_obj, displayio_parallelbus_obj_reset);
//| .. method:: send(command, data)
//|
//| Sends the given command value followed by the full set of data. Display state, such as
@ -133,6 +148,7 @@ STATIC mp_obj_t displayio_parallelbus_obj_send(mp_obj_t self, mp_obj_t command_o
MP_DEFINE_CONST_FUN_OBJ_3(displayio_parallelbus_send_obj, displayio_parallelbus_obj_send);
STATIC const mp_rom_map_elem_t displayio_parallelbus_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&displayio_parallelbus_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_parallelbus_send_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_parallelbus_locals_dict, displayio_parallelbus_locals_dict_table);

@ -40,7 +40,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
void common_hal_displayio_parallelbus_deinit(displayio_parallelbus_obj_t* self);
void common_hal_displayio_parallelbus_reset(mp_obj_t self);
bool common_hal_displayio_parallelbus_reset(mp_obj_t self);
bool common_hal_displayio_parallelbus_bus_free(mp_obj_t self);
bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t self);

@ -55,7 +55,9 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select);
common_hal_digitalio_digitalinout_switch_to_output(&self->chip_select, true, DRIVE_MODE_PUSH_PULL);
self->reset.base.type = &mp_type_NoneType;
if (reset != NULL) {
self->reset.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
never_reset_pin_number(reset->number);
@ -76,12 +78,16 @@ void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) {
reset_pin_number(self->reset.pin->number);
}
void common_hal_displayio_fourwire_reset(mp_obj_t obj) {
bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {
displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
if (self->reset.base.type == &mp_type_NoneType) {
return false;
}
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
common_hal_time_delay_ms(1);
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
common_hal_time_delay_ms(1);
return true;
}
bool common_hal_displayio_fourwire_bus_free(mp_obj_t obj) {

@ -55,7 +55,9 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
self->address = device_address;
self->reset.base.type = &mp_type_NoneType;
if (reset != NULL) {
self->reset.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
never_reset_pin_number(reset->number);
@ -71,16 +73,18 @@ void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {
reset_pin_number(self->reset.pin->number);
}
void common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {
bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {
displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
if (self->reset.base.type == &mp_type_NoneType) {
return false;
}
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
common_hal_mcu_delay_us(1);
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
return true;
}
bool common_hal_displayio_i2cdisplay_bus_free(mp_obj_t obj) {
displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
if (!common_hal_busio_i2c_try_lock(self->bus)) {

@ -33,7 +33,7 @@
#define NO_COMMAND 0x100
typedef void (*display_bus_bus_reset)(mp_obj_t bus);
typedef bool (*display_bus_bus_reset)(mp_obj_t bus);
typedef bool (*display_bus_bus_free)(mp_obj_t bus);
typedef bool (*display_bus_begin_transaction)(mp_obj_t bus);
typedef void (*display_bus_send)(mp_obj_t bus, bool command, bool toggle_every_byte, uint8_t *data, uint32_t data_length);

Loading…
Cancel
Save