APM:Libraries
Macros | Typedefs | Enumerations | Functions | Variables
usb.c File Reference
#include <usb.h>
#include <hal.h>
#include <systick.h>
#include <exti.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <boards.h>
Include dependency graph for usb.c:

Go to the source code of this file.

Macros

#define USB_CDCACM_CONTROL_LINE_DTR   (0x01)
 
#define USB_CDCACM_CONTROL_LINE_RTS   (0x02)
 

Typedefs

typedef uint8_t U8
 
typedef uint32_t U32
 
typedef uint16_t U16
 

Enumerations

enum  reset_state_t { DTR_UNSET, DTR_HIGH, DTR_NEGEDGE, DTR_LOW }
 

Functions

uint32_t USBD_OTG_ISR_Handler (const USB_OTG_CORE_HANDLE *pdev)
 
static U16 VCP_Init (void)
 
static U16 VCP_DeInit (void)
 
static U16 VCP_Ctrl (uint32_t Cmd, uint8_t *Buf, uint32_t Len)
 
static U16 VCP_DataTx (const uint8_t *Buf, uint32_t Len)
 
static U16 VCP_DataRx (uint8_t *Buf, uint32_t Len)
 
void OTG_FS_IRQHandler (void)
 
U8USBD_USR_DeviceDescriptor (U8 speed, U16 *length)
 
U8USBD_USR_LangIDStrDescriptor (U8 speed, U16 *length)
 
U8USBD_USR_ProductStrDescriptor (U8 speed, U16 *length)
 
U8USBD_USR_ManufacturerStrDescriptor (U8 speed, U16 *length)
 
U8USBD_USR_SerialStrDescriptor (U8 speed, U16 *length)
 
U8USBD_USR_ConfigStrDescriptor (U8 speed, U16 *length)
 
U8USBD_USR_InterfaceStrDescriptor (U8 speed, U16 *length)
 
void USBD_USR_Init (void)
 
void USBD_USR_DeviceReset (uint8_t speed)
 
void USBD_USR_DeviceConfigured (void)
 
void USBD_USR_DeviceSuspended (void)
 
void USBD_USR_DeviceResumed (void)
 
void USBD_USR_DeviceConnected (void)
 
void USBD_USR_DeviceDisconnected (void)
 
void usb_default_attr (usb_attr_t *attr)
 
void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev)
 
int usb_periphcfg (FunctionalState state)
 
int usb_configure (usb_attr_t *attr)
 
void usb_setParams (usb_attr_t *attr)
 
void USB_OTG_BSP_EnableInterrupt (USB_OTG_CORE_HANDLE *pdev)
 
void USB_OTG_BSP_DisableInterrupt ()
 
void USB_OTG_BSP_mDelay (const uint32_t msec)
 
void VCP_MarkWritten (unsigned sz)
 
unsigned VCP_SpaceAvailContig (void)
 
unsigned VCP_PutContig (void const *buff, unsigned len)
 
unsigned VCP_SpaceAvail (void)
 
unsigned VCP_DataAvail (void)
 
void VCP_MarkRead (unsigned sz)
 
unsigned VCP_GetContig (void *buff, unsigned max_len)
 
unsigned VCP_DataAvailContig (void)
 
int usb_open (void)
 
int usb_close (void)
 
uint8_t is_usb_connected (usb_attr_t *attr)
 
int usb_ioctl (int request, void *ctl)
 
void USB_OTG_BSP_uDelay (const uint32_t usec)
 
int usb_write (const uint8_t *buf, unsigned int nbytes)
 
int usb_read (void *buf, unsigned int nbytes)
 
uint32_t usb_data_available (void)
 
bool usb_get_dtr ()
 
void usb_reset_rx ()
 
void usb_reset_tx ()
 
uint16_t usb_tx_pending (void)
 
uint16_t usb_tx_space (void)
 
void VCP_SetUSBTxBlocking (uint8_t Mode)
 
uint8_t is_usb_opened ()
 
void reset_usb_opened ()
 

Variables

USB_OTG_CORE_HANDLE USB_OTG_dev
 
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END
 
static usb_attr_tusb_attr
 
static volatile U8 VCP_DTRHIGH = 0
 
static volatile U8 VCP_RTSHIGH = 0
 
static enum reset_state_t reset_state = DTR_UNSET
 
static const U16 rxfifo_size = USB_RXFIFO_SIZE
 
static ring_buffer _rxfifo IN_CCM
 
static ring_bufferrxfifo = &_rxfifo
 
static uint8_t rx_buf [USB_RXFIFO_SIZE]
 
static U8 preempt_prio
 
static U8 sub_prio
 
static U8 usb_ready
 
static U8 UsbTXBlock = 1
 
LINE_CODING linecoding
 
U8 APP_Rx_Buffer []
 
U32 APP_Rx_ptr_in
 
const CDC_IF_Prop_TypeDef VCP_fops
 
const USBD_Usr_cb_TypeDef USR_cb
 
static const USBD_DEVICE USR_CDC_desc
 
static U8 usb_connected =0
 
static U8 usb_opened =0
 

Macro Definition Documentation

◆ USB_CDCACM_CONTROL_LINE_DTR

#define USB_CDCACM_CONTROL_LINE_DTR   (0x01)

Referenced by VCP_Ctrl().

◆ USB_CDCACM_CONTROL_LINE_RTS

#define USB_CDCACM_CONTROL_LINE_RTS   (0x02)

Referenced by VCP_Ctrl().

Typedef Documentation

◆ U16

typedef uint16_t U16

Definition at line 30 of file usb.c.

◆ U32

typedef uint32_t U32

Definition at line 29 of file usb.c.

◆ U8

typedef uint8_t U8

Definition at line 28 of file usb.c.

Enumeration Type Documentation

◆ reset_state_t

Enumerator
DTR_UNSET 
DTR_HIGH 
DTR_NEGEDGE 
DTR_LOW 

Definition at line 42 of file usb.c.

Function Documentation

◆ is_usb_connected()

uint8_t is_usb_connected ( usb_attr_t attr)

Definition at line 705 of file usb.c.

Referenced by usb_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_usb_opened()

uint8_t is_usb_opened ( )

Definition at line 794 of file usb.c.

Referenced by F4Light::USBDriver::read(), and F4Light::USBDriver::write().

Here is the caller graph for this function:

◆ OTG_FS_IRQHandler()

void OTG_FS_IRQHandler ( void  )

Definition at line 168 of file usb.c.

Referenced by VCP_SpacePtr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_usb_opened()

void reset_usb_opened ( )

Definition at line 795 of file usb.c.

Referenced by F4Light::USBDriver::write().

Here is the caller graph for this function:

◆ usb_close()

int usb_close ( void  )

Definition at line 688 of file usb.c.

Referenced by F4Light::USBDriver::end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_configure()

int usb_configure ( usb_attr_t attr)

Definition at line 350 of file usb.c.

Referenced by usb_init(), and usb_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_data_available()

uint32_t usb_data_available ( void  )

Definition at line 764 of file usb.c.

Referenced by F4Light::USBDriver::available().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_default_attr()

void usb_default_attr ( usb_attr_t attr)

Definition at line 296 of file usb.c.

Referenced by usb_init().

Here is the caller graph for this function:

◆ usb_get_dtr()

bool usb_get_dtr ( )

Definition at line 768 of file usb.c.

◆ usb_ioctl()

int usb_ioctl ( int  request,
void *  ctl 
)

Definition at line 716 of file usb.c.

Here is the call graph for this function:

◆ usb_open()

int usb_open ( void  )

Definition at line 674 of file usb.c.

Referenced by usb_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ USB_OTG_BSP_DisableInterrupt()

void USB_OTG_BSP_DisableInterrupt ( )

Definition at line 388 of file usb.c.

Referenced by usb_periphcfg().

Here is the caller graph for this function:

◆ usb_periphcfg()

int usb_periphcfg ( FunctionalState  state)

Definition at line 314 of file usb.c.

Referenced by usb_close(), usb_open(), and VCP_SpacePtr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_read()

int usb_read ( void *  buf,
unsigned int  nbytes 
)

Definition at line 760 of file usb.c.

Referenced by usb_getc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_reset_rx()

void usb_reset_rx ( )

Definition at line 772 of file usb.c.

Here is the call graph for this function:

◆ usb_reset_tx()

void usb_reset_tx ( )

Definition at line 776 of file usb.c.

◆ usb_setParams()

void usb_setParams ( usb_attr_t attr)

Definition at line 365 of file usb.c.

Referenced by usb_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_tx_pending()

uint16_t usb_tx_pending ( void  )

Definition at line 780 of file usb.c.

Referenced by usb_getc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_tx_space()

uint16_t usb_tx_space ( void  )

Definition at line 784 of file usb.c.

Referenced by F4Light::USBDriver::txspace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_write()

int usb_write ( const uint8_t *  buf,
unsigned int  nbytes 
)

Definition at line 756 of file usb.c.

Referenced by usb_putc(), and F4Light::USBDriver::write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBD_OTG_ISR_Handler()

uint32_t USBD_OTG_ISR_Handler ( const USB_OTG_CORE_HANDLE pdev)

Referenced by OTG_FS_IRQHandler().

Here is the caller graph for this function:

◆ VCP_Ctrl()

static U16 VCP_Ctrl ( uint32_t  Cmd,
uint8_t *  Buf,
uint32_t  Len 
)
static

Definition at line 444 of file usb.c.

◆ VCP_DataAvail()

unsigned VCP_DataAvail ( void  )

Definition at line 609 of file usb.c.

Referenced by usb_data_available().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_DataAvailContig()

unsigned VCP_DataAvailContig ( void  )

Definition at line 636 of file usb.c.

Referenced by VCP_GetContig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_DataRx()

static U16 VCP_DataRx ( uint8_t *  Buf,
uint32_t  Len 
)
static

Definition at line 644 of file usb.c.

Referenced by usb_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_DataTx()

U16 VCP_DataTx ( const uint8_t *  Buf,
uint32_t  Len 
)
static

Definition at line 583 of file usb.c.

Referenced by usb_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_DeInit()

static U16 VCP_DeInit ( void  )
static

Definition at line 431 of file usb.c.

◆ VCP_GetContig()

unsigned VCP_GetContig ( void *  buff,
unsigned  max_len 
)

Definition at line 625 of file usb.c.

Referenced by VCP_DataRx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_Init()

static U16 VCP_Init ( void  )
static

Definition at line 419 of file usb.c.

Here is the call graph for this function:

◆ VCP_MarkRead()

void VCP_MarkRead ( unsigned  sz)

Definition at line 618 of file usb.c.

Referenced by VCP_GetContig(), and VCP_SpacePtr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_MarkWritten()

void VCP_MarkWritten ( unsigned  sz)

Definition at line 549 of file usb.c.

Referenced by VCP_PutContig(), and VCP_SpacePtr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_PutContig()

unsigned VCP_PutContig ( void const *  buff,
unsigned  len 
)

Definition at line 564 of file usb.c.

Referenced by VCP_DataTx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_SetUSBTxBlocking()

void VCP_SetUSBTxBlocking ( uint8_t  Mode)

Definition at line 789 of file usb.c.

Referenced by VCP_SpacePtr().

Here is the caller graph for this function:

◆ VCP_SpaceAvail()

unsigned VCP_SpaceAvail ( void  )

Definition at line 575 of file usb.c.

Referenced by usb_tx_pending(), and usb_tx_space().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VCP_SpaceAvailContig()

unsigned VCP_SpaceAvailContig ( void  )

Definition at line 556 of file usb.c.

Referenced by VCP_PutContig().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ __ALIGN_END

Initial value:
=
{
0x12,
0x00,
0x02,
0x00,
0x00,
0x00,
0x00,
0x02,
}
#define USBD_CFG_MAX_NUM
Definition: usbd_conf.h:38
#define USBD_PID
Definition: usb.h:41
#define USBD_IDX_PRODUCT_STR
Definition: usbd_def.h:62
#define USBD_IDX_SERIAL_STR
Definition: usbd_def.h:63
#define USB_OTG_MAX_EP0_SIZE
Definition: usb_regs.h:71
#define USBD_VID
Definition: usb.h:40
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usbd_cdc_core.h:57
#define HIBYTE(x)
Definition: usbd_def.h:126
#define LOBYTE(x)
Definition: usbd_def.h:125
#define USBD_IDX_MFC_STR
Definition: usbd_def.h:61

Definition at line 36 of file usb.c.

◆ APP_Rx_Buffer

U8 APP_Rx_Buffer[]

◆ APP_Rx_ptr_in

U32 APP_Rx_ptr_in

Referenced by usb_reset_tx().

◆ IN_CCM

ring_buffer _rxfifo IN_CCM
static

Definition at line 54 of file usb.c.

◆ linecoding

LINE_CODING linecoding
Initial value:
=
{
115200,
0x00,
0x00,
0x08
}

Definition at line 69 of file usb.c.

◆ preempt_prio

U8 preempt_prio
static

Definition at line 63 of file usb.c.

Referenced by usb_open(), USB_OTG_BSP_EnableInterrupt(), and usb_setParams().

◆ reset_state

enum reset_state_t reset_state = DTR_UNSET
static

Definition at line 49 of file usb.c.

Referenced by VCP_Ctrl().

◆ rx_buf

uint8_t rx_buf[USB_RXFIFO_SIZE]
static

Definition at line 60 of file usb.c.

Referenced by F4Light::UART_PPM::UART_PPM(), and VCP_Init().

◆ rxfifo

ring_buffer* rxfifo = &_rxfifo
static

Definition at line 57 of file usb.c.

◆ rxfifo_size

const U16 rxfifo_size = USB_RXFIFO_SIZE
static

Definition at line 51 of file usb.c.

Referenced by VCP_Init().

◆ sub_prio

U8 sub_prio
static

Definition at line 63 of file usb.c.

Referenced by usb_open(), and usb_setParams().

◆ usb_attr

usb_attr_t* usb_attr
static

Definition at line 38 of file usb.c.

Referenced by usb_init(), and usb_ioctl().

◆ usb_connected

U8 usb_connected =0
static

◆ usb_opened

U8 usb_opened =0
static

◆ USB_OTG_dev

USB_OTG_CORE_HANDLE USB_OTG_dev

◆ usb_ready

U8 usb_ready
static

Definition at line 64 of file usb.c.

Referenced by usb_close(), usb_configure(), and usb_open().

◆ UsbTXBlock

U8 UsbTXBlock = 1
static

Definition at line 66 of file usb.c.

Referenced by VCP_SetUSBTxBlocking().

◆ USR_CDC_desc

const USBD_DEVICE USR_CDC_desc
static
Initial value:
=
{
}
U8 * USBD_USR_DeviceDescriptor(U8 speed, U16 *length)
Definition: usb.c:188
U8 * USBD_USR_InterfaceStrDescriptor(U8 speed, U16 *length)
Definition: usb.c:234
U8 * USBD_USR_ConfigStrDescriptor(U8 speed, U16 *length)
Definition: usb.c:226
U8 * USBD_USR_LangIDStrDescriptor(U8 speed, U16 *length)
Definition: usb.c:195
U8 * USBD_USR_ProductStrDescriptor(U8 speed, U16 *length)
Definition: usb.c:204
U8 * USBD_USR_SerialStrDescriptor(U8 speed, U16 *length)
Definition: usb.c:219
U8 * USBD_USR_ManufacturerStrDescriptor(U8 speed, U16 *length)
Definition: usb.c:212

Definition at line 116 of file usb.c.

◆ VCP_DTRHIGH

volatile U8 VCP_DTRHIGH = 0
static

Definition at line 39 of file usb.c.

Referenced by usb_get_dtr(), VCP_Ctrl(), and VCP_DataRx().

◆ VCP_fops

const CDC_IF_Prop_TypeDef VCP_fops
Initial value:
=
{
}
static U16 VCP_Init(void)
Definition: usb.c:419
static U16 VCP_DataTx(const uint8_t *Buf, uint32_t Len)
Definition: usb.c:583
static U16 VCP_Ctrl(uint32_t Cmd, uint8_t *Buf, uint32_t Len)
Definition: usb.c:444
static U16 VCP_DataRx(uint8_t *Buf, uint32_t Len)
Definition: usb.c:644
static U16 VCP_DeInit(void)
Definition: usb.c:431

Definition at line 94 of file usb.c.

◆ VCP_RTSHIGH

volatile U8 VCP_RTSHIGH = 0
static

Definition at line 40 of file usb.c.

Referenced by VCP_Ctrl().