extern void usbcdcSendByte(uint8_t c)
{
// Massive ugly delay required
uint32_t i, delay;
delay = ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 25000);
for ( i = 0; i < delay; i++ )
{
__asm("nop");
}
// Send byte to EP
USB_WriteEP (CDC_DEP_IN, (unsigned char *)&c, 1);
CDC_DepInEmpty = 1;
} |
void USB_Reset (void) {
LPC_USB->DevIntClr = 0x000FFFFF;
/* Enable all eight(8) EPs, note: EP won't be ready until it's
configured/enabled when device sending SetEPStatus command
to the command engine. */
LPC_USB->DevIntEn = DEV_STAT_INT | (0xFF<<1) |
(USB_SOF_EVENT ? FRAME_INT : 0);
/* enable interrupt on NAK for bulk OUT endpoints */
WrCmdDat(CMD_SET_MODE, DAT_WR_BYTE(INAK_AI));
return;
} |
/**************************************************************************/
/*!
@brief Sends a single byte to a pre-determined peripheral (UART, etc.).
@param[in] byte
Byte value to send
*/
/**************************************************************************/
void __putchar(const char c)
{
#ifdef CFG_PRINTF_UART
// Send output to UART
uartSendByte(c);
#endif
#ifdef CFG_PRINTF_USBCDC
// Send output to USB if connected
if (USB_Configuration) {
usbcdcSendByte(c);
}
#endif
#ifdef CFG_PRINTF_CWDEBUG
// Send output to the CW debug interface
debug_printf("%c", c);
#endif
} |
//use printf output to write UART or USB
#define USB_OUTPUT
//globals
volatile unsigned int string_counter;
volatile char string_buffer[64];
#ifdef USB_OUTPUT
int __write (int iFileHandle, uint8_t *pcBuffer, uint8_t iLength)
{
unsigned char len_count; //len counter
unsigned char print=0; //print flag
for(len_count=0;len_count< iLength;len_count++)//read loop
{
string_buffer[string_counter]= *pcBuffer; //fill buffer
if(*pcBuffer == 0x0D)print=1; //check return
pcBuffer++; //inc buffer pointer
string_counter++; //inc counter
}
if((string_counter>63) || print) //if max buffer or return
{
USB_WriteEP (CDC_DEP_IN, (unsigned char *)&string_buffer[0], string_counter);
string_counter=0; //reset counter
}
return iLength;
}
#else
// Function __write() ->printf
int __write (int iFileHandle, uint8_t *pcBuffer, uint8_t iLength)
{
UARTSend(pcBuffer,iLength);
return iLength;
}
#endif |