mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-13 05:46:30 +00:00
Merge pull request #12410 from s-hadinger/berry_i2c_driver
Berry added I2C_Driver class and patches
This commit is contained in:
commit
f6159f2f7f
@ -18,17 +18,18 @@ extern bclass* be_class_tasmota_driver; // Parent class
|
|||||||
/********** Solidified proto: init */
|
/********** Solidified proto: init */
|
||||||
be_define_local_const_str(init_str_name, "init", 380752755, 4);
|
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_source, "input", -103256197, 5);
|
||||||
be_define_local_const_str(init_str_0, "string", 398550328, 6);
|
be_define_local_const_str(init_str_0, "get_tasmota", 334356779, 11);
|
||||||
be_define_local_const_str(init_str_1, "get_tasmota", 334356779, 11);
|
be_define_local_const_str(init_str_1, "i2c_enabled", 218388101, 11);
|
||||||
be_define_local_const_str(init_str_2, "addr", 1087856498, 4);
|
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_3, "wire", -212213352, 4);
|
||||||
be_define_local_const_str(init_str_4, "wire_scan", -1623691416, 9);
|
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_5, "function", -1630125495, 8);
|
||||||
be_define_local_const_str(init_str_6, "format", -1180859054, 6);
|
be_define_local_const_str(init_str_6, "name", -1925595674, 4);
|
||||||
be_define_local_const_str(init_str_7, "I2C: %s detected on bus %d", 110398549, 26);
|
be_define_local_const_str(init_str_7, "I2C:", 813483371, 4);
|
||||||
be_define_local_const_str(init_str_8, "bus", 1607822841, 3);
|
be_define_local_const_str(init_str_8, "detected on bus", 1432002650, 15);
|
||||||
|
be_define_local_const_str(init_str_9, "bus", 1607822841, 3);
|
||||||
|
|
||||||
static const bvalue init_ktab[9] = {
|
static const bvalue init_ktab[10] = {
|
||||||
{ { .s=be_local_const_str(init_str_0) }, BE_STRING},
|
{ { .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_1) }, BE_STRING},
|
||||||
{ { .s=be_local_const_str(init_str_2) }, BE_STRING},
|
{ { .s=be_local_const_str(init_str_2) }, BE_STRING},
|
||||||
@ -38,36 +39,355 @@ static const bvalue init_ktab[9] = {
|
|||||||
{ { .s=be_local_const_str(init_str_6) }, 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_7) }, BE_STRING},
|
||||||
{ { .s=be_local_const_str(init_str_8) }, BE_STRING},
|
{ { .s=be_local_const_str(init_str_8) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(init_str_9) }, BE_STRING},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t init_code[20] = {
|
static const uint32_t init_code[44] = {
|
||||||
0xA40E0000, // 0000 IMPORT R3 R256
|
0x8C100100, // 0000 GETMET R4 R0 R256
|
||||||
0x8C100101, // 0001 GETMET R4 R0 R257
|
0x7C100200, // 0001 CALL R4 1
|
||||||
0x7C100200, // 0002 CALL R4 1
|
0x4C140000, // 0002 LDNIL 5
|
||||||
0x90020401, // 0003 SETMBR R0 R258 R1
|
0x20140605, // 0003 NE R5 R3 R5
|
||||||
0x8C140904, // 0004 GETMET R5 R4 R260
|
0x78160004, // 0004 JMPF R5 #000A
|
||||||
0x881C0102, // 0005 GETMBR R7 R0 R258
|
0x8C140901, // 0005 GETMET R5 R4 R257
|
||||||
0x7C140400, // 0006 CALL R5 2
|
0x5C1C0600, // 0006 MOVE R7 R3
|
||||||
0x90020605, // 0007 SETMBR R0 R259 R5
|
0x7C140400, // 0007 CALL R5 2
|
||||||
0x90020A02, // 0008 SETMBR R0 R261 R2
|
0x74160000, // 0008 JMPT R5 #000A
|
||||||
0x88140103, // 0009 GETMBR R5 R0 R259
|
0x80000A00, // 0009 RET 0 R5
|
||||||
0x78160007, // 000A JMPF R5 #0013
|
0x90020402, // 000A SETMBR R0 R258 R2
|
||||||
0x6014000F, // 000B GETGBL R5 G15
|
0x8C140904, // 000B GETMET R5 R4 R260
|
||||||
0x8C180706, // 000C GETMET R6 R3 R262
|
0x881C0102, // 000C GETMBR R7 R0 R258
|
||||||
0x58200007, // 000D LDCONST R8 K7
|
0x7C140400, // 000D CALL R5 2
|
||||||
0x88240105, // 000E GETMBR R9 R0 R261
|
0x90020605, // 000E SETMBR R0 R259 R5
|
||||||
0x88280103, // 000F GETMBR R10 R0 R259
|
0x88140103, // 000F GETMBR R5 R0 R259
|
||||||
0x88281508, // 0010 GETMBR R10 R10 R264
|
0x78160019, // 0010 JMPF R5 #002B
|
||||||
0x7C180800, // 0011 CALL R6 4
|
0x60140015, // 0011 GETGBL R5 G21
|
||||||
0x7C140200, // 0012 CALL R5 1
|
0x5C180200, // 0012 MOVE R6 R1
|
||||||
0x80000000, // 0013 RET 0 R0
|
0x7C140200, // 0013 CALL R5 1
|
||||||
|
0x1C140B05, // 0014 EQ R5 R5 R261
|
||||||
|
0x78160004, // 0015 JMPF R5 #001B
|
||||||
|
0x5C140200, // 0016 MOVE R5 R1
|
||||||
|
0x5C180000, // 0017 MOVE R6 R0
|
||||||
|
0x7C140200, // 0018 CALL R5 1
|
||||||
|
0x90020C05, // 0019 SETMBR R0 R262 R5
|
||||||
|
0x70020000, // 001A JMP #001C
|
||||||
|
0x90020C01, // 001B SETMBR R0 R262 R1
|
||||||
|
0x88140106, // 001C GETMBR R5 R0 R262
|
||||||
|
0x4C180000, // 001D LDNIL 6
|
||||||
|
0x1C140A06, // 001E EQ R5 R5 R6
|
||||||
|
0x78160001, // 001F JMPF R5 #0022
|
||||||
|
0x4C140000, // 0020 LDNIL 5
|
||||||
|
0x90020605, // 0021 SETMBR R0 R259 R5
|
||||||
|
0x88140103, // 0022 GETMBR R5 R0 R259
|
||||||
|
0x78160006, // 0023 JMPF R5 #002B
|
||||||
|
0x6014000F, // 0024 GETGBL R5 G15
|
||||||
|
0x58180007, // 0025 LDCONST R6 K7
|
||||||
|
0x881C0106, // 0026 GETMBR R7 R0 R262
|
||||||
|
0x58200008, // 0027 LDCONST R8 K8
|
||||||
|
0x88240103, // 0028 GETMBR R9 R0 R259
|
||||||
|
0x88241309, // 0029 GETMBR R9 R9 R265
|
||||||
|
0x7C140800, // 002A CALL R5 4
|
||||||
|
0x80000000, // 002B RET 0 R0
|
||||||
};
|
};
|
||||||
|
|
||||||
be_define_local_proto(init, 11, 3, 1, 0, 0);
|
be_define_local_proto(init, 10, 4, 1, 0, 0);
|
||||||
be_define_local_closure(init);
|
be_define_local_closure(init);
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: write8
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: write8 */
|
||||||
|
be_define_local_const_str(write8_str_name, "write8", -1160975764, 6);
|
||||||
|
be_define_local_const_str(write8_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(write8_str_0, "wire", -212213352, 4);
|
||||||
|
be_define_local_const_str(write8_str_1, "write", -1104765092, 5);
|
||||||
|
be_define_local_const_str(write8_str_2, "addr", 1087856498, 4);
|
||||||
|
|
||||||
|
static const bvalue write8_ktab[4] = {
|
||||||
|
{ { .s=be_local_const_str(write8_str_0) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(write8_str_1) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(write8_str_2) }, BE_STRING},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t write8_code[8] = {
|
||||||
|
0x880C0100, // 0000 GETMBR R3 R0 R256
|
||||||
|
0x8C0C0701, // 0001 GETMET R3 R3 R257
|
||||||
|
0x88140102, // 0002 GETMBR R5 R0 R258
|
||||||
|
0x5C180200, // 0003 MOVE R6 R1
|
||||||
|
0x5C1C0400, // 0004 MOVE R7 R2
|
||||||
|
0x58200003, // 0005 LDCONST R8 K3
|
||||||
|
0x7C0C0A00, // 0006 CALL R3 5
|
||||||
|
0x80040600, // 0007 RET 1 R3
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(write8, 9, 3, 1, 0, 0);
|
||||||
|
be_define_local_closure(write8);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: write_bit
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: write_bit */
|
||||||
|
be_define_local_const_str(write_bit_str_name, "write_bit", -1633976860, 9);
|
||||||
|
be_define_local_const_str(write_bit_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(write_bit_str_2, "write8", -1160975764, 6);
|
||||||
|
be_define_local_const_str(write_bit_str_3, "read8", -1492179129, 5);
|
||||||
|
|
||||||
|
static const bvalue write_bit_ktab[4] = {
|
||||||
|
{ { .i=0 }, BE_INT},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
{ { .s=be_local_const_str(write_bit_str_2) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(write_bit_str_3) }, BE_STRING},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t write_bit_code[26] = {
|
||||||
|
0x14100500, // 0000 LT R4 R2 R256
|
||||||
|
0x74120002, // 0001 JMPT R4 #0005
|
||||||
|
0x54120006, // 0002 LDINT R4 7
|
||||||
|
0x24100404, // 0003 GT R4 R2 R4
|
||||||
|
0x78120000, // 0004 JMPF R4 #0006
|
||||||
|
0x80000800, // 0005 RET 0 R4
|
||||||
|
0x38120202, // 0006 SHL R4 R257 R2
|
||||||
|
0x780E0007, // 0007 JMPF R3 #0010
|
||||||
|
0x8C140102, // 0008 GETMET R5 R0 R258
|
||||||
|
0x5C1C0200, // 0009 MOVE R7 R1
|
||||||
|
0x8C200103, // 000A GETMET R8 R0 R259
|
||||||
|
0x5C280200, // 000B MOVE R10 R1
|
||||||
|
0x7C200400, // 000C CALL R8 2
|
||||||
|
0x30201004, // 000D OR R8 R8 R4
|
||||||
|
0x7C140600, // 000E CALL R5 3
|
||||||
|
0x70020008, // 000F JMP #0019
|
||||||
|
0x8C140102, // 0010 GETMET R5 R0 R258
|
||||||
|
0x5C1C0200, // 0011 MOVE R7 R1
|
||||||
|
0x8C200103, // 0012 GETMET R8 R0 R259
|
||||||
|
0x5C280200, // 0013 MOVE R10 R1
|
||||||
|
0x7C200400, // 0014 CALL R8 2
|
||||||
|
0x542600FE, // 0015 LDINT R9 255
|
||||||
|
0x4241204, // 0016 SUB R9 R9 R4
|
||||||
|
0x2C201009, // 0017 AND R8 R8 R9
|
||||||
|
0x7C140600, // 0018 CALL R5 3
|
||||||
|
0x80000000, // 0019 RET 0 R0
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(write_bit, 11, 4, 1, 0, 0);
|
||||||
|
be_define_local_closure(write_bit);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: read8
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: read8 */
|
||||||
|
be_define_local_const_str(read8_str_name, "read8", -1492179129, 5);
|
||||||
|
be_define_local_const_str(read8_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(read8_str_0, "wire", -212213352, 4);
|
||||||
|
be_define_local_const_str(read8_str_1, "read", -824204347, 4);
|
||||||
|
be_define_local_const_str(read8_str_2, "addr", 1087856498, 4);
|
||||||
|
|
||||||
|
static const bvalue read8_ktab[4] = {
|
||||||
|
{ { .s=be_local_const_str(read8_str_0) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read8_str_1) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read8_str_2) }, BE_STRING},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t read8_code[7] = {
|
||||||
|
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||||
|
0x8C080501, // 0001 GETMET R2 R2 R257
|
||||||
|
0x88100102, // 0002 GETMBR R4 R0 R258
|
||||||
|
0x5C140200, // 0003 MOVE R5 R1
|
||||||
|
0x58180003, // 0004 LDCONST R6 K3
|
||||||
|
0x7C080800, // 0005 CALL R2 4
|
||||||
|
0x80040400, // 0006 RET 1 R2
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(read8, 7, 2, 1, 0, 0);
|
||||||
|
be_define_local_closure(read8);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: read12
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: read12 */
|
||||||
|
be_define_local_const_str(read12_str_name, "read12", -3890326, 6);
|
||||||
|
be_define_local_const_str(read12_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(read12_str_0, "wire", -212213352, 4);
|
||||||
|
be_define_local_const_str(read12_str_1, "read_bytes", -718234123, 10);
|
||||||
|
be_define_local_const_str(read12_str_2, "addr", 1087856498, 4);
|
||||||
|
|
||||||
|
static const bvalue read12_ktab[6] = {
|
||||||
|
{ { .s=be_local_const_str(read12_str_0) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read12_str_1) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read12_str_2) }, BE_STRING},
|
||||||
|
{ { .i=2 }, BE_INT},
|
||||||
|
{ { .i=0 }, BE_INT},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t read12_code[12] = {
|
||||||
|
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||||
|
0x8C080501, // 0001 GETMET R2 R2 R257
|
||||||
|
0x88100102, // 0002 GETMBR R4 R0 R258
|
||||||
|
0x5C140200, // 0003 MOVE R5 R1
|
||||||
|
0x58180003, // 0004 LDCONST R6 K3
|
||||||
|
0x7C080800, // 0005 CALL R2 4
|
||||||
|
0x940C0504, // 0006 GETIDX R3 R2 R260
|
||||||
|
0x54120003, // 0007 LDINT R4 4
|
||||||
|
0x380C0604, // 0008 SHL R3 R3 R4
|
||||||
|
0x94100505, // 0009 GETIDX R4 R2 R261
|
||||||
|
0xC0604, // 000A ADD R3 R3 R4
|
||||||
|
0x80040600, // 000B RET 1 R3
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(read12, 7, 2, 1, 0, 0);
|
||||||
|
be_define_local_closure(read12);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: read13
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: read13 */
|
||||||
|
be_define_local_const_str(read13_str_name, "read13", 12887293, 6);
|
||||||
|
be_define_local_const_str(read13_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(read13_str_0, "wire", -212213352, 4);
|
||||||
|
be_define_local_const_str(read13_str_1, "read_bytes", -718234123, 10);
|
||||||
|
be_define_local_const_str(read13_str_2, "addr", 1087856498, 4);
|
||||||
|
|
||||||
|
static const bvalue read13_ktab[6] = {
|
||||||
|
{ { .s=be_local_const_str(read13_str_0) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read13_str_1) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read13_str_2) }, BE_STRING},
|
||||||
|
{ { .i=2 }, BE_INT},
|
||||||
|
{ { .i=0 }, BE_INT},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t read13_code[12] = {
|
||||||
|
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||||
|
0x8C080501, // 0001 GETMET R2 R2 R257
|
||||||
|
0x88100102, // 0002 GETMBR R4 R0 R258
|
||||||
|
0x5C140200, // 0003 MOVE R5 R1
|
||||||
|
0x58180003, // 0004 LDCONST R6 K3
|
||||||
|
0x7C080800, // 0005 CALL R2 4
|
||||||
|
0x940C0504, // 0006 GETIDX R3 R2 R260
|
||||||
|
0x54120004, // 0007 LDINT R4 5
|
||||||
|
0x380C0604, // 0008 SHL R3 R3 R4
|
||||||
|
0x94100505, // 0009 GETIDX R4 R2 R261
|
||||||
|
0xC0604, // 000A ADD R3 R3 R4
|
||||||
|
0x80040600, // 000B RET 1 R3
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(read13, 7, 2, 1, 0, 0);
|
||||||
|
be_define_local_closure(read13);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: read24
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: read24 */
|
||||||
|
be_define_local_const_str(read24_str_name, "read24", 1808533811, 6);
|
||||||
|
be_define_local_const_str(read24_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(read24_str_0, "wire", -212213352, 4);
|
||||||
|
be_define_local_const_str(read24_str_1, "read_bytes", -718234123, 10);
|
||||||
|
be_define_local_const_str(read24_str_2, "addr", 1087856498, 4);
|
||||||
|
|
||||||
|
static const bvalue read24_ktab[7] = {
|
||||||
|
{ { .s=be_local_const_str(read24_str_0) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read24_str_1) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read24_str_2) }, BE_STRING},
|
||||||
|
{ { .i=3 }, BE_INT},
|
||||||
|
{ { .i=0 }, BE_INT},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
{ { .i=2 }, BE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t read24_code[16] = {
|
||||||
|
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||||
|
0x8C080501, // 0001 GETMET R2 R2 R257
|
||||||
|
0x88100102, // 0002 GETMBR R4 R0 R258
|
||||||
|
0x5C140200, // 0003 MOVE R5 R1
|
||||||
|
0x58180003, // 0004 LDCONST R6 K3
|
||||||
|
0x7C080800, // 0005 CALL R2 4
|
||||||
|
0x940C0504, // 0006 GETIDX R3 R2 R260
|
||||||
|
0x5412000F, // 0007 LDINT R4 16
|
||||||
|
0x380C0604, // 0008 SHL R3 R3 R4
|
||||||
|
0x94100505, // 0009 GETIDX R4 R2 R261
|
||||||
|
0x54160007, // 000A LDINT R5 8
|
||||||
|
0x38100805, // 000B SHL R4 R4 R5
|
||||||
|
0xC0604, // 000C ADD R3 R3 R4
|
||||||
|
0x94100506, // 000D GETIDX R4 R2 R262
|
||||||
|
0xC0604, // 000E ADD R3 R3 R4
|
||||||
|
0x80040600, // 000F RET 1 R3
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(read24, 7, 2, 1, 0, 0);
|
||||||
|
be_define_local_closure(read24);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
** Solidified function: read32
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/********** Solidified proto: read32 */
|
||||||
|
be_define_local_const_str(read32_str_name, "read32", 1741276240, 6);
|
||||||
|
be_define_local_const_str(read32_str_source, "input", -103256197, 5);
|
||||||
|
be_define_local_const_str(read32_str_0, "wire", -212213352, 4);
|
||||||
|
be_define_local_const_str(read32_str_1, "read_bytes", -718234123, 10);
|
||||||
|
be_define_local_const_str(read32_str_2, "addr", 1087856498, 4);
|
||||||
|
|
||||||
|
static const bvalue read32_ktab[7] = {
|
||||||
|
{ { .s=be_local_const_str(read32_str_0) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read32_str_1) }, BE_STRING},
|
||||||
|
{ { .s=be_local_const_str(read32_str_2) }, BE_STRING},
|
||||||
|
{ { .i=0 }, BE_INT},
|
||||||
|
{ { .i=1 }, BE_INT},
|
||||||
|
{ { .i=2 }, BE_INT},
|
||||||
|
{ { .i=3 }, BE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t read32_code[20] = {
|
||||||
|
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||||
|
0x8C080501, // 0001 GETMET R2 R2 R257
|
||||||
|
0x88100102, // 0002 GETMBR R4 R0 R258
|
||||||
|
0x5C140200, // 0003 MOVE R5 R1
|
||||||
|
0x541A0003, // 0004 LDINT R6 4
|
||||||
|
0x7C080800, // 0005 CALL R2 4
|
||||||
|
0x940C0503, // 0006 GETIDX R3 R2 R259
|
||||||
|
0x54120017, // 0007 LDINT R4 24
|
||||||
|
0x380C0604, // 0008 SHL R3 R3 R4
|
||||||
|
0x94100504, // 0009 GETIDX R4 R2 R260
|
||||||
|
0x5416000F, // 000A LDINT R5 16
|
||||||
|
0x38100805, // 000B SHL R4 R4 R5
|
||||||
|
0xC0604, // 000C ADD R3 R3 R4
|
||||||
|
0x94100505, // 000D GETIDX R4 R2 R261
|
||||||
|
0x54160007, // 000E LDINT R5 8
|
||||||
|
0x38100805, // 000F SHL R4 R4 R5
|
||||||
|
0xC0604, // 0010 ADD R3 R3 R4
|
||||||
|
0x94100506, // 0011 GETIDX R4 R2 R262
|
||||||
|
0xC0604, // 0012 ADD R3 R3 R4
|
||||||
|
0x80040600, // 0013 RET 1 R3
|
||||||
|
};
|
||||||
|
|
||||||
|
be_define_local_proto(read32, 7, 2, 1, 0, 0);
|
||||||
|
be_define_local_closure(read32);
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#if BE_USE_PRECOMPILED_OBJECT
|
#if BE_USE_PRECOMPILED_OBJECT
|
||||||
@ -82,7 +402,14 @@ void be_load_driver_i2c_lib(bvm *vm) {
|
|||||||
{ "name", NULL },
|
{ "name", NULL },
|
||||||
|
|
||||||
{ NULL, (bntvfunc) BE_CLOSURE }, /* mark section for berry closures */
|
{ NULL, (bntvfunc) BE_CLOSURE }, /* mark section for berry closures */
|
||||||
{ "add_cmd", (bntvfunc) &init_closure },
|
{ "init", (bntvfunc) &init_closure },
|
||||||
|
{ "write8", (bntvfunc) &write8_closure },
|
||||||
|
{ "write_bit", (bntvfunc) &write_bit_closure },
|
||||||
|
{ "read8", (bntvfunc) &read8_closure },
|
||||||
|
{ "read12", (bntvfunc) &read12_closure },
|
||||||
|
{ "read13", (bntvfunc) &read13_closure },
|
||||||
|
{ "read24", (bntvfunc) &read24_closure },
|
||||||
|
{ "read32", (bntvfunc) &read32_closure },
|
||||||
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
@ -105,6 +432,13 @@ class be_class_tasmota_i2c_driver (scope: global, name: I2C_Driver, super: be_cl
|
|||||||
addr, var
|
addr, var
|
||||||
name, var
|
name, var
|
||||||
|
|
||||||
add_cmd, closure(init_closure)
|
init, closure(init_closure)
|
||||||
|
write8, closure(write8_closure)
|
||||||
|
write_bit, closure(write_bit_closure)
|
||||||
|
read8, closure(read8_closure)
|
||||||
|
read12, closure(read12_closure)
|
||||||
|
read13, closure(read13_closure)
|
||||||
|
read24, closure(read24_closure)
|
||||||
|
read32, closure(read32_closure)
|
||||||
}
|
}
|
||||||
@const_object_info_end */
|
@const_object_info_end */
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,22 @@
|
|||||||
#include "be_constobj.h"
|
#include "be_constobj.h"
|
||||||
|
|
||||||
static be_define_const_map_slots(be_class_tasmota_i2c_driver_map) {
|
static be_define_const_map_slots(be_class_tasmota_i2c_driver_map) {
|
||||||
{ be_const_key(wire, -1), be_const_int(0) },
|
{ be_const_key(read32, -1), be_const_closure(read32_closure) },
|
||||||
{ be_const_key(addr, -1), be_const_int(1) },
|
{ be_const_key(write8, 6), be_const_closure(write8_closure) },
|
||||||
{ be_const_key(name, 1), be_const_int(2) },
|
{ be_const_key(name, -1), be_const_int(0) },
|
||||||
{ be_const_key(add_cmd, -1), be_const_closure(init_closure) },
|
{ be_const_key(addr, 10), be_const_int(1) },
|
||||||
|
{ be_const_key(read12, -1), be_const_closure(read12_closure) },
|
||||||
|
{ be_const_key(write_bit, 8), be_const_closure(write_bit_closure) },
|
||||||
|
{ be_const_key(read13, -1), be_const_closure(read13_closure) },
|
||||||
|
{ be_const_key(read24, -1), be_const_closure(read24_closure) },
|
||||||
|
{ be_const_key(wire, -1), be_const_int(2) },
|
||||||
|
{ be_const_key(init, -1), be_const_closure(init_closure) },
|
||||||
|
{ be_const_key(read8, -1), be_const_closure(read8_closure) },
|
||||||
};
|
};
|
||||||
|
|
||||||
static be_define_const_map(
|
static be_define_const_map(
|
||||||
be_class_tasmota_i2c_driver_map,
|
be_class_tasmota_i2c_driver_map,
|
||||||
4
|
11
|
||||||
);
|
);
|
||||||
|
|
||||||
BE_EXPORT_VARIABLE be_define_const_class(
|
BE_EXPORT_VARIABLE be_define_const_class(
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
** https://github.com/Skiars/berry/blob/master/LICENSE
|
** https://github.com/Skiars/berry/blob/master/LICENSE
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
#include "be_object.h"
|
#include "be_object.h"
|
||||||
|
#include "be_vm.h"
|
||||||
#include "be_exec.h"
|
#include "be_exec.h"
|
||||||
#include "be_mem.h"
|
#include "be_mem.h"
|
||||||
#include "be_gc.h"
|
#include "be_gc.h"
|
||||||
|
#include "be_class.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define READLINE_STEP 100
|
#define READLINE_STEP 100
|
||||||
@ -73,10 +75,34 @@ static int l_input(bvm *vm)
|
|||||||
|
|
||||||
static int l_super(bvm *vm)
|
static int l_super(bvm *vm)
|
||||||
{
|
{
|
||||||
if (be_top(vm)) {
|
int argc = be_top(vm);
|
||||||
|
if (argc) {
|
||||||
|
if (argc >= 2) {
|
||||||
|
if (be_isinstance(vm, 1) && be_isclass(vm, 2)) {
|
||||||
|
/* leveled super, i.e. fix the parenthood class level */
|
||||||
|
binstance *o = var_toobj(be_indexof(vm, 1));
|
||||||
|
bclass *bc = var_toobj(be_indexof(vm, 2));
|
||||||
|
while (o) {
|
||||||
|
bclass *c = be_instance_class(o);
|
||||||
|
if (c == bc) break; /* found */
|
||||||
|
o = be_instance_super(o);
|
||||||
|
}
|
||||||
|
bvalue *top = be_incrtop(vm);
|
||||||
|
if (o) {
|
||||||
|
var_setinstance(top, o); /* return the instance with the specified parent class */
|
||||||
|
} else {
|
||||||
|
var_setnil(top); /* not found, return nil */
|
||||||
|
}
|
||||||
|
be_return(vm);
|
||||||
|
} else {
|
||||||
|
be_raise(vm, "type_error", "leveled super() requires 'instance' and 'class' arguments");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* simple use of super */
|
||||||
be_getsuper(vm, 1);
|
be_getsuper(vm, 1);
|
||||||
be_return(vm);
|
be_return(vm);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
be_return_nil(vm);
|
be_return_nil(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
lib/libesp32/Berry/tests/super_leveled.be
Normal file
44
lib/libesp32/Berry/tests/super_leveled.be
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#- test for leveled use of super() -#
|
||||||
|
|
||||||
|
#- setup -#
|
||||||
|
class A def r() return 'a' end def f() return self.r() end end
|
||||||
|
class B:A def r() return 'b' end def f() return super(self,A).f() + 'b' end end
|
||||||
|
class C:B def r() return 'c' end def f() return super(self,B).f() + 'c' end end
|
||||||
|
a=A()
|
||||||
|
b=B()
|
||||||
|
c=C()
|
||||||
|
|
||||||
|
#- regular behavior -#
|
||||||
|
assert(classname(a) == 'A')
|
||||||
|
assert(classname(b) == 'B')
|
||||||
|
assert(classname(c) == 'C')
|
||||||
|
assert(a.r() == 'a')
|
||||||
|
assert(b.r() == 'b')
|
||||||
|
assert(c.r() == 'c')
|
||||||
|
assert(a.f() == 'a')
|
||||||
|
|
||||||
|
#- standard use of super() -#
|
||||||
|
assert(super(a) == nil)
|
||||||
|
assert(super(A) == nil)
|
||||||
|
assert(classname(super(B)) == 'A')
|
||||||
|
assert(classname(super(C)) == 'B')
|
||||||
|
assert(classname(super(super(C))) == 'A')
|
||||||
|
assert(super(super(super(C))) == nil)
|
||||||
|
|
||||||
|
#- super() levele -#
|
||||||
|
assert(super(a,A) == a)
|
||||||
|
assert(classname(super(a,A)) == 'A')
|
||||||
|
assert(classname(super(b,B)) == 'B')
|
||||||
|
assert(classname(super(c,C)) == 'C')
|
||||||
|
assert(classname(super(c,B)) == 'B')
|
||||||
|
assert(classname(super(c,A)) == 'A')
|
||||||
|
assert(super(c,map) == nil) #- not a parent class -#
|
||||||
|
|
||||||
|
#- wrapping it all -#
|
||||||
|
assert(a.f() == 'a')
|
||||||
|
assert(b.f() == 'bb')
|
||||||
|
|
||||||
|
#- the last one is tricky:
|
||||||
|
c.f() -> calls f() in class B -> calls f() in class A -> calls r() of overall class hence C
|
||||||
|
-#
|
||||||
|
assert(c.f() == 'cbc')
|
@ -1,94 +1,10 @@
|
|||||||
#-------------------------------------------------------------
|
|
||||||
- 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
|
- Generic driver for AXP192
|
||||||
-------------------------------------------------------------#
|
-------------------------------------------------------------#
|
||||||
class AXP192 : I2C_Driver
|
class AXP192 : I2C_Driver
|
||||||
def init()
|
def init()
|
||||||
super(self).init("AXP192", 0x34)
|
super(self, I2C_Driver).init("AXP192", 0x34)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return True = Battery Exist
|
# Return True = Battery Exist
|
||||||
@ -145,10 +61,10 @@ class AXP192 : I2C_Driver
|
|||||||
end
|
end
|
||||||
|
|
||||||
if ldo == 2
|
if ldo == 2
|
||||||
self.write1(0x28, self.read8(0x28) & 0x0F | ((voltage & 0x0F) << 4))
|
self.write8(0x28, self.read8(0x28) & 0x0F | ((voltage & 0x0F) << 4))
|
||||||
end
|
end
|
||||||
if ldo == 3
|
if ldo == 3
|
||||||
self.write1(0x28, self.read8(0x28) & 0xF0 | (voltage & 0x0F))
|
self.write8(0x28, self.read8(0x28) & 0xF0 | (voltage & 0x0F))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -191,7 +107,7 @@ class AXP192 : I2C_Driver
|
|||||||
elif dcdc == 2 addr = 0x23
|
elif dcdc == 2 addr = 0x23
|
||||||
end
|
end
|
||||||
|
|
||||||
self.write1(addr, self.read8(addr) & 0x80 | (v & 0x7F))
|
self.write8(addr, self.read8(addr) & 0x80 | (v & 0x7F))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set charging current
|
# Set charging current
|
||||||
@ -212,7 +128,7 @@ class AXP192 : I2C_Driver
|
|||||||
# 1240mA = 14
|
# 1240mA = 14
|
||||||
# 1320mA = 15
|
# 1320mA = 15
|
||||||
def set_chg_current(current_code)
|
def set_chg_current(current_code)
|
||||||
self.write1(0x33, self.read8(0x33) & 0xF0 | (current_code & 0x0F))
|
self.write8(0x33, self.read8(0x33) & 0xF0 | (current_code & 0x0F))
|
||||||
end
|
end
|
||||||
|
|
||||||
# // Low Volt Level 1, when APS Volt Output < 3.4496 V
|
# // Low Volt Level 1, when APS Volt Output < 3.4496 V
|
||||||
@ -265,20 +181,20 @@ end
|
|||||||
-------------------------------------------------------------#
|
-------------------------------------------------------------#
|
||||||
class AXP192_M5Stack_Core2 : AXP192
|
class AXP192_M5Stack_Core2 : AXP192
|
||||||
def init()
|
def init()
|
||||||
super(self).init()
|
super(self, AXP192).init()
|
||||||
|
|
||||||
if self.wire
|
if self.wire
|
||||||
# Disable vbus hold limit
|
# Disable vbus hold limit
|
||||||
self.write1(0x30, self.read8(0x30) & 0x04 | 0x02)
|
self.write8(0x30, self.read8(0x30) & 0x04 | 0x02)
|
||||||
|
|
||||||
# AXP192 GPIO1:OD OUTPUT
|
# AXP192 GPIO1:OD OUTPUT
|
||||||
self.write1(0x92, self.read8(0x92) & 0xF8)
|
self.write8(0x92, self.read8(0x92) & 0xF8)
|
||||||
|
|
||||||
# AXP192 GPIO2:OD OUTPUT
|
# AXP192 GPIO2:OD OUTPUT
|
||||||
self.write1(0x93, self.read8(0x93) & 0xF8)
|
self.write8(0x93, self.read8(0x93) & 0xF8)
|
||||||
|
|
||||||
# AXP192 RTC CHG rtc battery charging enabled
|
# AXP192 RTC CHG rtc battery charging enabled
|
||||||
self.write1(0x35, self.read8(0x35) & 0x1C | 0xA2)
|
self.write8(0x35, self.read8(0x35) & 0x1C | 0xA2)
|
||||||
|
|
||||||
# esp32 power voltage was set to 3.35v
|
# esp32 power voltage was set to 3.35v
|
||||||
self.set_esp_voltage(3350)
|
self.set_esp_voltage(3350)
|
||||||
@ -305,7 +221,7 @@ class AXP192_M5Stack_Core2 : AXP192
|
|||||||
self.set_chg_current(0) # 0 = 100mA
|
self.set_chg_current(0) # 0 = 100mA
|
||||||
|
|
||||||
# AXP192 GPIO4 - TBC what this does really?
|
# AXP192 GPIO4 - TBC what this does really?
|
||||||
self.write1(0x95, self.read8(0X95) & 0x72 | 0x84)
|
self.write8(0x95, self.read8(0X95) & 0x72 | 0x84)
|
||||||
|
|
||||||
# Button parameter setting
|
# Button parameter setting
|
||||||
# Current:
|
# Current:
|
||||||
@ -314,7 +230,7 @@ class AXP192_M5Stack_Core2 : AXP192
|
|||||||
# Automatic shutdown function setting when the key duration is longer than the shutdown duration = turn on
|
# Automatic shutdown function setting when the key duration is longer than the shutdown duration = turn on
|
||||||
# PWROK signal delay after power on = 64ms
|
# PWROK signal delay after power on = 64ms
|
||||||
# Shutdown duration setting = 4s
|
# Shutdown duration setting = 4s
|
||||||
self.write1(0x34, 0x4C)
|
self.write8(0x34, 0x4C)
|
||||||
|
|
||||||
# ADC all-on
|
# ADC all-on
|
||||||
# Bit 7: Battery voltage ADC enable
|
# Bit 7: Battery voltage ADC enable
|
||||||
@ -325,7 +241,7 @@ class AXP192_M5Stack_Core2 : AXP192
|
|||||||
# Bit 2: VBUS current ADC enable
|
# Bit 2: VBUS current ADC enable
|
||||||
# Bit 1: APS voltage ADC enable
|
# Bit 1: APS voltage ADC enable
|
||||||
# Bit 0: TS pin ADC function enable
|
# Bit 0: TS pin ADC function enable
|
||||||
self.write1(0x82, 0xFF)
|
self.write8(0x82, 0xFF)
|
||||||
|
|
||||||
# Reset LCD Controller
|
# Reset LCD Controller
|
||||||
self.set_lcd_reset(false)
|
self.set_lcd_reset(false)
|
||||||
@ -370,12 +286,12 @@ class AXP192_M5Stack_Core2 : AXP192
|
|||||||
# Bus Power Mode
|
# Bus Power Mode
|
||||||
def set_buf_power_mode(state)
|
def set_buf_power_mode(state)
|
||||||
if (state)
|
if (state)
|
||||||
self.write1(0x12, self.read8(0x12) & 0xBF) # set EXTEN to disable 5v boost
|
self.write8(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
|
self.write8(0x90, self.read8(0x90) & 0xF8 | 0x01) # set GPIO0 to float, using enternal pulldown resistor to enable supply from BUS_5VS
|
||||||
else
|
else
|
||||||
self.write1(0x91, self.read8(0x91) & 0x0F | 0xF0)
|
self.write8(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.write8(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
|
self.write8(0x12, self.read8(0x12) | 0x40) # set EXTEN to enable 5v boost
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -385,11 +301,10 @@ end
|
|||||||
-------------------------------------------------------------#
|
-------------------------------------------------------------#
|
||||||
class AXP192_M5StickC : AXP192
|
class AXP192_M5StickC : AXP192
|
||||||
def init()
|
def init()
|
||||||
super(self).init()
|
super(self, AXP192).init()
|
||||||
|
|
||||||
if self.wire
|
if self.wire
|
||||||
# Disable vbus hold limit
|
# Disable vbus hold limit
|
||||||
self.write1(0x30, 0x80)
|
self.write8(0x30, 0x80)
|
||||||
|
|
||||||
# lcd backlight voltage was set to 2.80v
|
# lcd backlight voltage was set to 2.80v
|
||||||
self.set_lcd_voltage(2800)
|
self.set_lcd_voltage(2800)
|
||||||
@ -398,7 +313,7 @@ end
|
|||||||
self.set_ldo_voltage(3, 3000)
|
self.set_ldo_voltage(3, 3000)
|
||||||
|
|
||||||
# Set ADC sample rate to 200hz
|
# Set ADC sample rate to 200hz
|
||||||
self.write1(0x84, 0xF2)
|
self.write8(0x84, 0xF2)
|
||||||
|
|
||||||
# set charging current to 100mA
|
# set charging current to 100mA
|
||||||
self.set_chg_current(0) # 0 = 100mA
|
self.set_chg_current(0) # 0 = 100mA
|
||||||
@ -413,10 +328,10 @@ end
|
|||||||
# Automatic shutdown function setting when the key duration is longer than the shutdown duration = turn on
|
# Automatic shutdown function setting when the key duration is longer than the shutdown duration = turn on
|
||||||
# PWROK signal delay after power on = 64ms
|
# PWROK signal delay after power on = 64ms
|
||||||
# Shutdown duration setting = 4s
|
# Shutdown duration setting = 4s
|
||||||
self.write1(0x36, 0x4C)
|
self.write8(0x36, 0x4C)
|
||||||
|
|
||||||
# Mic GPIO0 - floating
|
# Mic GPIO0 - floating
|
||||||
self.write1(0x90, 0x07)
|
self.write8(0x90, 0x07)
|
||||||
|
|
||||||
# enable LDO2, LDO3, DCDC1, DCDC3
|
# enable LDO2, LDO3, DCDC1, DCDC3
|
||||||
self.set_ldo_enable(2, true)
|
self.set_ldo_enable(2, true)
|
||||||
@ -425,17 +340,17 @@ end
|
|||||||
self.set_dcdc_enable(3, true)
|
self.set_dcdc_enable(3, true)
|
||||||
|
|
||||||
# Set temperature protection
|
# Set temperature protection
|
||||||
self.write1(0x39, 0xFC)
|
self.write8(0x39, 0xFC)
|
||||||
|
|
||||||
# Enable RTC BAT charge
|
# Enable RTC BAT charge
|
||||||
self.write1(0x35, 0xA2)
|
self.write8(0x35, 0xA2)
|
||||||
# Write1Byte(0x35, 0xa2 & (disableRTC ? 0x7F : 0xFF));
|
# Write1Byte(0x35, 0xa2 & (disableRTC ? 0x7F : 0xFF));
|
||||||
|
|
||||||
# Enable bat detection
|
# Enable bat detection
|
||||||
self.write1(0x32, 0x46)
|
self.write8(0x32, 0x46)
|
||||||
|
|
||||||
# Set Power off voltage 3.0v
|
# Set Power off voltage 3.0v
|
||||||
self.write1(0x31, self.read8(0x31) & 0xF8 | 0x04)
|
self.write8(0x31, self.read8(0x31) & 0xF8 | 0x04)
|
||||||
|
|
||||||
# ADC all-on
|
# ADC all-on
|
||||||
# Bit 7: Battery voltage ADC enable
|
# Bit 7: Battery voltage ADC enable
|
||||||
@ -446,7 +361,7 @@ end
|
|||||||
# Bit 2: VBUS current ADC enable
|
# Bit 2: VBUS current ADC enable
|
||||||
# Bit 1: APS voltage ADC enable
|
# Bit 1: APS voltage ADC enable
|
||||||
# Bit 0: TS pin ADC function enable
|
# Bit 0: TS pin ADC function enable
|
||||||
self.write1(0x82, 0xFF)
|
self.write8(0x82, 0xFF)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
104
tasmota/berry/drivers/i2c_driver.be
Normal file
104
tasmota/berry/drivers/i2c_driver.be
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#-------------------------------------------------------------
|
||||||
|
- IMPORTANT
|
||||||
|
- THIS CLASS IS ALREADY BAKED IN TASMOTA
|
||||||
|
-
|
||||||
|
- It is here for debugging and documentation purpose only
|
||||||
|
-------------------------------------------------------------#
|
||||||
|
|
||||||
|
#-------------------------------------------------------------
|
||||||
|
- I2C_Driver class to simplify development of I2C drivers
|
||||||
|
-
|
||||||
|
- I2C_Driver(name, addr [, i2c_index]) -> nil
|
||||||
|
- name: name of I2C device for logging, or function to detect the model
|
||||||
|
- 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 #- wire object to reach the device, if nil then the module is not initialized -#
|
||||||
|
var addr #- I2C address of the device -#
|
||||||
|
var name #- model namme of the device, cannot be nil -#
|
||||||
|
|
||||||
|
#- Init and look for device
|
||||||
|
- Input:
|
||||||
|
- name_or_detect : name of the device (if string)
|
||||||
|
or function to detect the precise model(if function)
|
||||||
|
the function is passed a single argument `self`
|
||||||
|
and must return a string, or `nil` if the device is invalid
|
||||||
|
- addr : I2C address of device (int 0..255)
|
||||||
|
- i2c_index : Tasmota I2C index, see `I2CDEVICES.md` (int)
|
||||||
|
--#
|
||||||
|
def init(name_or_detect, addr, i2c_index)
|
||||||
|
var tasmota = self.get_tasmota() #- retrieve the 'tasmota' singleton -#
|
||||||
|
|
||||||
|
#- 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 -#
|
||||||
|
|
||||||
|
if self.wire
|
||||||
|
#- find name of device, can be a string or a method -#
|
||||||
|
if type(name_or_detect) == 'function'
|
||||||
|
self.name = name_or_detect(self)
|
||||||
|
else
|
||||||
|
self.name = name_or_detect
|
||||||
|
end
|
||||||
|
#- if name is invalid, it means we can't detect device, abort -#
|
||||||
|
if self.name == nil self.wire = nil end
|
||||||
|
|
||||||
|
if self.wire
|
||||||
|
print("I2C:", self.name, "detected on bus", self.wire.bus)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#- write register with 8 bits value -#
|
||||||
|
def write8(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.write8(reg, self.read8(reg) | mark)
|
||||||
|
else self.write8(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
|
||||||
|
|
||||||
|
#- Example
|
||||||
|
|
||||||
|
d = I2C_Driver("MPU", 0x68, 58)
|
||||||
|
|
||||||
|
-#
|
@ -5,14 +5,13 @@
|
|||||||
- Alternative to xsns_85_mpu6886.ino
|
- Alternative to xsns_85_mpu6886.ino
|
||||||
-#
|
-#
|
||||||
|
|
||||||
class MPU6886 : Driver
|
class MPU6886 : I2C_Driver
|
||||||
var wire #- if wire == nil then the module is not initialized -#
|
|
||||||
var device
|
var device
|
||||||
var gres, ares
|
var gres, ares
|
||||||
var accel, gyro
|
var accel, gyro
|
||||||
|
|
||||||
def init()
|
def init()
|
||||||
self.wire = tasmota.wire_scan(0x68, 58)
|
super(self, I2C_Driver).init(self.detect_mpu, 0x68, 58)
|
||||||
|
|
||||||
if self.wire
|
if self.wire
|
||||||
var v = self.wire.read(0x68,0x75,1)
|
var v = self.wire.read(0x68,0x75,1)
|
||||||
@ -50,7 +49,22 @@ class MPU6886 : Driver
|
|||||||
|
|
||||||
self.gres = 2000.0/32768.0
|
self.gres = 2000.0/32768.0
|
||||||
self.ares = 8.0/32678.0
|
self.ares = 8.0/32678.0
|
||||||
print("I2C:","MPU"+str(self.device),"detected on bus",self.wire.bus)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#- detect the MPU model type -#
|
||||||
|
#- currently MPU6886 and MPU9250 -#
|
||||||
|
def detect_mpu()
|
||||||
|
if self.wire
|
||||||
|
var v = self.wire.read(0x68,0x75,1)
|
||||||
|
if v == 0x19 self.device = 6886
|
||||||
|
elif v == 0x71 self.device = 9250
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.device
|
||||||
|
return "MPU" + str(self.device)
|
||||||
|
end
|
||||||
|
#- don't return anything if invalid or unidentified -#
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -118,5 +132,6 @@ class MPU6886 : Driver
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
mpu_accel = MPU6886()
|
mpu_accel = MPU6886()
|
||||||
tasmota.add_driver(mpu_accel)
|
tasmota.add_driver(mpu_accel)
|
29
tasmota/berry/examples/reverse_iter.be
Normal file
29
tasmota/berry/examples/reverse_iter.be
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#- Example of reverse range function
|
||||||
|
|
||||||
|
Allows to do range for loops in reverse ordre:
|
||||||
|
|
||||||
|
> for i:reverse(5..8) print(i) end
|
||||||
|
3
|
||||||
|
2
|
||||||
|
1
|
||||||
|
>
|
||||||
|
|
||||||
|
-#
|
||||||
|
|
||||||
|
class reverse
|
||||||
|
var r
|
||||||
|
|
||||||
|
def init(r)
|
||||||
|
if issubclass(range, r)
|
||||||
|
self.r = r
|
||||||
|
else
|
||||||
|
raise 'type_error', 'Unsupported type of class'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def iter()
|
||||||
|
var iter_func = self.r.iter()
|
||||||
|
var offset = self.r.upper() + self.r.lower()
|
||||||
|
return def () return offset - iter_func() end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user