I2C functions added.

Rene Bartsch 2018-07-12 17:16:23 +02:00
parent c83ede71cf
commit 9e5a3b8d3d
1 changed files with 44 additions and 0 deletions

@ -30,6 +30,9 @@ boolean Xsns<driverID>(byte callback_id) {
// ???
boolean result = false;
// Check if I2C mode
// if(i2c_flg) {
// Check which callback ID is called by Tasmota
switch (callback_id) {
case FUNC_PRE_INIT:
@ -46,8 +49,10 @@ boolean Xsns<driverID>(byte callback_id) {
break;
case FUNC_JSON_APPEND:
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_APPEND:
break;
#endif // USE_WEBSERVER
case FUNC_SAVE_BEFORE_RESTART:
break;
case FUNC_COMMAND:
@ -67,6 +72,7 @@ boolean Xsns<driverID>(byte callback_id) {
case FUNC_FREE_MEM
break;
}
// } // i2c_flg
// Return boolean result
return result;
@ -155,6 +161,44 @@ AddLogSerial(LOG_LEVEL_INFO);
### void AddLogMissed(char *sensor, uint8_t misses)
???
### bool I2cValidRead8(uint8_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead16(uint16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidReadS16(int16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead16LE(uint16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidReadS16_LE(int16_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead24(int32_t *data, uint8_t addr, uint8_t reg)
### bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
These functions return `true` if 1, 2, 3 or `size` bytes can be read from the I2C address `addr` and register `reg` into `*data`.
Functions with a `S` read signed data types while functions without a `S` read unsigned data types.
Functions with LE read little endian byte order while functions without LE read machine byte order.
### uint8_t I2cRead8(uint8_t addr, uint8_t reg)
### uint16_t I2cRead16(uint8_t addr, uint8_t reg)
### int16_t I2cReadS16(uint8_t addr, uint8_t reg)
### uint16_t I2cRead16LE(uint8_t addr, uint8_t reg)
### int16_t I2cReadS16_LE(uint8_t addr, uint8_t reg)
### int32_t I2cRead24(uint8_t addr, uint8_t reg)
These functions return 1, 2 or 3 bytes from the I2C address `addr` and register `reg`.
Functions with a `S` read signed data types while functions without a `S` read unsigned data types.
Functions with LE read little endian byte order while functions without LE read machine byte order.
### bool I2cWrite8(uint8_t addr, uint8_t reg, uint16_t val)
### bool I2cWrite16(uint8_t addr, uint8_t reg, uint16_t val)
### bool I2cWrite(uint8_t addr, uint8_t reg, uint32_t val, uint8_t size)
These functions return true after successfully writing 1, 2 or `size` bytes to the I2C address `addr` and register `reg`.
### int8_t I2cReadBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len)
### int8_t I2cWriteBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len)
These functions copy `len` bytes from/to `*reg_data` starting at I2C address `addr` and register `reg`.
### void I2cScan(char *devs, unsigned int devs_len)
This functions writes a list of I2C addresses in use into the string `*dev` with maximum length `devs_len`.
### boolean I2cDevice(byte addr)
This functions checks if the I2C address `addr` is in use.
## Useful pre-processor directives
### PSTR("string")
This pre-processor directive saves RAM by storing strings in flash instead of RAM.