Merge remote-tracking branch 'adafruit/master' into fix_cpx_display

crypto-aes
Scott Shawcroft 4 years ago
commit de48e4b262
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59

@ -26,9 +26,11 @@
#include "boards/board.h"
#include "shared-bindings/board/__init__.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/busio/SPI.h"
#include "tick.h"
@ -71,8 +73,10 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
bus->base.type = &displayio_fourwire_type;
busio_spi_obj_t *spi = common_hal_board_create_spi();
common_hal_busio_spi_configure(spi, 12000000, 0, 0, 8);
common_hal_displayio_fourwire_construct(bus,
common_hal_board_create_spi(),
spi,
&pin_PA28, // Command or data
&pin_PA01, // Chip select
&pin_PA27); // Reset

@ -361,3 +361,13 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uin
uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) {
return samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt));
}
uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) {
void * hw = self->spi_desc.dev.prvt;
return hri_sercomspi_get_CTRLA_CPHA_bit(hw);
}
uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) {
void * hw = self->spi_desc.dev.prvt;
return hri_sercomspi_get_CTRLA_CPOL_bit(hw);
}

@ -327,3 +327,11 @@ uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) {
return 0;
}
}
uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) {
return 0;
}
uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) {
return 0;
}

@ -61,6 +61,12 @@ extern bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_o
// Return actual SPI bus frequency.
uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self);
// Return SPI bus phase.
uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self);
// Return SPI bus polarity.
uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self);
// This is used by the supervisor to claim SPI devices indefinitely.
extern void common_hal_busio_spi_never_reset(busio_spi_obj_t *self);

@ -295,6 +295,25 @@ const mp_obj_property_t displayio_display_height_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: bus
//|
//| The bus being used by the display
//|
//|
STATIC mp_obj_t displayio_display_obj_get_bus(mp_obj_t self_in) {
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
return self->bus;
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_bus_obj, displayio_display_obj_get_bus);
const mp_obj_property_t displayio_display_bus_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_display_get_bus_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_display_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_display_refresh_soon_obj) },
@ -305,6 +324,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table);

@ -41,8 +41,14 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
self->bus = spi;
common_hal_busio_spi_never_reset(self->bus);
// Our object is statically allocated off the heap so make sure the bus object lives to the end
// of the heap as well.
gc_never_free(self->bus);
self->frequency = common_hal_busio_spi_get_frequency(spi);
self->polarity = common_hal_busio_spi_get_polarity(spi);
self->phase = common_hal_busio_spi_get_phase(spi);
common_hal_digitalio_digitalinout_construct(&self->command, command);
common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL);
common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select);
@ -73,8 +79,8 @@ bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) {
if (!common_hal_busio_spi_try_lock(self->bus)) {
return false;
}
// TODO(tannewt): Stop hardcoding SPI frequency, polarity and phase.
common_hal_busio_spi_configure(self->bus, 12000000, 0, 0, 8);
common_hal_busio_spi_configure(self->bus, self->frequency, self->polarity,
self->phase, 8);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, false);
return true;
}

@ -38,6 +38,9 @@ typedef struct {
digitalio_digitalinout_obj_t command;
digitalio_digitalinout_obj_t chip_select;
digitalio_digitalinout_obj_t reset;
uint32_t frequency;
uint8_t polarity;
uint8_t phase;
} displayio_fourwire_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H

Loading…
Cancel
Save