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);
582 #ifdef USE_USB_LINE_CODING
584 set_linecoding(LineCoding);
588 USBRegisterDescriptors(abDescriptors);
594 USBHwRegisterEPIntHandler(
INT_IN_EP, NULL);
602 USBHwNakIntEnable(INACK_BI);
put_byte_t put_byte
put one byte
uint8_t(* get_byte_t)(void *)
static uint8_t abClassReqData[8]
check_free_space_t check_free_space
check if transmit buffer is not full
static uint8_t usb_serial_getch(struct usb_serial_periph *p)
static int usb_serial_check_free_space(struct usb_serial_periph *p, uint8_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_transmit(struct usb_serial_periph *p, uint8_t byte)
int fifo_free(fifo_t *fifo)
void * periph
pointer to parent implementation
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.
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.
get_byte_t get_byte
get a new char
int(* char_available_t)(void *)
void(* put_byte_t)(void *, uint8_t)
unsigned disableIRQ(void)
BOOL fifo_put(fifo_t *fifo, U8 c)
static void usb_serial_send(struct usb_serial_periph *p)
void(* send_message_t)(void *)
static uint8_t rxdata[VCOM_FIFO_SIZE]
static void USBIntHandler(void)
Interrupt handler.
static const uint8_t abDescriptors[]
int(* check_free_space_t)(void *, uint8_t)
Function pointers definition.
char_available_t char_available
check if a new character is available
int VCOM_putchar(int c)
Writes one character to VCOM port.
#define SET_CONTROL_LINE_STATE
static bool BulkOut_is_blocked
bool_t VCOM_check_free_space(uint8_t len)
Checks if buffer free in VCOM buffer.
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.
send_message_t send_message
send completed buffer