Skip to content

Commit 96ae87e

Browse files
committed
display is functional now
1 parent 0dfafe2 commit 96ae87e

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

ports/espressif/boards/m5stack_atoms3/board.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,106 @@
2525
*/
2626

2727
#include "supervisor/board.h"
28+
#include "mpconfigboard.h"
29+
#include "shared-bindings/busio/SPI.h"
30+
#include "shared-bindings/displayio/FourWire.h"
31+
#include "shared-bindings/microcontroller/Pin.h"
32+
#include "shared-module/displayio/__init__.h"
33+
#include "shared-module/displayio/mipi_constants.h"
34+
#include "shared-bindings/board/__init__.h"
35+
36+
displayio_fourwire_obj_t board_display_obj;
37+
38+
#define DELAY 0x80
39+
40+
// display init sequence according to LilyGO example app
41+
uint8_t display_init_sequence[] = {
42+
// sw reset
43+
0x01, 0 | DELAY, 0x96,
44+
// sleep out
45+
0x11, 0 | DELAY, 0xff,
46+
// normal display mode on
47+
// 0x13, 0,
48+
// display and color format settings
49+
// 0x36, 1, 0x68,
50+
// 0xB6, 2, 0x0A, 0x82,
51+
0x3A, 1 | DELAY, 0x55, 0x0a,
52+
0x36, 0x01, 0x08, // _MADCTL
53+
0x21, 0x80, 0x0A, // _INVON Hack and Delay 10ms
54+
0x13, 0x80, 0x0A, // _NORON and Delay 10ms
55+
0x36, 0x01, 0xC0, // _MADCTL
56+
// ST7789V frame rate setting
57+
// 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
58+
// voltages: VGH / VGL
59+
// 0xB7, 1, 0x35,
60+
// ST7789V power setting
61+
// 0xBB, 1, 0x28,
62+
// 0xC0, 1, 0x0C,
63+
// 0xC2, 2, 0x01, 0xFF,
64+
// 0xC3, 1, 0x10,
65+
// 0xC4, 1, 0x20,
66+
// 0xC6, 1, 0x0F,
67+
// 0xD0, 2, 0xA4, 0xA1,
68+
// ST7789V gamma setting
69+
// 0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17,
70+
// 0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E,
71+
// 0x21, 0,
72+
// display on
73+
0x29, 0 | DELAY, 0xff
74+
};
75+
76+
77+
void board_init(void) {
78+
displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
79+
// busio_spi_obj_t *spi = common_hal_board_create_spi(0);
80+
busio_spi_obj_t *spi = &bus->inline_bus;
81+
common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, false);
82+
common_hal_busio_spi_never_reset(spi);
83+
bus->base.type = &displayio_fourwire_type;
84+
85+
common_hal_displayio_fourwire_construct(
86+
bus,
87+
spi,
88+
&pin_GPIO33, // DC
89+
&pin_GPIO15, // CS
90+
&pin_GPIO34, // RST
91+
40000000, // baudrate
92+
0, // polarity
93+
0 // phase
94+
);
95+
displayio_display_obj_t *display = &allocate_display()->display;
96+
display->base.type = &displayio_display_type;
97+
98+
common_hal_displayio_display_construct(
99+
display,
100+
bus,
101+
128, // width (after rotation)
102+
128, // height (after rotation)
103+
2, // column start
104+
1, // row start
105+
0, // rotation
106+
16, // color depth
107+
false, // grayscale
108+
false, // pixels in a byte share a row. Only valid for depths < 8
109+
1, // bytes per cell. Only valid for depths < 8
110+
false, // reverse_pixels_in_byte. Only valid for depths < 8
111+
true, // reverse_pixels_in_word
112+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
113+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
114+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
115+
display_init_sequence,
116+
sizeof(display_init_sequence),
117+
&pin_GPIO16, // backlight pin
118+
NO_BRIGHTNESS_COMMAND,
119+
1.0f, // brightness
120+
false, // single_byte_bounds
121+
false, // data_as_commands
122+
true, // auto_refresh
123+
60, // native_frames_per_second
124+
true, // backlight_on_high
125+
false, // SH1107_addressing
126+
50000 // backlight pwm frequency
127+
);
128+
}
28129

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

ports/espressif/boards/m5stack_atoms3/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
#define CIRCUITPY_BOARD_I2C (2)
3535
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO39, .sda = &pin_GPIO38}, \
3636
{.scl = &pin_GPIO1, .sda = &pin_GPIO2}}
37+
38+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO17)
39+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO21)

ports/espressif/boards/m5stack_atoms3/pins.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
2727
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) },
2828

2929
{ MP_ROM_QSTR(MP_QSTR_D39), MP_ROM_PTR(&pin_GPIO39) },
30+
{ MP_ROM_QSTR(MP_QSTR_IMU_SCL), MP_ROM_PTR(&pin_GPIO39) },
3031
{ MP_ROM_QSTR(MP_QSTR_D38), MP_ROM_PTR(&pin_GPIO38) },
32+
{ MP_ROM_QSTR(MP_QSTR_IMU_SDA), MP_ROM_PTR(&pin_GPIO38) },
3133

3234
// lcd spi bus
3335
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO21) },
@@ -43,6 +45,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
4345

4446
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
4547
{ MP_ROM_QSTR(MP_QSTR_PORTA_I2C), MP_ROM_PTR(&board_porta_i2c_obj) },
48+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
4649

4750
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
4851
};

0 commit comments

Comments
 (0)