Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macropad rev B definion and fix for SH110x addressing #4864

Merged
merged 6 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 13 additions & 8 deletions ports/raspberrypi/boards/adafruit_macropad_rp2040/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions shared-module/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; // 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);
if (rows_per_buffer == 0) {
Expand Down
49 changes: 26 additions & 23 deletions shared-module/displayio/display_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -249,25 +253,25 @@ 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;
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);

Expand All @@ -288,27 +292,26 @@ 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;
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
// Page address command = 0xB0
if (SH1107_addressing) {
data[0] = y1 & 0x0F; // 0x00 to 0x0F
data[1] = (y1 >> 4 & 0x0F) | 0x10; // 0x10 to 0x17
data_length = 2;
// 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);

self->send(self->bus, data_type, chip_select, data, data_length);
displayio_display_core_end_transaction(self);

if (set_current_row_command != NO_COMMAND) {
Expand Down