Skip to content

Commit e54ea0c

Browse files
committed
initial commit
1 parent d8ca842 commit e54ea0c

File tree

5 files changed

+208
-0
lines changed

5 files changed

+208
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 CDarius
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+
#include "supervisor/board.h"
27+
#include "mpconfigboard.h"
28+
#include "shared-bindings/microcontroller/Pin.h"
29+
#include "shared-module/displayio/__init__.h"
30+
#include "shared-module/displayio/mipi_constants.h"
31+
32+
// display init sequence according to adafruit_st7735r.py library
33+
uint8_t display_init_sequence[] = {
34+
0x01, 0x80, 0x96, // SWRESET and Delay 150ms
35+
0x11, 0x80, 0xff, // SLPOUT and Delay
36+
0xb1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1
37+
0xb2, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR2
38+
0xb3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3
39+
0xb4, 0x01, 0x07, // _INVCTR line inversion
40+
0xc0, 0x03, 0xa2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
41+
0xc1, 0x01, 0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
42+
0xc2, 0x02, 0x0a, 0x00, // _PWCTR3 Opamp current small, Boost frequency
43+
0xc3, 0x02, 0x8a, 0x2a,
44+
0xc4, 0x02, 0x8a, 0xee,
45+
0xc5, 0x01, 0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
46+
0x36, 0x01, 0xc8, // MADCTL Rotate display
47+
0x3a, 0x01, 0x05, // COLMOD - 16bit color
48+
0xe0, 0x10, 0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
49+
0xe1, 0x10, 0x03, 0x1d, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1
50+
0x13, 0x80, 0x0a, // _NORON
51+
0x29, 0x80, 0x64 // _DISPON
52+
};
53+
54+
static bool display_init(void) {
55+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
56+
busio_spi_obj_t *spi = &bus->inline_bus;
57+
common_hal_busio_spi_construct(spi, &pin_GPIO3, &pin_GPIO4, NULL, false);
58+
common_hal_busio_spi_never_reset(spi);
59+
60+
bus->base.type = &fourwire_fourwire_type;
61+
62+
common_hal_fourwire_fourwire_construct(
63+
bus,
64+
spi,
65+
&pin_GPIO0, // DC
66+
&pin_GPIO2, // CS
67+
&pin_GPIO5, // RST
68+
10000000, // baudrate
69+
0, // polarity
70+
0 // phase
71+
);
72+
73+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
74+
display->base.type = &busdisplay_busdisplay_type;
75+
76+
common_hal_busdisplay_busdisplay_construct(
77+
display,
78+
bus,
79+
128, // width (after rotation)
80+
128, // height (after rotation)
81+
2, // column start
82+
1, // row start
83+
0, // rotation
84+
16, // color depth
85+
false, // grayscale
86+
false, // pixels in a byte share a row. Only valid for depths < 8
87+
1, // bytes per cell. Only valid for depths < 8
88+
false, // reverse_pixels_in_byte. Only valid for depths < 8
89+
true, // reverse_pixels_in_word
90+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
91+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
92+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
93+
display_init_sequence,
94+
sizeof(display_init_sequence),
95+
NULL, // backlight pin
96+
NO_BRIGHTNESS_COMMAND,
97+
1.0f, // brightness
98+
false, // single_byte_bounds
99+
false, // data_as_commands
100+
true, // auto_refresh
101+
80, // native_frames_per_second
102+
false, // backlight_on_high
103+
false, // SH1107_addressing
104+
50000 // backlight pwm frequency
105+
);
106+
107+
return true;
108+
}
109+
110+
void board_init(void) {
111+
display_init();
112+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Neradoc
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+
// Board setup
28+
#define MICROPY_HW_BOARD_NAME "Spotpear ESP32C3 LCD 1.44"
29+
#define MICROPY_HW_MCU_NAME "ESP32-C3FH4"
30+
31+
#define MICROPY_HW_LED_STATUS (&pin_GPIO11)
32+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CIRCUITPY_CREATOR_ID = 0x18760000
2+
CIRCUITPY_CREATION_ID = 0x00DD0001
3+
4+
IDF_TARGET = esp32c3
5+
6+
CIRCUITPY_ESP_FLASH_MODE = qio
7+
CIRCUITPY_ESP_FLASH_FREQ = 80m
8+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
9+
10+
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
// buttons
8+
{ MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO9) },
9+
{ MP_ROM_QSTR(MP_QSTR_BUTTON0), MP_ROM_PTR(&pin_GPIO9) },
10+
{ MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_GPIO8) },
11+
{ MP_ROM_QSTR(MP_QSTR_BUTTON2), MP_ROM_PTR(&pin_GPIO10) },
12+
13+
// Status LED
14+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO11) },
15+
16+
// SPI LCD
17+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO4) },
18+
{ MP_ROM_QSTR(MP_QSTR_LCD_SCK), MP_ROM_PTR(&pin_GPIO3) },
19+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO0) },
20+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO5) },
21+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO2) },
22+
23+
// UART (on header 1)
24+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO20) },
25+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO21) },
26+
27+
// User available GPIO, Header 1
28+
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
29+
{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
30+
{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },
31+
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
32+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
33+
34+
// Objects
35+
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_spi_obj) },
36+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
37+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
38+
};
39+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
# Component config
6+
#
7+
#
8+
# LWIP
9+
#
10+
CONFIG_LWIP_LOCAL_HOSTNAME="spotpear-esp32c3-lcd-1-44"
11+
# end of LWIP
12+
13+
# end of Component config
14+
15+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)