From 01195c2089ec189c30d875180f9def03e8862b57 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 6 Jun 2021 15:55:33 -0400 Subject: [PATCH 1/6] update to rev B --- .../adafruit_macropad_rp2040/mpconfigboard.h | 10 ++++++--- .../boards/adafruit_macropad_rp2040/pins.c | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_macropad_rp2040/mpconfigboard.h index 5900003713..00a97d088d 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/mpconfigboard.h +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/mpconfigboard.h @@ -1,7 +1,11 @@ #define MICROPY_HW_BOARD_NAME "Adafruit Macropad RP2040" #define MICROPY_HW_MCU_NAME "rp2040" -#define MICROPY_HW_NEOPIXEL (&pin_GPIO16) +#define MICROPY_HW_NEOPIXEL (&pin_GPIO19) -#define DEFAULT_I2C_BUS_SCL (&pin_GPIO25) -#define DEFAULT_I2C_BUS_SDA (&pin_GPIO24) +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO21) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO20) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO26) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO27) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO28) diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/pins.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/pins.c index 8ce16c0e9c..2e5890c1c4 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/pins.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/pins.c @@ -15,24 +15,29 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_KEY12), MP_ROM_PTR(&pin_GPIO12) }, { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, - { MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_SPEAKER_SHUTDOWN), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO16) }, { MP_ROM_QSTR(MP_QSTR_ENCODER_SWITCH), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO16) }, { MP_ROM_QSTR(MP_QSTR_ENCODER_A), MP_ROM_PTR(&pin_GPIO17) }, { MP_ROM_QSTR(MP_QSTR_ENCODER_B), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO19) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_OLED_CS), MP_ROM_PTR(&pin_GPIO22) }, { MP_ROM_QSTR(MP_QSTR_OLED_RESET), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_OLED_DC), MP_ROM_PTR(&pin_GPIO24) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO24) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO25) }, - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 8f1c25c8aeecba4d02e7811e5eb49afa96e1a412 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 6 Jun 2021 18:25:40 -0400 Subject: [PATCH 2/6] fix SH110x mode, the SH1107 is actually column not row mode BUT the SD1107 module we use is vertical orientation (confusing!) so row/col are NOT swapped. we will have to fix the SH1107 driver to match. this fix required for SH1106 (which uses the same page mode commands but ISNT rotated) --- shared-module/displayio/Display.c | 4 ++-- shared-module/displayio/display_core.c | 29 +++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 9117a50b78..c583ead54b 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -249,8 +249,8 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t // for SH1107 and other boundary constrained controllers // write one single row at a time if (self->SH1107_addressing) { - subrectangles = rows_per_buffer; // vertical (column mode) write each separately (height times) - rows_per_buffer = 1; + subrectangles = rows_per_buffer/8; // vertical (column mode) write each separately (height times) + rows_per_buffer = 8; } else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); if (rows_per_buffer == 0) { diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c index 5b4b20b344..86c104d9ad 100644 --- a/shared-module/displayio/display_core.c +++ b/shared-module/displayio/display_core.c @@ -260,14 +260,15 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, data[data_length++] = x2 >> 8; data[data_length++] = x2 & 0xff; } + // Quirk for SH1107 "SH1107_addressing" - // Note... column is y! page is x! - // Page address command = 0xB0 + // Column lower command = 0x00, Column upper command = 0x10 if (SH1107_addressing) { - // set the page to our x value - data[0] = 0xB0 | (x1 & 0x0F); - data_length = 1; + data[0] = ((x1 >> 4) & 0x0F) | 0x10; // 0x10 to 0x17 + data[1] = x1 & 0x0F; // 0x00 to 0x0F + data_length = 2; } + self->send(self->bus, data_type, chip_select, data, data_length); displayio_display_core_end_transaction(self); @@ -299,16 +300,16 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, data[data_length++] = y2 >> 8; data[data_length++] = y2 & 0xff; } - // Quirk for SH1107 "SH1107_addressing" - // Note... column is y! page is x! - // Column lower command = 0x00, Column upper command = 0x10 - if (SH1107_addressing) { - data[0] = y1 & 0x0F; // 0x00 to 0x0F - data[1] = (y1 >> 4 & 0x0F) | 0x10; // 0x10 to 0x17 - data_length = 2; - } - self->send(self->bus, data_type, chip_select, data, data_length); + // Quirk for SH1107 "SH1107_addressing" + // Page address command = 0xB0 + if (SH1107_addressing) { + // set the page to our y value + data[0] = 0xB0 | y1; + data_length = 1; + } + + self->send(self->bus, data_type, chip_select, data, data_length); displayio_display_core_end_transaction(self); if (set_current_row_command != NO_COMMAND) { From 3890271f19659654544c7a84e66a94198d01de23 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 6 Jun 2021 18:30:17 -0400 Subject: [PATCH 3/6] turn off all neopix when booting --- ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index c4021a83e9..400c8f858c 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -28,6 +28,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "supervisor/shared/board.h" void board_init(void) { } @@ -37,4 +38,6 @@ bool board_requests_safe_mode(void) { } void reset_board(void) { + // turn off any left over LED + board_reset_user_neopixels(&pin_GPIO19, 12); } From 2ff9e9766f4ae28f31ed997af075d20df2248ded Mon Sep 17 00:00:00 2001 From: lady ada Date: Mon, 7 Jun 2021 12:39:59 -0400 Subject: [PATCH 4/6] handclang --- ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c | 4 ++-- shared-module/displayio/Display.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 400c8f858c..a9f1226295 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -38,6 +38,6 @@ bool board_requests_safe_mode(void) { } void reset_board(void) { - // turn off any left over LED - board_reset_user_neopixels(&pin_GPIO19, 12); + // turn off any left over LED + board_reset_user_neopixels(&pin_GPIO19, 12); } diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index c583ead54b..8419ddb237 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -249,7 +249,7 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t // for SH1107 and other boundary constrained controllers // write one single row at a time if (self->SH1107_addressing) { - subrectangles = rows_per_buffer/8; // vertical (column mode) write each separately (height times) + subrectangles = rows_per_buffer / 8; // vertical (column mode) write each separately (height times) rows_per_buffer = 8; } else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); From b39dd845600082db76c3adb354e1e7de4cd99869 Mon Sep 17 00:00:00 2001 From: lady ada Date: Mon, 7 Jun 2021 19:43:49 -0400 Subject: [PATCH 5/6] move the col/row offsets to the top so oleds can take advantage of em --- shared-module/displayio/display_core.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c index 86c104d9ad..234c0a096b 100644 --- a/shared-module/displayio/display_core.c +++ b/shared-module/displayio/display_core.c @@ -216,10 +216,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, bool data_as_commands, bool always_toggle_chip_select, displayio_area_t *area, bool SH1107_addressing) { - uint16_t x1 = area->x1; - uint16_t x2 = area->x2; - uint16_t y1 = area->y1; - uint16_t y2 = area->y2; + uint16_t x1 = area->x1 + self->colstart; + uint16_t x2 = area->x2 + self->colstart; + uint16_t y1 = area->y1 + self->rowstart; + uint16_t y2 = area->y2 + self->rowstart; + // Collapse down the dimension where multiple pixels are in a byte. if (self->colorspace.depth < 8) { uint8_t pixels_per_byte = 8 / self->colorspace.depth; @@ -232,6 +233,9 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, } } + x2 -= 1; + y2 -= 1; + display_chip_select_behavior_t chip_select = CHIP_SELECT_UNTOUCHED; if (always_toggle_chip_select || data_as_commands) { chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE; @@ -249,12 +253,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, } else { data_type = DISPLAY_COMMAND; } + if (self->ram_width < 0x100) { - data[data_length++] = x1 + self->colstart; - data[data_length++] = x2 - 1 + self->colstart; + data[data_length++] = x1; + data[data_length++] = x2; } else { - x1 += self->colstart; - x2 += self->colstart - 1; data[data_length++] = x1 >> 8; data[data_length++] = x1 & 0xff; data[data_length++] = x2 >> 8; @@ -289,12 +292,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, self->send(self->bus, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, 1); data_length = 0; } + if (self->ram_height < 0x100) { - data[data_length++] = y1 + self->rowstart; - data[data_length++] = y2 - 1 + self->rowstart; + data[data_length++] = y1; + data[data_length++] = y2; } else { - y1 += self->rowstart; - y2 += self->rowstart - 1; data[data_length++] = y1 >> 8; data[data_length++] = y1 & 0xff; data[data_length++] = y2 >> 8; From 467a4e766470a52438744031b4ed7eda4b399697 Mon Sep 17 00:00:00 2001 From: lady ada Date: Mon, 7 Jun 2021 19:51:57 -0400 Subject: [PATCH 6/6] fix comment --- shared-module/displayio/Display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 8419ddb237..ba509c6986 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -249,7 +249,7 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t // for SH1107 and other boundary constrained controllers // write one single row at a time if (self->SH1107_addressing) { - subrectangles = rows_per_buffer / 8; // vertical (column mode) write each separately (height times) + subrectangles = rows_per_buffer / 8; // page addressing mode writes 8 rows at a time rows_per_buffer = 8; } else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped);