mirror of
https://github.com/FunKey-Project/FunKey-GPIO-Mapping.git
synced 2025-12-13 10:18:54 +01:00
added sanity check of GPIO expander values after a real interrupt or a timeout
This commit is contained in:
parent
4c3f0eca57
commit
0cfcca07cc
@ -27,29 +27,32 @@
|
||||
|
||||
###################################
|
||||
# Mapping:
|
||||
6, KEYBOARD, KEY_S, KEY_S, Start
|
||||
7, KEYBOARD, KEY_F, KEY_F, Fn
|
||||
6, KEYBOARD, KEY_S, KEY_S, Start
|
||||
7+6, KEYBOARD, KEY_K, KEY_K, Select
|
||||
3, KEYBOARD, KEY_U, KEY_U, Up
|
||||
7+3, KEYBOARD, KEY_P, KEY_P, Quick Save
|
||||
4, KEYBOARD, KEY_L, KEY_L, Left
|
||||
7+4, KEYBOARD, KEY_J, KEY_J, Aspect ratio factor --
|
||||
1, KEYBOARD, KEY_D, KEY_D, Down
|
||||
7+1, KEYBOARD, KEY_H, KEY_H, Aspect ratio mode change
|
||||
0, KEYBOARD, KEY_R, KEY_R, Right
|
||||
7+0, KEYBOARD, KEY_I, KEY_I, Aspect ratio factor ++
|
||||
15, KEYBOARD, KEY_N, KEY_N, R1
|
||||
# Bypass to remove when button axp working:
|
||||
7+15, KEYBOARD, KEY_Q, 7+11, Launch menu
|
||||
#7+15, KEYBOARD, KEY_O, KEY_O, R2
|
||||
2, KEYBOARD, KEY_M, KEY_M, L1
|
||||
7+2, KEYBOARD, KEY_V, KEY_V, L2
|
||||
12, KEYBOARD, KEY_B, KEY_B, B
|
||||
7+12, KEYBOARD, KEY_G, KEY_G, Brightness++
|
||||
14, KEYBOARD, KEY_A, KEY_A, A
|
||||
7+14, KEYBOARD, KEY_E, KEY_E, Volume--
|
||||
13, KEYBOARD, KEY_X, KEY_X, X
|
||||
7+13, KEYBOARD, KEY_W, KEY_W, Brightness--
|
||||
11, KEYBOARD, KEY_Y, KEY_Y, Y
|
||||
7+7, KEYBOARD, KEY_K, KEY_K, Select
|
||||
7+15, KEYBOARD, KEY_V, KEY_V, L2
|
||||
7+2, KEYBOARD, KEY_O, KEY_O, R2
|
||||
#7+3, SHELL_COMMAND, echo "Volume up", 6+3, Volume up
|
||||
#7+1, SHELL_COMMAND, echo "Volume down", 6+1, Volume down
|
||||
#7+0, SHELL_COMMAND, echo "Brightness up", 6+0, Brightness up
|
||||
#7+4, SHELL_COMMAND, echo "Brightness down", 6+4, Brightness down
|
||||
7+3, SHELL_COMMAND, /root/shell_cmds/start_gpsp.sh, 6+3, start gpsp
|
||||
7+1, SHELL_COMMAND, /root/shell_cmds/start_pcsx.sh, 6+1, start pcsx
|
||||
7+0, SHELL_COMMAND, /root/shell_cmds/start_psnes.sh, 6+0, start psnes
|
||||
7+4, SHELL_COMMAND, /root/shell_cmds/start_mednafen.sh, 6+4, start mednafen GBC
|
||||
7+11, SHELL_COMMAND, /root/shell_cmds/stop_all_emulators.sh, 6+4, stop all emulators
|
||||
7+11, KEYBOARD, KEY_C, KEY_C, Volume++
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <linux/input.h>
|
||||
#include "gpio_mapping.h"
|
||||
#include "driver_pcal6416a.h"
|
||||
@ -35,6 +36,10 @@
|
||||
#define GPIO_ERROR_PRINTF(...)
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* Static variables
|
||||
@ -277,8 +282,20 @@ int listen_gpios_interrupts(void)
|
||||
memset(mask_gpio_value, false, nb_mapped_gpios*sizeof(bool));
|
||||
memset(mask_gpio_current_interrupts, false, nb_mapped_gpios*sizeof(bool));
|
||||
|
||||
// Note the max_fd+1
|
||||
if (select(max_fd+1, NULL, NULL, &dup, NULL) < 0) {
|
||||
// Waiting for interrupt or timeout, Note the max_fd+1
|
||||
#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);
|
||||
#else
|
||||
int nb_interrupts = select(max_fd+1, NULL, NULL, &dup, NULL);
|
||||
#endif //TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP
|
||||
if(!nb_interrupts){
|
||||
// Timeout case
|
||||
GPIO_PRINTF(" Timeout, forcing sanity check\n");
|
||||
// Timeout forcing a "Found interrupt" event for sanity check
|
||||
interrupt_found = true;
|
||||
}
|
||||
else if ( nb_interrupts < 0) {
|
||||
perror("select");
|
||||
return -1;
|
||||
}
|
||||
@ -325,6 +342,14 @@ int listen_gpios_interrupts(void)
|
||||
GPIO_PRINTF(" --> Interrupt GPIO: %d, idx_pin: %d\n", gpio_pins[idx_gpio], idx_gpio);
|
||||
mask_gpio_current_interrupts[idx_gpio] = true;
|
||||
}
|
||||
|
||||
// Sanity check: if we missed an interrupt for some reason, check if the new values are the same
|
||||
if( !mask_gpio_current_interrupts[idx_gpio] &&
|
||||
(mask_gpio_value[idx_gpio] != previous_mask_gpio_value[idx_gpio]) ){
|
||||
// Print information
|
||||
GPIO_PRINTF(" --> No Interrupt (missed) but value has changed on GPIO: %d, idx_pin: %d\n", gpio_pins[idx_gpio], idx_gpio);
|
||||
mask_gpio_current_interrupts[idx_gpio] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user