mirror of https://github.com/arendst/Tasmota.git
LVGL prepare M5StickC
This commit is contained in:
parent
60a7a31e61
commit
6d54949273
|
@ -0,0 +1,110 @@
|
|||
/********************************************************************
|
||||
* Tasmota I2C_Driver class
|
||||
*
|
||||
* To use: `d = I2C_Driver(addr, name)`
|
||||
* where:
|
||||
* addr: I2C address of the device
|
||||
* name: name of the I2C chip for logging
|
||||
*
|
||||
*******************************************************************/
|
||||
#include "be_constobj.h"
|
||||
|
||||
extern bclass* be_class_tasmota_driver; // Parent class
|
||||
|
||||
/********************************************************************
|
||||
** Solidified function: init
|
||||
********************************************************************/
|
||||
|
||||
/********** Solidified proto: init */
|
||||
be_define_local_const_str(init_str_name, "init", 380752755, 4);
|
||||
be_define_local_const_str(init_str_source, "input", -103256197, 5);
|
||||
be_define_local_const_str(init_str_0, "string", 398550328, 6);
|
||||
be_define_local_const_str(init_str_1, "get_tasmota", 334356779, 11);
|
||||
be_define_local_const_str(init_str_2, "addr", 1087856498, 4);
|
||||
be_define_local_const_str(init_str_3, "wire", -212213352, 4);
|
||||
be_define_local_const_str(init_str_4, "wire_scan", -1623691416, 9);
|
||||
be_define_local_const_str(init_str_5, "name", -1925595674, 4);
|
||||
be_define_local_const_str(init_str_6, "format", -1180859054, 6);
|
||||
be_define_local_const_str(init_str_7, "I2C: %s detected on bus %d", 110398549, 26);
|
||||
be_define_local_const_str(init_str_8, "bus", 1607822841, 3);
|
||||
|
||||
static const bvalue init_ktab[9] = {
|
||||
{ { .s=be_local_const_str(init_str_0) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_1) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_2) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_3) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_4) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_5) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_6) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_7) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(init_str_8) }, BE_STRING},
|
||||
};
|
||||
|
||||
static const uint32_t init_code[20] = {
|
||||
0xA40E0000, // 0000 IMPORT R3 R256
|
||||
0x8C100101, // 0001 GETMET R4 R0 R257
|
||||
0x7C100200, // 0002 CALL R4 1
|
||||
0x90020401, // 0003 SETMBR R0 R258 R1
|
||||
0x8C140904, // 0004 GETMET R5 R4 R260
|
||||
0x881C0102, // 0005 GETMBR R7 R0 R258
|
||||
0x7C140400, // 0006 CALL R5 2
|
||||
0x90020605, // 0007 SETMBR R0 R259 R5
|
||||
0x90020A02, // 0008 SETMBR R0 R261 R2
|
||||
0x88140103, // 0009 GETMBR R5 R0 R259
|
||||
0x78160007, // 000A JMPF R5 #0013
|
||||
0x6014000F, // 000B GETGBL R5 G15
|
||||
0x8C180706, // 000C GETMET R6 R3 R262
|
||||
0x58200007, // 000D LDCONST R8 K7
|
||||
0x88240105, // 000E GETMBR R9 R0 R261
|
||||
0x88280103, // 000F GETMBR R10 R0 R259
|
||||
0x88281508, // 0010 GETMBR R10 R10 R264
|
||||
0x7C180800, // 0011 CALL R6 4
|
||||
0x7C140200, // 0012 CALL R5 1
|
||||
0x80000000, // 0013 RET 0 R0
|
||||
};
|
||||
|
||||
be_define_local_proto(init, 11, 3, 1, 0, 0);
|
||||
be_define_local_closure(init);
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
|
||||
#if BE_USE_PRECOMPILED_OBJECT
|
||||
#include "../generate/be_fixed_be_class_tasmota_i2c_driver.h"
|
||||
#endif
|
||||
|
||||
void be_load_driver_i2c_lib(bvm *vm) {
|
||||
#if !BE_USE_PRECOMPILED_OBJECT
|
||||
static const bnfuncinfo members[] = {
|
||||
{ "wire", NULL },
|
||||
{ "addr", NULL },
|
||||
{ "name", NULL },
|
||||
|
||||
{ NULL, (bntvfunc) BE_CLOSURE }, /* mark section for berry closures */
|
||||
{ "add_cmd", (bntvfunc) &init_closure },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
be_regclass(vm, "I2C_Driver", members);
|
||||
be_getglobal(vm, "I2C_Driver");
|
||||
be_getglobal(vm, "Driver");
|
||||
be_setsuper(vm, -2);
|
||||
be_pop(vm, 2);
|
||||
#else
|
||||
be_pushntvclass(vm, &be_class_tasmota_i2c_driver);
|
||||
be_setglobal(vm, "I2C_Driver");
|
||||
be_pop(vm, 1);
|
||||
#endif
|
||||
}
|
||||
/* @const_object_info_begin
|
||||
|
||||
class be_class_tasmota_i2c_driver (scope: global, name: I2C_Driver, super: be_class_Driver) {
|
||||
wire, var
|
||||
addr, var
|
||||
name, var
|
||||
|
||||
add_cmd, closure(init_closure)
|
||||
}
|
||||
@const_object_info_end */
|
|
@ -85,6 +85,7 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = {
|
|||
extern void be_load_tasmota_ntvlib(bvm *vm);
|
||||
extern void be_load_wirelib(bvm *vm);
|
||||
extern void be_load_driverlib(bvm *vm);
|
||||
extern void be_load_driver_i2c_lib(bvm *vm);
|
||||
|
||||
#ifdef USE_LVGL
|
||||
extern void be_load_lvgl_color_lib(bvm *vm);
|
||||
|
@ -102,10 +103,11 @@ BERRY_API void be_load_custom_libs(bvm *vm)
|
|||
/* be_load_xxxlib(vm); */
|
||||
#endif
|
||||
be_load_tasmota_ntvlib(vm);
|
||||
be_load_driverlib(vm);
|
||||
#ifdef USE_I2C
|
||||
be_load_wirelib(vm);
|
||||
be_load_driver_i2c_lib(vm);
|
||||
#endif // USE_I2C
|
||||
be_load_driverlib(vm);
|
||||
#ifdef USE_LVGL
|
||||
// LVGL
|
||||
be_load_lvgl_color_lib(vm);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,26 +1,27 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_tasmota_driver_map) {
|
||||
{ be_const_key(button_pressed, 1), be_const_int(0) },
|
||||
{ be_const_key(web_add_main_button, 5), be_const_int(1) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(web_add_main_button, 3), be_const_int(0) },
|
||||
{ be_const_key(web_sensor, -1), be_const_int(1) },
|
||||
{ be_const_key(every_100ms, -1), be_const_int(2) },
|
||||
{ be_const_key(json_append, 1), be_const_int(3) },
|
||||
{ be_const_key(every_second, -1), be_const_int(4) },
|
||||
{ be_const_key(button_pressed, -1), be_const_int(5) },
|
||||
{ be_const_key(save_before_restart, -1), be_const_int(6) },
|
||||
{ be_const_key(web_add_button, 7), be_const_int(7) },
|
||||
{ be_const_key(get_tasmota, 0), be_const_func(d_getTasmotaGlob) },
|
||||
{ be_const_key(web_add_button, 4), be_const_int(2) },
|
||||
{ be_const_key(web_sensor, -1), be_const_int(3) },
|
||||
{ be_const_key(json_append, -1), be_const_int(4) },
|
||||
{ be_const_key(display, -1), be_const_int(5) },
|
||||
{ be_const_key(every_100ms, -1), be_const_int(6) },
|
||||
{ be_const_key(save_before_restart, -1), be_const_int(7) },
|
||||
{ be_const_key(get_tasmota, -1), be_const_func(d_getTasmotaGlob) },
|
||||
{ be_const_key(every_second, 8), be_const_int(8) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_tasmota_driver_map,
|
||||
10
|
||||
11
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_tasmota_driver,
|
||||
8,
|
||||
9,
|
||||
NULL,
|
||||
Driver
|
||||
);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_tasmota_i2c_driver_map) {
|
||||
{ be_const_key(wire, -1), be_const_int(0) },
|
||||
{ be_const_key(addr, -1), be_const_int(1) },
|
||||
{ be_const_key(name, 1), be_const_int(2) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(init_closure) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_tasmota_i2c_driver_map,
|
||||
4
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_tasmota_i2c_driver,
|
||||
3,
|
||||
(bclass *)&be_class_tasmota_driver,
|
||||
I2C_Driver
|
||||
);
|
|
@ -0,0 +1,479 @@
|
|||
#-------------------------------------------------------------
|
||||
- I2C_Driver class to simplify development of I2C drivers
|
||||
-
|
||||
- I2C_Driver(name, addr [, i2c_index]) -> nil
|
||||
- name: name of I2C device for logging
|
||||
- addr: I2C address of device, will probe all I2C buses for it
|
||||
- i2c_index: (optional) check is the device is not disabled
|
||||
-------------------------------------------------------------#
|
||||
|
||||
class I2C_Driver : Driver
|
||||
var wire #- if wire == nil then the module is not initialized -#
|
||||
var addr
|
||||
var name
|
||||
|
||||
def init(name, addr, i2c_index)
|
||||
import string
|
||||
var tasmota = self.get_tasmota()
|
||||
#- check if the i2c index is disabled by Tasmota configuration -#
|
||||
if i2c_index != nil && !tasmota.i2c_enabled(i2c_index) return end
|
||||
|
||||
self.addr = addr #- address for AXP192 -#
|
||||
self.wire = tasmota.wire_scan(self.addr) #- get the right I2C bus -#
|
||||
self.name = name #- display name for I2C device -#
|
||||
|
||||
if self.wire
|
||||
print(string.format("I2C: %s detected on bus %d", self.name, self.wire.bus))
|
||||
end
|
||||
end
|
||||
|
||||
#- verify if the device is what is expected -#
|
||||
#- this method needs to be overriden -#
|
||||
def verify()
|
||||
return true
|
||||
end
|
||||
|
||||
# def log_write1(reg, val)
|
||||
# import string
|
||||
# var tasmota = self.get_tasmota()
|
||||
# tasmota.log(string.format("I2C: (0x%02X) write %02X:%02X", self.addr, reg, val))
|
||||
# end
|
||||
|
||||
def write1(reg, val)
|
||||
# self.log_write1(reg, val)
|
||||
return self.wire.write(self.addr, reg, val, 1)
|
||||
end
|
||||
|
||||
# Set or clear a specific bit in a register
|
||||
# write_bit(reg:int, bit:int, state:bool) -> nil
|
||||
# reg: I2C register number (0..255)
|
||||
# bit: bit of I2C register to change (0..7)
|
||||
# state: boolean value to write to specified bit
|
||||
def write_bit(reg, bit, state)
|
||||
if bit < 0 || bit > 7 return end
|
||||
var mark = 1 << bit
|
||||
if state self.write1(reg, self.read8(reg) | mark)
|
||||
else self.write1(reg, self.read8(reg) & (0xFF - mark))
|
||||
end
|
||||
end
|
||||
|
||||
# read 8 bits
|
||||
def read8(reg)
|
||||
return self.wire.read(self.addr, reg, 1)
|
||||
end
|
||||
# read 12 bits
|
||||
def read12(reg)
|
||||
var buf = self.wire.read_bytes(self.addr, reg, 2)
|
||||
return (buf[0] << 4) + buf[1]
|
||||
end
|
||||
# read 13 bits
|
||||
def read13(reg)
|
||||
var buf = self.wire.read_bytes(self.addr, reg, 2)
|
||||
return (buf[0] << 5) + buf[1]
|
||||
end
|
||||
# read 24 bits
|
||||
def read24(reg)
|
||||
var buf = self.wire.read_bytes(self.addr, reg, 3)
|
||||
return (buf[0] << 16) + (buf[1] << 8) + buf[2]
|
||||
end
|
||||
# read 32 bits
|
||||
def read32(reg)
|
||||
var buf = self.wire.read_bytes(self.addr, reg, 4)
|
||||
return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]
|
||||
end
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------
|
||||
- Generic driver for AXP192
|
||||
-------------------------------------------------------------#
|
||||
class AXP192 : I2C_Driver
|
||||
def init()
|
||||
super(self).init("AXP192", 0x34)
|
||||
end
|
||||
|
||||
# Return True = Battery Exist
|
||||
def battery_present()
|
||||
if self.wire.read(self.addr, 0x01, 1) & 0x20 return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
# Input Power Status ???
|
||||
def get_input_power_status()
|
||||
return self.wire.read(self.addr, 0x00, 1)
|
||||
end
|
||||
|
||||
# Battery Charging Status
|
||||
def get_battery_chargin_status()
|
||||
return self.wire.read(self.addr, 0x01, 1)
|
||||
end
|
||||
|
||||
# AXP chip temperature in °C
|
||||
def get_temp()
|
||||
return self.read12(0x5E) * 0.1 - 144.7
|
||||
end
|
||||
|
||||
def get_bat_power()
|
||||
return self.read24(0x70) * 0.00055
|
||||
end
|
||||
|
||||
def get_bat_voltage()
|
||||
return self.read12(0x78) * 0.0011
|
||||
end
|
||||
def get_bat_current()
|
||||
return (self.read13(0x7A) - self.read13(0x7C)) * 0.5
|
||||
end
|
||||
def get_bat_charge_current()
|
||||
return self.read13(0x7A) * 0.5
|
||||
end
|
||||
def get_aps_voltage()
|
||||
return self.read12(0x7E) * 0.0014
|
||||
end
|
||||
def get_vbus_voltage()
|
||||
return self.read12(0x5A) * 0.0017
|
||||
end
|
||||
def get_vbus_current()
|
||||
return self.read12(0x5C) * 0.375
|
||||
end
|
||||
|
||||
# set LDO voltage
|
||||
# ldo: 2/3
|
||||
# voltage: (mV) 1800mV - 3300mV in 100mV steps
|
||||
def set_ldo_voltage(ldo, voltage)
|
||||
if voltage > 3300 voltage = 15
|
||||
else voltage = (voltage / 100) - 18
|
||||
end
|
||||
|
||||
if ldo == 2
|
||||
self.write1(0x28, self.read8(0x28) & 0x0F | ((voltage & 0x0F) << 4))
|
||||
end
|
||||
if ldo == 3
|
||||
self.write1(0x28, self.read8(0x28) & 0xF0 | (voltage & 0x0F))
|
||||
end
|
||||
end
|
||||
|
||||
# set DCDC enable, 1/2/3
|
||||
def set_dcdc_enable(dcdc, state)
|
||||
if dcdc == 1 self.write_bit(0x12, 0, state) end
|
||||
if dcdc == 2 self.write_bit(0x12, 4, state) end
|
||||
if dcdc == 3 self.write_bit(0x12, 1, state) end
|
||||
end
|
||||
|
||||
# set LDO enable, 2/3 (LDO 1 is always on)
|
||||
def set_ldo_enable(ldo, state)
|
||||
if ldo == 2 self.write_bit(0x12, 2, state) end
|
||||
if ldo == 3 self.write_bit(0x12, 3, state) end
|
||||
end
|
||||
|
||||
# set GPIO output state 0/1/2 and 3/4
|
||||
def write_gpio(gpio, state)
|
||||
if gpio >= 0 && gpio <= 2
|
||||
self.write_bit(0x94, gpio, state)
|
||||
elif gpio >= 3 && gpio <= 4
|
||||
self.write_bit(0x96, gpio - 3, state)
|
||||
end
|
||||
end
|
||||
|
||||
# Set voltage on DC-DC1/2/3
|
||||
# dcdc: 1/2/3 (warning some C libs start at 0)
|
||||
# voltage:
|
||||
def set_dc_voltage(dcdc, voltage)
|
||||
if dcdc < 1 || dcdc > 3 return end
|
||||
var v
|
||||
if voltage < 700 v = 0
|
||||
elif voltage > 3500 v = 112
|
||||
elif dcdc == 2 && voltage > 2275 v = 63 # dcdc2 is limited to 2.275V
|
||||
else v = (voltage - 700) / 25
|
||||
end
|
||||
|
||||
var addr = 0x26
|
||||
if dcdc == 3 addr = 0x27
|
||||
elif dcdc == 2 addr = 0x23
|
||||
end
|
||||
|
||||
self.write1(addr, self.read8(addr) & 0x80 | (v & 0x7F))
|
||||
end
|
||||
|
||||
# Set charging current
|
||||
# 100mA = 0
|
||||
# 190mA = 1
|
||||
# 280mA = 2
|
||||
# 360mA = 3
|
||||
# 450mA = 4
|
||||
# 550mA = 5
|
||||
# 630mA = 6
|
||||
# 700mA = 7
|
||||
# 780mA = 8
|
||||
# 880mA = 9
|
||||
# 960mA = 10
|
||||
# 1000mA = 11
|
||||
# 1080mA = 12
|
||||
# 1160mA = 13
|
||||
# 1240mA = 14
|
||||
# 1320mA = 15
|
||||
def set_chg_current(current_code)
|
||||
self.write1(0x33, self.read8(0x33) & 0xF0 | (current_code & 0x0F))
|
||||
end
|
||||
|
||||
# // Low Volt Level 1, when APS Volt Output < 3.4496 V
|
||||
# // Low Volt Level 2, when APS Volt Output < 3.3992 V, then this flag is SET (0x01)
|
||||
# // Flag will reset once battery volt is charged above Low Volt Level 1
|
||||
# // Note: now AXP192 have the Shutdown Voltage of 3.0V (B100) Def in REG 31H
|
||||
def get_warning_level()
|
||||
return self.read12(0x47) & 1
|
||||
end
|
||||
|
||||
#- trigger a read every second -#
|
||||
# def every_second()
|
||||
# if !self.wire return nil end #- exit if not initialized -#
|
||||
# end
|
||||
|
||||
#- display sensor value in the web UI -#
|
||||
def web_sensor()
|
||||
if !self.wire return nil end #- exit if not initialized -#
|
||||
import string
|
||||
var msg = string.format(
|
||||
"{s}VBus Voltage{m}%.3f V{e}"..
|
||||
"{s}VBus Current{m}%.1f mA{e}"..
|
||||
"{s}Batt Voltage{m}%.3f V{e}"..
|
||||
"{s}Batt Current{m}%.1f mA{e}"..
|
||||
#"{s}Batt Power{m}%.3f{e}"..
|
||||
"{s}Temp AXP{m}%.1f °C{e}",
|
||||
self.get_vbus_voltage(), self.get_vbus_voltage(),
|
||||
self.get_bat_voltage(), self.get_bat_current(),
|
||||
#self.get_bat_power(),
|
||||
self.get_temp()
|
||||
)
|
||||
tasmota.web_send_decimal(msg)
|
||||
end
|
||||
|
||||
#- add sensor value to teleperiod -#
|
||||
def json_append()
|
||||
if !self.wire return nil end #- exit if not initialized -#
|
||||
# import string
|
||||
# var ax = int(self.accel[0] * 1000)
|
||||
# var ay = int(self.accel[1] * 1000)
|
||||
# var az = int(self.accel[2] * 1000)
|
||||
# var msg = string.format(",\"MPU6886\":{\"AX\":%i,\"AY\":%i,\"AZ\":%i,\"GX\":%i,\"GY\":%i,\"GZ\":%i}",
|
||||
# ax, ay, az, self.gyro[0], self.gyro[1], self.gyro[2])
|
||||
# tasmota.response_append(msg)
|
||||
end
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------
|
||||
- Specialized driver for AXP192 of M5Stack Core 2
|
||||
-------------------------------------------------------------#
|
||||
class AXP192_M5Stack_Core2 : AXP192
|
||||
def init()
|
||||
super(self).init()
|
||||
|
||||
if self.wire
|
||||
# Disable vbus hold limit
|
||||
self.write1(0x30, self.read8(0x30) & 0x04 | 0x02)
|
||||
|
||||
# AXP192 GPIO1:OD OUTPUT
|
||||
self.write1(0x92, self.read8(0x92) & 0xF8)
|
||||
|
||||
# AXP192 GPIO2:OD OUTPUT
|
||||
self.write1(0x93, self.read8(0x93) & 0xF8)
|
||||
|
||||
# AXP192 RTC CHG rtc battery charging enabled
|
||||
self.write1(0x35, self.read8(0x35) & 0x1C | 0xA2)
|
||||
|
||||
# esp32 power voltage was set to 3.35v
|
||||
self.set_esp_voltage(3350)
|
||||
|
||||
# lcd backlight voltage was set to 2.80v
|
||||
self.set_lcd_voltage(2800)
|
||||
|
||||
# lcd logic and sdcard voltage preset to 3.3v
|
||||
self.set_ldo_voltage(2, 3300)
|
||||
|
||||
# vibrator voltage preset to 2v
|
||||
self.set_ldo_voltage(3, 2000)
|
||||
|
||||
# turn on logic and sdcard
|
||||
self.set_ldo_enable(2, true)
|
||||
|
||||
# turn on lcd backlight
|
||||
self.set_dcdc_enable(3, true)
|
||||
|
||||
# turn green led on
|
||||
self.set_led(true)
|
||||
|
||||
# set charging current to 100mA
|
||||
self.set_chg_current(0) # 0 = 100mA
|
||||
|
||||
# AXP192 GPIO4 - TBC what this does really?
|
||||
self.write1(0x95, self.read8(0X95) & 0x72 | 0x84)
|
||||
|
||||
# Button parameter setting
|
||||
# Current:
|
||||
# Boot time = 512ms
|
||||
# Long key press time setting = 1s
|
||||
# Automatic shutdown function setting when the key duration is longer than the shutdown duration = turn on
|
||||
# PWROK signal delay after power on = 64ms
|
||||
# Shutdown duration setting = 4s
|
||||
self.write1(0x34, 0x4C)
|
||||
|
||||
# ADC all-on
|
||||
# Bit 7: Battery voltage ADC enable
|
||||
# Bit 6: Battery current ADC enable
|
||||
# Bit 5: ACIN voltage ADC enable
|
||||
# Bit 4: ACIN current ADC enable
|
||||
# Bit 3: VBUS voltage ADC enable
|
||||
# Bit 2: VBUS current ADC enable
|
||||
# Bit 1: APS voltage ADC enable
|
||||
# Bit 0: TS pin ADC function enable
|
||||
self.write1(0x82, 0xFF)
|
||||
|
||||
# Reset LCD Controller
|
||||
self.set_lcd_reset(false)
|
||||
self.get_tasmota().delay(100) # wait for 100ms
|
||||
self.set_lcd_reset(true)
|
||||
self.get_tasmota().delay(100) # wait for 100ms
|
||||
|
||||
# bus power mode_output
|
||||
self.set_buf_power_mode(false)
|
||||
end
|
||||
end
|
||||
|
||||
# set ESP voltage on DCDC1
|
||||
def set_esp_voltage(voltage)
|
||||
if voltage >= 3000 && voltage <= 3400
|
||||
self.set_dc_voltage(1, voltage)
|
||||
end
|
||||
end
|
||||
|
||||
# set LCD backlight voltage on DCDC3
|
||||
def set_lcd_voltage(voltage)
|
||||
if voltage < 2500 voltage = 2500 end
|
||||
if voltage > 3300 voltage = 3300 end
|
||||
self.set_ldo_voltage(2, voltage)
|
||||
end
|
||||
|
||||
# set state of the green led, GPIO 1
|
||||
def set_led(state)
|
||||
self.write_gpio(1, !state)
|
||||
end
|
||||
|
||||
# LCD Controller Reset pin
|
||||
def set_lcd_reset(state)
|
||||
self.write_gpio(4, state)
|
||||
end
|
||||
|
||||
# Speaker enable
|
||||
def set_speaker_enable(state)
|
||||
self.write_gpio(2, state)
|
||||
end
|
||||
|
||||
# Bus Power Mode
|
||||
def set_buf_power_mode(state)
|
||||
if (state)
|
||||
self.write1(0x12, self.read8(0x12) & 0xBF) # set EXTEN to disable 5v boost
|
||||
self.write1(0x90, self.read8(0x90) & 0xF8 | 0x01) # set GPIO0 to float, using enternal pulldown resistor to enable supply from BUS_5VS
|
||||
else
|
||||
self.write1(0x91, self.read8(0x91) & 0x0F | 0xF0)
|
||||
self.write1(0x90, self.read8(0x90) & 0xF8 | 0x02) # set GPIO0 to LDO OUTPUT , pullup N_VBUSEN to disable supply from BUS_5V
|
||||
self.write1(0x12, self.read8(0x12) | 0x40) # set EXTEN to enable 5v boost
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------
|
||||
- Specialized driver for AXP192 of M5StickC
|
||||
-------------------------------------------------------------#
|
||||
class AXP192_M5StickC : AXP192
|
||||
def init()
|
||||
super(self).init()
|
||||
|
||||
if self.wire
|
||||
# Disable vbus hold limit
|
||||
self.write1(0x30, 0x80)
|
||||
|
||||
# lcd backlight voltage was set to 2.80v
|
||||
self.set_lcd_voltage(2800)
|
||||
|
||||
# set LDO3 3.0V TFT
|
||||
self.set_ldo_voltage(3, 3000)
|
||||
|
||||
# Set ADC sample rate to 200hz
|
||||
self.write1(0x84, 0xF2)
|
||||
|
||||
# set charging current to 100mA
|
||||
self.set_chg_current(0) # 0 = 100mA
|
||||
|
||||
# esp32 power voltage was set to 3.3v
|
||||
self.set_esp_voltage(3300)
|
||||
|
||||
# PEK key parameter setting
|
||||
# Current:
|
||||
# Boot time setting = 512ms
|
||||
# Long press time setting = 1s
|
||||
# Automatic shutdown function setting when the key duration is longer than the shutdown duration = turn on
|
||||
# PWROK signal delay after power on = 64ms
|
||||
# Shutdown duration setting = 4s
|
||||
self.write1(0x36, 0x4C)
|
||||
|
||||
# Mic GPIO0 - floating
|
||||
self.write1(0x90, 0x07)
|
||||
|
||||
# enable LDO2, LDO3, DCDC1, DCDC3
|
||||
self.set_ldo_enable(2, true)
|
||||
self.set_ldo_enable(3, true)
|
||||
self.set_dcdc_enable(1, true)
|
||||
self.set_dcdc_enable(3, true)
|
||||
|
||||
# Set temperature protection
|
||||
self.write1(0x39, 0xFC)
|
||||
|
||||
# Enable RTC BAT charge
|
||||
self.write1(0x35, 0xA2)
|
||||
# Write1Byte(0x35, 0xa2 & (disableRTC ? 0x7F : 0xFF));
|
||||
|
||||
# Enable bat detection
|
||||
self.write1(0x32, 0x46)
|
||||
|
||||
# Set Power off voltage 3.0v
|
||||
self.write1(0x31, self.read8(0x31) & 0xF8 | 0x04)
|
||||
|
||||
# ADC all-on
|
||||
# Bit 7: Battery voltage ADC enable
|
||||
# Bit 6: Battery current ADC enable
|
||||
# Bit 5: ACIN voltage ADC enable
|
||||
# Bit 4: ACIN current ADC enable
|
||||
# Bit 3: VBUS voltage ADC enable
|
||||
# Bit 2: VBUS current ADC enable
|
||||
# Bit 1: APS voltage ADC enable
|
||||
# Bit 0: TS pin ADC function enable
|
||||
self.write1(0x82, 0xFF)
|
||||
end
|
||||
end
|
||||
|
||||
# set ESP voltage on DCDC1
|
||||
def set_esp_voltage(voltage)
|
||||
if voltage >= 3000 && voltage <= 3400
|
||||
self.set_dc_voltage(1, voltage)
|
||||
end
|
||||
end
|
||||
|
||||
# set LCD backlight voltage on DCDC3
|
||||
def set_lcd_voltage(voltage)
|
||||
if voltage < 2500 voltage = 2500 end
|
||||
if voltage > 3300 voltage = 3300 end
|
||||
self.set_ldo_voltage(2, voltage)
|
||||
end
|
||||
|
||||
# LCD Controller Reset pin
|
||||
def set_lcd_reset(state)
|
||||
self.set_ldo_enable(3, state)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# axp = AXP192_M5Stack_Core2()
|
||||
# tasmota.add_driver(axp)
|
||||
|
||||
|
||||
axp = AXP192_M5StickC()
|
||||
tasmota.add_driver(axp)
|
|
@ -0,0 +1,36 @@
|
|||
:H,ST7735S,80,160,16,SPI,1,*,*,*,*,*,*,*,16
|
||||
:I
|
||||
01,80
|
||||
11,E0
|
||||
B1,3,05,3C,3C
|
||||
B2,3,05,3C,3C
|
||||
B3,6,05,3C,3C,05,3C,3C
|
||||
B4,1,07
|
||||
C0,3,A4,04,84
|
||||
C1,1,C5
|
||||
C2,2,0D,00
|
||||
C3,2,8D,6A
|
||||
C4,2,8D,EE
|
||||
C5,1,21
|
||||
FC,1,80
|
||||
F0,1,11
|
||||
D6,1,CB
|
||||
20,0
|
||||
36,1,C8
|
||||
3A,1,05
|
||||
2A,4,00,02,00,81
|
||||
2B,4,00,01,00,A0
|
||||
E0,10,0D,0C,0C,0E,0E,00,00,00,00,09,23,31,00,0C,03,1A
|
||||
E1,10,0A,05,06,07,08,01,00,00,00,05,20,2E,00,0A,01,1A
|
||||
13,A0
|
||||
29,E0
|
||||
:o,28
|
||||
:O,29
|
||||
:A,2A,2B,2C,16
|
||||
:R,36
|
||||
:0,CC,1A,01,00
|
||||
:1,A8,01,1A,01
|
||||
:2,08,1A,01,02
|
||||
:3,68,01,1A,03
|
||||
:i,21,20
|
||||
#
|
|
@ -695,7 +695,6 @@
|
|||
// Commands xdrv_52_berry.ino - Berry scripting language
|
||||
#define D_PRFX_BR "Br"
|
||||
#define D_CMND_BR_RUN ""
|
||||
#define D_CMND_BR_RESET "Reset"
|
||||
#define D_BR_NOT_STARTED "Berry not started"
|
||||
|
||||
// Commands xsns_02_analog.ino
|
||||
|
|
|
@ -656,6 +656,11 @@
|
|||
// #define USE_DISPLAY_SH1106 // [DisplayModel 7] [I2cDriver6] Enable SH1106 Oled 128x64 display (I2C addresses 0x3C and 0x3D)
|
||||
#endif // USE_I2C
|
||||
|
||||
|
||||
// -- Universal Display Driver ---------------------------------
|
||||
// #define USE_UNIVERSAL_DISPLAY // New universal display driver for both I2C and SPI
|
||||
#define MAX_TOUCH_BUTTONS 16 // Virtual touch buttons
|
||||
|
||||
// -- SPI sensors ---------------------------------
|
||||
//#define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC)
|
||||
|
||||
|
|
|
@ -367,6 +367,9 @@ void setup(void) {
|
|||
#ifdef ROTARY_V1
|
||||
RotaryInit();
|
||||
#endif // ROTARY_V1
|
||||
#ifdef USE_BERRY
|
||||
BerryInit();
|
||||
#endif // USE_BERRY
|
||||
|
||||
XdrvCall(FUNC_PRE_INIT);
|
||||
XsnsCall(FUNC_PRE_INIT);
|
||||
|
|
|
@ -115,7 +115,6 @@
|
|||
#define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
|
||||
#define USE_DISPLAY_MODES1TO5
|
||||
#define USE_TOUCH_BUTTONS
|
||||
#define MAX_TOUCH_BUTTONS 16
|
||||
#endif
|
||||
#define JPEG_PICTS
|
||||
#define USE_FT5206
|
||||
|
|
|
@ -36,6 +36,10 @@ extern FS *ufsp;
|
|||
extern FS *ffsp;
|
||||
#endif
|
||||
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
extern VButton *buttons[MAX_TOUCH_BUTTONS];
|
||||
#endif
|
||||
|
||||
// drawing color is WHITE
|
||||
// on epaper the whole display buffer is transfered inverted this results in white paper
|
||||
uint16_t fg_color = 1;
|
||||
|
|
|
@ -946,7 +946,7 @@ void UfsEditor(void) {
|
|||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("UFS: UfsEditor: read=%d"), l);
|
||||
if (l < 0) { break; }
|
||||
buf[l] = '\0';
|
||||
WSContentSend_P((const char*)buf);
|
||||
WSContentSend_P(PSTR("%s"), buf);
|
||||
filelen -= l;
|
||||
}
|
||||
fp.close();
|
||||
|
|
|
@ -162,4 +162,18 @@ const char berry_autoexec[] =
|
|||
"end "
|
||||
"end "
|
||||
;
|
||||
|
||||
const char berry_preinit[] =
|
||||
// load "autoexec.be" using import, which loads either .be or .bec file
|
||||
"import string "
|
||||
"try "
|
||||
"load('preinit.be') "
|
||||
"except .. as e,m "
|
||||
"if e=='io_error' && string.find(m, \"preinit.be\")>0 "
|
||||
"log(\"BRY: no preinit.be\") "
|
||||
"else "
|
||||
"log(\"BRY: exception in preinit.be: \"+e+\": \"+m) "
|
||||
"end "
|
||||
"end "
|
||||
;
|
||||
#endif // USE_BERRY
|
||||
|
|
|
@ -29,11 +29,11 @@ extern "C" {
|
|||
}
|
||||
|
||||
const char kBrCommands[] PROGMEM = D_PRFX_BR "|" // prefix
|
||||
D_CMND_BR_RUN "|" D_CMND_BR_RESET
|
||||
D_CMND_BR_RUN
|
||||
;
|
||||
|
||||
void (* const BerryCommand[])(void) PROGMEM = {
|
||||
CmndBrRun, CmndBrReset,
|
||||
CmndBrRun,
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -234,7 +234,7 @@ void BerryObservability(bvm *vm, int event...) {
|
|||
/*********************************************************************************************\
|
||||
* VM Init
|
||||
\*********************************************************************************************/
|
||||
void BrReset(void) {
|
||||
void BerryInit(void) {
|
||||
// clean previous VM if any
|
||||
if (berry.vm != nullptr) {
|
||||
be_vm_delete(berry.vm);
|
||||
|
@ -280,6 +280,9 @@ void BrReset(void) {
|
|||
// AddLog(LOG_LEVEL_INFO, PSTR("After Berry"));
|
||||
|
||||
berry_init_ok = true;
|
||||
|
||||
// Run pre-init
|
||||
BrAutoexec(berry_preinit); // run 'preinit.be' if present
|
||||
} while (0);
|
||||
|
||||
if (!berry_init_ok) {
|
||||
|
@ -291,15 +294,22 @@ void BrReset(void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void BrAutoexec(void) {
|
||||
if (berry.vm == nullptr) { return; }
|
||||
/*********************************************************************************************\
|
||||
* Execute a script in Flash file-system
|
||||
*
|
||||
* Two options supported:
|
||||
* berry_preinit: load "preinit.be" to configure the device before driver pre-init and init
|
||||
* (typically I2C drivers, and AXP192/AXP202 configuration)
|
||||
* berry_autoexec: load "autoexec.be" once all drivers are initialized
|
||||
\*********************************************************************************************/
|
||||
void BrAutoexec(const char * init_script) {
|
||||
if (berry.vm == nullptr || TasmotaGlobal.no_autoexec) { return; } // abort is berry is not running, or bootloop prevention kicked in
|
||||
|
||||
int32_t ret_code1, ret_code2;
|
||||
bool berry_init_ok = false;
|
||||
|
||||
// load 'autoexec.be' or 'autoexec.bec'
|
||||
ret_code1 = be_loadstring(berry.vm, berry_autoexec);
|
||||
ret_code1 = be_loadstring(berry.vm, init_script);
|
||||
// be_dumpstack(berry.vm);
|
||||
if (ret_code1 != 0) {
|
||||
be_pop(berry.vm, 2);
|
||||
|
@ -368,15 +378,6 @@ void CmndBrRun(void) {
|
|||
checkBeTop();
|
||||
}
|
||||
|
||||
//
|
||||
// Command `BrReset`
|
||||
//
|
||||
void CmndBrReset(void) {
|
||||
if (berry.vm == nullptr) { ResponseCmndChar_P(PSTR(D_BR_NOT_STARTED)); return; }
|
||||
|
||||
BrReset();
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Berry console
|
||||
\*********************************************************************************************/
|
||||
|
@ -692,13 +693,13 @@ bool Xdrv52(uint8_t function)
|
|||
bool result = false;
|
||||
|
||||
switch (function) {
|
||||
//case FUNC_PRE_INIT:
|
||||
case FUNC_INIT:
|
||||
BrReset();
|
||||
break;
|
||||
// case FUNC_PRE_INIT: // we start Berry in pre_init so that other modules can call Berry in their init methods
|
||||
// // case FUNC_INIT:
|
||||
// BerryInit();
|
||||
// break;
|
||||
case FUNC_LOOP:
|
||||
if (!berry.autoexec_done) {
|
||||
BrAutoexec(); // run autoexec.be at first tick, so we know all modules are initialized
|
||||
BrAutoexec(berry_autoexec); // run autoexec.be at first tick, so we know all modules are initialized
|
||||
berry.autoexec_done = true;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
|
||||
#if defined(USE_FT5206) || defined(USE_XPT2046) || defined(USE_LILYGO47)
|
||||
#if defined(USE_FT5206) || defined(USE_XPT2046) || defined(USE_LILYGO47) || defined(USE_TOUCH_BUTTONS)
|
||||
|
||||
// #ifdef USE_DISPLAY_LVGL_ONLY
|
||||
// #undef USE_TOUCH_BUTTONS
|
||||
|
|
Loading…
Reference in New Issue