Merge pull request #4864 from ladyada/main

macropad rev B definion and fix for SH110x addressing
This commit is contained in:
Limor "Ladyada" Fried 2021-06-07 21:59:56 -04:00 committed by GitHub
commit c1c101ca2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 39 deletions

View File

@ -28,6 +28,7 @@
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
#include "supervisor/shared/board.h"
void board_init(void) { void board_init(void) {
} }
@ -37,4 +38,6 @@ bool board_requests_safe_mode(void) {
} }
void reset_board(void) { void reset_board(void) {
// turn off any left over LED
board_reset_user_neopixels(&pin_GPIO19, 12);
} }

View File

@ -1,7 +1,11 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Macropad RP2040" #define MICROPY_HW_BOARD_NAME "Adafruit Macropad RP2040"
#define MICROPY_HW_MCU_NAME "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_SCL (&pin_GPIO21)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO24) #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)

View File

@ -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_KEY12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, { 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_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_A), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_ENCODER_B), MP_ROM_PTR(&pin_GPIO18) }, { 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_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_SCK), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { 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); MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -249,8 +249,8 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t
// for SH1107 and other boundary constrained controllers // for SH1107 and other boundary constrained controllers
// write one single row at a time // write one single row at a time
if (self->SH1107_addressing) { if (self->SH1107_addressing) {
subrectangles = rows_per_buffer; // 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 = 1; rows_per_buffer = 8;
} else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { } else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped);
if (rows_per_buffer == 0) { if (rows_per_buffer == 0) {

View File

@ -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, 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, bool data_as_commands, bool always_toggle_chip_select,
displayio_area_t *area, bool SH1107_addressing) { displayio_area_t *area, bool SH1107_addressing) {
uint16_t x1 = area->x1; uint16_t x1 = area->x1 + self->colstart;
uint16_t x2 = area->x2; uint16_t x2 = area->x2 + self->colstart;
uint16_t y1 = area->y1; uint16_t y1 = area->y1 + self->rowstart;
uint16_t y2 = area->y2; uint16_t y2 = area->y2 + self->rowstart;
// Collapse down the dimension where multiple pixels are in a byte. // Collapse down the dimension where multiple pixels are in a byte.
if (self->colorspace.depth < 8) { if (self->colorspace.depth < 8) {
uint8_t pixels_per_byte = 8 / self->colorspace.depth; 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; display_chip_select_behavior_t chip_select = CHIP_SELECT_UNTOUCHED;
if (always_toggle_chip_select || data_as_commands) { if (always_toggle_chip_select || data_as_commands) {
chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE; chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE;
@ -249,25 +253,25 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
} else { } else {
data_type = DISPLAY_COMMAND; data_type = DISPLAY_COMMAND;
} }
if (self->ram_width < 0x100) { if (self->ram_width < 0x100) {
data[data_length++] = x1 + self->colstart; data[data_length++] = x1;
data[data_length++] = x2 - 1 + self->colstart; data[data_length++] = x2;
} else { } else {
x1 += self->colstart;
x2 += self->colstart - 1;
data[data_length++] = x1 >> 8; data[data_length++] = x1 >> 8;
data[data_length++] = x1 & 0xff; data[data_length++] = x1 & 0xff;
data[data_length++] = x2 >> 8; data[data_length++] = x2 >> 8;
data[data_length++] = x2 & 0xff; data[data_length++] = x2 & 0xff;
} }
// Quirk for SH1107 "SH1107_addressing" // 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) { if (SH1107_addressing) {
// set the page to our x value data[0] = ((x1 >> 4) & 0x0F) | 0x10; // 0x10 to 0x17
data[0] = 0xB0 | (x1 & 0x0F); data[1] = x1 & 0x0F; // 0x00 to 0x0F
data_length = 1; data_length = 2;
} }
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); displayio_display_core_end_transaction(self);
@ -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); self->send(self->bus, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, 1);
data_length = 0; data_length = 0;
} }
if (self->ram_height < 0x100) { if (self->ram_height < 0x100) {
data[data_length++] = y1 + self->rowstart; data[data_length++] = y1;
data[data_length++] = y2 - 1 + self->rowstart; data[data_length++] = y2;
} else { } else {
y1 += self->rowstart;
y2 += self->rowstart - 1;
data[data_length++] = y1 >> 8; data[data_length++] = y1 >> 8;
data[data_length++] = y1 & 0xff; data[data_length++] = y1 & 0xff;
data[data_length++] = y2 >> 8; data[data_length++] = y2 >> 8;
data[data_length++] = y2 & 0xff; 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); displayio_display_core_end_transaction(self);
if (set_current_row_command != NO_COMMAND) { if (set_current_row_command != NO_COMMAND) {