|
@@ -39,7 +39,8 @@
|
|
|
|
|
|
// This define forces to perform a gpio sanity check after a timeout.
|
|
|
// If not declared, there will be no timeout and no periodical sanity check of GPIO expander values
|
|
|
-#define TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP 2
|
|
|
+#define TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP 1
|
|
|
+//#define TIMEOUT_MICROSEC_SANITY_CHECK_GPIO_EXP (500*1000)
|
|
|
|
|
|
// This is for debug purposes on cards or eval boards that do not have the AXP209
|
|
|
#define ENABLE_AXP209_INTERRUPTS
|
|
@@ -195,8 +196,8 @@ static int init_gpio_interrupt(int pin_nb, int *fd_saved)
|
|
|
|
|
|
//Initializing I2C interrupt GPIO
|
|
|
gpio_export(pin_nb);
|
|
|
- //gpio_set_edge(cur_pin_nb, "both"); // Can be rising, falling or both
|
|
|
- gpio_set_edge(pin_nb, "falling"); // Can be rising, falling or both
|
|
|
+ gpio_set_edge(pin_nb, "both"); // Can be rising, falling or both
|
|
|
+ //gpio_set_edge(pin_nb, "falling"); // Can be rising, falling or both
|
|
|
*fd_saved = gpio_fd_open(pin_nb, O_RDONLY);
|
|
|
GPIO_PRINTF("fd is: %d\n", *fd_saved);
|
|
|
|
|
@@ -301,7 +302,7 @@ int listen_gpios_interrupts(void)
|
|
|
char buffer[2];
|
|
|
int value;
|
|
|
int idx_gpio;
|
|
|
- int nb_interrupts;
|
|
|
+ int nb_interrupts = 0;
|
|
|
bool previous_mask_gpio_value[nb_mapped_gpios];
|
|
|
bool mask_gpio_current_interrupts[nb_mapped_gpios];
|
|
|
|
|
@@ -315,7 +316,11 @@ int listen_gpios_interrupts(void)
|
|
|
|
|
|
// If interrupt not already found, waiting for interrupt or timeout, Note the max_fd+1
|
|
|
if(!interrupt_i2c_expander_found && !interrupt_axp209_found){
|
|
|
-#ifdef TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP
|
|
|
+ // Listen to interrupts
|
|
|
+#ifdef TIMEOUT_MICROSEC_SANITY_CHECK_GPIO_EXP
|
|
|
+ struct timeval timeout = {0, TIMEOUT_MICROSEC_SANITY_CHECK_GPIO_EXP};
|
|
|
+ nb_interrupts = select(max_fd+1, NULL, NULL, &dup, &timeout);
|
|
|
+#elif TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP
|
|
|
struct timeval timeout = {TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP, 0};
|
|
|
nb_interrupts = select(max_fd+1, NULL, NULL, &dup, &timeout);
|
|
|
#else
|
|
@@ -349,13 +354,16 @@ int listen_gpios_interrupts(void)
|
|
|
|
|
|
// remove end of line char
|
|
|
buffer[1] = '\0';
|
|
|
- value = 1-atoi(buffer);
|
|
|
+ value = atoi(buffer);
|
|
|
+ //value = 1-atoi(buffer);
|
|
|
|
|
|
// Found interrupt
|
|
|
if(cur_fd == gpio_fd_interrupt_expander_gpio){
|
|
|
+ GPIO_PRINTF("Found interrupt generated by PCAL6416AHF \r\n");
|
|
|
interrupt_i2c_expander_found = true;
|
|
|
}
|
|
|
else if(cur_fd == gpio_fd_interrupt_axp209){
|
|
|
+ GPIO_PRINTF("Found interrupt generated by AXP209\r\n");
|
|
|
interrupt_axp209_found = true;
|
|
|
}
|
|
|
}
|
|
@@ -365,7 +373,7 @@ int listen_gpios_interrupts(void)
|
|
|
|
|
|
#ifdef ENABLE_AXP209_INTERRUPTS
|
|
|
if(interrupt_axp209_found){
|
|
|
- GPIO_PRINTF(" Found interrupt AXP209\n");
|
|
|
+ GPIO_PRINTF(" Processing interrupt AXP209\n");
|
|
|
int val_int_bank_3 = axp209_read_interrupt_bank_3();
|
|
|
if(val_int_bank_3 < 0){
|
|
|
GPIO_PRINTF(" Could not read AXP209 with I2C\n");
|
|
@@ -386,6 +394,7 @@ int listen_gpios_interrupts(void)
|
|
|
#endif //ENABLE_AXP209_INTERRUPTS
|
|
|
|
|
|
if(interrupt_i2c_expander_found){
|
|
|
+ GPIO_PRINTF(" Processing interrupt PCAL6416AHF\n");
|
|
|
// Read I2C GPIO masks:
|
|
|
int val_i2c_mask_interrupted = pcal6416a_read_mask_interrupts();
|
|
|
if(val_i2c_mask_interrupted < 0){
|