Tasmota/lib/libesp32/Berry/default/be_wirelib.c

149 lines
5.3 KiB
C
Raw Normal View History

2021-02-28 19:50:37 +00:00
/********************************************************************
* Tasmota lib
*
* To use: `import wire`
*
* 2 wire communication - I2C
*******************************************************************/
2021-04-28 18:30:19 +01:00
#include "be_constobj.h"
2021-02-28 19:50:37 +00:00
2021-04-24 11:11:06 +01:00
#ifdef USE_I2C
2021-03-13 21:42:24 +00:00
extern int b_wire_init(bvm *vm);
2021-02-28 19:50:37 +00:00
extern int b_wire_begintransmission(bvm *vm);
extern int b_wire_endtransmission(bvm *vm);
extern int b_wire_requestfrom(bvm *vm);
extern int b_wire_available(bvm *vm);
extern int b_wire_write(bvm *vm);
extern int b_wire_read(bvm *vm);
2021-03-07 18:37:18 +00:00
extern int b_wire_scan(bvm *vm);
extern int b_wire_validwrite(bvm *vm);
2021-03-03 07:34:38 +00:00
extern int b_wire_validread(bvm *vm);
2021-03-20 17:44:35 +00:00
extern int b_wire_detect(bvm *vm);
2021-03-03 07:34:38 +00:00
/********************************************************************
2021-09-15 18:36:48 +01:00
** Solidified function: write_bytes
********************************************************************/
2021-09-15 18:36:48 +01:00
be_local_closure(write_bytes, /* name */
be_nested_proto(
2021-09-15 18:36:48 +01:00
7, /* nstack */
4, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
2021-09-15 18:36:48 +01:00
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_string("_begin_transmission", -1515506120, 19),
/* K1 */ be_nested_string("_write", -2079504471, 6),
/* K2 */ be_nested_string("_end_transmission", -1057486896, 17),
}),
2021-09-15 18:36:48 +01:00
(be_nested_const_str("write_bytes", 1227543792, 11)),
(be_nested_const_str("input", -103256197, 5)),
( &(const binstruction[12]) { /* code */
0x8C100100, // 0000 GETMET R4 R0 K0
0x5C180200, // 0001 MOVE R6 R1
0x7C100400, // 0002 CALL R4 2
2021-09-15 18:36:48 +01:00
0x8C100101, // 0003 GETMET R4 R0 K1
0x5C180400, // 0004 MOVE R6 R2
0x7C100400, // 0005 CALL R4 2
2021-09-15 18:36:48 +01:00
0x8C100101, // 0006 GETMET R4 R0 K1
0x5C180600, // 0007 MOVE R6 R3
0x7C100400, // 0008 CALL R4 2
2021-09-15 18:36:48 +01:00
0x8C100102, // 0009 GETMET R4 R0 K2
0x7C100200, // 000A CALL R4 1
0x80000000, // 000B RET 0
})
)
);
/*******************************************************************/
/********************************************************************
2021-09-15 18:36:48 +01:00
** Solidified function: read_bytes
********************************************************************/
2021-09-15 18:36:48 +01:00
be_local_closure(read_bytes, /* name */
be_nested_proto(
2021-09-15 18:36:48 +01:00
8, /* nstack */
4, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
2021-09-15 18:36:48 +01:00
( &(const bvalue[ 6]) { /* constants */
/* K0 */ be_nested_string("_begin_transmission", -1515506120, 19),
/* K1 */ be_nested_string("_write", -2079504471, 6),
/* K2 */ be_nested_string("_end_transmission", -1057486896, 17),
/* K3 */ be_nested_string("_request_from", -329818692, 13),
/* K4 */ be_nested_string("_available", 1306196581, 10),
/* K5 */ be_nested_string("_read", 346717030, 5),
}),
2021-09-15 18:36:48 +01:00
(be_nested_const_str("read_bytes", -718234123, 10)),
(be_nested_const_str("input", -103256197, 5)),
( &(const binstruction[24]) { /* code */
0x8C100100, // 0000 GETMET R4 R0 K0
0x5C180200, // 0001 MOVE R6 R1
0x7C100400, // 0002 CALL R4 2
2021-09-15 18:36:48 +01:00
0x8C100101, // 0003 GETMET R4 R0 K1
0x5C180400, // 0004 MOVE R6 R2
0x7C100400, // 0005 CALL R4 2
2021-09-15 18:36:48 +01:00
0x8C100102, // 0006 GETMET R4 R0 K2
0x50180000, // 0007 LDBOOL R6 0 0
0x7C100400, // 0008 CALL R4 2
2021-09-15 18:36:48 +01:00
0x8C100103, // 0009 GETMET R4 R0 K3
0x5C180200, // 000A MOVE R6 R1
0x5C1C0600, // 000B MOVE R7 R3
0x7C100600, // 000C CALL R4 3
0x60100015, // 000D GETGBL R4 G21
0x5C140600, // 000E MOVE R5 R3
0x7C100200, // 000F CALL R4 1
0x8C140104, // 0010 GETMET R5 R0 K4
0x7C140200, // 0011 CALL R5 1
0x78160003, // 0012 JMPF R5 #0017
0x8C140105, // 0013 GETMET R5 R0 K5
0x7C140200, // 0014 CALL R5 1
0x40140805, // 0015 CONNECT R5 R4 R5
0x7001FFF8, // 0016 JMP #0010
0x80040800, // 0017 RET 1 R4
})
)
);
/*******************************************************************/
2021-09-15 18:36:48 +01:00
2021-04-28 18:30:19 +01:00
#include "../generate/be_fixed_be_class_tasmota_wire.h"
2021-04-28 18:30:19 +01:00
void be_load_wirelib(bvm *vm) {
be_pushntvclass(vm, &be_class_tasmota_wire);
be_setglobal(vm, "Wire");
be_pop(vm, 1);
}
2021-02-28 19:50:37 +00:00
/* @const_object_info_begin
2021-04-28 18:30:19 +01:00
class be_class_tasmota_wire (scope: global, name: Wire) {
bus, var
init, func(b_wire_init)
_begin_transmission, func(b_wire_begintransmission)
_end_transmission, func(b_wire_endtransmission)
_request_from, func(b_wire_requestfrom)
_available, func(b_wire_available)
_write, func(b_wire_write)
_read, func(b_wire_read)
scan, func(b_wire_scan)
write, func(b_wire_validwrite)
read, func(b_wire_validread)
detect, func(b_wire_detect)
read_bytes, closure(read_bytes_closure)
write_bytes, closure(write_bytes_closure)
2021-02-28 19:50:37 +00:00
}
@const_object_info_end */
2021-04-24 11:11:06 +01:00
#endif // USE_I2C