added interrupt detection on both edges, added .gitignore

This commit is contained in:
Vincent-FK 2019-10-09 05:18:23 +08:00
parent 3613ac0884
commit c245d61322
4 changed files with 37 additions and 11 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Don't track content of these folders
# Compiled source #
###################
*.o
funkey_gpio_management

View File

@ -52,10 +52,20 @@ bool pcal6416a_init(void) {
return false; return false;
} }
uint16_t val_enable_pullups = 0xffff; uint16_t val_enable_direction = 0xffff;
i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_EN_PULLUPDOWN , val_enable_pullups ); i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_CONFIG , val_enable_direction );
uint16_t val_enable_interrupts = 0x0000; uint16_t val_enable_latch = 0x0000;
i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_INPUT_LATCH , val_enable_latch );
uint16_t val_enable_pullups = 0xffff;
i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_EN_PULLUPDOWN , val_enable_pullups );
uint16_t val_sel_pullups = 0xffff;
i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_SEL_PULLUPDOWN , val_sel_pullups );
//uint16_t val_enable_interrupts = 0x0000;
uint16_t val_enable_interrupts = 0x0320;
i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_INT_MASK , val_enable_interrupts ); i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_INT_MASK , val_enable_interrupts );
return true; return true;

View File

@ -22,7 +22,7 @@
################################### ###################################
# Pins declaration: # Pins declaration:
0,1,2,3,4,6,7,11,12,13,14,15 0,1,2,3,4,6,7,10,11,12,13,14,15
################################### ###################################
@ -52,6 +52,7 @@
7+13, KEYBOARD, KEY_W, KEY_W, Brightness-- 7+13, KEYBOARD, KEY_W, KEY_W, Brightness--
11, KEYBOARD, KEY_Y, KEY_Y, Y 11, KEYBOARD, KEY_Y, KEY_Y, Y
7+11, KEYBOARD, KEY_C, KEY_C, Volume++ 7+11, KEYBOARD, KEY_C, KEY_C, Volume++
10, KEYBOARD, KEY_T, KEY_T, Poweroff

View File

@ -39,7 +39,8 @@
// This define forces to perform a gpio sanity check after a timeout. // 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 // 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 // This is for debug purposes on cards or eval boards that do not have the AXP209
#define ENABLE_AXP209_INTERRUPTS #define ENABLE_AXP209_INTERRUPTS
@ -195,8 +196,8 @@ static int init_gpio_interrupt(int pin_nb, int *fd_saved)
//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(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, "falling"); // Can be rising, falling or both
*fd_saved = gpio_fd_open(pin_nb, O_RDONLY); *fd_saved = gpio_fd_open(pin_nb, O_RDONLY);
GPIO_PRINTF("fd is: %d\n", *fd_saved); GPIO_PRINTF("fd is: %d\n", *fd_saved);
@ -301,7 +302,7 @@ int listen_gpios_interrupts(void)
char buffer[2]; char buffer[2];
int value; int value;
int idx_gpio; int idx_gpio;
int nb_interrupts; int nb_interrupts = 0;
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];
@ -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 not already found, waiting for interrupt or timeout, Note the max_fd+1
if(!interrupt_i2c_expander_found && !interrupt_axp209_found){ 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}; struct timeval timeout = {TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP, 0};
nb_interrupts = select(max_fd+1, NULL, NULL, &dup, &timeout); nb_interrupts = select(max_fd+1, NULL, NULL, &dup, &timeout);
#else #else
@ -349,13 +354,16 @@ 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 = 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){
GPIO_PRINTF("Found interrupt generated by PCAL6416AHF \r\n");
interrupt_i2c_expander_found = true; interrupt_i2c_expander_found = true;
} }
else if(cur_fd == gpio_fd_interrupt_axp209){ else if(cur_fd == gpio_fd_interrupt_axp209){
GPIO_PRINTF("Found interrupt generated by AXP209\r\n");
interrupt_axp209_found = true; interrupt_axp209_found = true;
} }
} }
@ -365,7 +373,7 @@ int listen_gpios_interrupts(void)
#ifdef ENABLE_AXP209_INTERRUPTS #ifdef ENABLE_AXP209_INTERRUPTS
if(interrupt_axp209_found){ 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(); int val_int_bank_3 = axp209_read_interrupt_bank_3();
if(val_int_bank_3 < 0){ if(val_int_bank_3 < 0){
GPIO_PRINTF(" Could not read AXP209 with I2C\n"); GPIO_PRINTF(" Could not read AXP209 with I2C\n");
@ -386,6 +394,7 @@ int listen_gpios_interrupts(void)
#endif //ENABLE_AXP209_INTERRUPTS #endif //ENABLE_AXP209_INTERRUPTS
if(interrupt_i2c_expander_found){ if(interrupt_i2c_expander_found){
GPIO_PRINTF(" Processing interrupt PCAL6416AHF\n");
// Read I2C GPIO masks: // Read I2C GPIO masks:
int val_i2c_mask_interrupted = pcal6416a_read_mask_interrupts(); int val_i2c_mask_interrupted = pcal6416a_read_mask_interrupts();
if(val_i2c_mask_interrupted < 0){ if(val_i2c_mask_interrupted < 0){