Skip to content

Commit fc8c7b0

Browse files
authored
Merge pull request #8931 from CDarius/m5dial
Add M5Stack Dial development board
2 parents 86f3daa + c476951 commit fc8c7b0

File tree

5 files changed

+255
-0
lines changed

5 files changed

+255
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 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-bindings/busio/SPI.h"
30+
#include "shared-bindings/fourwire/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+
fourwire_fourwire_obj_t board_display_obj;
37+
38+
uint8_t display_init_sequence[] = {
39+
0xFE, 0x00, // Inter Register Enable1 (FEh)
40+
0xEF, 0x00, // Inter Register Enable2 (EFh)
41+
0xB6, 0x02, 0x00, 0x00, // Display Function Control (B6h) [S1→S360 source, G1→G32 gate]
42+
0x36, 0x01, 0x48, // Memory Access Control(36h) [Invert Row order, invert vertical scan order]
43+
0x3a, 0x01, 0x55, // COLMOD: Pixel Format Set (3Ah) [16 bits / pixel]
44+
0xC3, 0x01, 0x13, // Power Control 2 (C3h) [VREG1A = 5.06, VREG1B = 0.68]
45+
0xC4, 0x01, 0x13, // Power Control 3 (C4h) [VREG2A = -3.7, VREG2B = 0.68]
46+
0xC9, 0x01, 0x22, // Power Control 4 (C9h)
47+
0xF0, 0x06, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2a, // SET_GAMMA1 (F0h)
48+
0xF1, 0x06, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6f, // SET_GAMMA2 (F1h)
49+
0xF2, 0x06, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2a, // SET_GAMMA3 (F2h)
50+
0xF3, 0x06, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6f, // SET_GAMMA4 (F3h)
51+
52+
0x66, 0x0a, 0x3c, 0x00, 0xcd, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00,
53+
0x67, 0x0a, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98,
54+
0x74, 0x07, 0x10, 0x85, 0x80, 0x00, 0x00, 0x4e, 0x00,
55+
0x98, 0x02, 0x3e, 0x07,
56+
57+
0x35, 0x00, // Tearing Effect Line ON (35h) [both V-blanking and H-blanking]
58+
0x21, 0x00, // Display Inversion ON (21h)
59+
0x11, 0x80, 0x78, // Sleep Out Mode (11h) and delay(120)
60+
0x29, 0x80, 0x14, // Display ON (29h) and delay(20)
61+
0x2a, 0x04, 0x00, 0x00, 0x00, 239, // Column Address Set (2Ah) [Start col = 0, end col = 239]
62+
0x2b, 0x04, 0x00, 0x00, 0x00, 239, // Row Address Set (2Bh) [Start row = 0, end row = 239]
63+
};
64+
65+
void board_init(void) {
66+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
67+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
68+
bus->base.type = &fourwire_fourwire_type;
69+
70+
common_hal_fourwire_fourwire_construct(
71+
bus,
72+
spi,
73+
&pin_GPIO4, // DC
74+
&pin_GPIO7, // CS
75+
&pin_GPIO8, // RST
76+
40000000, // baudrate
77+
0, // polarity
78+
0 // phase
79+
);
80+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
81+
display->base.type = &busdisplay_busdisplay_type;
82+
83+
common_hal_busdisplay_busdisplay_construct(
84+
display,
85+
bus,
86+
240, // width (after rotation)
87+
240, // height (after rotation)
88+
0, // column start
89+
0, // row start
90+
0, // rotation
91+
16, // color depth
92+
false, // grayscale
93+
false, // pixels in a byte share a row. Only valid for depths < 8
94+
1, // bytes per cell. Only valid for depths < 8
95+
false, // reverse_pixels_in_byte. Only valid for depths < 8
96+
true, // reverse_pixels_in_word
97+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
98+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
99+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
100+
display_init_sequence,
101+
sizeof(display_init_sequence),
102+
&pin_GPIO9, // backlight pin
103+
NO_BRIGHTNESS_COMMAND,
104+
0.8f, // brightness
105+
false, // single_byte_bounds
106+
false, // data_as_commands
107+
true, // auto_refresh
108+
60, // native_frames_per_second
109+
true, // backlight_on_high
110+
false, // SH1107_addressing
111+
50000 // backlight pwm frequency
112+
);
113+
}
114+
115+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
116+
// Hold pind must be set high to avoid a power off when battery powered
117+
if (pin_number == 46) {
118+
// Turn on hold output
119+
gpio_set_direction(46, GPIO_MODE_DEF_OUTPUT);
120+
gpio_set_level(46, true);
121+
return true;
122+
}
123+
return false;
124+
}
125+
126+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
127+
128+
// TODO: Should we turn off the display when asleep, in board_deinit() ?
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 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+
27+
// Micropython setup
28+
29+
#define MICROPY_HW_BOARD_NAME "M5Stack Dial"
30+
#define MICROPY_HW_MCU_NAME "ESP32S3"
31+
32+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO21)
33+
34+
#define CIRCUITPY_BOARD_I2C (2)
35+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO12, .sda = &pin_GPIO11}, \
36+
{.scl = &pin_GPIO15, .sda = &pin_GPIO13}}
37+
38+
#define CIRCUITPY_BOARD_SPI (1)
39+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO6, .mosi = &pin_GPIO5}}
40+
41+
#define CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP (1)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
USB_VID = 0x303A
2+
USB_PID = 0x81DD
3+
4+
USB_PRODUCT = "M5stack - Dial"
5+
USB_MANUFACTURER = "M5Stack"
6+
7+
IDF_TARGET = esp32s3
8+
9+
CIRCUITPY_ESP_FLASH_MODE = qio
10+
CIRCUITPY_ESP_FLASH_FREQ = 80m
11+
CIRCUITPY_ESP_FLASH_SIZE = 8MB
12+
13+
CIRCUITPY_ESPCAMERA = 0
14+
CIRCUITPY_PARALLELDISPLAYBUS = 0
15+
16+
OPTIMIZATION_FLAGS = -Os
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "shared-module/displayio/__init__.h"
4+
5+
CIRCUITPY_BOARD_BUS_SINGLETON(porta_i2c, i2c, 1)
6+
7+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
8+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
9+
10+
// Port A
11+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO15) },
12+
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
13+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO13) },
14+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
15+
16+
// Port B
17+
{ MP_ROM_QSTR(MP_QSTR_PORTB_IN), MP_ROM_PTR(&pin_GPIO1) },
18+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
19+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO1) },
20+
{ MP_ROM_QSTR(MP_QSTR_PORTB_OUT), MP_ROM_PTR(&pin_GPIO2) },
21+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
22+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) },
23+
24+
// Encoder
25+
{ MP_ROM_QSTR(MP_QSTR_ENC_A), MP_ROM_PTR(&pin_GPIO41) },
26+
{ MP_ROM_QSTR(MP_QSTR_ENC_B), MP_ROM_PTR(&pin_GPIO40) },
27+
28+
// Button
29+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
30+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
31+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
32+
33+
// Mish
34+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO21) },
35+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_IRQ), MP_ROM_PTR(&pin_GPIO14) },
36+
{ MP_ROM_QSTR(MP_QSTR_RFID_IRQ), MP_ROM_PTR(&pin_GPIO10) },
37+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO3) },
38+
{ MP_ROM_QSTR(MP_QSTR_KNOB_BUTTON), MP_ROM_PTR(&pin_GPIO42) },
39+
{ MP_ROM_QSTR(MP_QSTR_POWER_HOLD), MP_ROM_PTR(&pin_GPIO46) },
40+
41+
// Display
42+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO6) },
43+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO5) },
44+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO7) },
45+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO4) },
46+
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO8) },
47+
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO9) },
48+
49+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
50+
{ MP_ROM_QSTR(MP_QSTR_PORTA_I2C), MP_ROM_PTR(&board_porta_i2c_obj) },
51+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
52+
53+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
54+
};
55+
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="m5stack-dial"
11+
# end of LWIP
12+
13+
# end of Component config
14+
15+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)