Skip to content

Commit 3b875b8

Browse files
committed
Add the M5Stack M5Stick C Plus2 board
1 parent af2c232 commit 3b875b8

File tree

5 files changed

+230
-0
lines changed

5 files changed

+230
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2023 n0xa, 2025 bootc
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
#include "mpconfigboard.h"
9+
#include "shared-bindings/busio/SPI.h"
10+
#include "shared-bindings/busio/I2C.h"
11+
#include "shared-bindings/fourwire/FourWire.h"
12+
#include "shared-module/displayio/__init__.h"
13+
#include "shared-module/displayio/mipi_constants.h"
14+
#include "shared-bindings/board/__init__.h"
15+
#include "shared-bindings/microcontroller/Pin.h"
16+
#include "driver/gpio.h"
17+
#include "common-hal/microcontroller/Pin.h"
18+
19+
// display init sequence according to adafruit_st7735r.py library
20+
uint8_t display_init_sequence[] = {
21+
0x01, 0x80, 0x96, // SWRESET and Delay 150ms
22+
0x11, 0x80, 0xff, // SLPOUT and Delay
23+
0xb1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1
24+
0xb2, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR2
25+
0xb3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3
26+
0xb4, 0x01, 0x07, // _INVCTR line inversion
27+
0xc0, 0x03, 0xa2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
28+
0xc1, 0x01, 0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
29+
0xc2, 0x02, 0x0a, 0x00, // _PWCTR3 Opamp current small, Boost frequency
30+
0xc3, 0x02, 0x8a, 0x2a,
31+
0xc4, 0x02, 0x8a, 0xee,
32+
0xc5, 0x01, 0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
33+
0x36, 0x01, 0xc8, // MADCTL Rotate display
34+
0x21, 0x00, // _INVON
35+
0x3a, 0x01, 0x05, // COLMOD - 16bit color
36+
0xe0, 0x10, 0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
37+
0xe1, 0x10, 0x03, 0x1d, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1
38+
0x13, 0x80, 0x0a, // _NORON
39+
0x29, 0x80, 0x64 // _DISPON
40+
};
41+
42+
static void display_init(void) {
43+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
44+
busio_spi_obj_t *spi = &bus->inline_bus;
45+
common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false);
46+
common_hal_busio_spi_never_reset(spi);
47+
48+
bus->base.type = &fourwire_fourwire_type;
49+
50+
common_hal_fourwire_fourwire_construct(
51+
bus,
52+
spi,
53+
&pin_GPIO14, // DC
54+
&pin_GPIO5, // CS
55+
&pin_GPIO12, // RST
56+
10000000, // baudrate
57+
0, // polarity
58+
0 // phase
59+
);
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+
135, // width (after rotation)
68+
240, // height (after rotation)
69+
40, // column start
70+
52, // row start
71+
1, // 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_GPIO27, // 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+
60, // native_frames_per_second
90+
true, // backlight_on_high
91+
false, // SH1107_addressing
92+
50000 // backlight pwm frequency
93+
);
94+
}
95+
96+
void board_init(void) {
97+
display_init();
98+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2023 n0xa, 2025 bootc
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Micropython setup
10+
11+
#define MICROPY_HW_BOARD_NAME "M5Stack Stick C Plus2"
12+
#define MICROPY_HW_MCU_NAME "ESP32"
13+
14+
#define MICROPY_HW_LED_STATUS (&pin_GPIO19)
15+
16+
#define CIRCUITPY_BOARD_I2C (2)
17+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}, \
18+
{.scl = &pin_GPIO33, .sda = &pin_GPIO32}}
19+
20+
// For entering safe mode
21+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO37)
22+
23+
// Explanation of how a user got into safe mode
24+
#define BOARD_USER_SAFE_MODE_ACTION MP_ERROR_TEXT("You pressed button A at start up.")
25+
26+
// UART pins attached to the USB-serial converter chip
27+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
28+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CIRCUITPY_CREATOR_ID = 0x10151015
2+
CIRCUITPY_CREATION_ID = 0x0032000C
3+
4+
IDF_TARGET = esp32
5+
6+
CIRCUITPY_ESP_FLASH_MODE = qio
7+
CIRCUITPY_ESP_FLASH_FREQ = 80m
8+
CIRCUITPY_ESP_FLASH_SIZE = 8MB
9+
10+
CIRCUITPY_ESP_PSRAM_MODE = qio
11+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
12+
CIRCUITPY_ESP_PSRAM_SIZE = 2MB
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2023 n0xa, 2025 bootc
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/board/__init__.h"
8+
#include "shared-module/displayio/__init__.h"
9+
10+
CIRCUITPY_BOARD_BUS_SINGLETON(grove_i2c, i2c, 1)
11+
12+
static const mp_rom_map_elem_t board_module_globals_table[] = {
13+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
14+
15+
// Pin port on the top
16+
{ MP_ROM_QSTR(MP_QSTR_G26), MP_ROM_PTR(&pin_GPIO26) },
17+
{ MP_ROM_QSTR(MP_QSTR_G36), MP_ROM_PTR(&pin_GPIO36) }, // G36/G25 pin
18+
{ MP_ROM_QSTR(MP_QSTR_G25), MP_ROM_PTR(&pin_GPIO25) }, // G36/G25 pin
19+
{ MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_GPIO0) }, // also PDM_MIC_CLK
20+
21+
// Grove port on the bottom
22+
{ MP_ROM_QSTR(MP_QSTR_G32), MP_ROM_PTR(&pin_GPIO32) },
23+
{ MP_ROM_QSTR(MP_QSTR_GROVE_SDA), MP_ROM_PTR(&pin_GPIO32) },
24+
{ MP_ROM_QSTR(MP_QSTR_G33), MP_ROM_PTR(&pin_GPIO33) },
25+
{ MP_ROM_QSTR(MP_QSTR_GROVE_SCL), MP_ROM_PTR(&pin_GPIO33) },
26+
{ MP_ROM_QSTR(MP_QSTR_GROVE_I2C), MP_ROM_PTR(&board_grove_i2c_obj) },
27+
28+
// Buttons
29+
{ MP_ROM_QSTR(MP_QSTR_G37), MP_ROM_PTR(&pin_GPIO37) },
30+
{ MP_ROM_QSTR(MP_QSTR_BTN_A), MP_ROM_PTR(&pin_GPIO37) },
31+
{ MP_ROM_QSTR(MP_QSTR_G39), MP_ROM_PTR(&pin_GPIO39) },
32+
{ MP_ROM_QSTR(MP_QSTR_BTN_B), MP_ROM_PTR(&pin_GPIO39) },
33+
{ MP_ROM_QSTR(MP_QSTR_G35), MP_ROM_PTR(&pin_GPIO35) },
34+
{ MP_ROM_QSTR(MP_QSTR_BTN_C), MP_ROM_PTR(&pin_GPIO35) },
35+
{ MP_ROM_QSTR(MP_QSTR_BTN_PWR), MP_ROM_PTR(&pin_GPIO35) }, // also WAKE
36+
37+
// Buzzer / Speaker
38+
{ MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_GPIO2) },
39+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO2) },
40+
41+
// Red and IR LED (single pin)
42+
{ MP_ROM_QSTR(MP_QSTR_G19), MP_ROM_PTR(&pin_GPIO19) },
43+
{ MP_ROM_QSTR(MP_QSTR_IR_LED), MP_ROM_PTR(&pin_GPIO19) },
44+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO19) },
45+
46+
// LCD display
47+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO15) },
48+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO13) },
49+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO14) },
50+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO12) },
51+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO5) },
52+
{ MP_ROM_QSTR(MP_QSTR_LCD_BL), MP_ROM_PTR(&pin_GPIO27) },
53+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
54+
55+
// Battery voltage sense
56+
{ MP_ROM_QSTR(MP_QSTR_G38), MP_ROM_PTR(&pin_GPIO38) },
57+
{ MP_ROM_QSTR(MP_QSTR_BAT_ADC), MP_ROM_PTR(&pin_GPIO38) },
58+
59+
// Microphone
60+
{ MP_ROM_QSTR(MP_QSTR_PDM_MIC_CLK), MP_ROM_PTR(&pin_GPIO0) },
61+
{ MP_ROM_QSTR(MP_QSTR_G34), MP_ROM_PTR(&pin_GPIO34) },
62+
{ MP_ROM_QSTR(MP_QSTR_PDM_MIC_DATA), MP_ROM_PTR(&pin_GPIO34) },
63+
64+
// Internal I2C (IMU and RTC)
65+
{ MP_ROM_QSTR(MP_QSTR_G21), MP_ROM_PTR(&pin_GPIO21) },
66+
{ MP_ROM_QSTR(MP_QSTR_SYS_SDA), MP_ROM_PTR(&pin_GPIO21) },
67+
{ MP_ROM_QSTR(MP_QSTR_G22), MP_ROM_PTR(&pin_GPIO22) },
68+
{ MP_ROM_QSTR(MP_QSTR_SYS_SCL), MP_ROM_PTR(&pin_GPIO22) },
69+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
70+
71+
// Sleep/Wake signal
72+
{ MP_ROM_QSTR(MP_QSTR_WAKE), MP_ROM_PTR(&pin_GPIO35) },
73+
74+
// Power hold
75+
{ MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_GPIO4) },
76+
{ MP_ROM_QSTR(MP_QSTR_HOLD), MP_ROM_PTR(&pin_GPIO4) },
77+
};
78+
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)