Browse Source

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

Vincent-FK 4 years ago
parent
commit
3613ac0884
16 changed files with 79 additions and 34 deletions
  1. 0 0
      Makefile
  2. 28 2
      driver_axp209.c
  3. 10 1
      driver_axp209.h
  4. 0 0
      driver_pcal6416a.c
  5. 0 0
      driver_pcal6416a.h
  6. 0 0
      funkey_gpio_management.c
  7. 0 0
      funkey_gpio_mapping.conf
  8. 0 0
      gpio-utils.c
  9. 0 0
      gpio-utils.h
  10. 41 31
      gpio_mapping.c
  11. 0 0
      gpio_mapping.h
  12. 0 0
      keydefs.c
  13. 0 0
      read_conf_file.c
  14. 0 0
      read_conf_file.h
  15. 0 0
      uinput.c
  16. 0 0
      uinput.h

+ 0 - 0
Makefile


+ 28 - 2
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;
-}
+}

+ 10 - 1
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 

+ 0 - 0
driver_pcal6416a.c


+ 0 - 0
driver_pcal6416a.h


+ 0 - 0
funkey_gpio_management.c


+ 0 - 0
funkey_gpio_mapping.conf


+ 0 - 0
gpio-utils.c


+ 0 - 0
gpio-utils.h


+ 41 - 31
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;
-			}
-
-			// remove end of line char
-			buffer[1] = '\0';
-			value = 1-atoi(buffer);*/
+				// 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);
 
-			// 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;
 }
+

+ 0 - 0
gpio_mapping.h


+ 0 - 0
keydefs.c


+ 0 - 0
read_conf_file.c


+ 0 - 0
read_conf_file.h


+ 0 - 0
uinput.c


+ 0 - 0
uinput.h