Skip to content

Commit

Permalink
[usb_serial] convert usb_serial to generic device API
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Nov 4, 2014
1 parent b7ea8e1 commit f1a64a9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Expand Up @@ -4,8 +4,8 @@
#serial USB (e.g. /dev/ttyACM0)

ifeq ($(ARCH), lpc21)
ap.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_DEVICE=UsbS -DPPRZ_UART=UsbS
ap.CFLAGS += -DDOWNLINK_TRANSPORT=PprzTransport -DDATALINK=PPRZ -DUSE_USB_SERIAL -DUSE_USB_HIGH_PCLK
ap.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_DEVICE=usb_serial -DPPRZ_UART=UsbS
ap.CFLAGS += -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=PPRZ -DUSE_USB_SERIAL -DUSE_USB_HIGH_PCLK
ap.srcs += subsystems/datalink/downlink.c subsystems/datalink/pprz_transport.c
ap.srcs += $(SRC_FIRMWARE)/datalink.c
ap.srcs += $(SRC_ARCH)/usb_ser_hw.c $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbcontrol.c
Expand Down
Expand Up @@ -2,8 +2,8 @@
#serial USB (e.g. /dev/ttyACM0)

ifeq ($(ARCH), lpc21)
ap.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_DEVICE=UsbS -DPPRZ_UART=UsbS
ap.CFLAGS += -DDOWNLINK_TRANSPORT=PprzTransport -DDATALINK=PPRZ -DUSE_USB_SERIAL -DDefaultPeriodic='&telemetry_Main'
ap.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_DEVICE=usb_serial -DPPRZ_UART=UsbS
ap.CFLAGS += -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=PPRZ -DUSE_USB_SERIAL -DDefaultPeriodic='&telemetry_Main'
ap.srcs += subsystems/datalink/downlink.c subsystems/datalink/pprz_transport.c subsystems/datalink/telemetry.c
ap.srcs += $(SRC_FIRMWARE)/datalink.c $(SRC_FIRMWARE)/rotorcraft_telemetry.c
ap.srcs += $(SRC_ARCH)/usb_ser_hw.c $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbcontrol.c
Expand Down
27 changes: 24 additions & 3 deletions sw/airborne/arch/lpc21/usb_ser_hw.c
Expand Up @@ -434,7 +434,7 @@ int VCOM_check_available(void)
@param [in] bEP
@param [in] bEPStatus
*/
static void BulkOut(U8 bEP, U8 bEPStatus)
static void BulkOut(U8 bEP, U8 bEPStatus __attribute__((unused)))
{
int i, iLen;

Expand Down Expand Up @@ -463,7 +463,7 @@ static void BulkOut(U8 bEP, U8 bEPStatus)
@param [in] bEP
@param [in] bEPStatus
*/
static void BulkIn(U8 bEP, U8 bEPStatus)
static void BulkIn(U8 bEP, U8 bEPStatus __attribute__((unused)))
{
int i, iLen;

Expand Down Expand Up @@ -541,14 +541,29 @@ static void USBIntHandler(void)
}


static void USBFrameHandler(U16 wFrame)
static void USBFrameHandler(U16 wFrame __attribute__((unused)))
{
if (fifo_avail(&txfifo) > 0) {
// data available, enable NAK interrupt on bulk in
USBHwNakIntEnable(INACK_BI);
}
}

// Periph with generic device API
struct usb_serial_periph usb_serial;

// Functions for the generic device API
static int usb_serial_check_free_space(struct usb_serial_periph* p __attribute__((unused)), uint8_t len)
{
return (int)VCOM_check_free_space(len);
}

static void usb_serial_transmit(struct usb_serial_periph* p __attribute__((unused)), uint8_t byte)
{
VCOM_putchar(byte);
}

static void usb_serial_send(struct usb_serial_periph* p __attribute__((unused))) { }

void VCOM_init(void) {
// initialise stack
Expand Down Expand Up @@ -588,6 +603,12 @@ void VCOM_init(void) {

// connect to bus
USBHwConnect(TRUE);

// Configure generic device
usb_serial.device.periph = (void *)(&usb_serial);
usb_serial.device.check_free_space = (check_free_space_t) usb_serial_check_free_space;
usb_serial.device.transmit = (transmit_t) usb_serial_transmit;
usb_serial.device.send_message = (send_message_t) usb_serial_send;
}


Expand Down
8 changes: 8 additions & 0 deletions sw/airborne/mcu_periph/usb_serial.h
Expand Up @@ -30,8 +30,16 @@

#include <inttypes.h>
#include "std.h"
#include "mcu_periph/device.h"
//#include "usb_serial_hw.h"

struct usb_serial_periph {
/** Generic device interface */
struct device device;
};

extern struct usb_serial_periph usb_serial;

void VCOM_init(void);
int VCOM_putchar(int c);
int VCOM_getchar(void);
Expand Down

0 comments on commit f1a64a9

Please sign in to comment.