feat: added interrupt for high level
This commit is contained in:
parent
46019d0141
commit
9ead86ba5e
@ -15,7 +15,7 @@
|
||||
|
||||
1. Enable interrupt support only if input GPIO's are used.
|
||||
2. All the INT GPIO's on the extenders must be connected to the one GPIO on ESP.
|
||||
3. The input GPIO's are always pullup to the power supply. They must be connected to ground to trigger an interrupt.
|
||||
3. The input GPIO's are always pullup to the power supply.
|
||||
|
||||
## Dependencies
|
||||
|
||||
@ -133,6 +133,6 @@ void app_main(void)
|
||||
void zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) // Required only if used input GPIO interrupts.
|
||||
{
|
||||
zh_pcf8574_event_on_isr_t *event = event_data;
|
||||
printf("Interrupt happened on device address 0x%02X on GPIO number %d.\n", event->i2c_address, event->gpio_number);
|
||||
printf("Interrupt happened on device address 0x%02X on GPIO number %d at level %d.\n", event->i2c_address, event->gpio_number, event->gpio_level);
|
||||
}
|
||||
```
|
||||
|
@ -73,6 +73,7 @@ extern "C"
|
||||
{
|
||||
uint8_t i2c_address; // The i2c address of PCF8574 expander that caused the interrupt.
|
||||
uint8_t gpio_number; // The GPIO that caused the interrupt.
|
||||
bool gpio_level; // The GPIO level that caused the interrupt.
|
||||
} zh_pcf8574_event_on_isr_t;
|
||||
|
||||
/**
|
||||
|
@ -1 +1 @@
|
||||
1.2.0
|
||||
1.3.0
|
13
zh_pcf8574.c
13
zh_pcf8574.c
@ -223,8 +223,9 @@ static void IRAM_ATTR _zh_pcf8574_isr_processing_task(void *pvParameter)
|
||||
zh_pcf8574_event_on_isr_t event = {0};
|
||||
event.i2c_address = handle->i2c_address;
|
||||
event.gpio_number = 0xFF;
|
||||
uint8_t reg_temp = 0;
|
||||
esp_err_t err = _zh_pcf8574_read_register(handle, ®_temp);
|
||||
uint8_t old_reg = handle->gpio_status;
|
||||
uint8_t new_reg = 0;
|
||||
esp_err_t err = _zh_pcf8574_read_register(handle, &new_reg);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ZH_PCF8574_LOGE_ERR("PCF8574 isr processing failed. Failed to read expander register.", err);
|
||||
@ -232,9 +233,13 @@ static void IRAM_ATTR _zh_pcf8574_isr_processing_task(void *pvParameter)
|
||||
}
|
||||
for (uint8_t j = 0; j <= 7; ++j)
|
||||
{
|
||||
if (((handle->gpio_work_mode & _gpio_matrix[j]) != 0) && ((reg_temp & _gpio_matrix[j]) == 0))
|
||||
if ((handle->gpio_work_mode & _gpio_matrix[j]) != 0)
|
||||
{
|
||||
event.gpio_number = j;
|
||||
if ((old_reg & _gpio_matrix[j]) != (new_reg & _gpio_matrix[j]))
|
||||
{
|
||||
event.gpio_number = j;
|
||||
event.gpio_level = new_reg & _gpio_matrix[j];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user