Skip to content

Commit beab76c

Browse files
committed
Added M5Stack Core Fire board
1 parent edce717 commit beab76c

File tree

4 files changed

+247
-0
lines changed

4 files changed

+247
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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/displayio/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+
displayio_fourwire_obj_t board_display_obj;
37+
38+
39+
// display init sequence according to M5Gfx
40+
uint8_t display_init_sequence[] = {
41+
0x01,0x80,0x80, // Software reset then delay 0x80 (128ms)
42+
0xC8,0x03,0xFF,0x93,0x42, // Turn on the external command
43+
0xC0,0x02,0x12, 0x12, // Power Control 1
44+
0xC1,0x01,0x03, // Power Control 2
45+
0xC5,0x01,0xF2, // VCOM Control 1
46+
0xB0,0x01,0xE0, // RGB Interface SYNC Mode
47+
0xF6,0x03,0x01, 0x00, 0x00, // Interface control
48+
0XE0,0x0F,0x00,0x0C,0x11,0x04,0x11,0x08,0x37,0x89,0x4C,0x06,0x0C,0x0A,0x2E,0x34,0x0F, // Positive Gamma Correction
49+
0xE1,0x0F,0x00,0x0B,0x11,0x05,0x13,0x09,0x33,0x67,0x48,0x07,0x0E,0x0B,0x2E,0x33,0x0F, // Negative Gamma Correction
50+
0xB6,0x04,0x08,0x82,0x1D,0x04, // Display Function Control
51+
0x3A,0x01,0x55, // COLMOD: Pixel Format Set 16 bit
52+
0x21,0x00, // Display inversion ON
53+
0x36,0x01,0x08, // Memory Access Control: RGB order
54+
0x11,0x80,0x78, // Exit Sleep then delay 0x78 (120ms)
55+
0x29,0x80,0x78, // Display on then delay 0x78 (120ms)
56+
};
57+
58+
void board_init(void) {
59+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
60+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
61+
bus->base.type = &displayio_fourwire_type;
62+
63+
common_hal_displayio_fourwire_construct(
64+
bus,
65+
spi,
66+
&pin_GPIO27, // DC
67+
&pin_GPIO14, // CS
68+
&pin_GPIO33, // RST
69+
40000000, // baudrate
70+
0, // polarity
71+
0 // phase
72+
);
73+
74+
displayio_display_obj_t *display = &displays[0].display;
75+
display->base.type = &displayio_display_type;
76+
77+
common_hal_displayio_display_construct(
78+
display,
79+
bus,
80+
320, // width (after rotation)
81+
240, // height (after rotation)
82+
0, // column start
83+
0, // row start
84+
0, // rotation
85+
16, // color depth
86+
false, // grayscale
87+
false, // pixels in a byte share a row. Only valid for depths < 8
88+
1, // bytes per cell. Only valid for depths < 8
89+
false, // reverse_pixels_in_byte. Only valid for depths < 8
90+
true, // reverse_pixels_in_word
91+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
92+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
93+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
94+
display_init_sequence,
95+
sizeof(display_init_sequence),
96+
&pin_GPIO32, // backlight pin
97+
NO_BRIGHTNESS_COMMAND,
98+
1.0f, // brightness
99+
false, // single_byte_bounds
100+
false, // data_as_commands
101+
true, // auto_refresh
102+
61, // native_frames_per_second
103+
true, // backlight_on_high
104+
false, // SH1107_addressing
105+
50000 // backlight pwm frequency
106+
);
107+
108+
}
109+
110+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
111+
// Set speaker gpio to ground to prevent noise from the speaker
112+
if (pin_number == 25) {
113+
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
114+
gpio_set_level(pin_number, false);
115+
return true;
116+
}
117+
return false;
118+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Dan Halbert 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+
// Micropython setup
28+
29+
#define MICROPY_HW_BOARD_NAME "M5Stack Core Fire"
30+
#define MICROPY_HW_MCU_NAME "ESP32"
31+
32+
#define CIRCUITPY_BOARD_I2C (1)
33+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}}
34+
35+
#define CIRCUITPY_BOARD_SPI (1)
36+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO19}}
37+
38+
#define CIRCUITPY_BOARD_UART (1)
39+
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO17, .rx = &pin_GPIO16}}
40+
41+
// UART pins attached to the USB-serial converter chip
42+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
43+
#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 = 0x00320001
3+
4+
IDF_TARGET = esp32
5+
6+
# The default queue depth of 16 overflows on release builds,
7+
# so increase it to 32.
8+
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
9+
10+
CIRCUITPY_ESP_FLASH_MODE = qio
11+
CIRCUITPY_ESP_FLASH_FREQ = 80m
12+
CIRCUITPY_ESP_FLASH_SIZE = 16MB
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
// External pins are in silkscreen order, from top to bottom, left side, then right side
8+
9+
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) },
10+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
11+
12+
{ MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_GPIO16) },
13+
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) },
14+
15+
{ MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_GPIO17) },
16+
{ MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) },
17+
18+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO2) },
19+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
20+
21+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) },
22+
23+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO25) },
24+
{ MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) },
25+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO25) },
26+
27+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO26) },
28+
{ MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) },
29+
30+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO35) },
31+
{ MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35) },
32+
33+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO36) },
34+
{ MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO36) },
35+
36+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO21) },
37+
{ MP_ROM_QSTR(MP_QSTR_PORTA_SDA), MP_ROM_PTR(&pin_GPIO21) },
38+
{ MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) },
39+
40+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) },
41+
{ MP_ROM_QSTR(MP_QSTR_PORTA_SCL), MP_ROM_PTR(&pin_GPIO22) },
42+
{ MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) },
43+
44+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO23) },
45+
{ MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO23) },
46+
47+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO19) },
48+
{ MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) },
51+
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) },
52+
53+
54+
// buttons
55+
{ MP_ROM_QSTR(MP_QSTR_BTN_A), MP_ROM_PTR(&pin_GPIO39) },
56+
{ MP_ROM_QSTR(MP_QSTR_BTN_B), MP_ROM_PTR(&pin_GPIO38) },
57+
{ MP_ROM_QSTR(MP_QSTR_BTN_C), MP_ROM_PTR(&pin_GPIO37) },
58+
59+
// sd card
60+
{ MP_ROM_QSTR(MP_QSTR_SD_CS),MP_ROM_PTR(&pin_GPIO4) },
61+
62+
// tft
63+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO14) },
64+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO27) },
65+
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO33) },
66+
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO32) },
67+
68+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
69+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
70+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
71+
72+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
73+
};
74+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)