1
0
Fork 0

Add NKRO support for LUFA

This commit is contained in:
tmk 2013-07-28 17:34:41 +09:00
parent c7d309e34b
commit daa4a4235f
10 changed files with 168 additions and 177 deletions

View file

@ -37,8 +37,10 @@ static uint16_t last_consumer_report = 0;
static inline void add_key_byte(uint8_t code);
static inline void del_key_byte(uint8_t code);
#ifdef NKRO_ENABLE
static inline void add_key_bit(uint8_t code);
static inline void del_key_bit(uint8_t code);
#endif
void host_set_driver(host_driver_t *d)
@ -63,11 +65,11 @@ void host_keyboard_send(report_keyboard_t *report)
(*driver->send_keyboard)(report);
if (debug_keyboard) {
dprint("keys: ");
for (int i = 0; i < REPORT_KEYS; i++) {
dprintf("%02X ", keyboard_report->keys[i]);
dprint("keyboard_report: ");
for (uint8_t i = 0; i < REPORT_SIZE; i++) {
dprintf("%02X ", keyboard_report->raw[i]);
}
dprintf(" mods: %02X\n", keyboard_report->mods);
dprint("\n");
}
}
@ -122,8 +124,9 @@ void host_del_key(uint8_t key)
void host_clear_keys(void)
{
for (int8_t i = 0; i < REPORT_KEYS; i++) {
keyboard_report->keys[i] = 0;
// not clea mods
for (int8_t i = 1; i < REPORT_SIZE; i++) {
keyboard_report->raw[i] = 0;
}
}
@ -155,8 +158,8 @@ void host_clear_mods(void)
uint8_t host_has_anykey(void)
{
uint8_t cnt = 0;
for (int i = 0; i < REPORT_KEYS; i++) {
if (keyboard_report->keys[i])
for (uint8_t i = 1; i < REPORT_SIZE; i++) {
if (keyboard_report->raw[i])
cnt++;
}
return cnt;
@ -172,9 +175,9 @@ uint8_t host_get_first_key(void)
#ifdef NKRO_ENABLE
if (keyboard_nkro) {
uint8_t i = 0;
for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++)
for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
;
return i<<3 | biton(keyboard_report->keys[i]);
return i<<3 | biton(keyboard_report->nkro.bits[i]);
}
#endif
return keyboard_report->keys[0];
@ -222,18 +225,18 @@ static inline void add_key_byte(uint8_t code)
static inline void del_key_byte(uint8_t code)
{
int i = 0;
for (; i < REPORT_KEYS; i++) {
for (uint8_t i = 0; i < REPORT_KEYS; i++) {
if (keyboard_report->keys[i] == code) {
keyboard_report->keys[i] = 0;
}
}
}
#ifdef NKRO_ENABLE
static inline void add_key_bit(uint8_t code)
{
if ((code>>3) < REPORT_KEYS) {
keyboard_report->keys[code>>3] |= 1<<(code&7);
if ((code>>3) < REPORT_BITS) {
keyboard_report->nkro.bits[code>>3] |= 1<<(code&7);
} else {
dprintf("add_key_bit: can't add: %02X\n", code);
}
@ -241,9 +244,10 @@ static inline void add_key_bit(uint8_t code)
static inline void del_key_bit(uint8_t code)
{
if ((code>>3) < REPORT_KEYS) {
keyboard_report->keys[code>>3] &= ~(1<<(code&7));
if ((code>>3) < REPORT_BITS) {
keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7));
} else {
dprintf("del_key_bit: can't del: %02X\n", code);
}
}
#endif

View file

@ -72,14 +72,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* key report size(NKRO or boot mode) */
#if defined(PROTOCOL_PJRC)
#if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE)
# include "usb.h"
# if defined(KBD2_REPORT_KEYS) && KBD2_REPORT_KEYS > KBD_REPORT_KEYS
# define REPORT_KEYS KBD2_REPORT_KEYS
# else
# define REPORT_KEYS KBD_REPORT_KEYS
# endif
# define REPORT_SIZE KBD2_SIZE
# define REPORT_KEYS (KBD2_SIZE - 2)
# define REPORT_BITS (KBD2_SIZE - 1)
#elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE)
# include "protocol/lufa/descriptor.h"
# define REPORT_SIZE NKRO_EPSIZE
# define REPORT_KEYS (NKRO_EPSIZE - 2)
# define REPORT_BITS (NKRO_EPSIZE - 1)
#else
# define REPORT_SIZE 8
# define REPORT_KEYS 6
#endif
@ -88,11 +94,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" {
#endif
typedef union {
uint8_t raw[REPORT_SIZE];
struct {
uint8_t mods;
uint8_t reserved;
uint8_t keys[REPORT_KEYS];
};
#ifdef NKRO_ENABLE
struct {
uint8_t mods;
uint8_t bits[REPORT_BITS];
} nkro;
#endif
} __attribute__ ((packed)) report_keyboard_t;
/*
typedef struct {
uint8_t mods;
uint8_t rserved;
uint8_t reserved;
uint8_t keys[REPORT_KEYS];
} __attribute__ ((packed)) report_keyboard_t;
*/
typedef struct {
uint8_t buttons;