mirror of
https://github.com/FunKey-Project/FunKey-GPIO-Mapping.git
synced 2025-12-13 10:18:54 +01:00
Compare commits
8 Commits
FunKey-GPI
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7dc08577b | ||
|
|
c008cbfc1a | ||
|
|
87d400a345 | ||
|
|
44035d48c2 | ||
|
|
66fc9ce9d9 | ||
|
|
2922367bc8 | ||
|
|
254f91c2b3 | ||
|
|
e2b637f3bd |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
###################
|
||||
*.o
|
||||
funkey_gpio_management
|
||||
termfix
|
||||
|
||||
4
README.md
Normal file
4
README.md
Normal 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).
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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] */
|
||||
|
||||
@ -491,4 +491,3 @@ int listen_gpios_interrupts(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
17
uinput.c
17
uinput.c
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user