Browse Source

Make usb_main more USB_DRIVER #define independent.

tags/v2.9
flabbergast 8 years ago
parent
commit
1d115301d4

+ 1
- 1
tmk_core/protocol/chibios/chibios.mk View File

include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional). # RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk
# Other files (optional). # Other files (optional).


# Define linker script file here # Define linker script file here

+ 1
- 1
tmk_core/protocol/chibios/main.c View File

palClearPad(GPIOC, GPIOC_LED_BLUE); palClearPad(GPIOC, GPIOC_LED_BLUE);


/* Init USB */ /* Init USB */
init_usb_driver();
init_usb_driver(&USB_DRIVER);


/* init printf */ /* init printf */
init_printf(NULL,sendchar_pf); init_printf(NULL,sendchar_pf);

+ 25
- 25
tmk_core/protocol/chibios/usb_main.c View File

#endif /* NKRO_ENABLE */ #endif /* NKRO_ENABLE */
/* arm the idle timer if boot protocol & idle */ /* arm the idle timer if boot protocol & idle */
osalSysLockFromISR(); osalSysLockFromISR();
chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, NULL);
chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
osalSysUnlockFromISR(); osalSysUnlockFromISR();
} }
} }
if(keyboard_idle) { if(keyboard_idle) {
#endif /* NKRO_ENABLE */ #endif /* NKRO_ENABLE */
osalSysLockFromISR(); osalSysLockFromISR();
chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, NULL);
chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
osalSysUnlockFromISR(); osalSysUnlockFromISR();
} }
usbSetupTransfer(usbp, NULL, 0, NULL); usbSetupTransfer(usbp, NULL, 0, NULL);
/* /*
* Initialize the USB driver * Initialize the USB driver
*/ */
void init_usb_driver(void) {
void init_usb_driver(USBDriver *usbp) {
/* /*
* Activates the USB driver and then the USB bus pull-up on D+. * Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable * Note, a delay is inserted in order to not have to disconnect the cable
* after a reset. * after a reset.
*/ */
usbDisconnectBus(&USB_DRIVER);
usbDisconnectBus(usbp);
chThdSleepMilliseconds(1500); chThdSleepMilliseconds(1500);
usbStart(&USB_DRIVER, &usbcfg);
usbConnectBus(&USB_DRIVER);
usbStart(usbp, &usbcfg);
usbConnectBus(usbp);


chVTObjectInit(&keyboard_idle_timer); chVTObjectInit(&keyboard_idle_timer);
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
oqObjectInit(&console_queue, console_queue_buffer, sizeof(console_queue_buffer), console_queue_onotify, NULL);
oqObjectInit(&console_queue, console_queue_buffer, sizeof(console_queue_buffer), console_queue_onotify, (void *)usbp);
chVTObjectInit(&console_flush_timer); chVTObjectInit(&console_flush_timer);
#endif #endif
} }
/* Idle requests timer code /* Idle requests timer code
* callback (called from ISR, unlocked state) */ * callback (called from ISR, unlocked state) */
static void keyboard_idle_timer_cb(void *arg) { static void keyboard_idle_timer_cb(void *arg) {
(void)arg;
USBDriver *usbp = (USBDriver *)arg;


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 */
if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
if(usbGetDriverStateI(usbp) != USB_ACTIVE) {
/* do not rearm the timer, should be enabled on IDLE request */ /* do not rearm the timer, should be enabled on IDLE request */
osalSysUnlockFromISR(); osalSysUnlockFromISR();
return; return;
#endif /* NKRO_ENABLE */ #endif /* NKRO_ENABLE */
/* TODO: are we sure we want the KBD_ENDPOINT? */ /* TODO: are we sure we want the KBD_ENDPOINT? */
osalSysUnlockFromISR(); osalSysUnlockFromISR();
usbPrepareTransmit(&USB_DRIVER, KBD_ENDPOINT, (uint8_t *)&keyboard_report_sent, sizeof(keyboard_report_sent));
usbPrepareTransmit(usbp, KBD_ENDPOINT, (uint8_t *)&keyboard_report_sent, sizeof(keyboard_report_sent));
osalSysLockFromISR(); osalSysLockFromISR();
usbStartTransmitI(&USB_DRIVER, KBD_ENDPOINT);
usbStartTransmitI(usbp, KBD_ENDPOINT);
/* rearm the timer */ /* rearm the timer */
chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, NULL);
chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
} }


/* do not rearm the timer if the condition above fails /* do not rearm the timer if the condition above fails
osalSysLockFromISR(); osalSysLockFromISR();


/* rearm the timer */ /* rearm the timer */
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, NULL);
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_SIZE) {
/* Callback when data is inserted into the output queue /* Callback when data is inserted into the output queue
* Called from a locked state */ * Called from a locked state */
void console_queue_onotify(io_queue_t *qp) { void console_queue_onotify(io_queue_t *qp) {
(void)qp;
USBDriver *usbp = qGetLink(qp);


if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE)
if(usbGetDriverStateI(usbp) != USB_ACTIVE)
return; return;


if(!usbGetTransmitStatusI(&USB_DRIVER, CONSOLE_ENDPOINT)
if(!usbGetTransmitStatusI(usbp, CONSOLE_ENDPOINT)
&& (chOQGetFullI(&console_queue) >= CONSOLE_SIZE)) { && (chOQGetFullI(&console_queue) >= CONSOLE_SIZE)) {
osalSysUnlock(); osalSysUnlock();
usbPrepareQueuedTransmit(&USB_DRIVER, CONSOLE_ENDPOINT, &console_queue, CONSOLE_SIZE);
usbPrepareQueuedTransmit(usbp, CONSOLE_ENDPOINT, &console_queue, CONSOLE_SIZE);
osalSysLock(); osalSysLock();
usbStartTransmitI(&USB_DRIVER, CONSOLE_ENDPOINT);
usbStartTransmitI(usbp, CONSOLE_ENDPOINT);
} }
} }


/* Flush timer code /* Flush timer code
* callback (called from ISR, unlocked state) */ * callback (called from ISR, unlocked state) */
static void console_flush_cb(void *arg) { static void console_flush_cb(void *arg) {
(void)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_SIZE]; /* 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 */
if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
if(usbGetDriverStateI(usbp) != USB_ACTIVE) {
/* rearm the timer */ /* rearm the timer */
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, NULL);
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
osalSysUnlockFromISR(); osalSysUnlockFromISR();
return; return;
} }
/* 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_SIZE)) {
/* rearm the timer */ /* rearm the timer */
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, NULL);
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
osalSysUnlockFromISR(); osalSysUnlockFromISR();
return; return;
} }
for(i = n; i < CONSOLE_SIZE; i++) for(i = n; i < CONSOLE_SIZE; i++)
buf[i] = 0; buf[i] = 0;
osalSysUnlockFromISR(); osalSysUnlockFromISR();
usbPrepareTransmit(&USB_DRIVER, CONSOLE_ENDPOINT, buf, CONSOLE_SIZE);
usbPrepareTransmit(usbp, CONSOLE_ENDPOINT, buf, CONSOLE_SIZE);
osalSysLockFromISR(); osalSysLockFromISR();
(void)usbStartTransmitI(&USB_DRIVER, CONSOLE_ENDPOINT);
(void)usbStartTransmitI(usbp, CONSOLE_ENDPOINT);


/* rearm the timer */ /* rearm the timer */
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, NULL);
chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
osalSysUnlockFromISR(); osalSysUnlockFromISR();
} }



+ 1
- 1
tmk_core/protocol/chibios/usb_main.h View File

#define USB_DRIVER USBD1 #define USB_DRIVER USBD1


/* Initialize the USB driver and bus */ /* Initialize the USB driver and bus */
void init_usb_driver(void);
void init_usb_driver(USBDriver *usbp);


/* --------------- /* ---------------
* Keyboard header * Keyboard header

Loading…
Cancel
Save