diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/driver_axp209.c b/driver_axp209.c old mode 100644 new mode 100755 index a4b61ae..9b8af52 --- a/driver_axp209.c +++ b/driver_axp209.c @@ -18,7 +18,7 @@ /**************************************************************** * Defines ****************************************************************/ -#define DEBUG_AXP209_PRINTF (1) +#define DEBUG_AXP209_PRINTF (0) #if (DEBUG_AXP209_PRINTF) #define DEBUG_PRINTF(...) printf(__VA_ARGS__); @@ -50,6 +50,25 @@ bool axp209_init(void) { printf("In axp209_init - Failed to acquire bus access and/or talk to slave.\n"); // ERROR HANDLING; you can check errno to see what went wrong return false; + } + + // Enable only chosen interrupts (PEK short and long presses) + int err; + err = i2c_smbus_write_byte_data(fd_axp209 , AXP209_INTERRUPT_BANK_1_ENABLE, 0x00); + if(err < 0){ + printf("ERROR initializing interrupts for AXP209\n"); + } + err = i2c_smbus_write_byte_data(fd_axp209 , AXP209_INTERRUPT_BANK_2_ENABLE, 0x00); + if(err < 0){ + printf("ERROR initializing interrupts for AXP209\n"); + } + err = i2c_smbus_write_byte_data(fd_axp209 , AXP209_INTERRUPT_BANK_4_ENABLE, 0x00); + if(err < 0){ + printf("ERROR initializing interrupts for AXP209\n"); + } + err = i2c_smbus_write_byte_data(fd_axp209 , AXP209_INTERRUPT_BANK_5_ENABLE, 0x00); + if(err < 0){ + printf("ERROR initializing interrupts for AXP209\n"); } return true; @@ -66,6 +85,13 @@ int axp209_read_interrupt_bank_3(void){ if(val < 0){ return val; } + + // Clear interrupts + int err = i2c_smbus_write_byte_data(fd_axp209 , AXP209_INTERRUPT_BANK_3_STATUS, 0xFF); + if(err < 0){ + return err; + } + DEBUG_PRINTF("READ AXP209_INTERRUPT_BANK_3_STATUS: 0x%02X\n",val); return 0xFF & val; -} \ No newline at end of file +} diff --git a/driver_axp209.h b/driver_axp209.h old mode 100644 new mode 100755 index ae5cabf..02a341f --- a/driver_axp209.h +++ b/driver_axp209.h @@ -14,7 +14,16 @@ #define AXP209_I2C_ADDR 0x34 // Chip registers adresses -#define AXP209_INTERRUPT_BANK_3_STATUS 0x4A +#define AXP209_INTERRUPT_BANK_1_ENABLE 0x40 +#define AXP209_INTERRUPT_BANK_1_STATUS 0x48 +#define AXP209_INTERRUPT_BANK_2_ENABLE 0x41 +#define AXP209_INTERRUPT_BANK_2_STATUS 0x49 +#define AXP209_INTERRUPT_BANK_3_ENABLE 0x42 +#define AXP209_INTERRUPT_BANK_3_STATUS 0x4A +#define AXP209_INTERRUPT_BANK_4_ENABLE 0x43 +#define AXP209_INTERRUPT_BANK_4_STATUS 0x4B +#define AXP209_INTERRUPT_BANK_5_ENABLE 0x44 +#define AXP209_INTERRUPT_BANK_5_STATUS 0x4C // Masks #define AXP209_INTERRUPT_PEK_SHORT_PRESS 0x02 diff --git a/driver_pcal6416a.c b/driver_pcal6416a.c old mode 100644 new mode 100755 diff --git a/driver_pcal6416a.h b/driver_pcal6416a.h old mode 100644 new mode 100755 diff --git a/funkey_gpio_management.c b/funkey_gpio_management.c old mode 100644 new mode 100755 diff --git a/funkey_gpio_mapping.conf b/funkey_gpio_mapping.conf old mode 100644 new mode 100755 diff --git a/gpio-utils.c b/gpio-utils.c old mode 100644 new mode 100755 diff --git a/gpio-utils.h b/gpio-utils.h old mode 100644 new mode 100755 diff --git a/gpio_mapping.c b/gpio_mapping.c index 400d14e..3e15e75 100644 --- a/gpio_mapping.c +++ b/gpio_mapping.c @@ -22,7 +22,7 @@ return(EXIT_FAILURE); \ } while(0) -#define DEBUG_GPIO_PRINTF (1) +#define DEBUG_GPIO_PRINTF (0) #define ERROR_GPIO_PRINTF (1) #if (DEBUG_GPIO_PRINTF) @@ -42,7 +42,10 @@ #define TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP 2 // This is for debug purposes on cards or eval boards that do not have the AXP209 -//#define ENABLE_AXP209_INTERRUPTS +#define ENABLE_AXP209_INTERRUPTS + +#define KEY_IDX_MAPPED_FOR_SHORT_PEK_PRESS 16 //KEY_Q +#define KEY_IDX_MAPPED_FOR_LONG_PEK_PRESS 28 //KEY_ENTER /**************************************************************** @@ -190,9 +193,6 @@ static int init_gpio_interrupt(int pin_nb, int *fd_saved) // Variables GPIO_PRINTF("Initializing Interrupt on GPIO pin: %d\n", pin_nb); - // Init fds fd_set - FD_ZERO(&fds); - //Initializing I2C interrupt GPIO gpio_export(pin_nb); //gpio_set_edge(cur_pin_nb, "both"); // Can be rising, falling or both @@ -248,6 +248,9 @@ int init_mapping_gpios(int * gpio_pins_to_declare, int nb_gpios_to_declare, // Next node in chained list current = current->next_mapped_gpio; } while(current != NULL); + + // Init fds fd_set + FD_ZERO(&fds); // Init GPIO interrupt from I2C GPIO expander GPIO_PRINTF(" Initiating interrupt for GPIO_PIN_I2C_EXPANDER_INTERRUPT\n"); @@ -295,9 +298,10 @@ int deinit_mapping_gpios(void) int listen_gpios_interrupts(void) { // Variables - //char buffer[2]; - //int value; + char buffer[2]; + int value; int idx_gpio; + int nb_interrupts; bool previous_mask_gpio_value[nb_mapped_gpios]; bool mask_gpio_current_interrupts[nb_mapped_gpios]; @@ -313,9 +317,9 @@ int listen_gpios_interrupts(void) if(!interrupt_i2c_expander_found && !interrupt_axp209_found){ #ifdef TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP struct timeval timeout = {TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP, 0}; - int nb_interrupts = select(max_fd+1, NULL, NULL, &dup, &timeout); + nb_interrupts = select(max_fd+1, NULL, NULL, &dup, &timeout); #else - int nb_interrupts = select(max_fd+1, NULL, NULL, &dup, NULL); + nb_interrupts = select(max_fd+1, NULL, NULL, &dup, NULL); #endif //TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP if(!nb_interrupts){ // Timeout case @@ -329,30 +333,32 @@ int listen_gpios_interrupts(void) } } - // Check if interrupt from I2C expander or AXP209 - // Check which cur_fd is available for read - for (int cur_fd = 0; cur_fd <= max_fd; cur_fd++) { - if (FD_ISSET(cur_fd, &dup)) { - /*// Rewind file - lseek(cur_fd, 0, SEEK_SET); + if(nb_interrupts){ + // Check if interrupt from I2C expander or AXP209 + // Check which cur_fd is available for read + for (int cur_fd = 0; cur_fd <= max_fd; cur_fd++) { + if (FD_ISSET(cur_fd, &dup)) { + // Rewind file + lseek(cur_fd, 0, SEEK_SET); - // Read current gpio value - if (read(cur_fd, & buffer, 2) != 2) { - perror("read"); - break; - } + // Read current gpio value + if (read(cur_fd, & buffer, 2) != 2) { + perror("read"); + break; + } + + // remove end of line char + buffer[1] = '\0'; + value = 1-atoi(buffer); - // remove end of line char - buffer[1] = '\0'; - value = 1-atoi(buffer);*/ - - // Found interrupt - if(cur_fd == gpio_fd_interrupt_expander_gpio){ - interrupt_i2c_expander_found = true; - } - else if(cur_fd == gpio_fd_interrupt_axp209){ - interrupt_axp209_found = true; - } + // Found interrupt + if(cur_fd == gpio_fd_interrupt_expander_gpio){ + interrupt_i2c_expander_found = true; + } + else if(cur_fd == gpio_fd_interrupt_axp209){ + interrupt_axp209_found = true; + } + } } } @@ -369,9 +375,12 @@ int listen_gpios_interrupts(void) if(val_int_bank_3 & AXP209_INTERRUPT_PEK_SHORT_PRESS){ GPIO_PRINTF(" AXP209 short PEK key press detected\n"); + sendKeyAndStopKey(KEY_IDX_MAPPED_FOR_SHORT_PEK_PRESS); + } if(val_int_bank_3 & AXP209_INTERRUPT_PEK_LONG_PRESS){ GPIO_PRINTF(" AXP209 long PEK key press detected\n"); + sendKeyAndStopKey(KEY_IDX_MAPPED_FOR_LONG_PEK_PRESS); } } #endif //ENABLE_AXP209_INTERRUPTS @@ -440,3 +449,4 @@ int listen_gpios_interrupts(void) return 0; } + diff --git a/gpio_mapping.h b/gpio_mapping.h old mode 100644 new mode 100755 diff --git a/keydefs.c b/keydefs.c old mode 100644 new mode 100755 diff --git a/read_conf_file.c b/read_conf_file.c old mode 100644 new mode 100755 diff --git a/read_conf_file.h b/read_conf_file.h old mode 100644 new mode 100755 diff --git a/uinput.c b/uinput.c old mode 100644 new mode 100755 diff --git a/uinput.h b/uinput.h old mode 100644 new mode 100755