57 #include "lpcusb/usbapi.h"
61 #error PCLK needs to be higher than 18MHz for USB to work properly
66 #define USB_VIC_SLOT 10
69 #define INT_IN_EP 0x81
70 #define BULK_OUT_EP 0x05
71 #define BULK_IN_EP 0x82
73 #define MAX_PACKET_SIZE 64
75 #define LE_WORD(x) ((x)&0xFF),((x)>>8)
78 #define CS_INTERFACE 0x24
79 #define CS_ENDPOINT 0x25
81 #define SET_LINE_CODING 0x20
82 #define GET_LINE_CODING 0x21
83 #define SET_CONTROL_LINE_STATE 0x22
85 #define VCOM_FIFO_SIZE 128
119 static void USBIntHandler(
void) __attribute__((interrupt("IRQ")));
121 static
void BulkOut(U8 bEP, U8 bEPStatus);
123 #ifdef USE_USB_LINE_CODING
231 'L', 0,
'P', 0,
'C', 0,
'U', 0,
'S', 0,
'B', 0,
235 'U', 0,
'S', 0,
'B', 0,
'S', 0,
'e', 0,
'r', 0,
'i', 0,
'a', 0,
'l', 0,
239 '1', 0,
'2', 0,
'3', 0,
'4', 0,
'5', 0,
'6', 0,
'7', 0,
'8', 0,
259 if (next == fifo->
tail) {
297 #ifdef USE_USB_LINE_CODING
363 #ifdef USE_USB_LINE_CODING
432 static void BulkOut(U8 bEP, U8 bEPStatus __attribute__((unused)))
444 for (i = 0; i < iLen; i++) {
461 static void BulkIn(U8 bEP, U8 bEPStatus __attribute__((unused)))
467 USBHwNakIntEnable(0);
495 switch (pSetup->bRequest) {
499 memcpy((U8 *)&LineCoding, *ppbData, 7);
501 #ifdef USE_USB_LINE_CODING
503 set_linecoding(LineCoding);
510 *ppbData = (U8 *)&LineCoding;
542 USBHwNakIntEnable(INACK_BI);
563 for (i = 0; i < len; i++) {
590 #ifdef USE_USB_LINE_CODING
592 set_linecoding(LineCoding);
596 USBRegisterDescriptors(abDescriptors);
602 USBHwRegisterEPIntHandler(
INT_IN_EP, NULL);
610 USBHwNakIntEnable(INACK_BI);
static uint8_t abClassReqData[8]
static uint8_t usb_serial_getch(struct usb_serial_periph *p)
static int usb_serial_check_free_space(struct usb_serial_periph *p, long *fd, uint16_t len)
void VCOM_send_message(void)
static void BulkOut(U8 bEP, U8 bEPStatus)
Local function to handle incoming bulk data.
static int usb_serial_char_available(struct usb_serial_periph *p)
struct usb_serial_periph usb_serial
static void usb_serial_send(struct usb_serial_periph *p, long fd)
static void usb_serial_transmit_buffer(struct usb_serial_periph *p, long fd, uint8_t *data, uint16_t len)
int fifo_free(fifo_t *fifo)
static TLineCoding LineCoding
void fifo_init(fifo_t *fifo, U8 *buf)
static void BulkIn(U8 bEP, U8 bEPStatus)
Local function to handle outgoing bulk data.
struct link_device device
Generic device interface.
bool VCOM_check_free_space(uint16_t len)
Checks if buffer free in VCOM buffer.
int VCOM_getchar(void)
Reads one character from VCOM port.
static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
Local function to handle the USB-CDC class requests.
static void usb_serial_transmit(struct usb_serial_periph *p, long fd, uint8_t byte)
unsigned disableIRQ(void)
BOOL fifo_put(fifo_t *fifo, U8 c)
static uint8_t rxdata[VCOM_FIFO_SIZE]
static void USBIntHandler(void)
Interrupt handler.
static const uint8_t abDescriptors[]
int VCOM_putchar(int c)
Writes one character to VCOM port.
#define SET_CONTROL_LINE_STATE
static bool BulkOut_is_blocked
static void USBFrameHandler(U16 wFrame)
int fifo_avail(fifo_t *fifo)
BOOL fifo_get(fifo_t *fifo, U8 *pc)
void VCOM_allow_linecoding(uint8_t mode)
static uint8_t abBulkBuf[64]
static uint8_t txdata[VCOM_FIFO_SIZE]
int VCOM_check_available(void)
Checks if data available in VCOM buffer.