Skip to content

Commit 0977384

Browse files
authored
Merge pull request #7754 from Neradoc/add-display-lolin-pico
Add builtin display to lolin pico
2 parents 9c1d834 + b88e76d commit 0977384

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

ports/espressif/boards/lolin_s2_pico/board.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,76 @@
2727
#include "supervisor/board.h"
2828
#include "mpconfigboard.h"
2929
#include "shared-bindings/microcontroller/Pin.h"
30+
#include "shared-bindings/board/__init__.h"
31+
#include "shared-bindings/displayio/I2CDisplay.h"
32+
#include "shared-module/displayio/__init__.h"
33+
#include "shared-module/displayio/mipi_constants.h"
34+
#include "shared-bindings/busio/I2C.h"
35+
#include "supervisor/shared/board.h"
36+
#include "shared-bindings/board/__init__.h"
37+
38+
uint8_t display_init_sequence[] = { // SSD1306
39+
0xAE, 0, // DISPLAY_OFF
40+
0x20, 1, 0x00, // Set memory addressing to horizontal mode.
41+
0x81, 1, 0xcf, // set contrast control
42+
0xA1, 0, // Column 127 is segment 0
43+
0xA6, 0, // Normal display
44+
0xc8, 0, // Normal display
45+
0xA8, 1, 0x1f, // Mux ratio is height-1
46+
0xd5, 1, 0x80, // Set divide ratio
47+
0xd9, 1, 0xf1, // Set pre-charge period
48+
0xda, 1, 0x02, // Set com configuration to 2 if height is 32 and width not 64
49+
0xdb, 1, 0x40, // Set vcom configuration
50+
0x8d, 1, 0x14, // Enable charge pump
51+
0xAF, 0, // DISPLAY_ON
52+
};
53+
54+
static void display_init(void) {
55+
busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
56+
57+
displayio_i2cdisplay_obj_t *bus = &displays[0].i2cdisplay_bus;
58+
bus->base.type = &displayio_i2cdisplay_type;
59+
common_hal_displayio_i2cdisplay_construct(bus,
60+
i2c,
61+
0x3c,
62+
&pin_GPIO18 // reset
63+
);
64+
65+
displayio_display_obj_t *display = &displays[0].display;
66+
display->base.type = &displayio_display_type;
67+
common_hal_displayio_display_construct(display,
68+
bus,
69+
128, // Width
70+
32, // Height
71+
0, // column start
72+
0, // row start
73+
0, // rotation
74+
1, // Color depth
75+
true, // grayscale
76+
false, // pixels in byte share row. Only used with depth < 8
77+
1, // bytes per cell. Only valid for depths < 8
78+
false, // reverse_pixels_in_byte. Only valid for depths < 8
79+
true, // reverse_pixels_in_word
80+
0x21, // Set column command
81+
0x22, // Set row command
82+
44, // Write ram command
83+
display_init_sequence,
84+
sizeof(display_init_sequence),
85+
NULL, // no backlight pin
86+
0x81, // brightness command
87+
1.0f, // brightness
88+
true, // single_byte_bounds
89+
true, // data as commands
90+
true, // auto_refresh
91+
60, // native_frames_per_second
92+
true, // backlight_on_high
93+
false, // SH1107_addressing
94+
0); // backlight pwm frequency
95+
}
3096

3197
void board_init(void) {
98+
// init display
99+
display_init();
32100
// Debug UART
33101
#ifdef DEBUG
34102
common_hal_never_reset_pin(&pin_GPIO43);

ports/espressif/boards/lolin_s2_pico/pins.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
23

34
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
45
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
@@ -52,5 +53,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
5253
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) }, // Not labelled on booard, on schematic
5354
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO37) },// Not labelled on booard, on schematic
5455
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
56+
57+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
5558
};
5659
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)