Skip to content

Commit 2bd02fa

Browse files
committed
Made board.DISPLAY available
1 parent 1704518 commit 2bd02fa

3 files changed

Lines changed: 93 additions & 2 deletions

File tree

ports/espressif/boards/waveshare_esp32_s3_amoled_241/board.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,93 @@
33
// SPDX-License-Identifier: MIT
44

55
#include "supervisor/board.h"
6+
#include "mpconfigboard.h"
7+
#include "shared-bindings/microcontroller/Pin.h"
8+
9+
#include "shared-bindings/qspibus/QSPIBus.h"
10+
#include "shared-bindings/busdisplay/BusDisplay.h"
11+
#include "shared-module/displayio/__init__.h"
12+
#include "shared-module/displayio/mipi_constants.h"
13+
14+
// RM690B0 AMOLED initialization sequence.
15+
// Format: command byte, length | 0x80 (if delay), data bytes..., [delay ms]
16+
// Based on vendor recommendations, tested with Waveshare 2.41" AMOLED panel.
17+
static const uint8_t display_init_sequence[] = {
18+
// Page select and configuration
19+
0xFE, 0x01, 0x20, // Enter user command mode
20+
0x26, 0x01, 0x0A, // Bias setting
21+
0x24, 0x01, 0x80, // Source output control
22+
0xFE, 0x01, 0x13, // Page 13
23+
0xEB, 0x01, 0x0E, // Vendor command
24+
0xFE, 0x01, 0x00, // Return to page 0
25+
// Display configuration
26+
0x3A, 0x01, 0x55, // COLMOD: 16-bit RGB565
27+
0xC2, 0x81, 0x00, 0x0A, // Vendor command + 10ms delay
28+
0x35, 0x00, // Tearing effect line on (no data)
29+
0x51, 0x81, 0x00, 0x0A, // Brightness control + 10ms delay
30+
// Power on
31+
0x11, 0x80, 0x50, // Sleep out + 80ms delay
32+
// Display window (MV=1: CASET→rows, RASET→cols)
33+
0x2A, 0x04, 0x00, 0x10, 0x01, 0xD1, // CASET: 16..465 (450px + 16 offset)
34+
0x2B, 0x04, 0x00, 0x00, 0x02, 0x57, // RASET: 0..599 (600px)
35+
// Enable display
36+
0x29, 0x80, 0x0A, // Display on + 10ms delay
37+
// Memory access: MV=1, ML=1 for landscape
38+
0x36, 0x81, 0x30, 0x0A, // MADCTL + 10ms delay
39+
// Brightness
40+
0x51, 0x01, 0xFF, // Set brightness to maximum
41+
};
642

743
void board_init(void) {
44+
// 1. Allocate and construct QSPI bus
45+
qspibus_qspibus_obj_t *bus = &allocate_display_bus_or_raise()->qspi_bus;
46+
bus->base.type = &qspibus_qspibus_type;
47+
48+
common_hal_qspibus_qspibus_construct(bus,
49+
CIRCUITPY_LCD_CLK, // clock
50+
CIRCUITPY_LCD_D0, // data0
51+
CIRCUITPY_LCD_D1, // data1
52+
CIRCUITPY_LCD_D2, // data2
53+
CIRCUITPY_LCD_D3, // data3
54+
CIRCUITPY_LCD_CS, // cs
55+
NULL, // dcx (not used, QSPI uses encoded commands)
56+
CIRCUITPY_LCD_RESET, // reset
57+
40000000); // 40 MHz
58+
59+
// 2. Allocate and construct BusDisplay with RM690B0 init sequence.
60+
// Physical panel: 450 cols × 600 rows.
61+
// MADCTL MV=1 swaps row/col → logical 600×450 landscape.
62+
busdisplay_busdisplay_obj_t *display = &allocate_display_or_raise()->display;
63+
display->base.type = &busdisplay_busdisplay_type;
64+
65+
common_hal_busdisplay_busdisplay_construct(display,
66+
bus,
67+
600, // width (logical, after MV=1 swap)
68+
450, // height (logical, after MV=1 swap)
69+
0, // colstart
70+
16, // rowstart (physical row offset)
71+
0, // rotation
72+
16, // color_depth (RGB565)
73+
false, // grayscale
74+
false, // pixels_in_byte_share_row
75+
1, // bytes_per_cell
76+
false, // reverse_pixels_in_byte
77+
false, // reverse_bytes_in_word
78+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set_column_command
79+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set_row_command
80+
MIPI_COMMAND_WRITE_MEMORY_START, // write_ram_command
81+
(uint8_t *)display_init_sequence,
82+
sizeof(display_init_sequence),
83+
NULL, // backlight_pin (AMOLED — no backlight GPIO)
84+
0x51, // brightness_command
85+
1.0f, // brightness
86+
false, // single_byte_bounds
87+
false, // data_as_commands
88+
true, // auto_refresh
89+
60, // native_frames_per_second
90+
true, // backlight_on_high
91+
false, // SH1107_addressing
92+
50000); // backlight_pwm_frequency
893
}
94+
95+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/espressif/boards/waveshare_esp32_s3_amoled_241/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// ESP32-S3 main task stack is 24KB; verified safe with this board.
2222
#define CIRCUITPY_QSPI_DISPLAY_AREA_BUFFER_SIZE (2048)
2323

24-
// AMOLED Display (displayio + qspibus path)
25-
#define CIRCUITPY_BOARD_DISPLAY (0)
24+
// AMOLED Display (displayio + qspibus path) - initialized in board_init()
25+
#define CIRCUITPY_BOARD_DISPLAY (1)
2626
#define CIRCUITPY_LCD_CS (&pin_GPIO9)
2727
#define CIRCUITPY_LCD_CLK (&pin_GPIO10)
2828
#define CIRCUITPY_LCD_D0 (&pin_GPIO11)

ports/espressif/boards/waveshare_esp32_s3_amoled_241/pins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "py/mphal.h"
77
#include "shared-bindings/board/__init__.h"
88
#include "shared-bindings/microcontroller/Pin.h"
9+
#include "shared-module/displayio/__init__.h"
910

1011
static const mp_rom_map_elem_t board_module_globals_table[] = {
1112
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
@@ -96,5 +97,8 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
9697
{ MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, // Available
9798
{ MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, // Available
9899
{ MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, // Available
100+
101+
// Board display (initialized in board_init)
102+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
99103
};
100104
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)