Browse Source

added interrupt detection on both edges, added .gitignore

Vincent-FK 4 years ago
parent
commit
c245d61322
4 changed files with 36 additions and 10 deletions
  1. 6 0
      .gitignore
  2. 12 2
      driver_pcal6416a.c
  3. 2 1
      funkey_gpio_mapping.conf
  4. 16 7
      gpio_mapping.c

+ 6 - 0
.gitignore

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

+ 12 - 2
driver_pcal6416a.c

@@ -52,10 +52,20 @@ bool pcal6416a_init(void) {
         return false;
     }
 
+    uint16_t val_enable_direction = 0xffff;
+    i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_CONFIG , val_enable_direction );
+
+    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 );
+    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 = 0x0000;
+    uint16_t val_enable_interrupts = 0x0320;
  	i2c_smbus_write_word_data ( fd_i2c_expander , PCAL6416A_INT_MASK , val_enable_interrupts );
 
  	return true;

+ 2 - 1
funkey_gpio_mapping.conf

@@ -22,7 +22,7 @@
 
 ###################################
 #	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--
 11, KEYBOARD, KEY_Y, KEY_Y, Y
 7+11, KEYBOARD, KEY_C, KEY_C, Volume++
+10, KEYBOARD, KEY_T, KEY_T, Poweroff
 
 
 

+ 16 - 7
gpio_mapping.c

@@ -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){