// Send NKRO keyboard interrupts packet(s)
case 1:
- // Check modifiers
- if ( USBKeys_Changed & USBKeyChangeState_Modifiers )
+ // Check system control keys
+ if ( USBKeys_Changed & USBKeyChangeState_System )
{
- UEDATX = 0x01; // ID
- UEDATX = USBKeys_Modifiers;
+ UEDATX = 0x02; // ID
+ UEDATX = USBKeys_SysCtrl;
UEINTX = 0; // Finished with ID
- USBKeys_Changed &= ~USBKeyChangeState_Modifiers; // Mark sent
+ USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
}
- // Check main key section
- else if ( USBKeys_Changed & USBKeyChangeState_MainKeys )
+
+ // Check consumer control keys
+ if ( USBKeys_Changed & USBKeyChangeState_Consumer )
{
UEDATX = 0x03; // ID
-
- // 4-164 (first 20 bytes)
- for ( uint8_t byte = 0; byte < 20; byte++ )
- UEDATX = USBKeys_Keys[ byte ];
-
+ UEDATX = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
+ UEDATX = (uint8_t)(USBKeys_ConsCtrl >> 8);
UEINTX = 0; // Finished with ID
- USBKeys_Changed &= ~USBKeyChangeState_MainKeys; // Mark sent
+ USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
}
- // Check secondary key section
- else if ( USBKeys_Changed & USBKeyChangeState_SecondaryKeys )
+
+ // Standard HID Keyboard
+ if ( USBKeys_Changed )
{
- UEDATX = 0x04; // ID
+ UEDATX = 0x01; // ID
- // 176-221 (last 6 bytes)
- for ( uint8_t byte = 20; byte < 26; byte++ )
+ // Modifiers
+ UEDATX = USBKeys_Modifiers;
+
+ // 4-49 (first 6 bytes)
+ for ( uint8_t byte = 0; byte < 6; byte++ )
UEDATX = USBKeys_Keys[ byte ];
- UEINTX = 0; // Finished with ID
+ // 51-155 (Middle 14 bytes)
+ for ( uint8_t byte = 6; byte < 20; byte++ )
+ UEDATX = USBKeys_Keys[ byte ];
- USBKeys_Changed &= ~USBKeyChangeState_SecondaryKeys; // Mark sent
- }
- // Check system control keys
- else if ( USBKeys_Changed & USBKeyChangeState_System )
- {
- UEDATX = 0x05; // ID
- UEDATX = USBKeys_SysCtrl;
- UEINTX = 0; // Finished with ID
+ // 157-164 (Next byte)
+ for ( uint8_t byte = 20; byte < 21; byte++ )
+ UEDATX = USBKeys_Keys[ byte ];
+
+ // 176-221 (last 6 bytes)
+ for ( uint8_t byte = 21; byte < 27; byte++ )
+ UEDATX = USBKeys_Keys[ byte ];
- USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
- }
- // Check consumer control keys
- else if ( USBKeys_Changed & USBKeyChangeState_Consumer )
- {
- UEDATX = 0x06; // ID
- UEDATX = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
- UEDATX = (uint8_t)(USBKeys_ConsCtrl >> 8);
UEINTX = 0; // Finished with ID
- USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
+ USBKeys_Changed = USBKeyChangeState_None; // Mark sent
}
break;
}
// transmit a character. 0 returned on success, -1 on error
-int8_t usb_serial_putchar(uint8_t c)
+int8_t usb_serial_putchar( uint8_t c )
{
uint8_t timeout, intr_state;
// transmit a character, but do not wait if the buffer is full,
// 0 returned on success, -1 on buffer full or error
-int8_t usb_serial_putchar_nowait(uint8_t c)
+int8_t usb_serial_putchar_nowait( uint8_t c )
{
uint8_t intr_state;
// controller in the PC will not allocate bandwitdh without a pending read request.
// (thanks to Victor Suarez for testing and feedback and initial code)
-int8_t usb_serial_write(const char *buffer, uint16_t size)
+int8_t usb_serial_write( const char *buffer, uint16_t size )
{
uint8_t timeout, intr_state, write_size;
cli();
UENUM = CDC_TX_ENDPOINT;
// if we gave up due to timeout before, don't wait again
- /*
+
if (transmit_previous_timeout) {
if (!(UEINTX & (1<<RWAL))) {
SREG = intr_state;
}
transmit_previous_timeout = 0;
}
- */
+
// each iteration of this loop transmits a packet
while (size) {
// wait for the FIFO to be ready to accept data
// This doesn't actually transmit the data - that is impossible!
// USB devices only transmit when the host allows, so the best
// we can do is release the FIFO buffer for when the host wants it
-void usb_serial_flush_output(void)
+void usb_serial_flush_output()
{
uint8_t intr_state;
// it remains buffered (either here or on the host) and can not be
// lost because you weren't listening at the right time, like it
// would in real serial communication.
-int8_t usb_serial_set_control(uint8_t signals)
+int8_t usb_serial_set_control( uint8_t signals )
{
uint8_t intr_state;