Added M5Stack Stick C board
This commit is contained in:
parent
6013cde6a8
commit
208fb341e2
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
*
|
||||
* 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_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_LDO23_OUT_VOLTAGE 0x28
|
||||
#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_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_500mA 0b00000001
|
||||
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_100mA 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_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_IRQ_1_ENABLE 0x40
|
||||
#define AXP192_IRQ_2_ENABLE 0x41
|
||||
#define AXP192_IRQ_3_ENABLE 0x42
|
||||
#define AXP192_IRQ_4_ENABLE 0x43
|
||||
#define AXP192_IRQ_5_ENABLE 0x4a
|
||||
|
||||
#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_3_PEK_SHORT_PRESS 0b00000010
|
||||
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
|
||||
|
||||
#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_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_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_GPIO1_FUNCTION_PWM2_OUTPUT 0b00000010
|
||||
#define AXP192_GPIO2_FUNCTION_GENERAL_INPUT 0b00000001
|
||||
#define AXP192_GPIO2_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
|
||||
|
||||
#define AXP192_PWM1_DUTY_RATIO 0x9A
|
||||
|
||||
#endif
|
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "axp192.h"
|
||||
|
||||
// display init sequence according to adafruit_st7735r.py library
|
||||
uint8_t display_init_sequence[] = {
|
||||
0x01,0x80,0x96, // SWRESET and Delay 150ms
|
||||
0x11,0x80,0xff, // SLPOUT and Delay
|
||||
0xb1,0x03,0x01,0x2C,0x2D, // _FRMCTR1
|
||||
0xb2,0x03,0x01,0x2C,0x2D, // _FRMCTR2
|
||||
0xb3,0x06,0x01,0x2C,0x2D,0x01,0x2C,0x2D, // _FRMCTR3
|
||||
0xb4,0x01,0x07, // _INVCTR line inversion
|
||||
0xc0,0x03,0xa2,0x02,0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
|
||||
0xc1,0x01,0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
|
||||
0xc2,0x02,0x0a,0x00, // _PWCTR3 Opamp current small, Boost frequency
|
||||
0xc3,0x02,0x8a,0x2a,
|
||||
0xc4,0x02,0x8a,0xee,
|
||||
0xc5,0x01,0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
|
||||
0x36,0x01,0xc8, // MADCTL Rotate display
|
||||
0x21,0x00, // _INVON
|
||||
0x3a,0x01,0x05, // COLMOD - 16bit color
|
||||
0xe0,0x10,0x02,0x1c,0x07,0x12,0x37,0x32,0x29,0x2d,0x29,0x25,0x2B,0x39,0x00,0x01,0x03,0x10, // _GMCTRP1 Gamma
|
||||
0xe1,0x10,0x03,0x1d,0x07,0x06,0x2E,0x2C,0x29,0x2D,0x2E,0x2E,0x37,0x3F,0x00,0x00,0x02,0x10, // _GMCTRN1
|
||||
0x13,0x80,0x0a, // _NORON
|
||||
0x29,0x80,0x64 // _DISPON
|
||||
};
|
||||
|
||||
static bool pmic_init(void) {
|
||||
int rc;
|
||||
// uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0);
|
||||
|
||||
// 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 disabled
|
||||
write_buf[0] = AXP192_VBUS_IPSOUT;
|
||||
write_buf[1] = 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;
|
||||
}
|
||||
|
||||
// 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: 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_CURRENT_100mA;
|
||||
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: 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_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: 90h
|
||||
// GPIO0(LDOio0) floating
|
||||
write_buf[0] = AXP192_GPIO0_FUNCTION;
|
||||
write_buf[1] = 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;
|
||||
}
|
||||
|
||||
// Reg: 91h
|
||||
// GPIO0(LDOio0) 2.8V
|
||||
write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE;
|
||||
write_buf[1] = AXP192_GPIO0_LDO_VOLTAGE_2_8V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 28h
|
||||
// LDO2 (TFT backlight): 2.8V
|
||||
// LDO3 (TFT logic): 3.0V
|
||||
write_buf[0] = AXP192_LDO23_OUT_VOLTAGE;
|
||||
write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V |
|
||||
AXP192_LDO23_OUT_VOLTAGE_LDO3_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 EXTEN, DCDC1, LDO2 and LDO3
|
||||
write_buf[0] = AXP192_DCDC13_LDO23_CTRL;
|
||||
write_buf[1] = AXP192_DCDC13_LDO23_CTRL_EXTEN |
|
||||
AXP192_DCDC13_LDO23_CTRL_LDO3 |
|
||||
AXP192_DCDC13_LDO23_CTRL_LDO2 |
|
||||
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: 28h
|
||||
// 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;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool display_init(void) {
|
||||
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
|
||||
bus->base.type = &displayio_fourwire_type;
|
||||
|
||||
common_hal_displayio_fourwire_construct(
|
||||
bus,
|
||||
spi,
|
||||
&pin_GPIO23, // DC
|
||||
&pin_GPIO5, // CS
|
||||
&pin_GPIO18, // RST
|
||||
40000000, // 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,
|
||||
80, // width (after rotation)
|
||||
160, // height (after rotation)
|
||||
26, // column start
|
||||
1, // 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
|
||||
80, // native_frames_per_second
|
||||
false, // backlight_on_high
|
||||
false, // SH1107_addressing
|
||||
50000 // backlight pwm frequency
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void board_init(void) {
|
||||
if (!pmic_init()) {
|
||||
mp_printf(&mp_plat_print, "could not initialize axp192 pmic\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!display_init()) {
|
||||
mp_printf(&mp_plat_print, "could not initialize ili9342c LCD");
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 Stick C"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32"
|
||||
|
||||
#define MICROPY_HW_LED_STATUS (&pin_GPIO10)
|
||||
|
||||
#define CIRCUITPY_BOARD_I2C (1)
|
||||
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}}
|
||||
|
||||
// For entering safe mode
|
||||
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO37)
|
||||
|
||||
// Explanation of how a user got into safe mode
|
||||
#define BOARD_USER_SAFE_MODE_ACTION translate("Button A was pressed at start up.\n")
|
||||
|
||||
// UART pins attached to the USB-serial converter chip
|
||||
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
|
||||
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
|
|
@ -0,0 +1,9 @@
|
|||
CIRCUITPY_CREATOR_ID = 0x10151015
|
||||
CIRCUITPY_CREATION_ID = 0x00320007
|
||||
|
||||
IDF_TARGET = esp32
|
||||
|
||||
CIRCUITPY_ESP_FLASH_MODE = qio
|
||||
CIRCUITPY_ESP_FLASH_FREQ = 80m
|
||||
CIRCUITPY_ESP_FLASH_SIZE = 4MB
|
||||
CIRCUITPY_ESP32_CAMERA = 0
|
|
@ -0,0 +1,53 @@
|
|||
#include "shared-bindings/board/__init__.h"
|
||||
#include "shared-module/displayio/__init__.h"
|
||||
|
||||
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_A26), MP_ROM_PTR(&pin_GPIO26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) },
|
||||
|
||||
{ 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_A0), MP_ROM_PTR(&pin_GPIO0) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_PORTA_SDA), MP_ROM_PTR(&pin_GPIO32) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO32) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_PORTA_SCL), MP_ROM_PTR(&pin_GPIO33) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO33) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_IR_LED), MP_ROM_PTR(&pin_GPIO9) },
|
||||
|
||||
// buttons
|
||||
{ MP_ROM_QSTR(MP_QSTR_BTN_A), MP_ROM_PTR(&pin_GPIO37) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BTN_B), MP_ROM_PTR(&pin_GPIO39) },
|
||||
|
||||
// internal i2c bus
|
||||
{ MP_ROM_QSTR(MP_QSTR_SYS_SDA), MP_ROM_PTR(&pin_GPIO21) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SYS_SCL), MP_ROM_PTR(&pin_GPIO22) },
|
||||
|
||||
// internal devices interrupt
|
||||
{ MP_ROM_QSTR(MP_QSTR_SYS_INT), MP_ROM_PTR(&pin_GPIO35) },
|
||||
|
||||
// pdm microphone
|
||||
{ MP_ROM_QSTR(MP_QSTR_PDM_MIC_CLK), MP_ROM_PTR(&pin_GPIO0) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PDM_MIC_DATA), MP_ROM_PTR(&pin_GPIO34) },
|
||||
|
||||
// lcd spi bus
|
||||
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO23) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO18) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO5) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SYS_I2C), MP_ROM_PTR(&board_i2c_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
|
@ -0,0 +1,26 @@
|
|||
CONFIG_ESP32_SPIRAM_SUPPORT=n
|
||||
|
||||
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
|
||||
#
|
||||
# LWIP
|
||||
#
|
||||
CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskStickC"
|
||||
# end of LWIP
|
||||
|
||||
# Uncomment (remove ###) to send ESP_LOG output to TX/RX pins
|
||||
### #
|
||||
### # ESP System Settings
|
||||
### #
|
||||
### CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
|
||||
### # CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set
|
||||
### CONFIG_ESP_CONSOLE_UART_CUSTOM=y
|
||||
### CONFIG_ESP_CONSOLE_NONE is not set
|
||||
### CONFIG_ESP_CONSOLE_UART=y
|
||||
### CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0=y
|
||||
### # CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1 is not set
|
||||
### CONFIG_ESP_CONSOLE_UART_NUM=0
|
||||
### CONFIG_ESP_CONSOLE_UART_TX_GPIO=17
|
||||
### CONFIG_ESP_CONSOLE_UART_RX_GPIO=16
|
||||
### CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
|
||||
### # CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5 is not set
|
||||
### # end of ESP System Settings
|
Loading…
Reference in New Issue