Compare commits

..

No commits in common. "master" and "FunKey-GPIO-Mapping-FunKey-1.1.0" have entirely different histories.

5 changed files with 10 additions and 42 deletions

1
.gitignore vendored
View File

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

View File

@ -1,4 +0,0 @@
# 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,26 +26,11 @@
#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
@ -55,32 +40,20 @@ static i2c_expander_t i2c_chip[] = {
* 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_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;
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;
}
}
/// 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;
}

View File

@ -12,7 +12,6 @@
****************************************************************/
// 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,3 +491,4 @@ int listen_gpios_interrupts(void)
return 0;
}