mirror of
https://xff.cz/git/pinephone-keyboard/
synced 2024-11-09 22:15:42 +01:00
Update inputd to make it work with the latest firmware API
This commit is contained in:
parent
62e2ebe7ec
commit
4a1abce0eb
1 changed files with 16 additions and 15 deletions
31
i2c-inputd.c
31
i2c-inputd.c
|
@ -25,15 +25,15 @@
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <linux/uinput.h>
|
#include <linux/uinput.h>
|
||||||
|
|
||||||
#define MEGI_PROTO_BUG 1
|
|
||||||
|
|
||||||
int read_kb(int fd, uint8_t data[16])
|
int read_kb(int fd, uint8_t data[16])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint8_t b = 5;
|
|
||||||
|
uint8_t b = REG_KEYMATRIX_STATE_CRC8;
|
||||||
|
|
||||||
struct i2c_msg msgs[] = {
|
struct i2c_msg msgs[] = {
|
||||||
{ KB_ADDR, 0, 1, &b },
|
{ KB_ADDR, 0, 1, &b },
|
||||||
{ KB_ADDR, I2C_M_RD, 16, data },
|
{ KB_ADDR, I2C_M_RD, REG_KEYMATRIX_STATE_END - REG_KEYMATRIX_STATE_CRC8 + 1, data },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i2c_rdwr_ioctl_data msg = {
|
struct i2c_rdwr_ioctl_data msg = {
|
||||||
|
@ -44,7 +44,15 @@ int read_kb(int fd, uint8_t data[16])
|
||||||
ret = ioctl(fd, I2C_RDWR, &msg);
|
ret = ioctl(fd, I2C_RDWR, &msg);
|
||||||
syscall_error(ret < 0, "I2C_RDWR failed");
|
syscall_error(ret < 0, "I2C_RDWR failed");
|
||||||
|
|
||||||
return ret == 1 ? 0 : -1;
|
// for (int i = 0; i < REG_KEYMATRIX_STATE_END - REG_KEYMATRIX_STATE_CRC8 + 1; i++)
|
||||||
|
// printf("%02hhx", data[i]);
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
uint8_t crc = crc8(data + 1, REG_KEYMATRIX_STATE_END - REG_KEYMATRIX_STATE_CRC8);
|
||||||
|
if (crc != data[0])
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return ret == 2 ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_kb(int fd, uint8_t* data)
|
int write_kb(int fd, uint8_t* data)
|
||||||
|
@ -256,18 +264,11 @@ void update_keys(uint8_t* map)
|
||||||
if (map[c] != 0xff && map[c] & (1u << r)) {
|
if (map[c] != 0xff && map[c] & (1u << r)) {
|
||||||
uint8_t el_idx = (r << 4) | c;
|
uint8_t el_idx = (r << 4) | c;
|
||||||
uint8_t phys_idx = el_phys_map[el_idx];
|
uint8_t phys_idx = el_phys_map[el_idx];
|
||||||
if (phys_idx != 0xff && n_keys < 128) {
|
if (phys_idx != 0xff && n_keys < 128)
|
||||||
#if MEGI_PROTO_BUG
|
|
||||||
int key = keymap_base[phys_idx][0];
|
|
||||||
if (key == KEY_LEFTCTRL || key == KEY_Z) // ignore these keys on my keyboard
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
keys[n_keys++] = phys_idx;
|
keys[n_keys++] = phys_idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// which pressed keys are no longer pressed?
|
// which pressed keys are no longer pressed?
|
||||||
for (int j = 0; j < pressed_count; j++) {
|
for (int j = 0; j < pressed_count; j++) {
|
||||||
|
@ -327,8 +328,8 @@ int main(int ac, char* av[])
|
||||||
if (ret)
|
if (ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// print_bitmap(buf + 4);
|
//print_bitmap(buf + 1);
|
||||||
update_keys(buf + 4);
|
update_keys(buf + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue