Skip to content

Commit 903df42

Browse files
committed
Merge branch 'feat/i2c_bus_version_update' into 'master'
feat(i2c_bus): i2c_bus component version update Closes AEG-1919 See merge request ae_group/esp-iot-solution!1082
2 parents 6d8e9c9 + e9c03f9 commit 903df42

File tree

20 files changed

+1034
-316
lines changed

20 files changed

+1034
-316
lines changed

components/i2c_bus/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# ChangeLog
22

3+
## v1.0.0 - 2024-9-19
4+
5+
### Enhancements:
6+
7+
- Component version maintenance and documentation enhancement.
8+
- Support `esp_driver_i2c` driver.
9+
310
## v0.1.0 - 2024-5-27
411

512
First release version.

components/i2c_bus/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
idf_component_register(SRC_DIRS "."
1+
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.3")
2+
set(SRC_FILE "i2c_bus_v2.c")
3+
set(REQ esp_driver_i2c)
4+
else()
5+
set(SRC_FILE "i2c_bus.c")
6+
set(REQ driver)
7+
endif()
8+
9+
idf_component_register(SRCS ${SRC_FILE}
210
INCLUDE_DIRS "include"
3-
REQUIRES driver)
11+
REQUIRES ${REQ})
412
include(package_manager)
513
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})

components/i2c_bus/README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,49 @@ Please use the component manager command `add-dependency` to add the `i2c_bus` t
2020

2121
```
2222
idf.py add-dependency "espressif/i2c_bus=*"
23-
```
23+
```
24+
25+
Alternatively, you can create `idf_component.yml`. More is in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html).
26+
27+
## Example use
28+
29+
```c
30+
#include <stdio.h>
31+
#include "freertos/FreeRTOS.h"
32+
#include "freertos/task.h"
33+
#include "i2c_bus.h"
34+
35+
#define I2C_MASTER_SCL_IO (gpio_num_t)15 /*!< gpio number for I2C master clock */
36+
#define I2C_MASTER_SDA_IO (gpio_num_t)16 /*!< gpio number for I2C master data */
37+
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
38+
#define ESP_SLAVE_ADDR 0x28 /*!< ESP32 slave address, you can set any 7bit value */
39+
#define DATA_LENGTH 64 /*!<Data buffer length for test buffer*/
40+
41+
void app_main(void)
42+
{
43+
44+
uint8_t *data_wr = (uint8_t *)malloc(DATA_LENGTH);
45+
46+
i2c_config_t conf = {
47+
.mode = I2C_MODE_MASTER,
48+
.sda_io_num = I2C_MASTER_SDA_IO,
49+
.sda_pullup_en = GPIO_PULLUP_ENABLE,
50+
.scl_io_num = I2C_MASTER_SCL_IO,
51+
.scl_pullup_en = GPIO_PULLUP_ENABLE,
52+
.master.clk_speed = I2C_MASTER_FREQ_HZ,
53+
};
54+
55+
i2c_bus_handle_t i2c0_bus = i2c_bus_create(I2C_NUM_0, &conf);
56+
i2c_bus_device_handle_t i2c0_device1 = i2c_bus_device_create(i2c0_bus, ESP_SLAVE_ADDR, 0);
57+
for (int i = 0; i < DATA_LENGTH; i++)
58+
{
59+
data_wr[i] = i;
60+
}
61+
62+
i2c_bus_write_bytes(i2c0_device1, NULL_I2C_MEM_ADDR, DATA_LENGTH, data_wr);
63+
free(data_wr);
64+
i2c_bus_device_delete(&i2c0_device1);
65+
i2c_bus_delete(&i2c0_bus);
66+
}
67+
68+
```

components/i2c_bus/i2c_bus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ esp_err_t i2c_bus_read_reg16(i2c_bus_device_handle_t dev_handle, uint16_t mem_ad
364364
I2C_BUS_MUTEX_TAKE(i2c_device->i2c_bus->mutex, ESP_ERR_TIMEOUT);
365365
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
366366

367-
if (mem_address != NULL_I2C_MEM_ADDR) {
367+
if (mem_address != NULL_I2C_MEM_16BIT_ADDR) {
368368
i2c_master_start(cmd);
369369
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
370370
i2c_master_write(cmd, memAddress8, 2, I2C_ACK_CHECK_EN);
@@ -417,7 +417,7 @@ esp_err_t i2c_bus_write_reg16(i2c_bus_device_handle_t dev_handle, uint16_t mem_a
417417
i2c_master_start(cmd);
418418
i2c_master_write_byte(cmd, (i2c_device->dev_addr << 1) | I2C_MASTER_WRITE, I2C_ACK_CHECK_EN);
419419

420-
if (mem_address != NULL_I2C_MEM_ADDR) {
420+
if (mem_address != NULL_I2C_MEM_16BIT_ADDR) {
421421
i2c_master_write(cmd, memAddress8, 2, I2C_ACK_CHECK_EN);
422422
}
423423

0 commit comments

Comments
 (0)