Skip to content

Commit

Permalink
Migrate KSZ8863 driver to new I2C driver implementation
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
bogdankolendovskyy committed Nov 26, 2024
1 parent 047629a commit c0f1edf
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 109 deletions.
39 changes: 16 additions & 23 deletions ksz8863/examples/simple_switch/main/simple_switch_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
esp_err_t ret;
/* we can get the ethernet driver handle from event data */
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
/* we should not try to use KSZ8863-specific ioctl commands with the general host handle, only with port handles */
esp_eth_handle_t host_eth_handle = *(esp_eth_handle_t *)arg;

switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ret = esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num);
ret = eth_handle != host_eth_handle ? esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num) : ESP_FAIL;
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Ethernet Link Up Port %" PRIi32, port_num + 1);
} else {
Expand All @@ -146,7 +148,7 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
break;
case ETHERNET_EVENT_DISCONNECTED:
ret = esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num);
ret = eth_handle != host_eth_handle ? esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num) : ESP_FAIL;
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Ethernet Link Down Port %" PRIi32, port_num + 1);
} else {
Expand Down Expand Up @@ -179,37 +181,28 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
ESP_LOGI(TAG, "~~~~~~~~~~~");
}

esp_err_t i2c_init(i2c_port_t i2c_master_port, i2c_config_t *i2c_conf)
{
esp_err_t ret;

ESP_GOTO_ON_ERROR(i2c_param_config(i2c_master_port, i2c_conf), err, TAG, "I2C parameters configuration failed");
ESP_GOTO_ON_ERROR(i2c_driver_install(i2c_master_port, i2c_conf->mode, 0, 0, 0), err, TAG, "I2C driver install failed");

return ESP_OK;
err:
return ret;
}

// board specific initialization routine, user to update per specific needs
esp_err_t ksz8863_board_specific_init(esp_eth_handle_t eth_handle)
{
esp_err_t ret = ESP_OK;

#if CONFIG_EXAMPLE_CTRL_I2C
// initialize I2C interface
i2c_config_t i2c_bus_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = CONFIG_EXAMPLE_I2C_SDA_GPIO,
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.scl_io_num = CONFIG_EXAMPLE_I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = CONFIG_EXAMPLE_I2C_CLOCK_KHZ * 1000,
.sda_io_num = CONFIG_EXAMPLE_I2C_SDA_GPIO,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true
};
ESP_GOTO_ON_ERROR(i2c_init(CONFIG_EXAMPLE_I2C_MASTER_PORT, &i2c_bus_config), err, TAG, "I2C initialization failed");
i2c_master_bus_handle_t bus_handle;
ESP_GOTO_ON_ERROR(i2c_new_master_bus(&i2c_mst_config, &bus_handle), err, TAG, "I2C initialization failed");
ksz8863_ctrl_i2c_config_t i2c_dev_config = {
.bus_handle = bus_handle,
.dev_addr = KSZ8863_I2C_DEV_ADDR,
.i2c_master_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.i2c_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.scl_speed_hz = CONFIG_EXAMPLE_I2C_CLOCK_KHZ * 1000
};
ksz8863_ctrl_intf_config_t ctrl_intf_cfg = {
.host_mode = KSZ8863_I2C_MODE,
Expand Down Expand Up @@ -318,7 +311,7 @@ void app_main(void)
ESP_ERROR_CHECK(esp_eth_driver_install(&p2_config, &p2_eth_handle));

// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, &host_eth_handle));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

// start Ethernet driver state machines
Expand Down
39 changes: 16 additions & 23 deletions ksz8863/examples/switch_mode/main/switch_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
esp_err_t ret;
/* we can get the ethernet driver handle from event data */
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
/* we should not try to use KSZ8863-specific ioctl commands with the general host handle, only with port handles */
esp_eth_handle_t host_eth_handle = *(esp_eth_handle_t *)arg;

switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ret = esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num);
ret = eth_handle != host_eth_handle ? esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num) : ESP_FAIL;
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Ethernet Link Up Port %" PRIi32, port_num + 1);
} else {
Expand All @@ -185,7 +187,7 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
break;
case ETHERNET_EVENT_DISCONNECTED:
ret = esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num);
ret = eth_handle != host_eth_handle ? esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num) : ESP_FAIL;
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Ethernet Link Down Port %" PRIi32, port_num + 1);
} else {
Expand Down Expand Up @@ -218,37 +220,28 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
ESP_LOGI(TAG, "~~~~~~~~~~~");
}

esp_err_t i2c_init(i2c_port_t i2c_master_port, i2c_config_t *i2c_conf)
{
esp_err_t ret;

ESP_GOTO_ON_ERROR(i2c_param_config(i2c_master_port, i2c_conf), err, TAG, "I2C parameters configuration failed");
ESP_GOTO_ON_ERROR(i2c_driver_install(i2c_master_port, i2c_conf->mode, 0, 0, 0), err, TAG, "I2C driver install failed");

return ESP_OK;
err:
return ret;
}

// board specific initialization routine, user to update per specific needs
esp_err_t ksz8863_board_specific_init(esp_eth_handle_t eth_handle)
{
esp_err_t ret = ESP_OK;

#if CONFIG_EXAMPLE_CTRL_I2C
// initialize I2C interface
i2c_config_t i2c_bus_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = CONFIG_EXAMPLE_I2C_SDA_GPIO,
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.scl_io_num = CONFIG_EXAMPLE_I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = CONFIG_EXAMPLE_I2C_CLOCK_KHZ * 1000,
.sda_io_num = CONFIG_EXAMPLE_I2C_SDA_GPIO,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true
};
ESP_GOTO_ON_ERROR(i2c_init(CONFIG_EXAMPLE_I2C_MASTER_PORT, &i2c_bus_config), err, TAG, "I2C initialization failed");
i2c_master_bus_handle_t bus_handle;
ESP_GOTO_ON_ERROR(i2c_new_master_bus(&i2c_mst_config, &bus_handle), err, TAG, "I2C initialization failed");
ksz8863_ctrl_i2c_config_t i2c_dev_config = {
.bus_handle = bus_handle,
.dev_addr = KSZ8863_I2C_DEV_ADDR,
.i2c_master_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.i2c_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.scl_speed_hz = CONFIG_EXAMPLE_I2C_CLOCK_KHZ * 1000
};
ksz8863_ctrl_intf_config_t ctrl_intf_cfg = {
.host_mode = KSZ8863_I2C_MODE,
Expand Down Expand Up @@ -371,7 +364,7 @@ void app_main(void)
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, ksz8863_esp_eth_new_netif_glue_switch(&sw_netif_glue_cfg)));

// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, &host_eth_handle));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

// start Ethernet driver state machines
Expand Down
39 changes: 16 additions & 23 deletions ksz8863/examples/two_ports_mode/main/two_ports_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
esp_err_t ret;
/* we can get the ethernet driver handle from event data */
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
/* we should not try to use KSZ8863-specific ioctl commands with the general host handle, only with port handles */
esp_eth_handle_t host_eth_handle = *(esp_eth_handle_t *)arg;

switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ret = esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num);
ret = eth_handle != host_eth_handle ? esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num) : ESP_FAIL;
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Ethernet Link Up Port %" PRIi32, port_num + 1);
} else {
Expand All @@ -178,7 +180,7 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
break;
case ETHERNET_EVENT_DISCONNECTED:
ret = esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num);
ret = eth_handle != host_eth_handle ? esp_eth_ioctl(eth_handle, KSZ8863_ETH_CMD_G_PORT_NUM, &port_num) : ESP_FAIL;
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Ethernet Link Down Port %" PRIi32, port_num + 1);
} else {
Expand Down Expand Up @@ -211,37 +213,28 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
ESP_LOGI(TAG, "~~~~~~~~~~~");
}

esp_err_t i2c_init(i2c_port_t i2c_master_port, i2c_config_t *i2c_conf)
{
esp_err_t ret;

ESP_GOTO_ON_ERROR(i2c_param_config(i2c_master_port, i2c_conf), err, TAG, "I2C parameters configuration failed");
ESP_GOTO_ON_ERROR(i2c_driver_install(i2c_master_port, i2c_conf->mode, 0, 0, 0), err, TAG, "I2C driver install failed");

return ESP_OK;
err:
return ret;
}

// board specific initialization routine, user to update per specific needs
esp_err_t ksz8863_board_specific_init(esp_eth_handle_t eth_handle)
{
esp_err_t ret = ESP_OK;

#if CONFIG_EXAMPLE_CTRL_I2C
// initialize I2C interface
i2c_config_t i2c_bus_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = CONFIG_EXAMPLE_I2C_SDA_GPIO,
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.scl_io_num = CONFIG_EXAMPLE_I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = CONFIG_EXAMPLE_I2C_CLOCK_KHZ * 1000,
.sda_io_num = CONFIG_EXAMPLE_I2C_SDA_GPIO,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true
};
ESP_GOTO_ON_ERROR(i2c_init(CONFIG_EXAMPLE_I2C_MASTER_PORT, &i2c_bus_config), err, TAG, "I2C initialization failed");
i2c_master_bus_handle_t bus_handle;
ESP_GOTO_ON_ERROR(i2c_new_master_bus(&i2c_mst_config, &bus_handle), err, TAG, "I2C initialization failed");
ksz8863_ctrl_i2c_config_t i2c_dev_config = {
.bus_handle = bus_handle,
.dev_addr = KSZ8863_I2C_DEV_ADDR,
.i2c_master_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.i2c_port = CONFIG_EXAMPLE_I2C_MASTER_PORT,
.scl_speed_hz = CONFIG_EXAMPLE_I2C_CLOCK_KHZ * 1000
};
ksz8863_ctrl_intf_config_t ctrl_intf_cfg = {
.host_mode = KSZ8863_I2C_MODE,
Expand Down Expand Up @@ -386,7 +379,7 @@ void app_main(void)
ESP_ERROR_CHECK(esp_netif_attach(eth_netif_port[1], esp_eth_new_netif_glue(p2_eth_handle)));

// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, &host_eth_handle));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

// start Ethernet driver state machines
Expand Down
6 changes: 4 additions & 2 deletions ksz8863/include/ksz8863_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma once

#include "esp_err.h"
#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "driver/spi_master.h"
#include "esp_eth_driver.h" // for esp_eth_handle_t

Expand All @@ -24,7 +24,9 @@ typedef enum {

typedef struct {
uint8_t dev_addr;
i2c_port_t i2c_master_port;
uint32_t scl_speed_hz;
i2c_port_num_t i2c_port;
i2c_master_bus_handle_t bus_handle;
} ksz8863_ctrl_i2c_config_t;

typedef struct {
Expand Down
2 changes: 2 additions & 0 deletions ksz8863/src/esp_eth_ksz8863.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <sys/queue.h>
#include "esp_log.h"
#include "esp_check.h"
#include "driver/gpio.h"
#include "esp_rom_gpio.h"

#include "esp_eth_ksz8863.h"
#include "ksz8863.h" // registers
Expand Down
72 changes: 34 additions & 38 deletions ksz8863/src/ksz8863_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#define KSZ8863_SPI_LOCK_TIMEOUT_MS 500

typedef struct {
i2c_port_t i2c_port;
uint8_t dev_addr;
uint32_t scl_speed_hz;
i2c_port_num_t i2c_port;
i2c_master_bus_handle_t bus_handle;
} ksz8863_i2c_spec_t;

typedef struct {
Expand Down Expand Up @@ -57,56 +59,48 @@ static inline bool bus_unlock(void)
static esp_err_t ksz8863_i2c_write(uint8_t reg_addr, uint8_t *data, size_t len)
{
esp_err_t ret = ESP_OK;
i2c_port_t i2c_port = s_ksz8863_ctrl_intf->i2c_bus_spec.i2c_port;
uint8_t dev_addr = s_ksz8863_ctrl_intf->i2c_bus_spec.dev_addr;

i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "I2C link create error");
ESP_GOTO_ON_ERROR(i2c_master_start(cmd), err, TAG, "I2C master start error");
ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd, dev_addr | I2C_MASTER_WRITE, true), err, TAG, "I2C master write error");
ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd, reg_addr, true), err, TAG, "I2C master write error");
if (likely(reg_addr != KSZ8863_RESET_ADDR)) {
ESP_GOTO_ON_ERROR(i2c_master_write(cmd, data, len, true), err, TAG, "I2C master write error");
} else {
// when SW reset is performed, KSZ does not generate ACK
ESP_GOTO_ON_ERROR(i2c_master_write(cmd, data, len, false), err, TAG, "I2C master write error");
}
ESP_GOTO_ON_ERROR(i2c_master_stop(cmd), err, TAG, "I2C master stop error");
// Lock since multiple MAC/PHY instances exist and the KSZ may be also accessed by user (MAC tables, etc...)
ESP_GOTO_ON_FALSE(bus_lock(KSZ8863_I2C_LOCK_TIMEOUT_MS), ESP_ERR_TIMEOUT, err, TAG, "I2C bus lock timeout");
ESP_GOTO_ON_ERROR(i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(KSZ8863_I2C_TIMEOUT_MS)), err_release, TAG,
"I2C master command begin error");
uint8_t *reg_addr_and_data = malloc(len + 1);

i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = s_ksz8863_ctrl_intf->i2c_bus_spec.dev_addr >> 1,
.scl_speed_hz = s_ksz8863_ctrl_intf->i2c_bus_spec.scl_speed_hz,
.flags.disable_ack_check = (reg_addr == KSZ8863_RESET_ADDR)
};

i2c_master_dev_handle_t dev_handle;
ESP_GOTO_ON_ERROR(i2c_master_bus_add_device(s_ksz8863_ctrl_intf->i2c_bus_spec.bus_handle, &dev_cfg, &dev_handle), err, TAG, "Error when trying to add the I2C device");

reg_addr_and_data[0] = reg_addr;
memcpy(reg_addr_and_data + 1, data, len);
ESP_GOTO_ON_ERROR(i2c_master_transmit(dev_handle, reg_addr_and_data, len + 1, KSZ8863_I2C_TIMEOUT_MS), err_release, TAG, "Error during i2c write operation");
err_release:
bus_unlock();
i2c_master_bus_rm_device(dev_handle);
err:
i2c_cmd_link_delete(cmd);
free(reg_addr_and_data);
return ret;
}

static esp_err_t ksz8863_i2c_read(uint8_t reg_addr, uint8_t *data, size_t len)
{
esp_err_t ret = ESP_OK;
i2c_port_t i2c_port = s_ksz8863_ctrl_intf->i2c_bus_spec.i2c_port;
uint8_t dev_addr = s_ksz8863_ctrl_intf->i2c_bus_spec.dev_addr;

i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "I2C link create error");
ESP_GOTO_ON_ERROR(i2c_master_start(cmd), err, TAG, "I2C master start error");
ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd, dev_addr | I2C_MASTER_WRITE, true), err, TAG, "I2C master write error");
ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd, reg_addr, true), err, TAG, "I2C master write error");
// restart before read
ESP_GOTO_ON_ERROR(i2c_master_start(cmd), err, TAG, "I2C master start error");
ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd, dev_addr | I2C_MASTER_READ, true), err, TAG, "I2C master write error");;
ESP_GOTO_ON_ERROR(i2c_master_read(cmd, data, len, I2C_MASTER_LAST_NACK), err, TAG, "I2C master read error");
ESP_GOTO_ON_ERROR(i2c_master_stop(cmd), err, TAG, "I2C master stop error");;
i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = s_ksz8863_ctrl_intf->i2c_bus_spec.dev_addr >> 1,
.scl_speed_hz = s_ksz8863_ctrl_intf->i2c_bus_spec.scl_speed_hz,
};

i2c_master_dev_handle_t dev_handle;
ESP_GOTO_ON_ERROR(i2c_master_bus_add_device(s_ksz8863_ctrl_intf->i2c_bus_spec.bus_handle, &dev_cfg, &dev_handle), err, TAG, "Error when trying to add the I2C device");

// Lock since multiple MAC/PHY instances exist and the KSZ may be also accessed by user (MAC tables, etc...)
ESP_GOTO_ON_FALSE(bus_lock(KSZ8863_I2C_LOCK_TIMEOUT_MS), ESP_ERR_TIMEOUT, err, TAG, "I2C bus lock timeout");
ESP_GOTO_ON_ERROR(i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(KSZ8863_I2C_TIMEOUT_MS)), err_release, TAG,
"I2C master command begin error");
ESP_GOTO_ON_ERROR(i2c_master_transmit_receive(dev_handle, &reg_addr, 1, data, len, KSZ8863_I2C_TIMEOUT_MS), err_release, TAG, "Error during i2c read operation");
err_release:
bus_unlock();
i2c_master_bus_rm_device(dev_handle);
err:
i2c_cmd_link_delete(cmd);
return ret;
}

Expand Down Expand Up @@ -293,8 +287,10 @@ esp_err_t ksz8863_ctrl_intf_init(ksz8863_ctrl_intf_config_t *config)

switch (config->host_mode) {
case KSZ8863_I2C_MODE:
s_ksz8863_ctrl_intf->i2c_bus_spec.i2c_port = config->i2c_dev_config->i2c_master_port;
s_ksz8863_ctrl_intf->i2c_bus_spec.dev_addr = config->i2c_dev_config->dev_addr;
s_ksz8863_ctrl_intf->i2c_bus_spec.scl_speed_hz = config->i2c_dev_config->scl_speed_hz;
s_ksz8863_ctrl_intf->i2c_bus_spec.i2c_port = config->i2c_dev_config->i2c_port;
s_ksz8863_ctrl_intf->i2c_bus_spec.bus_handle = config->i2c_dev_config->bus_handle;

s_ksz8863_ctrl_intf->ksz8863_reg_read = ksz8863_i2c_read;
s_ksz8863_ctrl_intf->ksz8863_reg_write = ksz8863_i2c_write;
Expand Down

0 comments on commit c0f1edf

Please sign in to comment.