Add M5Stack Core2

This commit is contained in:
CDario 2023-04-11 12:29:43 +00:00
parent 06aa426e76
commit 88644613b5
6 changed files with 1107 additions and 0 deletions

View File

@ -0,0 +1,286 @@
/*
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Stephen Oliver
* Copyright (c) 2023 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.
*/
#ifndef MICROPY_AXP192_H
#define MICROPY_AXP192_H
#define AXP192_I2C_ADDRESS 0x34
#define AXP192_INPUT_POWER_STATE 0x00
#define AXP192_INPUT_POWER_STATE_ACIN_IS_PRESENT 0b10000000
#define AXP192_INPUT_POWER_STATE_ACIN_AVAILABLE 0b01000000
#define AXP192_INPUT_POWER_STATE_VBUS_IS_PRESENT 0b00100000
#define AXP192_INPUT_POWER_STATE_VBUS_AVAILABLE 0b00010000
#define AXP192_INPUT_POWER_STATE_VBUS_GREATER_VHOLD_BEFORE_USE 0b00001000
#define AXP192_INPUT_POWER_STATE_BATT_CURRENT_DIR_IS_CHARGING 0b00000100
#define AXP192_INPUT_POWER_STATE_ACIN_VBUS_PCB_SHORTED 0b00000010
#define AXP192_INPUT_POWER_STATE_BOOT_SOURCE_ACIN_OR_VBUS 0b00000001
#define AXP192_EXTEN_DCDC2_CTRL 0x10
#define AXP192_EXTEN_DCDC2_CTRL_EXTEN 0b00000100
#define AXP192_EXTEN_DCDC2_CTRL_DCDC2 0b00000001
#define AXP192_DCDC13_LDO23_CTRL 0x12
#define AXP192_DCDC13_LDO23_CTRL_EXTEN 0b01000000
#define AXP192_DCDC13_LDO23_CTRL_LDO3 0b00001000
#define AXP192_DCDC13_LDO23_CTRL_LDO2 0b00000100
#define AXP192_DCDC13_LDO23_CTRL_DCDC3 0b00000010
#define AXP192_DCDC13_LDO23_CTRL_DCDC1 0b00000001
#define AXP192_DCDC2_OUT_VOLTAGE 0x25
#define AXP192_DCDC1_OUT_VOLTAGE 0x26
#define AXP192_DCDC1_OUT_VOLTAGE_3_350V 0b01101010
#define AXP192_DCDC3_OUT_VOLTAGE 0x27
#define AXP192_DCDC3_OUT_VOLTAGE_3_0V 0b01011100
#define AXP192_LDO23_OUT_VOLTAGE 0x28
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_3_3V 0b11110000
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_3_0V 0b11000000
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V 0b10100000
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_MASK 0b11110000
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_3_0V 0b00001100
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_2_8V 0b00001010
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_1_8V 0b00000000
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_MASK 0b00001111
#define AXP192_VBUS_IPSOUT 0x30
#define AXP192_VBUS_IPSOUT_IGNORE_VBUSEN 0b10000000
#define AXP192_VBUS_IPSOUT_VHOLD_LIMIT 0b01000000
#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_4_4V 0b00100000
#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_MASK 0b00111000
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT 0b00000010
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_100mA 0b00000001
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA 0b00000000
#define AXP192_POWER_OFF_VOLTAGE 0x31
#define AXP192_POWER_OFF_VOLTAGE_2_6V 0b0000
#define AXP192_POWER_OFF_VOLTAGE_2_7V 0b0001
#define AXP192_POWER_OFF_VOLTAGE_2_8V 0b0010
#define AXP192_POWER_OFF_VOLTAGE_2_9V 0b0011
#define AXP192_POWER_OFF_VOLTAGE_3_0V 0b0100
#define AXP192_POWER_OFF_VOLTAGE_3_1V 0b0101
#define AXP192_POWER_OFF_VOLTAGE_3_2V 0b0110
#define AXP192_POWER_OFF_VOLTAGE_3_3V 0b0111
#define AXP192_POWER_OFF_VOLTAGE_MASK 0b0111
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL 0x32
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_OFF 0b10000000
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON 0b01000000
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_3_0S 0b00000011
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S 0b00000010
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_1_0S 0b00000001
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_0_5S 0b00000000
#define AXP192_CHARGING_CTRL1 0x33
#define AXP192_CHARGING_CTRL1_ENABLE 0b10000000
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_36V 0b01100000
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_20V 0b01000000
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_15V 0b00100000
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_10V 0b00000000
#define AXP192_CHARGING_CTRL1_VOLTAGE_MASK 0b01100000
#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_15PERC 0b00010000
#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC 0b00000000
#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_MASK 0b00010000
#define AXP192_CHARGING_CTRL1_CURRENT_100mA 0b00000000
#define AXP192_CHARGING_CTRL1_CURRENT_190mA 0b00000001
#define AXP192_CHARGING_CTRL1_CURRENT_280mA 0b00000010
#define AXP192_CHARGING_CTRL1_CURRENT_360mA 0b00000011
#define AXP192_CHARGING_CTRL1_CURRENT_450mA 0b00000100
#define AXP192_CHARGING_CTRL1_CURRENT_550mA 0b00000101
#define AXP192_CHARGING_CTRL1_CURRENT_630mA 0b00000110
#define AXP192_CHARGING_CTRL1_CURRENT_700mA 0b00000111
#define AXP192_CHARGING_CTRL1_CURRENT_780mA 0b00001000
#define AXP192_CHARGING_CTRL1_CURRENT_880mA 0b00001001
#define AXP192_CHARGING_CTRL1_CURRENT_960mA 0b00001010
#define AXP192_CHARGING_CTRL1_CURRENT_1000mA 0b00001011
#define AXP192_CHARGING_CTRL1_CURRENT_MASK 0b00001111
#define AXP192_CHARGING_CTRL2 0x34
#define AXP192_BACKUP_BATT 0x35
#define AXP192_BACKUP_BATT_CHARGING_ENABLE 0b10000000
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_2_5V 0b01100000
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V 0b00100000
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_1V 0b00000000
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_MASK 0b01100000
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_400uA 0b00000011
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA 0b00000010
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_100uA 0b00000001
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_50uA 0b00000000
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_MASK 0b00000011
#define AXP192_PEK 0x36
#define AXP192_PEK_SHORT_PRESS_1S 0b11000000
#define AXP192_PEK_SHORT_PRESS_512mS 0b10000000
#define AXP192_PEK_SHORT_PRESS_256mS 0b01000000
#define AXP192_PEK_SHORT_PRESS_128mS 0b00000000
#define AXP192_PEK_SHORT_PRESS_MASK 0b11000000
#define AXP192_PEK_LONG_PRESS_2_5S 0b00110000
#define AXP192_PEK_LONG_PRESS_2_0S 0b00100000
#define AXP192_PEK_LONG_PRESS_1_5S 0b00010000
#define AXP192_PEK_LONG_PRESS_1_0S 0b00000000
#define AXP192_PEK_LONG_PRESS_MASK 0b00110000
#define AXP192_PEK_LONG_PRESS_POWER_OFF 0b00001000
#define AXP192_PEK_PWROK_DELAY_64mS 0b00000100
#define AXP192_PEK_PWROK_DELAY_32mS 0b00000000
#define AXP192_PEK_PWROK_DELAY_MASK 0b00000100
#define AXP192_PEK_POWER_OFF_TIME_12S 0b00000011
#define AXP192_PEK_POWER_OFF_TIME_8S 0b00000010
#define AXP192_PEK_POWER_OFF_TIME_6S 0b00000001
#define AXP192_PEK_POWER_OFF_TIME_4S 0b00000000
#define AXP192_PEK_POWER_OFF_TIME_MASK 0b00000011
#define AXP192_BATT_TEMP_LOW_THRESH 0x38
#define AXP192_BATT_TEMP_HIGH_THRESH 0x39
#define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100
#define AXP192_APS_LOW_BATT_LEVEL_1 0x3A
#define AXP192_APS_LOW_BATT_LEVEL_2 0x3B
#define AXP192_APS_LOW_BATT_VOLTAGE_3_695V 0b10010100
#define AXP192_APS_LOW_BATT_VOLTAGE_3_600V 0b10000011
#define AXP192_IRQ_1_ENABLE 0x40
#define AXP192_IRQ_2_ENABLE 0x41
#define AXP192_IRQ_3_ENABLE 0x42
#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
#define AXP192_IRQ_4_ENABLE 0x43
#define AXP192_IRQ_4_LOW_VOLTAGE_WARNING 0b00000001
#define AXP192_IRQ_5_ENABLE 0x4a
#define AXP192_IRQ_X_DISABLE_ALL 0b00000000
#define AXP192_IRQ_1_STATUS 0x44
#define AXP192_IRQ_2_STATUS 0x45
#define AXP192_IRQ_3_STATUS 0x46
#define AXP192_IRQ_4_STATUS 0x47
#define AXP192_IRQ_5_STATUS 0x4d
#define AXP192_IRQ_X_CLEAR_STATUS 0b11111111
#define AXP192_ADC_ACIN_VOLTAGE_H 0x56
#define AXP192_ADC_ACIN_VOLTAGE_L 0x57
#define AXP192_ADC_ACIN_CURRENT_H 0x58
#define AXP192_ADC_ACIN_CURRENT_L 0x59
#define AXP192_ADC_VBUS_VOLTAGE_H 0x5a
#define AXP192_ADC_VBUS_VOLTAGE_L 0x5b
#define AXP192_ADC_VBUS_CURRENT_H 0x5c
#define AXP192_ADC_VBUS_CURRENT_L 0x5d
#define AXP192_ADC_INTERNAL_TEMP_H 0x5e
#define AXP192_ADC_INTERNAL_TEMP_L 0x5f
#define AXP192_ADC_BATT_VOLTAGE_H 0x78
#define AXP192_ADC_BATT_VOLTAGE_L 0x79
#define AXP192_ADC_BATT_POWER_H 0x70
#define AXP192_ADC_BATT_POWER_M 0x71
#define AXP192_ADC_BATT_POWER_L 0x72
#define AXP192_ADC_BATT_CHARGE_CURRENT_H 0x7a
#define AXP192_ADC_BATT_CHARGE_CURRENT_L 0x7b
#define AXP192_ADC_BATT_DISCHARGE_CURRENT_H 0x7c
#define AXP192_ADC_BATT_DISCHARGE_CURRENT_L 0x7d
#define AXP192_ADC_APS_VOLTAGE_H 0x7e
#define AXP192_ADC_APS_VOLTAGE_L 0x7f
#define AXP192_ADC_ENABLE_1 0x82
#define AXP192_ADC_ENABLE_1_BATT_VOL 0b10000000
#define AXP192_ADC_ENABLE_1_BATT_CUR 0b01000000
#define AXP192_ADC_ENABLE_1_ACIN_VOL 0b00100000
#define AXP192_ADC_ENABLE_1_ACIN_CUR 0b00010000
#define AXP192_ADC_ENABLE_1_VBUS_VOL 0b00001000
#define AXP192_ADC_ENABLE_1_VBUS_CUR 0b00000100
#define AXP192_ADC_ENABLE_1_APS_VOL 0b00000010
#define AXP192_ADC_ENABLE_1_TS_PIN 0b00000001
#define AXP192_ADC_ENABLE_2 0x83
#define AXP192_ADC_ENABLE_2_TEMP_MON 0b10000000
#define AXP192_ADC_ENABLE_2_GPIO0 0b00001000
#define AXP192_ADC_ENABLE_2_GPIO1 0b00000100
#define AXP192_ADC_ENABLE_2_GPIO2 0b00000010
#define AXP192_ADC_ENABLE_2_GPIO3 0b00000001
#define AXP192_ADC_TS 0x84
#define AXP192_ADC_TS_SAMPLE_200HZ 0b11000000
#define AXP192_ADC_TS_SAMPLE_100HZ 0b10000000
#define AXP192_ADC_TS_SAMPLE_50HZ 0b01000000
#define AXP192_ADC_TS_SAMPLE_25HZ 0b00000000
#define AXP192_ADC_TS_SAMPLE_MASK 0b11000000
#define AXP192_ADC_TS_OUT_CUR_80uA 0b00110000
#define AXP192_ADC_TS_OUT_CUR_60uA 0b00100000
#define AXP192_ADC_TS_OUT_CUR_40uA 0b00010000
#define AXP192_ADC_TS_OUT_CUR_20uA 0b00000000
#define AXP192_ADC_TS_OUT_CUR_MASK 0b00110000
#define AXP192_ADC_TS_PIN_TEMP_MON 0b00000000
#define AXP192_ADC_TS_PIN_EXTERN_ADC 0b00000100
#define AXP192_ADC_TS_PIN_OUT_ALWAYS 0b00000011
#define AXP192_ADC_TS_PIN_OUT_SAVE_ENG 0b00000010
#define AXP192_ADC_TS_PIN_OUT_CHG 0b00000001
#define AXP192_ADC_TS_PIN_OUT_DIS 0b00000000
#define AXP192_ADC_TS_PIN_OUT_MASK 0b00000011
#define AXP192_GPIO0_FUNCTION 0x90
#define AXP192_GPIO0_FUNCTION_MASK 0b00000111
#define AXP192_GPIO0_FUNCTION_FLOATING 0b00000111
#define AXP192_GPIO0_FUNCTION_LOW_OUTPUT 0b00000101
#define AXP192_GPIO0_FUNCTION_ADC_INPUT 0b00000100
#define AXP192_GPIO0_FUNCTION_LDO_OUTPUT 0b00000010
#define AXP192_GPIO0_FUNCTION_GENERAL_INPUT 0b00000001
#define AXP192_GPIO0_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
#define AXP192_GPIO0_LDO_VOLTAGE 0x91
#define AXP192_GPIO0_LDO_VOLTAGE_MASK 0b11110000
#define AXP192_GPIO0_LDO_VOLTAGE_3_3V 0b11110000
#define AXP192_GPIO0_LDO_VOLTAGE_2_8V 0b10100000
#define AXP192_GPIO0_LDO_VOLTAGE_1_8V 0b00000000
#define AXP192_GPIO1_FUNCTION 0x92
#define AXP192_GPIO1_FUNCTION_FLOATING 0b00000111
#define AXP192_GPIO1_FUNCTION_LOW_OUTPUT 0b00000101
#define AXP192_GPIO1_FUNCTION_ADC_INPUT 0b00000100
#define AXP192_GPIO1_FUNCTION_PWM1_OUTPUT 0b00000010
#define AXP192_GPIO1_FUNCTION_GENERAL_INPUT 0b00000001
#define AXP192_GPIO1_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
#define AXP192_GPIO2_FUNCTION 0x93
#define AXP192_GPIO2_FUNCTION_FLOATING 0b00000111
#define AXP192_GPIO2_FUNCTION_LOW_OUTPUT 0b00000101
#define AXP192_GPIO2_FUNCTION_ADC_INPUT 0b00000100
#define AXP192_GPIO2_FUNCTION_PWM2_OUTPUT 0b00000010
#define AXP192_GPIO2_FUNCTION_GENERAL_INPUT 0b00000001
#define AXP192_GPIO2_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
#define AXP192_PWM1_OUTPUT_FREQUECY 0x98
#define AXP192_PWM1_DUTY_RATIO_Y1 0x99
#define AXP192_PWM1_DUTY_RATIO_Y2 0x9A
#endif

View File

@ -0,0 +1,632 @@
/*
*
* The MIT License (MIT)
*
* Copyright (c) 2023 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.
*/
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/busio/I2C.h"
#include "shared-bindings/displayio/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"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"
#include "axp192.h"
displayio_fourwire_obj_t board_display_obj;
#define DELAY 0x80
#define PMIC_POWER_SOURCE_USB 0
#define PMIC_POWER_SOURCE_M_BUS 1
// display init sequence according to M5Gfx
uint8_t display_init_sequence[] = {
0x01,DELAY,0x80, // Software reset then delay 0x80 (128ms)
0xC8,0x03,0xFF,0x93,0x42, // Turn on the external command
0xC0,0x02,0x12, 0x12, // Power Control 1
0xC1,0x01,0x03, // Power Control 2
0xC5,0x01,0xF2, // VCOM Control 1
0xB0,0x01,0xE0, // RGB Interface SYNC Mode
0xF6,0x03,0x01, 0x00, 0x00, // Interface control
0XE0,0x0F,0x00,0x0C,0x11,0x04,0x11,0x08,0x37,0x89,0x4C,0x06,0x0C,0x0A,0x2E,0x34,0x0F, // Positive Gamma Correction
0xE1,0x0F,0x00,0x0B,0x11,0x05,0x13,0x09,0x33,0x67,0x48,0x07,0x0E,0x0B,0x2E,0x33,0x0F, // Negative Gamma Correction
0xB6,0x04,0x08,0x82,0x1D,0x04, // Display Function Control
0x3A,0x01,0x55, // COLMOD: Pixel Format Set 16 bit
0x21,0x00, // Display inversion ON
0x36,0x01,0x08, // Memory Access Control: RGB order
0x11,DELAY,0x78, // Exit Sleep then delay 0x78 (120ms)
0x29,DELAY,0x78, // Display on then delay 0x78 (120ms)
};
static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) {
int rc;
uint8_t read_buf[1];
uint8_t write_buf[2];
switch (source)
{
case PMIC_POWER_SOURCE_USB:
// Set GPIO to 3.3V (when LDO OUTPUT mode is active)
write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_LDO_VOLTAGE_MASK) | AXP192_GPIO0_LDO_VOLTAGE_3_3V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Set GPIO0 to LDO_OUTPUT to set N_VBUSEN high
// When N_VBUSEN is high IPSOUT do not select VBUS as source (BUS_5V)
write_buf[0] = AXP192_GPIO0_FUNCTION;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_LDO_OUTPUT;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
#if M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT
// Set EXTENT output high to enable 5V power boost
write_buf[0] = AXP192_EXTEN_DCDC2_CTRL;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = read_buf[0] | AXP192_EXTEN_DCDC2_CTRL_EXTEN;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
#endif
// Enable VBUS-IPSOUT when N_VBUSEN is high
write_buf[0] = AXP192_VBUS_IPSOUT;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = read_buf[0] & ~AXP192_VBUS_IPSOUT_IGNORE_VBUSEN;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
return true;
case PMIC_POWER_SOURCE_M_BUS:
// Enable VBUS-IPSOUT regardless of f N_VBUSEN
write_buf[0] = AXP192_VBUS_IPSOUT;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = read_buf[0] | AXP192_VBUS_IPSOUT_IGNORE_VBUSEN;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Set EXTENT output low to disable 5V power boost
write_buf[0] = AXP192_EXTEN_DCDC2_CTRL;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = read_buf[0] & ~AXP192_EXTEN_DCDC2_CTRL_EXTEN;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Set GPIO0 to float and the pull down resistor set N_VBUSEN low
// When N_VBUSEN is low IPSOUT select VBUS as source (BUS_5V)
write_buf[0] = AXP192_GPIO0_FUNCTION;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_FLOATING;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
return true;
default:
return false;
}
}
static bool pmic_disable_all_irq(busio_i2c_obj_t *i2c) {
int rc;
// uint8_t read_buf[1];
uint8_t write_buf[2];
// Reg: 40h
// IRQ enable control register 1
write_buf[0] = AXP192_IRQ_1_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 41h
// IRQ enable control register 2
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 42h
// IRQ enable control register 3
// Enable power on key short and long press interrupt
write_buf[0] = AXP192_IRQ_3_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 43h
// IRQ enable control register 4
// Enable power on key short and long press interrupt
write_buf[0] = AXP192_IRQ_4_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 4Ah
// IRQ enable control register 5
write_buf[0] = AXP192_IRQ_5_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
return true;
}
static bool pmic_clear_all_irq(busio_i2c_obj_t *i2c) {
int rc;
// uint8_t read_buf[1];
uint8_t write_buf[2];
// Reg: 44h
// IRQ enable control register 1
write_buf[0] = AXP192_IRQ_1_STATUS;
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 45h
// IRQ enable control register 2
write_buf[0] = AXP192_IRQ_2_STATUS;
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 46h
// IRQ enable control register 3
write_buf[0] = AXP192_IRQ_3_STATUS;
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 47h
// IRQ enable control register 4
write_buf[0] = AXP192_IRQ_4_STATUS;
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 4Ah
// IRQ enable control register 5
write_buf[0] = AXP192_IRQ_5_STATUS;
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
return true;
}
static bool pmic_enable_default_irq(busio_i2c_obj_t *i2c) {
int rc;
// uint8_t read_buf[1];
uint8_t write_buf[2];
// Reg: 42h
// IRQ enable control register 3
// Enable power on key short and long press interrupt
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS |
AXP192_IRQ_3_PEK_LONG_PRESS;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 43h
// IRQ enable control register 4
// Enable power on key short and long press interrupt
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING;
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
return true;
}
static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
int rc;
uint8_t read_buf[1];
uint8_t write_buf[2];
// Reg: 30h
// The VBUS-IPSOUT path can be selected to be opened regardless of the status of N_VBUSEN
// VBUS VHOLD pressure limit control disabled
// VBUS current limit control enabled
write_buf[0] = AXP192_VBUS_IPSOUT;
write_buf[1] = AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT |
AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 31h
// VOFF Shutdown voltage setting ( 3.0V )
write_buf[0] = AXP192_POWER_OFF_VOLTAGE;
write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 32h
// Charge function enable control bit, including internal and external channels
// Charging target voltage: 4.2V
// Charging end current: End charging when charging current is less than 10% setting
// Internal path charging current: 100mA
write_buf[0] = AXP192_POWER_OFF_BATT_CHGLED_CTRL;
write_buf[1] = AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON |
AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 33h
// Charge function enable control bit, including internal and external channels
// Charging target voltage: 4.2V
// Charging end current: End charging when charging current is less than 10% setting
// Internal path charging current: 100mA
write_buf[0] = AXP192_CHARGING_CTRL1;
write_buf[1] = AXP192_CHARGING_CTRL1_ENABLE |
AXP192_CHARGING_CTRL1_VOLTAGE_4_20V |
AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC |
AXP192_CHARGING_CTRL1_CURRENT_360mA;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 35h
// Enable RTC battery charge: 3.0V, 200uA
write_buf[0] = AXP192_BACKUP_BATT;
write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE |
AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V |
AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 36h
// Power on: Short press 128ms
// Power off: Long press 1s
// Power OK delay 64ms
// Power off delay 4s
write_buf[0] = AXP192_PEK;
write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS |
AXP192_PEK_LONG_PRESS_1_0S |
AXP192_PEK_LONG_PRESS_POWER_OFF |
AXP192_PEK_PWROK_DELAY_64mS |
AXP192_PEK_POWER_OFF_TIME_4S;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 3Ah
// APS Low battery warning level 1: 3.695V
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1;
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 3Bh
// APS Low battery warning level 2: 3.600V
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2;
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 82h
// ADC all on
write_buf[0] = AXP192_ADC_ENABLE_1;
write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL |
AXP192_ADC_ENABLE_1_BATT_CUR |
AXP192_ADC_ENABLE_1_ACIN_VOL |
AXP192_ADC_ENABLE_1_ACIN_CUR |
AXP192_ADC_ENABLE_1_VBUS_VOL |
AXP192_ADC_ENABLE_1_VBUS_CUR |
AXP192_ADC_ENABLE_1_APS_VOL |
AXP192_ADC_ENABLE_1_TS_PIN;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 83h
// ADC temperature on
write_buf[0] = AXP192_ADC_ENABLE_2;
write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 84h
// ADC 25Hz
write_buf[0] = AXP192_ADC_TS;
write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ |
AXP192_ADC_TS_OUT_CUR_80uA |
AXP192_ADC_TS_PIN_TEMP_MON |
AXP192_ADC_TS_PIN_OUT_SAVE_ENG;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 98h
// PWM1 frequency
write_buf[0] = AXP192_PWM1_OUTPUT_FREQUECY;
write_buf[1] = 0x00;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 99h
// PWM1 duty cycle Y1
write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y1;
write_buf[1] = 0xFF;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 9Ah
// PWM1 duty cycle Y2
write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y2;
write_buf[1] = 0xFF;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 93h
// Speaker off (GPIO2 output low)
write_buf[0] = AXP192_GPIO2_FUNCTION;
write_buf[1] = AXP192_GPIO2_FUNCTION_LOW_OUTPUT;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 28h
// LDO2 (SD + TFT Logic): 3.3V
// LDO3 (Vibration motore): Set to minimum voltage 1.8V
write_buf[0] = AXP192_LDO23_OUT_VOLTAGE;
write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_3_3V |
AXP192_LDO23_OUT_VOLTAGE_LDO3_1_8V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 26h
// DCDC1 (ESP32 VDD): 3.350V
write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE;
write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 27h
// DCDC3 (TFT backlight): 3.0V
write_buf[0] = AXP192_DCDC3_OUT_VOLTAGE;
write_buf[1] = AXP192_DCDC3_OUT_VOLTAGE_3_0V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 12h
// Enable:
// DCDC1 ESP32 VDD, touch screen and 3.3V on M-Bus
// DCDC3 LCD backlight
// LDO2 LCD logic and SD card
write_buf[0] = AXP192_DCDC13_LDO23_CTRL;
write_buf[1] = AXP192_DCDC13_LDO23_CTRL_LDO2 |
AXP192_DCDC13_LDO23_CTRL_DCDC3 |
AXP192_DCDC13_LDO23_CTRL_DCDC1;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 92h
// Set GPIO1 Sys green LED output as PWM
// PWM duty cycle is set to 100% therefore sys led is off
write_buf[0] = AXP192_GPIO1_FUNCTION;
write_buf[1] = AXP192_GPIO1_FUNCTION_PWM1_OUTPUT;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
/*
* Select power source:
* If there is voltage on VBUS means that BUS_5V is powered from M-BUS
* and it can use VBUS as power source. If no voltage is present on VBUS
* disable VBUS and rely on ACIN (USB_5V) as power source.
*/
write_buf[0] = AXP192_INPUT_POWER_STATE;
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
if (rc != 0) {
return false;
}
uint8_t powersource = (read_buf[0] & AXP192_INPUT_POWER_STATE_VBUS_AVAILABLE) ?
PMIC_POWER_SOURCE_M_BUS : PMIC_POWER_SOURCE_USB;
if (!pmic_set_power_source(powersource, internal_i2c)) {
return false;
}
if (!pmic_disable_all_irq(internal_i2c)) {
return false;
}
if (!pmic_clear_all_irq(internal_i2c)) {
return false;
}
if (!pmic_enable_default_irq(internal_i2c)) {
return false;
}
return true;
}
static bool display_init(void) {
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
bus->base.type = &displayio_fourwire_type;
common_hal_displayio_fourwire_construct(
bus,
spi,
&pin_GPIO15, // DC
&pin_GPIO5, // CS
NULL, // RST
32000000, // baudrate
0, // polarity
0 // phase
);
displayio_display_obj_t *display = &displays[0].display;
display->base.type = &displayio_display_type;
common_hal_displayio_display_construct(
display,
bus,
320, // 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),
NULL, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh
61, // native_frames_per_second
true, // backlight_on_high
false, // SH1107_addressing
50000 // backlight pwm frequency
);
return true;
}
void board_init(void) {
busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0);
if (!pmic_init(internal_i2c)) {
mp_printf(&mp_plat_print, "could not initialize axp192 pmic\n");
return;
}
if (!display_init()) {
mp_printf(&mp_plat_print, "could not initialize the display");
return;
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2023 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 Core2"
#define MICROPY_HW_MCU_NAME "ESP32"
#define CIRCUITPY_BOARD_I2C (2)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}, \
{.scl = &pin_GPIO33, .sda = &pin_GPIO32}}
#define CIRCUITPY_BOARD_SPI (1)
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO38}}
#define CIRCUITPY_BOARD_UART (1)
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO14, .rx = &pin_GPIO13}}
// UART pins attached to the USB-serial converter chip
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)

View File

@ -0,0 +1,18 @@
CIRCUITPY_CREATOR_ID = 0x10151015
CIRCUITPY_CREATION_ID = 0x00320008
IDF_TARGET = esp32
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 16MB
M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT = 1
CFLAGS += -DM5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT=$(M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT)
# Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests

View File

@ -0,0 +1,93 @@
#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
// External pins are in silkscreen order, from top to bottom, left side, then right side
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO38) },
{ MP_ROM_QSTR(MP_QSTR_D38), MP_ROM_PTR(&pin_GPIO38) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_PORTC_RX), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_PORTA_SDA), MP_ROM_PTR(&pin_GPIO32) },
{ MP_ROM_QSTR(MP_QSTR_D32), MP_ROM_PTR(&pin_GPIO32) },
{ MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_A27), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_I2S_DATA_SPK), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_A35), MP_ROM_PTR(&pin_GPIO35) },
{ MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35) },
{ MP_ROM_QSTR(MP_QSTR_PORTB_IN), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_A36), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_A25), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_PORTB_OUT), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_A26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_PORTC_TX), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_PORTA_SCL), MP_ROM_PTR(&pin_GPIO33) },
{ MP_ROM_QSTR(MP_QSTR_D33), MP_ROM_PTR(&pin_GPIO33) },
{ MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_I2S_WS_SPK), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_I2S_PDM_CLOCK_MIC), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_I2S_PDM_DATA_MIC), MP_ROM_PTR(&pin_GPIO34) },
{ MP_ROM_QSTR(MP_QSTR_D34), MP_ROM_PTR(&pin_GPIO34) },
{ MP_ROM_QSTR(MP_QSTR_A34), MP_ROM_PTR(&pin_GPIO34) },
// tft
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO15) },
// { MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO33) }, AXP_IO4
// { MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO32) }, AXP_DC3
// sd card
{ MP_ROM_QSTR(MP_QSTR_SD_CS),MP_ROM_PTR(&pin_GPIO4) },
// touch screen
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SCR_IRQ),MP_ROM_PTR(&pin_GPIO4) },
{ 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_UART), MP_ROM_PTR(&board_uart_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,34 @@
CONFIG_ESP32_ECO3_CACHE_LOCK_FIX=y
CONFIG_ESP32_SPIRAM_SUPPORT=y
CONFIG_ESP32_REV_MIN_3=y
#
# LWIP
#
CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskCore2"
# end of LWIP
#
# SPI RAM config
#
# CONFIG_SPIRAM_TYPE_AUTO=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
CONFIG_SPIRAM_TYPE_ESPPSRAM64=y
CONFIG_SPIRAM_SIZE=8388608
# end of SPI RAM config
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
# CONFIG_SPIRAM_RODATA is not set
CONFIG_SPIRAM_SPEED_80M=y
# CONFIG_SPIRAM_SPEED_40M is not set
# CONFIG_SPIRAM_SPEED_26M is not set
# CONFIG_SPIRAM_SPEED_20M is not set
CONFIG_SPIRAM=y
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
CONFIG_SPIRAM_USE_MEMMAP=y
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
# CONFIG_SPIRAM_USE_MALLOC is not set
CONFIG_SPIRAM_MEMTEST=y
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set