- Sending characters to the UART before it's ready would overflow the buffer causing it to hang - Added a check to make sure the interface is ready before starting to send characters - Removed the incorrect check for the usbMuxUart to make sure usb is ready before sending over the uartsimple
set( MacroModule "PartialMap" ) | set( MacroModule "PartialMap" ) | ||||
##| Sends the current list of usb key codes through USB HID | ##| Sends the current list of usb key codes through USB HID | ||||
set( OutputModule "usbMuxUart" ) | |||||
set( OutputModule "uartOut" ) | |||||
##| Debugging source to use, each module has it's own set of defines that it sets | ##| Debugging source to use, each module has it's own set of defines that it sets | ||||
set( DebugModule "full" ) | set( DebugModule "full" ) |
volatile uint8_t uart0_buffer_items = 0; | volatile uint8_t uart0_buffer_items = 0; | ||||
volatile uint8_t uart0_buffer[uart0_buffer_size]; | volatile uint8_t uart0_buffer[uart0_buffer_size]; | ||||
volatile uint8_t uart_configured = 0; | |||||
// ----- Interrupt Functions ----- | // ----- Interrupt Functions ----- | ||||
} | } | ||||
// ----- Functions ----- | // ----- Functions ----- | ||||
void uart_serial_setup() | void uart_serial_setup() | ||||
{ | { | ||||
// Indication that the UART is not ready yet | |||||
uart_configured = 0; | |||||
// Setup the the UART interface for keyboard data input | // Setup the the UART interface for keyboard data input | ||||
SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating | SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating | ||||
// Add interrupt to the vector table | // Add interrupt to the vector table | ||||
NVIC_ENABLE_IRQ( IRQ_UART0_STATUS ); | NVIC_ENABLE_IRQ( IRQ_UART0_STATUS ); | ||||
// UART is now ready to use | |||||
uart_configured = 1; | |||||
} | } | ||||
// Get the next character, or -1 if nothing received | // Get the next character, or -1 if nothing received | ||||
int uart_serial_getchar() | int uart_serial_getchar() | ||||
{ | { | ||||
if ( !uart_configured ) | |||||
return -1; | |||||
unsigned int value = -1; | unsigned int value = -1; | ||||
// Check to see if the FIFO has characters | // Check to see if the FIFO has characters | ||||
// Transmit a character. 0 returned on success, -1 on error | // Transmit a character. 0 returned on success, -1 on error | ||||
int uart_serial_putchar( uint8_t c ) | int uart_serial_putchar( uint8_t c ) | ||||
{ | { | ||||
if ( !uart_configured ) | |||||
return -1; | |||||
while ( !( UART0_SFIFO & UART_SFIFO_TXEMPT ) ); // Wait till there is room to send | while ( !( UART0_SFIFO & UART_SFIFO_TXEMPT ) ); // Wait till there is room to send | ||||
UART0_D = c; | UART0_D = c; | ||||
int uart_serial_write( const void *buffer, uint32_t size ) | int uart_serial_write( const void *buffer, uint32_t size ) | ||||
{ | { | ||||
if ( !uart_configured ) | |||||
return -1; | |||||
const uint8_t *data = (const uint8_t *)buffer; | const uint8_t *data = (const uint8_t *)buffer; | ||||
uint32_t position = 0; | uint32_t position = 0; | ||||
// USB Includes | // USB Includes | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
#include "avr/uart_serial.h" | |||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | ||||
#include "arm/uart_serial.h" | #include "arm/uart_serial.h" | ||||
#endif | #endif | ||||
inline void Output_firmwareReload() | inline void Output_firmwareReload() | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
uart_debug_reload(); | |||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | ||||
uart_device_reload(); | uart_device_reload(); | ||||
#endif | #endif | ||||
inline int Output_getchar() | inline int Output_getchar() | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
// XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes) | |||||
return (int)uart_serial_getchar(); | |||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | ||||
return uart_serial_getchar(); | return uart_serial_getchar(); | ||||
#endif | #endif | ||||
inline int Output_putstr( char* str ) | inline int Output_putstr( char* str ) | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR | ||||
uint16_t count = 0; | |||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM | #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM | ||||
uint32_t count = 0; | uint32_t count = 0; | ||||
#endif | #endif | ||||
inline void Output_softReset() | inline void Output_softReset() | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
uart_debug_software_reset(); | |||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) | ||||
SOFTWARE_RESET(); | SOFTWARE_RESET(); | ||||
#endif | #endif |
while ( str[count] != '\0' ) | while ( str[count] != '\0' ) | ||||
count++; | count++; | ||||
// Make sure USB is configured first | |||||
if ( usb_configured() ) | |||||
{ | |||||
// First send to UART | |||||
uart_serial_write( str, count ); | |||||
} | |||||
// First send to UART | |||||
uart_serial_write( str, count ); | |||||
// Then send to USB | // Then send to USB | ||||
return usb_serial_write( str, count ); | return usb_serial_write( str, count ); |