1
0

NKRO fixes.

This commit is contained in:
flabbergast 2015-09-10 12:48:44 +01:00
parent 9540016b12
commit a24ddf3403
4 changed files with 52 additions and 49 deletions

View File

@ -84,6 +84,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE # define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) # define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) # define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
#elif defined(PROTOCOL_CHIBIOS) && defined(NKRO_ENABLE)
# include "protocol/chibios/usb_main.h"
# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
#else #else
# define KEYBOARD_REPORT_SIZE 8 # define KEYBOARD_REPORT_SIZE 8

View File

@ -40,6 +40,14 @@
* ------------------------- * -------------------------
*/ */
/* declarations */
uint8_t keyboard_leds(void);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
/* host struct */
host_driver_t chibios_driver = { host_driver_t chibios_driver = {
keyboard_leds, keyboard_leds,
send_keyboard, send_keyboard,
@ -52,14 +60,15 @@ host_driver_t chibios_driver = {
/* TESTING /* TESTING
* Amber LED blinker thread, times are in milliseconds. * Amber LED blinker thread, times are in milliseconds.
*/ */
// uint8_t blinkLedState = 0; /* set this variable to non-zero anywhere to blink once */
// static THD_WORKING_AREA(waThread1, 128); // uint8_t blinkLed = 0;
// static THD_FUNCTION(Thread1, arg) { // static THD_WORKING_AREA(waBlinkerThread, 128);
// static THD_FUNCTION(blinkerThread, arg) {
// (void)arg; // (void)arg;
// chRegSetThreadName("blinker1"); // chRegSetThreadName("blinkOrange");
// while(true) { // while(true) {
// if(blinkLedState) { // if(blinkLed) {
// blinkLedState = 0; // blinkLed = 0;
// palSetPad(GPIOC, GPIOC_LED_ORANGE); // palSetPad(GPIOC, GPIOC_LED_ORANGE);
// chThdSleepMilliseconds(100); // chThdSleepMilliseconds(100);
// palClearPad(GPIOC, GPIOC_LED_ORANGE); // palClearPad(GPIOC, GPIOC_LED_ORANGE);
@ -82,7 +91,7 @@ int main(void) {
palClearPad(GPIOC, GPIOC_LED_BLUE); palClearPad(GPIOC, GPIOC_LED_BLUE);
// TESTING // TESTING
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);
/* Init USB */ /* Init USB */
init_usb_driver(&USB_DRIVER); init_usb_driver(&USB_DRIVER);

View File

@ -20,11 +20,11 @@
#include "usb_main.h" #include "usb_main.h"
#include "host.h"
#include "debug.h" #include "debug.h"
#ifdef SLEEP_LED_ENABLE #ifdef SLEEP_LED_ENABLE
#include "sleep_led.h" #include "sleep_led.h"
#include "led.h" #include "led.h"
#include "host.h"
#endif #endif
/* --------------------------------------------------------- /* ---------------------------------------------------------
@ -39,7 +39,7 @@ volatile uint16_t keyboard_idle_count = 0;
static virtual_timer_t keyboard_idle_timer; static virtual_timer_t keyboard_idle_timer;
static void keyboard_idle_timer_cb(void *arg); static void keyboard_idle_timer_cb(void *arg);
#ifdef NKRO_ENABLE #ifdef NKRO_ENABLE
bool keyboard_nkro = true; extern bool keyboard_nkro;
#endif /* NKRO_ENABLE */ #endif /* NKRO_ENABLE */
report_keyboard_t keyboard_report_sent = {{0}}; report_keyboard_t keyboard_report_sent = {{0}};
@ -250,7 +250,7 @@ static const uint8_t console_hid_report_desc_data[] = {
0x75, 0x08, // report size = 8 bits 0x75, 0x08, // report size = 8 bits
0x15, 0x00, // logical minimum = 0 0x15, 0x00, // logical minimum = 0
0x26, 0xFF, 0x00, // logical maximum = 255 0x26, 0xFF, 0x00, // logical maximum = 255
0x95, CONSOLE_SIZE, // report count 0x95, CONSOLE_EPSIZE, // report count
0x09, 0x75, // usage 0x09, 0x75, // usage
0x81, 0x02, // Input (array) 0x81, 0x02, // Input (array)
0xC0 // end collection 0xC0 // end collection
@ -374,7 +374,7 @@ static const uint8_t hid_configuration_descriptor_data[] = {
/* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */ /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
USB_DESC_ENDPOINT(KBD_ENDPOINT | 0x80, // bEndpointAddress USB_DESC_ENDPOINT(KBD_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (Interrupt) 0x03, // bmAttributes (Interrupt)
KBD_SIZE, // wMaxPacketSize KBD_EPSIZE,// wMaxPacketSize
10), // bInterval 10), // bInterval
#ifdef MOUSE_ENABLE #ifdef MOUSE_ENABLE
@ -404,7 +404,7 @@ static const uint8_t hid_configuration_descriptor_data[] = {
/* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */ /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
USB_DESC_ENDPOINT(MOUSE_ENDPOINT | 0x80, // bEndpointAddress USB_DESC_ENDPOINT(MOUSE_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (Interrupt) 0x03, // bmAttributes (Interrupt)
MOUSE_SIZE, // wMaxPacketSize MOUSE_EPSIZE, // wMaxPacketSize
1), // bInterval 1), // bInterval
#endif /* MOUSE_ENABLE */ #endif /* MOUSE_ENABLE */
@ -430,7 +430,7 @@ static const uint8_t hid_configuration_descriptor_data[] = {
/* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */ /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
USB_DESC_ENDPOINT(CONSOLE_ENDPOINT | 0x80, // bEndpointAddress USB_DESC_ENDPOINT(CONSOLE_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (Interrupt) 0x03, // bmAttributes (Interrupt)
CONSOLE_SIZE, // wMaxPacketSize CONSOLE_EPSIZE, // wMaxPacketSize
1), // bInterval 1), // bInterval
#endif /* CONSOLE_ENABLE */ #endif /* CONSOLE_ENABLE */
@ -456,7 +456,7 @@ static const uint8_t hid_configuration_descriptor_data[] = {
/* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */ /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
USB_DESC_ENDPOINT(EXTRA_ENDPOINT | 0x80, // bEndpointAddress USB_DESC_ENDPOINT(EXTRA_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (Interrupt) 0x03, // bmAttributes (Interrupt)
EXTRA_SIZE, // wMaxPacketSize EXTRA_EPSIZE, // wMaxPacketSize
10), // bInterval 10), // bInterval
#endif /* EXTRAKEY_ENABLE */ #endif /* EXTRAKEY_ENABLE */
@ -482,7 +482,7 @@ static const uint8_t hid_configuration_descriptor_data[] = {
/* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */ /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
USB_DESC_ENDPOINT(NKRO_ENDPOINT | 0x80, // bEndpointAddress USB_DESC_ENDPOINT(NKRO_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (Interrupt) 0x03, // bmAttributes (Interrupt)
NKRO_SIZE, // wMaxPacketSize NKRO_EPSIZE, // wMaxPacketSize
1), // bInterval 1), // bInterval
#endif /* NKRO_ENABLE */ #endif /* NKRO_ENABLE */
}; };
@ -665,7 +665,7 @@ static const USBEndpointConfig kbd_ep_config = {
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
kbd_in_cb, /* IN notification callback */ kbd_in_cb, /* IN notification callback */
NULL, /* OUT notification callback */ NULL, /* OUT notification callback */
KBD_SIZE, /* IN maximum packet size */ KBD_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */ 0, /* OUT maximum packet size */
&kbd_ep_state, /* IN Endpoint state */ &kbd_ep_state, /* IN Endpoint state */
NULL, /* OUT endpoint state */ NULL, /* OUT endpoint state */
@ -683,7 +683,7 @@ static const USBEndpointConfig mouse_ep_config = {
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
mouse_in_cb, /* IN notification callback */ mouse_in_cb, /* IN notification callback */
NULL, /* OUT notification callback */ NULL, /* OUT notification callback */
MOUSE_SIZE, /* IN maximum packet size */ MOUSE_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */ 0, /* OUT maximum packet size */
&mouse_ep_state, /* IN Endpoint state */ &mouse_ep_state, /* IN Endpoint state */
NULL, /* OUT endpoint state */ NULL, /* OUT endpoint state */
@ -702,7 +702,7 @@ static const USBEndpointConfig console_ep_config = {
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
console_in_cb, /* IN notification callback */ console_in_cb, /* IN notification callback */
NULL, /* OUT notification callback */ NULL, /* OUT notification callback */
CONSOLE_SIZE, /* IN maximum packet size */ CONSOLE_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */ 0, /* OUT maximum packet size */
&console_ep_state, /* IN Endpoint state */ &console_ep_state, /* IN Endpoint state */
NULL, /* OUT endpoint state */ NULL, /* OUT endpoint state */
@ -721,7 +721,7 @@ static const USBEndpointConfig extra_ep_config = {
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
extra_in_cb, /* IN notification callback */ extra_in_cb, /* IN notification callback */
NULL, /* OUT notification callback */ NULL, /* OUT notification callback */
EXTRA_SIZE, /* IN maximum packet size */ EXTRA_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */ 0, /* OUT maximum packet size */
&extra_ep_state, /* IN Endpoint state */ &extra_ep_state, /* IN Endpoint state */
NULL, /* OUT endpoint state */ NULL, /* OUT endpoint state */
@ -740,7 +740,7 @@ static const USBEndpointConfig nkro_ep_config = {
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
nkro_in_cb, /* IN notification callback */ nkro_in_cb, /* IN notification callback */
NULL, /* OUT notification callback */ NULL, /* OUT notification callback */
NKRO_SIZE, /* IN maximum packet size */ NKRO_EPSIZE, /* IN maximum packet size */
0, /* OUT maximum packet size */ 0, /* OUT maximum packet size */
&nkro_ep_state, /* IN Endpoint state */ &nkro_ep_state, /* IN Endpoint state */
NULL, /* OUT endpoint state */ NULL, /* OUT endpoint state */
@ -1178,9 +1178,9 @@ void console_in_cb(USBDriver *usbp, usbep_t ep) {
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp); chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
/* Check if there is data to send left in the output queue */ /* Check if there is data to send left in the output queue */
if(chOQGetFullI(&console_queue) >= CONSOLE_SIZE) { if(chOQGetFullI(&console_queue) >= CONSOLE_EPSIZE) {
osalSysUnlockFromISR(); osalSysUnlockFromISR();
usbPrepareQueuedTransmit(usbp, CONSOLE_ENDPOINT, &console_queue, CONSOLE_SIZE); usbPrepareQueuedTransmit(usbp, CONSOLE_ENDPOINT, &console_queue, CONSOLE_EPSIZE);
osalSysLockFromISR(); osalSysLockFromISR();
usbStartTransmitI(usbp, CONSOLE_ENDPOINT); usbStartTransmitI(usbp, CONSOLE_ENDPOINT);
} }
@ -1197,9 +1197,9 @@ void console_queue_onotify(io_queue_t *qp) {
return; return;
if(!usbGetTransmitStatusI(usbp, CONSOLE_ENDPOINT) if(!usbGetTransmitStatusI(usbp, CONSOLE_ENDPOINT)
&& (chOQGetFullI(&console_queue) >= CONSOLE_SIZE)) { && (chOQGetFullI(&console_queue) >= CONSOLE_EPSIZE)) {
osalSysUnlock(); osalSysUnlock();
usbPrepareQueuedTransmit(usbp, CONSOLE_ENDPOINT, &console_queue, CONSOLE_SIZE); usbPrepareQueuedTransmit(usbp, CONSOLE_ENDPOINT, &console_queue, CONSOLE_EPSIZE);
osalSysLock(); osalSysLock();
usbStartTransmitI(usbp, CONSOLE_ENDPOINT); usbStartTransmitI(usbp, CONSOLE_ENDPOINT);
} }
@ -1210,7 +1210,7 @@ void console_queue_onotify(io_queue_t *qp) {
static void console_flush_cb(void *arg) { static void console_flush_cb(void *arg) {
USBDriver *usbp = (USBDriver *)arg; USBDriver *usbp = (USBDriver *)arg;
size_t i, n; size_t i, n;
uint8_t buf[CONSOLE_SIZE]; /* TODO: a solution without extra buffer? */ uint8_t buf[CONSOLE_EPSIZE]; /* TODO: a solution without extra buffer? */
osalSysLockFromISR(); osalSysLockFromISR();
/* check that the states of things are as they're supposed to */ /* check that the states of things are as they're supposed to */
@ -1222,7 +1222,7 @@ static void console_flush_cb(void *arg) {
} }
/* don't do anything if the queue is empty or has enough stuff in it */ /* don't do anything if the queue is empty or has enough stuff in it */
if(((n = oqGetFullI(&console_queue)) == 0) || (n >= CONSOLE_SIZE)) { if(((n = oqGetFullI(&console_queue)) == 0) || (n >= CONSOLE_EPSIZE)) {
/* rearm the timer */ /* rearm the timer */
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp); chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
osalSysUnlockFromISR(); osalSysUnlockFromISR();
@ -1232,10 +1232,10 @@ static void console_flush_cb(void *arg) {
/* there's stuff hanging in the queue - so dequeue and send */ /* there's stuff hanging in the queue - so dequeue and send */
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
buf[i] = (uint8_t)oqGetI(&console_queue); buf[i] = (uint8_t)oqGetI(&console_queue);
for(i = n; i < CONSOLE_SIZE; i++) for(i = n; i < CONSOLE_EPSIZE; i++)
buf[i] = 0; buf[i] = 0;
osalSysUnlockFromISR(); osalSysUnlockFromISR();
usbPrepareTransmit(usbp, CONSOLE_ENDPOINT, buf, CONSOLE_SIZE); usbPrepareTransmit(usbp, CONSOLE_ENDPOINT, buf, CONSOLE_EPSIZE);
osalSysLockFromISR(); osalSysLockFromISR();
(void)usbStartTransmitI(usbp, CONSOLE_ENDPOINT); (void)usbStartTransmitI(usbp, CONSOLE_ENDPOINT);

View File

@ -20,7 +20,7 @@
#define _USB_MAIN_H_ #define _USB_MAIN_H_
// TESTING // TESTING
// extern uint8_t blinkLedState; // extern uint8_t blinkLed;
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
@ -44,19 +44,19 @@ void init_usb_driver(USBDriver *usbp);
/* main keyboard (6kro) */ /* main keyboard (6kro) */
#define KBD_INTERFACE 0 #define KBD_INTERFACE 0
#define KBD_ENDPOINT 1 #define KBD_ENDPOINT 1
#define KBD_SIZE 8 #define KBD_EPSIZE 8
#define KBD_REPORT_KEYS (KBD_SIZE - 2) #define KBD_REPORT_KEYS (KBD_EPSIZE - 2)
/* secondary keyboard */ /* secondary keyboard */
#ifdef NKRO_ENABLE #ifdef NKRO_ENABLE
#define NKRO_INTERFACE 4 #define NKRO_INTERFACE 4
#define NKRO_ENDPOINT 5 #define NKRO_ENDPOINT 5
#define NKRO_SIZE 16 #define NKRO_EPSIZE 16
#define NKRO_REPORT_KEYS (NKRO_SIZE - 1) #define NKRO_REPORT_KEYS (NKRO_EPSIZE - 1)
#endif #endif
/* this defines report_keyboard_t and computes REPORT_SIZE defines */ /* this defines report_keyboard_t and computes REPORT_SIZE defines */
#include "report.h" // #include "report.h"
/* extern report_keyboard_t keyboard_report_sent; */ /* extern report_keyboard_t keyboard_report_sent; */
@ -80,7 +80,7 @@ void nkro_in_cb(USBDriver *usbp, usbep_t ep);
#define MOUSE_INTERFACE 1 #define MOUSE_INTERFACE 1
#define MOUSE_ENDPOINT 2 #define MOUSE_ENDPOINT 2
#define MOUSE_SIZE 8 #define MOUSE_EPSIZE 8
/* mouse IN request callback handler */ /* mouse IN request callback handler */
void mouse_in_cb(USBDriver *usbp, usbep_t ep); void mouse_in_cb(USBDriver *usbp, usbep_t ep);
@ -95,7 +95,7 @@ void mouse_in_cb(USBDriver *usbp, usbep_t ep);
#define EXTRA_INTERFACE 3 #define EXTRA_INTERFACE 3
#define EXTRA_ENDPOINT 4 #define EXTRA_ENDPOINT 4
#define EXTRA_SIZE 8 #define EXTRA_EPSIZE 8
/* extrakey IN request callback handler */ /* extrakey IN request callback handler */
void extra_in_cb(USBDriver *usbp, usbep_t ep); void extra_in_cb(USBDriver *usbp, usbep_t ep);
@ -116,11 +116,11 @@ typedef struct {
#define CONSOLE_INTERFACE 2 #define CONSOLE_INTERFACE 2
#define CONSOLE_ENDPOINT 3 #define CONSOLE_ENDPOINT 3
#define CONSOLE_SIZE 16 #define CONSOLE_EPSIZE 16
/* Number of IN reports that can be stored inside the output queue */ /* Number of IN reports that can be stored inside the output queue */
#define CONSOLE_QUEUE_CAPACITY 2 #define CONSOLE_QUEUE_CAPACITY 2
#define CONSOLE_QUEUE_BUFFER_SIZE (CONSOLE_QUEUE_CAPACITY * CONSOLE_SIZE) #define CONSOLE_QUEUE_BUFFER_SIZE (CONSOLE_QUEUE_CAPACITY * CONSOLE_EPSIZE)
/* Console flush time */ /* Console flush time */
#define CONSOLE_FLUSH_MS 50 #define CONSOLE_FLUSH_MS 50
@ -138,15 +138,4 @@ void console_in_cb(USBDriver *usbp, usbep_t ep);
void sendchar_pf(void *p, char c); void sendchar_pf(void *p, char c);
/* ---------------------------
* Host driver functions (TMK)
* ---------------------------
*/
uint8_t keyboard_leds(void);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
#endif /* _USB_MAIN_H_ */ #endif /* _USB_MAIN_H_ */