crashtest-r0ket/firmware/applications/cdc.c

77 lines
2.0 KiB
C
Raw Normal View History

2011-07-10 17:45:47 +00:00
#include <stdint.h>
#include "core/usbcdc/usb.h"
#include "core/usbcdc/usbcore.h"
#include "core/usbcdc/usbhw.h"
#include "core/usbcdc/cdcuser.h"
#include "core/usbcdc/cdc_buf.h"
2011-07-17 08:53:52 +00:00
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/render.h"
#include "lcd/allfonts.h"
2011-07-10 17:45:47 +00:00
volatile unsigned int lastTick;
int puts(const char * str)
{
// There must be at least 1ms between USB frames (of up to 64 bytes)
// This buffers all data and writes it out from the buffer one frame
// and one millisecond at a time
if (USB_Configuration)
{
while(*str)
cdcBufferWrite(*str++);
// Check if we can flush the buffer now or if we need to wait
unsigned int currentTick = systickGetTicks();
if (currentTick != lastTick)
{
uint8_t frame[64];
uint32_t bytesRead = 0;
while (cdcBufferDataPending())
{
// Read up to 64 bytes as long as possible
bytesRead = cdcBufferReadLen(frame, 64);
USB_WriteEP (CDC_DEP_IN, frame, bytesRead);
systickDelay(1);
}
lastTick = currentTick;
}
}
return 0;
}
void main_cdc(void)
{
2011-07-17 08:53:52 +00:00
int dx = 0;
2011-07-10 17:45:47 +00:00
//lastTick = systickGetTicks(); // Used to control output/printf timing
2011-07-17 08:53:52 +00:00
lcdPrintln("Init USB"); lcdRefresh();
2011-07-10 17:45:47 +00:00
CDC_Init(); // Initialise VCOM
USB_Init(); // USB Initialization
USB_Connect(TRUE); // USB Connect
// Wait until USB is configured or timeout occurs
uint32_t usbTimeout = 0;
2011-07-17 08:53:52 +00:00
while ( usbTimeout < CFG_USBCDC_INITTIMEOUT / 10 )
2011-07-10 17:45:47 +00:00
{
if (USB_Configuration) break;
delayms(10); // Wait 10ms
usbTimeout++;
}
2011-07-17 08:53:52 +00:00
lcdPrintln("Done"); lcdRefresh();
2011-07-10 17:45:47 +00:00
uint8_t buf[2] = {0,0};
int l;
while(1){
CDC_OutBufAvailChar(&l);
if( l ){
l = 1;
CDC_RdOutBuf (buf, &l);
puts(buf);
2011-07-17 08:53:52 +00:00
dx=DoString(dx,0,buf);
lcdDisplay();
2011-07-10 17:45:47 +00:00
}
//puts("hello world\r\n");
//delayms(1);
}
}