Skip to content

Commit 68af554

Browse files
committed
set up display at reset (yayay!)
1 parent 91b98dc commit 68af554

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

  • ports/espressif/boards/espressif_esp32s3_lcd_ev

ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,131 @@
2626

2727
#include "supervisor/board.h"
2828
#include "mpconfigboard.h"
29+
#include "shared-bindings/board/__init__.h"
30+
#include "shared-bindings/busio/I2C.h"
31+
#include "shared-bindings/dotclockframebuffer/DotClockFramebuffer.h"
32+
#include "shared-bindings/dotclockframebuffer/__init__.h"
33+
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
2934
#include "shared-bindings/microcontroller/Pin.h"
35+
#include "shared-module/displayio/__init__.h"
3036

37+
static const uint8_t display_init_sequence[] = {
38+
0xf0, 5, 0x55, 0xaa, 0x52, 0x08, 0x00,
39+
0xf6, 2, 0x5a, 0x87,
40+
0xc1, 1, 0x3f,
41+
0xc2, 1, 0x0e,
42+
0xc6, 1, 0xf8,
43+
0xc9, 1, 0x10,
44+
0xcd, 1, 0x25,
45+
0xf8, 1, 0x8a,
46+
0xac, 1, 0x45,
47+
0xa0, 1, 0xdd,
48+
0xa7, 1, 0x47,
49+
0xfa, 4, 0x00, 0x00, 0x00, 0x04,
50+
0x86, 4, 0x99, 0xa3, 0xa3, 0x51,
51+
0xa3, 1, 0xee,
52+
0xfd, 3, 0x3c, 0x3c, 0x00,
53+
0x71, 1, 0x48,
54+
0x72, 1, 0x48,
55+
0x73, 2, 0x00, 0x44,
56+
0x97, 1, 0xee,
57+
0x83, 1, 0x93,
58+
0x9a, 1, 0x72,
59+
0x9b, 1, 0x5a,
60+
0x82, 2, 0x2c, 0x2c,
61+
0xb1, 1, 0x10,
62+
0x6d, 32, 0x00, 0x1f, 0x19, 0x1a, 0x10, 0x0e, 0x0c, 0x0a, 0x02, 0x07, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x08, 0x01, 0x09, 0x0b, 0x0d, 0x0f, 0x1a, 0x19, 0x1f, 0x00,
63+
0x64, 16, 0x38, 0x05, 0x01, 0xdb, 0x03, 0x03, 0x38, 0x04, 0x01, 0xdc, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a,
64+
0x65, 16, 0x38, 0x03, 0x01, 0xdd, 0x03, 0x03, 0x38, 0x02, 0x01, 0xde, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a,
65+
0x66, 16, 0x38, 0x01, 0x01, 0xdf, 0x03, 0x03, 0x38, 0x00, 0x01, 0xe0, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a,
66+
0x67, 16, 0x30, 0x01, 0x01, 0xe1, 0x03, 0x03, 0x30, 0x02, 0x01, 0xe2, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a,
67+
0x68, 13, 0x00, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a,
68+
0x60, 8, 0x38, 0x08, 0x7a, 0x7a, 0x38, 0x09, 0x7a, 0x7a,
69+
0x63, 8, 0x31, 0xe4, 0x7a, 0x7a, 0x31, 0xe5, 0x7a, 0x7a,
70+
0x69, 7, 0x04, 0x22, 0x14, 0x22, 0x14, 0x22, 0x08,
71+
0x6b, 1, 0x07,
72+
0x7a, 2, 0x08, 0x13,
73+
0x7b, 2, 0x08, 0x13,
74+
0xd1, 52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
75+
0xd2, 52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
76+
0xd3, 52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
77+
0xd4, 52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
78+
0xd5, 52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
79+
0xd6, 52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
80+
0x3a, 1, 0x66,
81+
0x3a, 1, 0x66,
82+
0x11, 0x80, 120,
83+
0x29, 0x80, 20
84+
};
85+
86+
static const mcu_pin_obj_t *red_pins[] = {
87+
&pin_GPIO1, &pin_GPIO2, &pin_GPIO42, &pin_GPIO41, &pin_GPIO40
88+
};
89+
static const mcu_pin_obj_t *green_pins[] = {
90+
&pin_GPIO21, &pin_GPIO47, &pin_GPIO48, &pin_GPIO45, &pin_GPIO38, &pin_GPIO39
91+
};
92+
static const mcu_pin_obj_t *blue_pins[] = {
93+
&pin_GPIO10, &pin_GPIO11, &pin_GPIO12, &pin_GPIO13, &pin_GPIO14
94+
};
3195
void board_init(void) {
96+
dotclockframebuffer_framebuffer_obj_t *framebuffer = &allocate_display_bus_or_raise()->dotclock;
97+
framebuffer->base.type = &dotclockframebuffer_framebuffer_type;
98+
99+
common_hal_dotclockframebuffer_framebuffer_construct(
100+
framebuffer,
101+
/* de */ &pin_GPIO17,
102+
/* vsync */ &pin_GPIO3,
103+
/* hsync */ &pin_GPIO46,
104+
/* dclk */ &pin_GPIO9,
105+
/* data */ red_pins, MP_ARRAY_SIZE(red_pins), green_pins, MP_ARRAY_SIZE(green_pins), blue_pins, MP_ARRAY_SIZE(blue_pins),
106+
/* frequency */ 6500000,
107+
/* width x height */ 480, 480,
108+
/* horizontal: pulse, back & front porch, idle */ 13, 20, 40, false,
109+
/* vertical: pulse, back & front porch, idle */ 15, 20, 40, false,
110+
/* de_idle_high */ false,
111+
/* pclk_active_high */ true,
112+
/* pclk_idle_high */ false,
113+
/* overscan_left */ 0
114+
);
115+
116+
framebufferio_framebufferdisplay_obj_t *disp = &allocate_display_or_raise()->framebuffer_display;
117+
disp->base.type = &framebufferio_framebufferdisplay_type;
118+
common_hal_framebufferio_framebufferdisplay_construct(
119+
disp,
120+
framebuffer,
121+
0,
122+
true
123+
);
124+
125+
busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
126+
const int i2c_device_address = 32;
127+
128+
common_hal_busio_i2c_try_lock(i2c);
129+
130+
{
131+
uint8_t buf[2] = {3, 0xf1}; // set GPIO direction
132+
common_hal_busio_i2c_write(i2c, i2c_device_address, buf, sizeof(buf));
133+
}
134+
135+
{
136+
uint8_t buf[2] = {2, 0}; // set all output pins low initially
137+
common_hal_busio_i2c_write(i2c, i2c_device_address, buf, sizeof(buf));
138+
}
139+
140+
common_hal_busio_i2c_unlock(i2c);
141+
142+
dotclockframebuffer_ioexpander_spi_bus spibus = {
143+
.bus = i2c,
144+
.i2c_device_address = i2c_device_address,
145+
.i2c_write_size = 2,
146+
.addr_reg_shadow = { .u32 = 1 }, // GPIO data at register 1
147+
.cs_mask = 0x100 << 1, // data payload is at byte 2
148+
.mosi_mask = 0x100 << 3,
149+
.clk_mask = 0x100 << 2,
150+
};
151+
152+
dotclockframebuffer_ioexpander_send_init_sequence(&spibus, display_init_sequence, sizeof(display_init_sequence));
153+
32154
}
33155

34156
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

0 commit comments

Comments
 (0)