summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/i2c.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-02-24 19:54:18 +0100
committerUros Majstorovic <majstor@majstor.org>2021-02-24 19:54:18 +0100
commit4dea6262b57f614cabd5cf4fa96c1e3d83c45fb4 (patch)
tree765eb9b4322c6158089232cccf6a30eb62ba90d9 /fw/esp32/components/eos/i2c.c
parent3050565531af2b3a09f2213893f10c64cf9fe43f (diff)
upgraded to esp-idf 4.2
Diffstat (limited to 'fw/esp32/components/eos/i2c.c')
-rw-r--r--fw/esp32/components/eos/i2c.c35
1 files changed, 7 insertions, 28 deletions
diff --git a/fw/esp32/components/eos/i2c.c b/fw/esp32/components/eos/i2c.c
index 5b8fcc7..828e4cd 100644
--- a/fw/esp32/components/eos/i2c.c
+++ b/fw/esp32/components/eos/i2c.c
@@ -19,10 +19,6 @@ static const char *TAG = "EOS I2C";
#define ACK_VAL 0x0 /*!< I2C ack value */
#define NCK_VAL 0x1 /*!< I2C nack value */
-/**
- * @brief i2c initialization
- */
-
void eos_i2c_init(void) {
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
@@ -36,10 +32,6 @@ void eos_i2c_init(void) {
ESP_LOGI(TAG, "INIT");
}
-/**
- * @brief i2c read
- */
-
int eos_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) {
int i, ret;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
@@ -53,6 +45,7 @@ int eos_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) {
}
i2c_master_read_byte(cmd, data+i, NCK_VAL);
i2c_master_stop(cmd);
+
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
@@ -61,20 +54,6 @@ int eos_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) {
return EOS_OK;
}
-/**
- * @brief i2c read8
- */
-
-uint8_t eos_i2c_read8(uint8_t addr, uint8_t reg) {
- uint8_t data;
- eos_i2c_read(addr, reg, &data, 1);
- return data;
-}
-
-/**
- * @brief i2c write
- */
-
int eos_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) {
int i, ret;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
@@ -85,6 +64,7 @@ int eos_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) {
i2c_master_write_byte(cmd, *(data+i), ACK_CHECK_EN);
}
i2c_master_stop(cmd);
+
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
@@ -93,11 +73,10 @@ int eos_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) {
return EOS_OK;
}
-/**
- * @brief i2c write8
- */
-
-void eos_i2c_write8(uint8_t addr, uint8_t reg, uint8_t data) {
- eos_i2c_write(addr, reg, &data, 1);
+int eos_i2c_read8(uint8_t addr, uint8_t reg, uint8_t *data) {
+ return eos_i2c_read(addr, reg, data, 1);
}
+int eos_i2c_write8(uint8_t addr, uint8_t reg, uint8_t data) {
+ return eos_i2c_write(addr, reg, &data, 1);
+}