AXP209 working with KEY_Q mapped for PEK short press and KEY_ENTER for PEK long press

This commit is contained in:
Vincent-FK 2019-09-13 05:11:40 +08:00
parent 8344d3b9eb
commit 3613ac0884
16 changed files with 79 additions and 34 deletions

0
Makefile Normal file → Executable file
View File

28
driver_axp209.c Normal file → Executable file
View File

@ -18,7 +18,7 @@
/**************************************************************** /****************************************************************
* Defines * Defines
****************************************************************/ ****************************************************************/
#define DEBUG_AXP209_PRINTF (1) #define DEBUG_AXP209_PRINTF (0)
#if (DEBUG_AXP209_PRINTF) #if (DEBUG_AXP209_PRINTF)
#define DEBUG_PRINTF(...) printf(__VA_ARGS__); #define DEBUG_PRINTF(...) printf(__VA_ARGS__);
@ -52,6 +52,25 @@ bool axp209_init(void) {
return false; 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; return true;
} }
@ -66,6 +85,13 @@ int axp209_read_interrupt_bank_3(void){
if(val < 0){ if(val < 0){
return val; 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); DEBUG_PRINTF("READ AXP209_INTERRUPT_BANK_3_STATUS: 0x%02X\n",val);
return 0xFF & val; return 0xFF & val;
} }

9
driver_axp209.h Normal file → Executable file
View File

@ -14,7 +14,16 @@
#define AXP209_I2C_ADDR 0x34 #define AXP209_I2C_ADDR 0x34
// Chip registers adresses // Chip registers adresses
#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_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 // Masks
#define AXP209_INTERRUPT_PEK_SHORT_PRESS 0x02 #define AXP209_INTERRUPT_PEK_SHORT_PRESS 0x02

0
driver_pcal6416a.c Normal file → Executable file
View File

0
driver_pcal6416a.h Normal file → Executable file
View File

0
funkey_gpio_management.c Normal file → Executable file
View File

0
funkey_gpio_mapping.conf Normal file → Executable file
View File

0
gpio-utils.c Normal file → Executable file
View File

0
gpio-utils.h Normal file → Executable file
View File

View File

@ -22,7 +22,7 @@
return(EXIT_FAILURE); \ return(EXIT_FAILURE); \
} while(0) } while(0)
#define DEBUG_GPIO_PRINTF (1) #define DEBUG_GPIO_PRINTF (0)
#define ERROR_GPIO_PRINTF (1) #define ERROR_GPIO_PRINTF (1)
#if (DEBUG_GPIO_PRINTF) #if (DEBUG_GPIO_PRINTF)
@ -42,7 +42,10 @@
#define TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP 2 #define TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP 2
// This is for debug purposes on cards or eval boards that do not have the AXP209 // 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 // Variables
GPIO_PRINTF("Initializing Interrupt on GPIO pin: %d\n", pin_nb); GPIO_PRINTF("Initializing Interrupt on GPIO pin: %d\n", pin_nb);
// Init fds fd_set
FD_ZERO(&fds);
//Initializing I2C interrupt GPIO //Initializing I2C interrupt GPIO
gpio_export(pin_nb); gpio_export(pin_nb);
//gpio_set_edge(cur_pin_nb, "both"); // Can be rising, falling or both //gpio_set_edge(cur_pin_nb, "both"); // Can be rising, falling or both
@ -249,6 +249,9 @@ int init_mapping_gpios(int * gpio_pins_to_declare, int nb_gpios_to_declare,
current = current->next_mapped_gpio; current = current->next_mapped_gpio;
} while(current != NULL); } while(current != NULL);
// Init fds fd_set
FD_ZERO(&fds);
// Init GPIO interrupt from I2C GPIO expander // Init GPIO interrupt from I2C GPIO expander
GPIO_PRINTF(" Initiating interrupt for GPIO_PIN_I2C_EXPANDER_INTERRUPT\n"); GPIO_PRINTF(" Initiating interrupt for GPIO_PIN_I2C_EXPANDER_INTERRUPT\n");
init_gpio_interrupt(GPIO_PIN_I2C_EXPANDER_INTERRUPT, &gpio_fd_interrupt_expander_gpio); init_gpio_interrupt(GPIO_PIN_I2C_EXPANDER_INTERRUPT, &gpio_fd_interrupt_expander_gpio);
@ -295,9 +298,10 @@ int deinit_mapping_gpios(void)
int listen_gpios_interrupts(void) int listen_gpios_interrupts(void)
{ {
// Variables // Variables
//char buffer[2]; char buffer[2];
//int value; int value;
int idx_gpio; int idx_gpio;
int nb_interrupts;
bool previous_mask_gpio_value[nb_mapped_gpios]; bool previous_mask_gpio_value[nb_mapped_gpios];
bool mask_gpio_current_interrupts[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){ if(!interrupt_i2c_expander_found && !interrupt_axp209_found){
#ifdef TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP #ifdef TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP
struct timeval timeout = {TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP, 0}; 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 #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 #endif //TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP
if(!nb_interrupts){ if(!nb_interrupts){
// Timeout case // Timeout case
@ -329,11 +333,12 @@ int listen_gpios_interrupts(void)
} }
} }
if(nb_interrupts){
// Check if interrupt from I2C expander or AXP209 // Check if interrupt from I2C expander or AXP209
// Check which cur_fd is available for read // Check which cur_fd is available for read
for (int cur_fd = 0; cur_fd <= max_fd; cur_fd++) { for (int cur_fd = 0; cur_fd <= max_fd; cur_fd++) {
if (FD_ISSET(cur_fd, &dup)) { if (FD_ISSET(cur_fd, &dup)) {
/*// Rewind file // Rewind file
lseek(cur_fd, 0, SEEK_SET); lseek(cur_fd, 0, SEEK_SET);
// Read current gpio value // Read current gpio value
@ -344,7 +349,7 @@ int listen_gpios_interrupts(void)
// remove end of line char // remove end of line char
buffer[1] = '\0'; buffer[1] = '\0';
value = 1-atoi(buffer);*/ value = 1-atoi(buffer);
// Found interrupt // Found interrupt
if(cur_fd == gpio_fd_interrupt_expander_gpio){ if(cur_fd == gpio_fd_interrupt_expander_gpio){
@ -355,6 +360,7 @@ int listen_gpios_interrupts(void)
} }
} }
} }
}
#ifdef ENABLE_AXP209_INTERRUPTS #ifdef ENABLE_AXP209_INTERRUPTS
@ -369,9 +375,12 @@ int listen_gpios_interrupts(void)
if(val_int_bank_3 & AXP209_INTERRUPT_PEK_SHORT_PRESS){ if(val_int_bank_3 & AXP209_INTERRUPT_PEK_SHORT_PRESS){
GPIO_PRINTF(" AXP209 short PEK key press detected\n"); 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){ if(val_int_bank_3 & AXP209_INTERRUPT_PEK_LONG_PRESS){
GPIO_PRINTF(" AXP209 long PEK key press detected\n"); GPIO_PRINTF(" AXP209 long PEK key press detected\n");
sendKeyAndStopKey(KEY_IDX_MAPPED_FOR_LONG_PEK_PRESS);
} }
} }
#endif //ENABLE_AXP209_INTERRUPTS #endif //ENABLE_AXP209_INTERRUPTS
@ -440,3 +449,4 @@ int listen_gpios_interrupts(void)
return 0; return 0;
} }

0
gpio_mapping.h Normal file → Executable file
View File

0
keydefs.c Normal file → Executable file
View File

0
read_conf_file.c Normal file → Executable file
View File

0
read_conf_file.h Normal file → Executable file
View File

0
uinput.c Normal file → Executable file
View File

0
uinput.h Normal file → Executable file
View File