diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-07-05 19:01:54 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-07-19 16:06:11 -0700 |
| commit | 6797ec6ed396f65916fe816f8b2b49114253dd86 (patch) | |
| tree | 31f26206469b803be6d1ef3d5d5b61c27e2fff0b /ports | |
| parent | a98bfa628e9f4469bbad5bafb042d7a2c3c15346 (diff) | |
Add support for grayscale displays that are < 8 bit depth.
This also improves Palette so it stores the original RGB888 colors.
Lastly, it adds I2CDisplay as a display bus to talk over I2C. Particularly
useful for the SSD1306.
Fixes #1828. Fixes #1956
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/atmel-samd/boards/hallowing_m0_express/board.c | 3 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/pybadge/board.c | 3 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/pybadge_airlift/board.c | 3 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/pygamer/board.c | 3 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/pygamer_advance/board.c | 3 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/pyportal/board.c | 5 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/ugame10/board.c | 3 | ||||
| -rw-r--r-- | ports/atmel-samd/common-hal/busio/I2C.c | 9 | ||||
| -rw-r--r-- | ports/atmel-samd/common-hal/busio/SPI.h | 1 | ||||
| -rw-r--r-- | ports/atmel-samd/common-hal/displayio/ParallelBus.c | 17 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/I2C.c | 17 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/SPI.c | 2 |
12 files changed, 62 insertions, 7 deletions
diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index a0e160757..1bbbfbaf8 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -91,6 +91,8 @@ void board_init(void) { 1, // row start 0, // rotation 16, // Color depth + false, // Grayscale + false, // Pixels in a byte share a row. Only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -98,6 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, + 0x100, // Brightness command. Only available when <= 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 38902315a..7e6c11dd4 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -93,6 +93,8 @@ void board_init(void) { 0, // row start 270, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -100,6 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // no brightness command 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index a1f778df1..d7f291d7d 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -71,6 +71,8 @@ void board_init(void) { 0, // row start 90, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. Only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -78,6 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // brightness command, only valid <= 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 7b54b6fb5..e59b7c458 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -93,6 +93,8 @@ void board_init(void) { 0, // row start 270, // rotation 16, // Color depth + false, // Grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -100,6 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // Brightness command. Only available when < 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index d1c5edc99..b23353998 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -71,6 +71,8 @@ void board_init(void) { 0, // row start 90, // rotation 16, // Color depth + false, // Grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -78,6 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // Brightness command. Only available when < 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index bb80c5b48..7fffb764f 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -83,13 +83,16 @@ void board_init(void) { 0, // row start 0, // rotation 16, // Color depth + false, // grayscale + false, // pixels_in_byte_share_row (unused for depths > 8) MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command 0x37, // Set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - &pin_PB31, + &pin_PB31, // Backlight pin + 0x100, // Brightness command > 0xff is none s 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 828f0c87d..27a03ad91 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -91,6 +91,8 @@ void board_init(void) { 2, // row start 0, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. Only used with depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -98,6 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), NULL, + 0x100, // brightness command. Only valid <=0xff 1.0f, // brightness false, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index a0c04d65d..cdc616bbc 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -36,6 +36,8 @@ #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/shared/translate.h" +#include "common-hal/busio/SPI.h" // for never_reset_sercom + // Number of times to try to send packet if failed. #define ATTEMPTS 2 @@ -225,3 +227,10 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, } return MP_EIO; } + +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + never_reset_sercom(self->i2c_desc.device.hw); + + never_reset_pin_number(self->scl_pin); + never_reset_pin_number(self->sda_pin); +} diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 56d163a9d..a1c0e1517 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -43,6 +43,7 @@ typedef struct { } busio_spi_obj_t; void reset_sercoms(void); +void never_reset_sercom(Sercom* sercom); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/atmel-samd/common-hal/displayio/ParallelBus.c b/ports/atmel-samd/common-hal/displayio/ParallelBus.c index 7a5f61448..c370f7e52 100644 --- a/ports/atmel-samd/common-hal/displayio/ParallelBus.c +++ b/ports/atmel-samd/common-hal/displayio/ParallelBus.c @@ -31,6 +31,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/runtime.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/__init__.h" #include "tick.h" @@ -66,10 +67,6 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel 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 = &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); - self->write.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->write, write); common_hal_digitalio_digitalinout_switch_to_output(&self->write, true, DRIVE_MODE_PUSH_PULL); @@ -82,11 +79,21 @@ 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); + 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); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(4); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + } + never_reset_pin_number(command->number); never_reset_pin_number(chip_select->number); never_reset_pin_number(write->number); never_reset_pin_number(read->number); - never_reset_pin_number(reset->number); for (uint8_t i = 0; i < 8; i++) { never_reset_pin_number(data_pin + i); } diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 538c87f2d..71835d16a 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -57,13 +57,30 @@ STATIC twim_peripheral_t twim_peripherals[] = { #endif }; +STATIC bool never_reset[MP_ARRAY_SIZE(twim_peripherals)]; + void i2c_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + if (never_reset[i]) { + continue; + } nrf_twim_disable(twim_peripherals[i].twim.p_twim); twim_peripherals[i].in_use = false; } } +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + if (self->twim_peripheral == &twim_peripherals[i]) { + never_reset[i] = true; + + never_reset_pin_number(self->scl_pin_number); + never_reset_pin_number(self->sda_pin_number); + break; + } + } +} + static uint8_t twi_error_to_mp(const nrfx_err_t err) { switch (err) { case NRFX_ERROR_DRV_TWI_ERR_ANACK: diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 6ab6d9493..5f1aac193 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -61,7 +61,7 @@ STATIC spim_peripheral_t spim_peripherals[] = { #endif }; -STATIC bool never_reset[4]; +STATIC bool never_reset[MP_ARRAY_SIZE(spim_peripherals)]; void spi_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(spim_peripherals); i++) { |
