Compare commits

..

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

6 changed files with 12 additions and 57 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;
}

View File

@ -56,19 +56,6 @@
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
@ -198,7 +185,7 @@ int close_uinput(void)
int sendKey(int key, int value)
{
struct input_event_compat ie;
struct input_event ie;
//memset(&uidev_ev, 0, sizeof(struct input_event));
//gettimeofday(&uidev_ev.time, NULL);
ie.type = EV_KEY;
@ -207,7 +194,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_compat)) < 0)
if(write(uidev_fd, &ie, sizeof(struct input_event)) < 0)
die("error: write");
sendSync();