Skip to content

Commit 3de2c63

Browse files
committed
Added new board: M5Stack DinMeter (esp32s3)
1 parent a96f112 commit 3de2c63

File tree

5 files changed

+219
-0
lines changed

5 files changed

+219
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "mpconfigboard.h"
8+
#include "supervisor/board.h"
9+
#include "supervisor/shared/serial.h"
10+
#include "shared-bindings/busio/SPI.h"
11+
#include "shared-bindings/fourwire/FourWire.h"
12+
#include "shared-bindings/microcontroller/Pin.h"
13+
#include "shared-module/displayio/__init__.h"
14+
#include "shared-module/displayio/mipi_constants.h"
15+
#include "shared-bindings/board/__init__.h"
16+
#include "py/runtime.h"
17+
#include "py/ringbuf.h"
18+
#include "shared/runtime/interrupt_char.h"
19+
20+
21+
uint8_t display_init_sequence[] = {
22+
0x01, 0x80, 0x96, // SWRESET and Delay 150ms
23+
0x11, 0x80, 0xff, // SLPOUT and Delay
24+
0xb1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1
25+
0xb2, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR2
26+
0xb3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3
27+
0xb4, 0x01, 0x07, // _INVCTR line inversion
28+
0xc0, 0x03, 0xa2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
29+
0xc1, 0x01, 0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
30+
0xc2, 0x02, 0x0a, 0x00, // _PWCTR3 Opamp current small, Boost frequency
31+
0xc3, 0x02, 0x8a, 0x2a,
32+
0xc4, 0x02, 0x8a, 0xee,
33+
0xc5, 0x01, 0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
34+
0x36, 0x01, 0xc8, // MADCTL Rotate display
35+
0x21, 0x00, // _INVON
36+
0x3a, 0x01, 0x05, // COLMOD - 16bit color
37+
0xe0, 0x10, 0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
38+
0xe1, 0x10, 0x03, 0x1d, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1
39+
0x13, 0x80, 0x0a, // _NORON
40+
0x29, 0x80, 0x64 // _DISPON
41+
};
42+
43+
44+
// Overrides the weakly linked function from supervisor/shared/board.c
45+
void board_init(void) {
46+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
47+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
48+
bus->base.type = &fourwire_fourwire_type;
49+
50+
// see here for inspiration: https://github.com/m5stack/M5GFX/blob/33d7d3135e816a86a008fae8ab3757938cee95d2/src/M5GFX.cpp#L1350
51+
common_hal_fourwire_fourwire_construct(
52+
bus,
53+
spi,
54+
&pin_GPIO4, // DC
55+
&pin_GPIO7, // CS
56+
&pin_GPIO8, // RST
57+
40000000, // baudrate
58+
0, // polarity
59+
0 // phase
60+
);
61+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
62+
display->base.type = &busdisplay_busdisplay_type;
63+
64+
common_hal_busdisplay_busdisplay_construct(
65+
display,
66+
bus,
67+
240, // width (after rotation)
68+
135, // height (after rotation)
69+
40, // column start
70+
52, // row start
71+
0, // rotation
72+
16, // color depth
73+
false, // grayscale
74+
false, // pixels in a byte share a row. Only valid for depths < 8
75+
1, // bytes per cell. Only valid for depths < 8
76+
false, // reverse_pixels_in_byte. Only valid for depths < 8
77+
true, // reverse_pixels_in_word
78+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
79+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
80+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
81+
display_init_sequence,
82+
sizeof(display_init_sequence),
83+
&pin_GPIO9, // backlight pin
84+
NO_BRIGHTNESS_COMMAND,
85+
1.0f, // brightness
86+
false, // single_byte_bounds
87+
false, // data_as_commands
88+
true, // auto_refresh
89+
80, // native_frames_per_second
90+
true, // backlight_on_high
91+
false, // SH1107_addressing
92+
50000 // backlight pwm frequency
93+
);
94+
}
95+
96+
97+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
98+
// Hold pin must be set high to avoid a power off when battery powered
99+
if (pin_number == 46) {
100+
// Turn on hold output
101+
config_pin_as_output_with_level(pin_number, true);
102+
return true;
103+
}
104+
return false;
105+
}
106+
107+
// TODO: Should we turn off the display when asleep, in board_deinit() ?
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 CDarius
4+
// SPDX-FileCopyrightText: Copyright (c) 2025 juergenpabel
5+
//
6+
// SPDX-License-Identifier: MIT
7+
8+
#pragma once
9+
10+
// Micropython setup
11+
12+
#define MICROPY_HW_BOARD_NAME "M5Stack DinMeter"
13+
#define MICROPY_HW_MCU_NAME "ESP32S3"
14+
15+
#define CIRCUITPY_BOARD_I2C (2)
16+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO12, .sda = &pin_GPIO11}, \
17+
{.scl = &pin_GPIO15, .sda = &pin_GPIO13}}
18+
19+
#define CIRCUITPY_BOARD_SPI (1)
20+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO6, .mosi = &pin_GPIO5}}
21+
22+
#define CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP (1)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
USB_VID = 0x303A
2+
USB_PID = 0x81DD
3+
4+
USB_PRODUCT = "M5stack - DinMeter"
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+
# Very few pins.
14+
CIRCUITPY_ESPCAMERA = 0
15+
CIRCUITPY_PARALLELDISPLAYBUS = 0
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
// SPDX-FileCopyrightText: Copyright (c) 2025 Juergen Pabel
5+
//
6+
// SPDX-License-Identifier: MIT
7+
8+
#include "shared-bindings/board/__init__.h"
9+
10+
#include "shared-module/displayio/__init__.h"
11+
12+
CIRCUITPY_BOARD_BUS_SINGLETON(porta_i2c, i2c, 1)
13+
14+
static const mp_rom_map_elem_t board_module_globals_table[] = {
15+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
16+
17+
// Port A
18+
{ MP_ROM_QSTR(MP_QSTR_PORTA_SCL), MP_ROM_PTR(&pin_GPIO15) },
19+
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
20+
{ MP_ROM_QSTR(MP_QSTR_PORTA_SDA), MP_ROM_PTR(&pin_GPIO13) },
21+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
22+
23+
// Port B
24+
{ MP_ROM_QSTR(MP_QSTR_PORTB_IN), MP_ROM_PTR(&pin_GPIO1) },
25+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
26+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO1) },
27+
{ MP_ROM_QSTR(MP_QSTR_PORTB_OUT), MP_ROM_PTR(&pin_GPIO2) },
28+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
29+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) },
30+
31+
// Encoder
32+
{ MP_ROM_QSTR(MP_QSTR_ENC_A), MP_ROM_PTR(&pin_GPIO41) },
33+
{ MP_ROM_QSTR(MP_QSTR_ENC_B), MP_ROM_PTR(&pin_GPIO40) },
34+
35+
// Button
36+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
37+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
38+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
39+
40+
// Misc
41+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO11) },
42+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO12) },
43+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO3) },
44+
{ MP_ROM_QSTR(MP_QSTR_KNOB_BUTTON), MP_ROM_PTR(&pin_GPIO42) },
45+
{ MP_ROM_QSTR(MP_QSTR_POWER_HOLD), MP_ROM_PTR(&pin_GPIO46) },
46+
47+
// Display
48+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO6) },
49+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO5) },
50+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO7) },
51+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO4) },
52+
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO8) },
53+
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO9) },
54+
55+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
56+
{ MP_ROM_QSTR(MP_QSTR_PORTA_I2C), MP_ROM_PTR(&board_porta_i2c_obj) },
57+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
58+
59+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
60+
};
61+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
# Component config
6+
#
7+
#
8+
# LWIP
9+
#
10+
# end of LWIP
11+
12+
# end of Component config
13+
14+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)