Skip to content

Commit 76f9c18

Browse files
authored
Merge pull request #7843 from waptang/Waveshare_RP2040-LCD-0.96
Add Waveshare RP2040-LCD-0.96
2 parents 50e259f + af35337 commit 76f9c18

File tree

5 files changed

+209
-0
lines changed

5 files changed

+209
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "supervisor/board.h"
28+
#include "mpconfigboard.h"
29+
#include "shared-module/displayio/__init__.h"
30+
#include "shared-module/displayio/mipi_constants.h"
31+
32+
#define DELAY 0x80
33+
34+
35+
// display init sequence according to Adafruit_CircuitPython_ST7735R
36+
// https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
37+
uint8_t display_init_sequence[] = {
38+
// sw reset
39+
0x01, 0 | DELAY, 0x96,
40+
// SLPOUT and Delay
41+
0x11, 0 | DELAY, 0xFF,
42+
0xB1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1
43+
0xB3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3
44+
0xB4, 0x01, 0x07, // _INVCTR line inversion
45+
0xC0, 0x03, 0xA2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
46+
0xC1, 0x01, 0xC5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
47+
0xC2, 0x02, 0x0A, 0x00, // _PWCTR3 Opamp current small, Boost frequency
48+
0xC3, 0x02, 0x8A, 0x2A,
49+
0xC4, 0x02, 0x8A, 0xEE,
50+
0xC5, 0x01, 0x0E, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
51+
0x20, 0x00, // _INVOFF
52+
0x36, 0x01, 0x18, // _MADCTL bottom to top refresh
53+
// 1 clk cycle nonoverlap, 2 cycle gate rise, 3 cycle osc equalie,
54+
// fix on VTL
55+
0x3A, 0x01, 0x05, // COLMOD - 16bit color
56+
0xE0, 0x10, 0x02, 0x1C, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2D, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
57+
0xE1, 0x10, 0x03, 0x1D, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1
58+
0x13, 0 | DELAY, 0x0A, // _NORON
59+
0x29, 0 | DELAY, 0x64, // _DISPON
60+
// 0x36, 0x01, 0xC0, // _MADCTL Default rotation plus BGR encoding
61+
0x36, 0x01, 0xC8, // _MADCTL Default rotation plus RGB encoding
62+
0x21, 0x00, // _INVON
63+
};
64+
65+
static void display_init(void) {
66+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
67+
common_hal_busio_spi_construct(
68+
spi,
69+
&pin_GPIO10, // CLK
70+
&pin_GPIO11, // MOSI
71+
NULL, // MISO not connected
72+
false // Not half-duplex
73+
);
74+
75+
common_hal_busio_spi_never_reset(spi);
76+
77+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
78+
bus->base.type = &displayio_fourwire_type;
79+
80+
common_hal_displayio_fourwire_construct(
81+
bus,
82+
spi,
83+
&pin_GPIO8, // DC
84+
&pin_GPIO9, // CS
85+
&pin_GPIO12, // RST
86+
40000000, // baudrate
87+
0, // polarity
88+
0 // phase
89+
);
90+
91+
displayio_display_obj_t *display = &displays[0].display;
92+
display->base.type = &displayio_display_type;
93+
common_hal_displayio_display_construct(
94+
display,
95+
bus,
96+
160, // width (after rotation)
97+
80, // height (after rotation)
98+
26, // column start
99+
1, // row start
100+
90, // rotation
101+
16, // color depth
102+
false, // grayscale
103+
false, // pixels in a byte share a row. Only valid for depths < 8
104+
1, // bytes per cell. Only valid for depths < 8
105+
false, // reverse_pixels_in_byte. Only valid for depths < 8
106+
true, // reverse_pixels_in_word
107+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
108+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
109+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
110+
display_init_sequence,
111+
sizeof(display_init_sequence),
112+
&pin_GPIO25, // backlight pin
113+
NO_BRIGHTNESS_COMMAND,
114+
1.0f, // brightness
115+
false, // single_byte_bounds
116+
false, // data_as_commands
117+
true, // auto_refresh
118+
60, // native_frames_per_second
119+
true, // backlight_on_high
120+
false, // SH1107_addressing
121+
50000 // backlight pwm frequency
122+
);
123+
}
124+
125+
void board_init(void) {
126+
// Display
127+
display_init();
128+
}
129+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#define MICROPY_HW_BOARD_NAME "Waveshare RP2040-LCD-0.96"
2+
#define MICROPY_HW_MCU_NAME "rp2040"
3+
4+
#define CIRCUITPY_BOARD_I2C (1)
5+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO21, .sda = &pin_GPIO20}}
6+
7+
#define CIRCUITPY_BOARD_SPI (1)
8+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO19, .miso = &pin_GPIO16}}
9+
10+
#define CIRCUITPY_BOARD_UART (1)
11+
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO0, .rx = &pin_GPIO1}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
USB_VID = 0x2E8A
2+
USB_PID = 0x1021
3+
USB_PRODUCT = "Waveshare RP2040-LCD-0.96"
4+
USB_MANUFACTURER = "Waveshare Electronics"
5+
6+
CHIP_VARIANT = RP2040
7+
CHIP_FAMILY = rp2
8+
9+
EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
10+
11+
CIRCUITPY__EVE = 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Put board-specific pico-sdk definitions here. This file must exist.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
4+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
5+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
6+
7+
{ MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) },
8+
{ MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) },
9+
{ MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) },
10+
{ MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) },
11+
{ MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) },
12+
{ MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) },
13+
{ MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) },
14+
{ MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) },
15+
{ MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) },
16+
{ MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) },
17+
{ MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) },
18+
{ MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) },
19+
{ MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) },
20+
{ MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) },
21+
{ MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) },
22+
{ MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) },
23+
{ MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) },
24+
{ MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) },
25+
{ MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) },
26+
{ MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) },
27+
{ MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) },
28+
{ MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) },
29+
{ MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) },
30+
{ MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) },
31+
{ MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) },
32+
{ MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) },
33+
{ MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) },
34+
35+
// ADC
36+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) },
37+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) },
38+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) },
39+
{ MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) },
40+
{ MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) },
41+
{ MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) },
42+
43+
// 0.96 inch LCD ST7735s
44+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO8) },
45+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) },
46+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO10) },
47+
{ MP_ROM_QSTR(MP_QSTR_LCD_DIN), MP_ROM_PTR(&pin_GPIO11) },
48+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO12) },
49+
{ MP_ROM_QSTR(MP_QSTR_LCD_BL), MP_ROM_PTR(&pin_GPIO25) },
50+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
51+
52+
// Power pins
53+
{ MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_GPIO23) },
54+
{ MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO24) },
55+
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) },
56+
};
57+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)