usb serial
This commit is contained in:
@ -40,9 +40,6 @@
|
||||
#ifndef _LPCUSB_TYPE_H_
|
||||
#define _LPCUSB_TYPE_H_
|
||||
|
||||
// CodeRed - include NXP-produced type.h file
|
||||
#include "type.h"
|
||||
|
||||
typedef unsigned char U8; /**< unsigned 8-bit */
|
||||
typedef unsigned short int U16; /**< unsigned 16-bit */
|
||||
typedef unsigned int U32; /**< unsigned 32-bit */
|
||||
@ -50,10 +47,10 @@ typedef unsigned int U32; /**< unsigned 32-bit */
|
||||
|
||||
// CodeRed - comment out defines duplicated in NXP type.h
|
||||
|
||||
//typedef int BOOL; /**< #TRUE or #FALSE */
|
||||
typedef int BOOL; /**< #TRUE or #FALSE */
|
||||
|
||||
//#define TRUE 1 /**< TRUE */
|
||||
//#define FALSE 0 /**< FALSE */
|
||||
#define TRUE 1 /**< TRUE */
|
||||
#define FALSE 0 /**< FALSE */
|
||||
|
||||
//#ifndef NULL
|
||||
//#define NULL ((void*)0) /**< NULL pointer */
|
||||
|
@ -60,6 +60,9 @@ void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and ec
|
||||
|
||||
*/
|
||||
|
||||
/* Modified by Todd Fleming (TBF), 2017
|
||||
Replaced read polling API with callback API
|
||||
*/
|
||||
|
||||
#include "usbSerial.h"
|
||||
|
||||
@ -78,10 +81,12 @@ static U8 abBulkBuf[64];
|
||||
static U8 abClassReqData[8];
|
||||
|
||||
static U8 txdata[VCOM_FIFO_SIZE];
|
||||
static U8 rxdata[VCOM_FIFO_SIZE];
|
||||
//static U8 rxdata[VCOM_FIFO_SIZE];
|
||||
|
||||
static fifo_t txfifo;
|
||||
static fifo_t rxfifo;
|
||||
//static fifo_t rxfifo;
|
||||
|
||||
static UsbSerialReadCallback* usbSerialReadCallback = nullptr;
|
||||
|
||||
// forward declaration of interrupt handler
|
||||
void USBIntHandler(void);
|
||||
@ -207,15 +212,20 @@ static const U8 abDescriptors[] = {
|
||||
*/
|
||||
static void BulkOut(U8 bEP, U8 bEPStatus)
|
||||
{
|
||||
int i, iLen;
|
||||
int iLen;
|
||||
bEPStatus = bEPStatus;
|
||||
/* TBF: replaced rxfifo with callback
|
||||
if (fifo_free(&rxfifo) < MAX_PACKET_SIZE) {
|
||||
// may not fit into fifo
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// get data from USB into intermediate buffer
|
||||
iLen = USBHwEPRead(bEP, abBulkBuf, sizeof(abBulkBuf));
|
||||
if(usbSerialReadCallback)
|
||||
usbSerialReadCallback(abBulkBuf, iLen);
|
||||
/* TBF: replaced rxfifo with callback
|
||||
for (i = 0; i < iLen; i++) {
|
||||
// put into FIFO
|
||||
if (!fifo_put(&rxfifo, abBulkBuf[i])) {
|
||||
@ -224,6 +234,7 @@ static void BulkOut(U8 bEP, U8 bEPStatus)
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -307,7 +318,7 @@ static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
|
||||
void VCOM_init(void)
|
||||
{
|
||||
fifo_init(&txfifo, txdata);
|
||||
fifo_init(&rxfifo, rxdata);
|
||||
//fifo_init(&rxfifo, rxdata);
|
||||
}
|
||||
|
||||
|
||||
@ -328,13 +339,14 @@ int VCOM_putchar(int c)
|
||||
|
||||
@returns character read, or EOF if character could not be read
|
||||
*/
|
||||
/* TBF: replaced with callback
|
||||
int VCOM_getchar(void)
|
||||
{
|
||||
U8 c;
|
||||
|
||||
return fifo_get(&rxfifo, &c) ? c : EOF;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
Interrupt handler
|
||||
@ -342,7 +354,7 @@ int VCOM_getchar(void)
|
||||
Simply calls the USB ISR
|
||||
*/
|
||||
//void USBIntHandler(void)
|
||||
void USB_IRQHandler(void)
|
||||
extern "C" void USB_IRQHandler(void)
|
||||
{
|
||||
USBHwISR();
|
||||
}
|
||||
@ -364,8 +376,10 @@ void enable_USB_interrupts(void);
|
||||
main
|
||||
====
|
||||
**************************************************************************/
|
||||
int usbSerialInit()
|
||||
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback)
|
||||
{
|
||||
::usbSerialReadCallback = usbSerialReadCallback;
|
||||
|
||||
// initialise stack
|
||||
USBInit();
|
||||
|
||||
@ -428,6 +442,7 @@ void VCOM_putc(char c)
|
||||
{
|
||||
while(VCOM_putchar(c) == EOF);
|
||||
}
|
||||
/* TBF: replaced with callback
|
||||
char VCOM_getc()
|
||||
{
|
||||
int c;
|
||||
@ -438,6 +453,7 @@ char VCOM_getc()
|
||||
}
|
||||
return (char)c;
|
||||
}
|
||||
*/
|
||||
void VCOM_putHex(uint8_t hex)
|
||||
{
|
||||
uint8_t temp;
|
||||
@ -454,6 +470,7 @@ void VCOM_putHex(uint8_t hex)
|
||||
|
||||
VCOM_putc((char)temp);
|
||||
}
|
||||
/* TBF: replaced with callback
|
||||
void VCOM_gets(char* str)
|
||||
{
|
||||
char c;
|
||||
@ -483,7 +500,7 @@ void VCOM_gets_echo(char *str)
|
||||
}
|
||||
*str = '\0';
|
||||
}
|
||||
|
||||
*/
|
||||
/* Original code by ELM_ChaN. Modified by Martin Thomas */
|
||||
int xatoi (char **str, long *res)
|
||||
{
|
||||
|
@ -60,11 +60,15 @@ void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and ec
|
||||
|
||||
*/
|
||||
|
||||
/* Modified by Todd Fleming (TBF), 2017
|
||||
Replaced read polling API with callback API
|
||||
*/
|
||||
|
||||
#ifndef __USB_SERIAL_H__
|
||||
#define __USB_SERIAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
//extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
@ -94,8 +98,10 @@ extern "C" {
|
||||
|
||||
#include "serial_fifo.h"
|
||||
|
||||
int usbSerialInit(); // run once in main b4 main loop starts.
|
||||
// Receives serial data. Called by an interrupt.
|
||||
typedef void UsbSerialReadCallback(const U8* data, unsigned len);
|
||||
|
||||
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback); // run once in main b4 main loop starts.
|
||||
|
||||
/*
|
||||
Writes one character to VCOM port
|
||||
@ -110,20 +116,20 @@ int VCOM_putchar(int c);
|
||||
|
||||
@returns character read, or EOF if character could not be read
|
||||
*/
|
||||
int VCOM_getchar(void);
|
||||
//int VCOM_getchar(void);
|
||||
|
||||
void VCOM_puts(const char* str); //writes a null terminated string.
|
||||
void VCOM_putc(char c); // writes a character.
|
||||
void VCOM_putHex(uint8_t hex); // writes 0x.. hex value on the terminal.
|
||||
char VCOM_getc(); // returns character entered in the terminal. blocking function
|
||||
void VCOM_gets(char* str); // returns a string. '\r' or '\n' will terminate character collection.
|
||||
char VCOM_getc_echo(); // returns character entered and echoes the same back.
|
||||
void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and echoes back the same.
|
||||
//char VCOM_getc(); // returns character entered in the terminal. blocking function
|
||||
//void VCOM_gets(char* str); // returns a string. '\r' or '\n' will terminate character collection.
|
||||
//char VCOM_getc_echo(); // returns character entered and echoes the same back.
|
||||
//void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and echoes back the same.
|
||||
|
||||
void VCOM_printf(const char* str, ...); // Original code by Elm_CHaN. Modified by Martin Thomas
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
//}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -118,6 +118,7 @@ static void StallControlPipe(U8 bEPStat)
|
||||
// dump setup packet
|
||||
DBG("STALL on [");
|
||||
pb = (U8 *)&Setup;
|
||||
pb = pb;
|
||||
for (i = 0; i < 8; i++) {
|
||||
DBG(" %02x", *pb++);
|
||||
}
|
||||
|
Reference in New Issue
Block a user