Add M5Stack Dial board

This commit is contained in:
CDarius 2024-02-16 11:22:32 +01:00
parent 2e29772eb2
commit fe7d48edd0
5 changed files with 255 additions and 0 deletions

View file

@ -0,0 +1,128 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/fourwire/FourWire.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/board/__init__.h"
fourwire_fourwire_obj_t board_display_obj;
uint8_t display_init_sequence[] = {
0xFE, 0x00, // Inter Register Enable1 (FEh)
0xEF, 0x00, // Inter Register Enable2 (EFh)
0xB6, 0x02, 0x00, 0x00, // Display Function Control (B6h) [S1→S360 source, G1→G32 gate]
0x36, 0x01, 0x48, // Memory Access Control(36h) [Invert Row order, invert vertical scan order]
0x3a, 0x01, 0x55, // COLMOD: Pixel Format Set (3Ah) [16 bits / pixel]
0xC3, 0x01, 0x13, // Power Control 2 (C3h) [VREG1A = 5.06, VREG1B = 0.68]
0xC4, 0x01, 0x13, // Power Control 3 (C4h) [VREG2A = -3.7, VREG2B = 0.68]
0xC9, 0x01, 0x22, // Power Control 4 (C9h)
0xF0, 0x06, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2a, // SET_GAMMA1 (F0h)
0xF1, 0x06, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6f, // SET_GAMMA2 (F1h)
0xF2, 0x06, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2a, // SET_GAMMA3 (F2h)
0xF3, 0x06, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6f, // SET_GAMMA4 (F3h)
0x66, 0x0a, 0x3c, 0x00, 0xcd, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00,
0x67, 0x0a, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98,
0x74, 0x07, 0x10, 0x85, 0x80, 0x00, 0x00, 0x4e, 0x00,
0x98, 0x02, 0x3e, 0x07,
0x35, 0x00, // Tearing Effect Line ON (35h) [both V-blanking and H-blanking]
0x21, 0x00, // Display Inversion ON (21h)
0x11, 0x80, 0x78, // Sleep Out Mode (11h) and delay(120)
0x29, 0x80, 0x14, // Display ON (29h) and delay(20)
0x2a, 0x04, 0x00, 0x00, 0x00, 239, // Column Address Set (2Ah) [Start col = 0, end col = 239]
0x2b, 0x04, 0x00, 0x00, 0x00, 239, // Row Address Set (2Bh) [Start row = 0, end row = 239]
};
void board_init(void) {
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(
bus,
spi,
&pin_GPIO4, // DC
&pin_GPIO7, // CS
&pin_GPIO8, // RST
40000000, // baudrate
0, // polarity
0 // phase
);
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
display->base.type = &busdisplay_busdisplay_type;
common_hal_busdisplay_busdisplay_construct(
display,
bus,
240, // width (after rotation)
240, // height (after rotation)
0, // column start
0, // row start
0, // rotation
16, // color depth
false, // grayscale
false, // pixels in a byte share a row. Only valid for depths < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
display_init_sequence,
sizeof(display_init_sequence),
&pin_GPIO9, // backlight pin
NO_BRIGHTNESS_COMMAND,
0.8f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true, // backlight_on_high
false, // SH1107_addressing
50000 // backlight pwm frequency
);
}
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
// Hold pind must be set high to avoid a power off when battery powered
if (pin_number == 46) {
// Turn on hold output
gpio_set_direction(46, GPIO_MODE_DEF_OUTPUT);
gpio_set_level(46, true);
return true;
}
return false;
}
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
// TODO: Should we turn off the display when asleep, in board_deinit() ?

View file

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2024 CDarius
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// Micropython setup
#define MICROPY_HW_BOARD_NAME "M5Stack Dial"
#define MICROPY_HW_MCU_NAME "ESP32S3"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO21)
#define CIRCUITPY_BOARD_I2C (2)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO12, .sda = &pin_GPIO11}, \
{.scl = &pin_GPIO15, .sda = &pin_GPIO13}}
#define CIRCUITPY_BOARD_SPI (1)
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO6, .mosi = &pin_GPIO5}}
#define CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP (1)

View file

@ -0,0 +1,16 @@
USB_VID = 0x303A
USB_PID = 0x81DD
USB_PRODUCT = "M5stack - Dial"
USB_MANUFACTURER = "M5Stack"
IDF_TARGET = esp32s3
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 8MB
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0
OPTIMIZATION_FLAGS = -Os

View file

@ -0,0 +1,55 @@
#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"
CIRCUITPY_BOARD_BUS_SINGLETON(porta_i2c, i2c, 1)
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
// Port A
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
// Port B
{ MP_ROM_QSTR(MP_QSTR_PORTB_IN), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_PORTB_OUT), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) },
// Encoder
{ MP_ROM_QSTR(MP_QSTR_ENC_A), MP_ROM_PTR(&pin_GPIO41) },
{ MP_ROM_QSTR(MP_QSTR_ENC_B), MP_ROM_PTR(&pin_GPIO40) },
// Button
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
// Mish
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_IRQ), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_RFID_IRQ), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_KNOB_BUTTON), MP_ROM_PTR(&pin_GPIO42) },
{ MP_ROM_QSTR(MP_QSTR_POWER_HOLD), MP_ROM_PTR(&pin_GPIO46) },
// Display
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_PORTA_I2C), MP_ROM_PTR(&board_porta_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View file

@ -0,0 +1,15 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Component config
#
#
# LWIP
#
CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-dial"
# end of LWIP
# end of Component config
# end of Espressif IoT Development Framework Configuration