2 #include "usb_keyboard.h"
3 #include <Lib/USBLib.h>
4 #include <string.h> // for memcpy()
7 // Maximum number of transmit packets to queue so we don't starve other endpoints for memory
8 #define TX_PACKET_LIMIT 4
10 static uint8_t transmit_previous_timeout=0;
12 // When the PC isn't listening, how long do we wait before discarding data?
13 #define TX_TIMEOUT_MSEC 50
16 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596)
17 #elif F_CPU == 48000000
18 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428)
19 #elif F_CPU == 24000000
20 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262)
24 // send the contents of keyboard_keys and keyboard_modifier_keys
25 uint8_t usb_keyboard_send(void)
27 uint32_t wait_count=0;
28 usb_packet_t *tx_packet;
31 if (!usb_configuration) {
34 if (usb_tx_packet_count(KEYBOARD_ENDPOINT) < TX_PACKET_LIMIT) {
35 tx_packet = usb_malloc();
38 if (++wait_count > TX_TIMEOUT || transmit_previous_timeout) {
39 transmit_previous_timeout = 1;
44 *(tx_packet->buf) = USBKeys_Modifiers;
45 *(tx_packet->buf + 1) = 0;
46 memcpy(tx_packet->buf + 2, USBKeys_Array, USB_MAX_KEY_SEND);
48 usb_tx(KEYBOARD_ENDPOINT, tx_packet);