refactor: major refactoring
This commit is contained in:
12
README.md
12
README.md
@ -47,7 +47,7 @@ One expander on bus. All GPIO's as output (except P0 - input). Interrupt is enab
|
||||
#define I2C_PORT (I2C_NUM_MAX - 1)
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ESP8266
|
||||
i2c_master_bus_handle_t i2c_bus_handle = {0};
|
||||
i2c_master_bus_handle_t i2c_bus_handle = NULL;
|
||||
#endif
|
||||
|
||||
zh_pcf8574_handle_t pcf8574_handle = {0};
|
||||
@ -103,7 +103,7 @@ void app_main(void)
|
||||
pcf8574_init_config.i2c_handle = i2c_bus_handle;
|
||||
#endif
|
||||
pcf8574_init_config.i2c_address = 0x38;
|
||||
pcf8574_init_config.p0_gpio_work_mode = EXP_GPIO_INPUT; // Required only for input GPIO.
|
||||
pcf8574_init_config.p0_gpio_work_mode = true; // Required only for input GPIO.
|
||||
pcf8574_init_config.interrupt_gpio = GPIO_NUM_14; // Required only if used input GPIO interrupts.
|
||||
zh_pcf8574_init(&pcf8574_init_config, &pcf8574_handle);
|
||||
uint8_t reg = 0;
|
||||
@ -114,13 +114,13 @@ void app_main(void)
|
||||
zh_pcf8574_read(&pcf8574_handle, ®);
|
||||
print_gpio_status("GPIO status: ", reg);
|
||||
printf("Sets P0 to 0.\n");
|
||||
zh_pcf8574_write_gpio(&pcf8574_handle, EXP_GPIO_NUM_P0, 0); // GPIO P0 will not be changed because it is operating in input mode.
|
||||
zh_pcf8574_write_gpio(&pcf8574_handle, 0, false); // GPIO P0 will not be changed because it is operating in input mode.
|
||||
bool gpio = 0;
|
||||
zh_pcf8574_read_gpio(&pcf8574_handle, EXP_GPIO_NUM_P0, &gpio);
|
||||
zh_pcf8574_read_gpio(&pcf8574_handle, 0, &gpio);
|
||||
printf("P0 status: %d.\n", gpio);
|
||||
printf("Set P1 to 0.\n");
|
||||
zh_pcf8574_write_gpio(&pcf8574_handle, EXP_GPIO_NUM_P1, 0);
|
||||
zh_pcf8574_read_gpio(&pcf8574_handle, EXP_GPIO_NUM_P1, &gpio);
|
||||
zh_pcf8574_write_gpio(&pcf8574_handle, 1, false);
|
||||
zh_pcf8574_read_gpio(&pcf8574_handle, 1, &gpio);
|
||||
printf("P1 status: %d.\n", gpio);
|
||||
zh_pcf8574_read(&pcf8574_handle, ®);
|
||||
print_gpio_status("GPIO status: ", reg);
|
||||
|
12
zh_pcf8574.c
12
zh_pcf8574.c
@ -22,7 +22,7 @@ static zh_vector_t _vector = {0};
|
||||
|
||||
static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *config);
|
||||
static esp_err_t _zh_pcf8574_configure_i2c_device(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t *handle);
|
||||
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, const zh_pcf8574_handle_t *handle);
|
||||
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, const zh_pcf8574_handle_t handle);
|
||||
static void _zh_pcf8574_isr_handler(void *arg);
|
||||
static void _zh_pcf8574_isr_processing_task(void *pvParameter);
|
||||
static esp_err_t _zh_pcf8574_read_register(zh_pcf8574_handle_t *handle, uint8_t *reg);
|
||||
@ -53,7 +53,7 @@ esp_err_t zh_pcf8574_init(const zh_pcf8574_init_config_t *config, zh_pcf8574_han
|
||||
ZH_PCF8574_LOGI("GPIO setup completed successfully.");
|
||||
if (config->interrupt_gpio < GPIO_NUM_MAX && config->interrupt_gpio > GPIO_NUM_NC && handle->gpio_work_mode != 0)
|
||||
{
|
||||
err = _zh_pcf8574_configure_interrupts(config, handle);
|
||||
err = _zh_pcf8574_configure_interrupts(config, *handle);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
handle->is_initialized = false;
|
||||
@ -151,7 +151,7 @@ static esp_err_t _zh_pcf8574_configure_i2c_device(const zh_pcf8574_init_config_t
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, const zh_pcf8574_handle_t *handle)
|
||||
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, const zh_pcf8574_handle_t handle)
|
||||
{
|
||||
if (_interrupt_gpio != GPIO_NUM_MAX)
|
||||
{
|
||||
@ -189,7 +189,7 @@ static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t
|
||||
tskNO_AFFINITY);
|
||||
if (x_err != pdPASS)
|
||||
{
|
||||
ZH_PCF8574_LOGE("Failed to create ISR processing task.");
|
||||
ZH_PCF8574_LOGE("Failed to create isr processing task.");
|
||||
vSemaphoreDelete(_interrupt_semaphore);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@ -252,7 +252,7 @@ static void IRAM_ATTR _zh_pcf8574_isr_processing_task(void *pvParameter)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
esp_err_t _zh_pcf8574_read_register(zh_pcf8574_handle_t *handle, uint8_t *reg)
|
||||
static esp_err_t _zh_pcf8574_read_register(zh_pcf8574_handle_t *handle, uint8_t *reg)
|
||||
{
|
||||
ZH_PCF8574_LOGI("PCF8574 read started.");
|
||||
ZH_PCF8574_CHECK(handle != NULL || reg != NULL, ESP_ERR_INVALID_ARG, "PCF8574 read failed. Invalid argument.");
|
||||
@ -274,7 +274,7 @@ esp_err_t _zh_pcf8574_read_register(zh_pcf8574_handle_t *handle, uint8_t *reg)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t _zh_pcf8574_write_register(zh_pcf8574_handle_t *handle, uint8_t reg)
|
||||
static esp_err_t _zh_pcf8574_write_register(zh_pcf8574_handle_t *handle, uint8_t reg)
|
||||
{
|
||||
ZH_PCF8574_LOGI("PCF8574 write started.");
|
||||
ZH_PCF8574_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, "PCF8574 write failed. Invalid argument.");
|
||||
|
Reference in New Issue
Block a user