Skip to content

Commit 6797ec6

Browse files
committed
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 adafruit#1828. Fixes adafruit#1956
1 parent a98bfa6 commit 6797ec6

43 files changed

Lines changed: 855 additions & 198 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ports/atmel-samd/boards/hallowing_m0_express/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ void board_init(void) {
9191
1, // row start
9292
0, // rotation
9393
16, // Color depth
94+
false, // Grayscale
95+
false, // Pixels in a byte share a row. Only used for depth < 8
9496
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
9597
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
9698
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
9799
0x37, // set vertical scroll command
98100
display_init_sequence,
99101
sizeof(display_init_sequence),
100102
&pin_PA00,
103+
0x100, // Brightness command. Only available when <= 0xff
101104
1.0f, // brightness (ignored)
102105
true, // auto_brightness
103106
false, // single_byte_bounds

ports/atmel-samd/boards/pybadge/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ void board_init(void) {
9393
0, // row start
9494
270, // rotation
9595
16, // Color depth
96+
false, // grayscale
97+
false, // pixels in byte share row. only used for depth < 8
9698
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
9799
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
98100
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
99101
0x37, // set vertical scroll command
100102
display_init_sequence,
101103
sizeof(display_init_sequence),
102104
&pin_PA01, // backlight pin
105+
0x100, // no brightness command
103106
1.0f, // brightness (ignored)
104107
true, // auto_brightness
105108
false, // single_byte_bounds

ports/atmel-samd/boards/pybadge_airlift/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ void board_init(void) {
7171
0, // row start
7272
90, // rotation
7373
16, // Color depth
74+
false, // grayscale
75+
false, // pixels in byte share row. Only used for depth < 8
7476
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
7577
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
7678
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
7779
0x37, // set vertical scroll command
7880
display_init_sequence,
7981
sizeof(display_init_sequence),
8082
&pin_PA01, // backlight pin
83+
0x100, // brightness command, only valid <= 0xff
8184
1.0f, // brightness (ignored)
8285
true, // auto_brightness
8386
false, // single_byte_bounds

ports/atmel-samd/boards/pygamer/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ void board_init(void) {
9393
0, // row start
9494
270, // rotation
9595
16, // Color depth
96+
false, // Grayscale
97+
false, // pixels in a byte share a row. Only valid for depths < 8
9698
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
9799
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
98100
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
99101
0x37, // set vertical scroll command
100102
display_init_sequence,
101103
sizeof(display_init_sequence),
102104
&pin_PA01, // backlight pin
105+
0x100, // Brightness command. Only available when < 0xff
103106
1.0f, // brightness (ignored)
104107
true, // auto_brightness
105108
false, // single_byte_bounds

ports/atmel-samd/boards/pygamer_advance/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ void board_init(void) {
7171
0, // row start
7272
90, // rotation
7373
16, // Color depth
74+
false, // Grayscale
75+
false, // pixels in a byte share a row. Only valid for depths < 8
7476
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
7577
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
7678
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
7779
0x37, // set vertical scroll command
7880
display_init_sequence,
7981
sizeof(display_init_sequence),
8082
&pin_PA01, // backlight pin
83+
0x100, // Brightness command. Only available when < 0xff
8184
1.0f, // brightness (ignored)
8285
true, // auto_brightness
8386
false, // single_byte_bounds

ports/atmel-samd/boards/pyportal/board.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ void board_init(void) {
8383
0, // row start
8484
0, // rotation
8585
16, // Color depth
86+
false, // grayscale
87+
false, // pixels_in_byte_share_row (unused for depths > 8)
8688
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
8789
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
8890
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
8991
0x37, // Set vertical scroll command
9092
display_init_sequence,
9193
sizeof(display_init_sequence),
92-
&pin_PB31,
94+
&pin_PB31, // Backlight pin
95+
0x100, // Brightness command > 0xff is none s
9396
1.0f, // brightness (ignored)
9497
true, // auto_brightness
9598
false, // single_byte_bounds

ports/atmel-samd/boards/ugame10/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ void board_init(void) {
9191
2, // row start
9292
0, // rotation
9393
16, // Color depth
94+
false, // grayscale
95+
false, // pixels in byte share row. Only used with depth < 8
9496
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
9597
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
9698
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
9799
0x37, // set vertical scroll command
98100
display_init_sequence,
99101
sizeof(display_init_sequence),
100102
NULL,
103+
0x100, // brightness command. Only valid <=0xff
101104
1.0f, // brightness
102105
false, // auto_brightness
103106
false, // single_byte_bounds

ports/atmel-samd/common-hal/busio/I2C.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "shared-bindings/microcontroller/__init__.h"
3737
#include "supervisor/shared/translate.h"
3838

39+
#include "common-hal/busio/SPI.h" // for never_reset_sercom
40+
3941
// Number of times to try to send packet if failed.
4042
#define ATTEMPTS 2
4143

@@ -225,3 +227,10 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
225227
}
226228
return MP_EIO;
227229
}
230+
231+
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
232+
never_reset_sercom(self->i2c_desc.device.hw);
233+
234+
never_reset_pin_number(self->scl_pin);
235+
never_reset_pin_number(self->sda_pin);
236+
}

ports/atmel-samd/common-hal/busio/SPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct {
4343
} busio_spi_obj_t;
4444

4545
void reset_sercoms(void);
46+
void never_reset_sercom(Sercom* sercom);
4647

4748

4849
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H

ports/atmel-samd/common-hal/displayio/ParallelBus.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "common-hal/microcontroller/Pin.h"
3232
#include "py/runtime.h"
3333
#include "shared-bindings/digitalio/DigitalInOut.h"
34+
#include "shared-bindings/microcontroller/__init__.h"
3435

3536
#include "tick.h"
3637

@@ -66,10 +67,6 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
6667
common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select);
6768
common_hal_digitalio_digitalinout_switch_to_output(&self->chip_select, true, DRIVE_MODE_PUSH_PULL);
6869

69-
self->reset.base.type = &digitalio_digitalinout_type;
70-
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
71-
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
72-
7370
self->write.base.type = &digitalio_digitalinout_type;
7471
common_hal_digitalio_digitalinout_construct(&self->write, write);
7572
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
8279
self->write_group = &PORT->Group[write->number / 32];
8380
self->write_mask = 1 << (write->number % 32);
8481

82+
if (reset != NULL) {
83+
self->reset.base.type = &digitalio_digitalinout_type;
84+
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
85+
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
86+
never_reset_pin_number(reset->number);
87+
88+
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
89+
common_hal_mcu_delay_us(4);
90+
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
91+
}
92+
8593
never_reset_pin_number(command->number);
8694
never_reset_pin_number(chip_select->number);
8795
never_reset_pin_number(write->number);
8896
never_reset_pin_number(read->number);
89-
never_reset_pin_number(reset->number);
9097
for (uint8_t i = 0; i < 8; i++) {
9198
never_reset_pin_number(data_pin + i);
9299
}

0 commit comments

Comments
 (0)