Compare commits

...

8 Commits

Author SHA1 Message Date
Michel-FK
b7dc08577b
Create README.md 2021-04-28 16:36:29 +02:00
Vincent-FK
c008cbfc1a added break if chip found and passes not found messages as debug_printf when probing 2021-03-16 08:55:33 +01:00
Michel-FK
87d400a345 clean up multi I2C GPIO expander detection
Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
2021-03-16 08:28:05 +01:00
Michel-FK
44035d48c2 fix multi I2C GPIO expander detection
Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
2021-03-16 08:11:47 +01:00
Vincent-FK
66fc9ce9d9 corrected printf args 2021-03-15 23:37:17 +01:00
Vincent-FK
2922367bc8 bug correction when Probing PCAL9539A chip 2021-03-15 23:25:44 +01:00
Vincent-FK
254f91c2b3 added support for PCAL9539A 2021-03-15 23:16:09 +01:00
Michel-FK
e2b637f3bd add compatibilty with kernel with dates on 32 bits
Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
2020-12-21 21:38:38 +01:00
6 changed files with 57 additions and 12 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
###################
*.o
funkey_gpio_management
termfix

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# FunKey-GPIO-Mapping
Embedded Linux OS GPIO mapping daemon for the FunKey S retro-gaming console
**Note**: This repository is archived and read-only, as this functionality is now handled by [fkgpiod](https://github.com/FunKey-Project/fkgpiod).

View File

@ -26,11 +26,26 @@
#define DEBUG_PRINTF(...)
#endif
/****************************************************************
* Structures
****************************************************************/
typedef struct {
unsigned int address;
char *name;
} i2c_expander_t;
/****************************************************************
* Static variables
****************************************************************/
static int fd_i2c_expander;
static unsigned int i2c_expander_addr;
static char i2c0_sysfs_filename[] = "/dev/i2c-0";
static i2c_expander_t i2c_chip[] = {
{PCAL9539A_I2C_ADDR, "PCAL9539A"},
{PCAL6416A_I2C_ADDR, "PCAL6416A"},
{0, NULL}
};
/****************************************************************
* Static functions
@ -40,20 +55,32 @@ static char i2c0_sysfs_filename[] = "/dev/i2c-0";
* Public functions
****************************************************************/
bool pcal6416a_init(void) {
int i;
if ((fd_i2c_expander = open(i2c0_sysfs_filename,O_RDWR)) < 0) {
printf("Failed to open the I2C bus %s", i2c0_sysfs_filename);
// ERROR HANDLING; you can check errno to see what went wrong
return false;
}
/// Probing known I2C GPIO expander chips
for (i = 0, i2c_expander_addr = 0; i2c_chip[i].address; i++) {
if (ioctl(fd_i2c_expander,I2C_SLAVE,PCAL6416A_I2C_ADDR) < 0) {
printf("In pcal6416a_init - Failed to acquire bus access and/or talk to slave.\n");
// ERROR HANDLING; you can check errno to see what went wrong
if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL6416A_I2C_ADDR) < 0) {
printf("In pcal6416a_init - Failed to acquire FORCED bus access and/or talk to slave.\n");
// ERROR HANDLING; you can check errno to see what went wrong
return false;
}
if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, i2c_chip[i]) < 0 ||
pcal6416a_read_mask_interrupts() < 0) {
DEBUG_PRINTF("In %s - Failed to acquire bus access and/or talk to slave %s at address 0x%02X.\n",
__func__, i2c_chip[i].name, i2c_chip[i].address);
} else {
DEBUG_PRINTF("Found I2C gpio expander chip %s at address 0x%02X\n",
i2c_chip[i].name, i2c_chip[i].address);
i2c_expander_addr = i2c_chip[i].address;
break;
}
}
/// GPIO expander chip found?
if(!i2c_expander_addr){
printf("In %s - Failed to acquire bus access and/or talk to slave, exit\n", __func__);
return false;
}
@ -101,4 +128,4 @@ int pcal6416a_read_mask_active_GPIOs(void){
val = 0xFFFF-val;
DEBUG_PRINTF("READ PCAL6416A_INPUT (active GPIOs) : 0x%04X\n",val);
return (int) val;
}
}

View File

@ -12,6 +12,7 @@
****************************************************************/
// Chip physical address
#define PCAL6416A_I2C_ADDR 0x20
#define PCAL9539A_I2C_ADDR 0x76
// Chip registers adresses
#define PCAL6416A_INPUT 0x00 /* Input port [RO] */

View File

@ -491,4 +491,3 @@ int listen_gpios_interrupts(void)
return 0;
}

View File

@ -56,6 +56,19 @@
return(EXIT_FAILURE); \
} while(0)
// For compatibility with kernels having dates on 32 bits
struct timeval_compat
{
unsigned int tv_sec;
long int tv_usec;
};
struct input_event_compat {
struct timeval_compat time;
unsigned short type;
unsigned short code;
unsigned int value;
};
/****************************************************************
* Static functions declaration
@ -185,7 +198,7 @@ int close_uinput(void)
int sendKey(int key, int value)
{
struct input_event ie;
struct input_event_compat ie;
//memset(&uidev_ev, 0, sizeof(struct input_event));
//gettimeofday(&uidev_ev.time, NULL);
ie.type = EV_KEY;
@ -194,7 +207,7 @@ int sendKey(int key, int value)
ie.time.tv_sec = 0;
ie.time.tv_usec = 0;
UINPUT_PRINTF("sendKey: %d = %d\n", key, value);
if(write(uidev_fd, &ie, sizeof(struct input_event)) < 0)
if(write(uidev_fd, &ie, sizeof(struct input_event_compat)) < 0)
die("error: write");
sendSync();