From 358b1f33bbe30742d73bd829b8fba967ea7fc0e1 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sat, 4 Oct 2014 14:50:42 -0700 Subject: [PATCH] Adding timeout to virtual serial port writes - Was causing lock-ups until the serial port was read - Also checking each of the NKRO key types in each send loop --- Output/pjrcUSB/avr/usb_keyboard_serial.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Output/pjrcUSB/avr/usb_keyboard_serial.c b/Output/pjrcUSB/avr/usb_keyboard_serial.c index 9c2324e..260733d 100644 --- a/Output/pjrcUSB/avr/usb_keyboard_serial.c +++ b/Output/pjrcUSB/avr/usb_keyboard_serial.c @@ -114,7 +114,7 @@ inline void usb_keyboard_send() USBKeys_Changed &= ~USBKeyChangeState_Modifiers; // Mark sent } // Check main key section - else if ( USBKeys_Changed & USBKeyChangeState_MainKeys ) + if ( USBKeys_Changed & USBKeyChangeState_MainKeys ) { UEDATX = 0x03; // ID @@ -127,7 +127,7 @@ inline void usb_keyboard_send() USBKeys_Changed &= ~USBKeyChangeState_MainKeys; // Mark sent } // Check secondary key section - else if ( USBKeys_Changed & USBKeyChangeState_SecondaryKeys ) + if ( USBKeys_Changed & USBKeyChangeState_SecondaryKeys ) { UEDATX = 0x04; // ID @@ -140,7 +140,7 @@ inline void usb_keyboard_send() USBKeys_Changed &= ~USBKeyChangeState_SecondaryKeys; // Mark sent } // Check tertiary key section - else if ( USBKeys_Changed & USBKeyChangeState_TertiaryKeys ) + if ( USBKeys_Changed & USBKeyChangeState_TertiaryKeys ) { UEDATX = 0x05; // ID @@ -153,7 +153,7 @@ inline void usb_keyboard_send() USBKeys_Changed &= ~USBKeyChangeState_TertiaryKeys; // Mark sent } // Check system control keys - else if ( USBKeys_Changed & USBKeyChangeState_System ) + if ( USBKeys_Changed & USBKeyChangeState_System ) { UEDATX = 0x06; // ID UEDATX = USBKeys_SysCtrl; @@ -162,7 +162,7 @@ inline void usb_keyboard_send() USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent } // Check consumer control keys - else if ( USBKeys_Changed & USBKeyChangeState_Consumer ) + if ( USBKeys_Changed & USBKeyChangeState_Consumer ) { UEDATX = 0x07; // ID UEDATX = (uint8_t)(USBKeys_ConsCtrl & 0x00FF); @@ -253,7 +253,7 @@ void usb_serial_flush_input() } // 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; @@ -304,7 +304,7 @@ int8_t usb_serial_putchar(uint8_t c) // 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; @@ -338,7 +338,7 @@ int8_t usb_serial_putchar_nowait(uint8_t c) // 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; @@ -351,7 +351,7 @@ int8_t usb_serial_write(const char *buffer, uint16_t 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<