APM:Libraries
Classes | Macros | Typedefs | Enumerations | Functions | Variables
usb.h File Reference
#include <hal_types.h>
#include <gpio_hal.h>
#include <usart.h>
#include <stdbool.h>
#include "../STM32_USB_Driver/usb_bsp.h"
#include "../STM32_USB_Driver/usb_regs.h"
#include "../STM32_USB_Driver/usbd_conf.h"
#include "../STM32_USB_Driver/usbd_usr.h"
#include "../STM32_USB_Driver/usbd_desc.h"
#include "../STM32_USB_Driver/usbd_cdc_core.h"
#include "../STM32_USB_Driver/usbd_ioreq.h"
#include "../STM32_USB_Driver/usbd_req.h"
#include "../STM32_USB_Driver/usbd_core.h"
#include "../STM32_USB_Driver/ring_buff.h"
#include "../STM32_USB_Driver/min_max.h"
Include dependency graph for usb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LINE_CODING
 
struct  usb_attr_t
 
struct  usb_descriptor_device
 
struct  usb_descriptor_config_header
 
struct  usb_descriptor_interface
 
struct  usb_descriptor_endpoint
 
struct  usb_descriptor_string
 

Macros

#define USBD_MANUFACTURER_STRING   "RevoMini"
 
#define USBD_PRODUCT_FS_STRING   "3DR Virtual COM"
 
#define USBD_SERIALNUMBER_FS_STRING   "00000000050C"
 
#define USBD_CONFIGURATION_FS_STRING   "VCP Config"
 
#define USBD_INTERFACE_FS_STRING   "VCP Interface"
 
#define USBD_VID   0x26ac
 
#define USBD_PID   0x0011
 
#define USBD_LANGID_STRING   0x409
 
#define USB_RXFIFO_SIZE   256
 
#define USB_TXFIFO_SIZE   256
 
#define USB_IRQ   OTG_FS_IRQn
 
#define USB_AF   GPIO_AF_OTG1_FS
 
#define USB_CLOCK   RCC_AHB2Periph_OTG_FS
 
#define DM_PIN_PORT   _GPIOA
 
#define DM_PIN_PIN   11
 
#define DP_PIN_PORT   _GPIOA
 
#define DP_PIN_PIN   12
 
#define I_USB_CLEAR   1
 
#define I_USB_CONNECTED   2
 
#define I_USB_GETATTR   3
 
#define I_USB_SETATTR   4
 
#define DEFAULT_CONFIG   0
 
#define OTHER_CONFIG   1
 
#define USB_DESCRIPTOR_TYPE_DEVICE   0x01
 
#define USB_DESCRIPTOR_TYPE_CONFIGURATION   0x02
 
#define USB_DESCRIPTOR_TYPE_STRING   0x03
 
#define USB_DESCRIPTOR_TYPE_INTERFACE   0x04
 
#define USB_DESCRIPTOR_TYPE_ENDPOINT   0x05
 
#define USB_DESCRIPTOR_STRING_LEN(x)   (2 + (x << 1))
 
#define USB_DESCRIPTOR_STRING(len)
 
#define USB_CONFIG_ATTR_BUSPOWERED   0b10000000
 
#define USB_CONFIG_ATTR_SELF_POWERED   0b11000000
 
#define USB_EP_TYPE_INTERRUPT   0x03
 
#define USB_EP_TYPE_BULK   0x02
 
#define USB_DESCRIPTOR_ENDPOINT_IN   0x80
 
#define USB_DESCRIPTOR_ENDPOINT_OUT   0x00
 
#define USB_ISR_MSK   0xBF00
 

Typedefs

typedef struct usb_descriptor_device usb_descriptor_device
 
typedef struct usb_descriptor_config_header usb_descriptor_config_header
 
typedef struct usb_descriptor_interface usb_descriptor_interface
 
typedef struct usb_descriptor_endpoint usb_descriptor_endpoint
 
typedef struct usb_descriptor_string usb_descriptor_string
 
typedef enum usb_dev_state usb_dev_state
 

Enumerations

enum  usb_dev_state {
  USB_UNCONNECTED, USB_ATTACHED, USB_POWERED, USB_SUSPENDED,
  USB_ADDRESSED, USB_CONFIGURED
}
 

Functions

int usb_open (void)
 
int usb_close (void)
 
int usb_ioctl (int request, void *ctl)
 
int usb_read (void *buf, unsigned int nbytes)
 
void usb_default_attr (usb_attr_t *attr)
 
int usb_configure (usb_attr_t *attr)
 
void usb_setParams (usb_attr_t *attr)
 
void USB_OTG_BSP_DisableInterrupt ()
 
void USB_OTG_BSP_mDelay (const uint32_t msec)
 
uint8_t is_usb_connected (usb_attr_t *attr)
 
uint8_t is_usb_opened ()
 
void reset_usb_opened ()
 
int usb_write (const uint8_t *buf, unsigned int nbytes)
 
uint32_t usb_data_available (void)
 
uint16_t usb_tx_space (void)
 
void usb_reset_rx ()
 
void usb_reset_tx ()
 
bool usb_get_dtr ()
 
static uint8_t usb_putc (uint8_t b)
 
static uint8_t usb_getc (void)
 
uint16_t usb_tx_pending (void)
 
static void usb_disconnect ()
 
void USB_OTG_BSP_uDelay (const uint32_t usec)
 
unsigned VCP_DataAvail (void)
 
unsigned VCP_SpaceAvail (void)
 
unsigned VCP_DataAvailContig (void)
 
unsigned VCP_SpaceAvailContig (void)
 
unsigned VCP_GetContig (void *buff, unsigned max_len)
 
unsigned VCP_PutContig (void const *buff, unsigned len)
 
unsigned VCP_Get (void *buff, unsigned max_len)
 
unsigned VCP_Put (void const *buff, unsigned len)
 
static uint8_t const * VCP_DataPtr (void)
 
static uint8_t * VCP_SpacePtr (void)
 
void VCP_MarkRead (unsigned sz)
 
void VCP_MarkWritten (unsigned sz)
 
int usb_periphcfg (FunctionalState state)
 
void VCP_SetUSBTxBlocking (uint8_t Mode)
 
void OTG_FS_IRQHandler (void)
 

Variables

USB_OTG_CORE_HANDLE USB_OTG_dev
 

Macro Definition Documentation

◆ DEFAULT_CONFIG

#define DEFAULT_CONFIG   0

Definition at line 157 of file usb.h.

◆ DM_PIN_PIN

#define DM_PIN_PIN   11

Definition at line 56 of file usb.h.

Referenced by usb_periphcfg().

◆ DM_PIN_PORT

#define DM_PIN_PORT   _GPIOA

Definition at line 55 of file usb.h.

Referenced by usb_periphcfg().

◆ DP_PIN_PIN

#define DP_PIN_PIN   12

Definition at line 58 of file usb.h.

Referenced by usb_periphcfg().

◆ DP_PIN_PORT

#define DP_PIN_PORT   _GPIOA

Definition at line 57 of file usb.h.

Referenced by usb_periphcfg().

◆ I_USB_CLEAR

#define I_USB_CLEAR   1

Definition at line 87 of file usb.h.

Referenced by usb_ioctl().

◆ I_USB_CONNECTED

#define I_USB_CONNECTED   2

Definition at line 88 of file usb.h.

Referenced by usb_ioctl().

◆ I_USB_GETATTR

#define I_USB_GETATTR   3

Definition at line 89 of file usb.h.

Referenced by usb_ioctl().

◆ I_USB_SETATTR

#define I_USB_SETATTR   4

Definition at line 90 of file usb.h.

Referenced by usb_ioctl().

◆ OTHER_CONFIG

#define OTHER_CONFIG   1

Definition at line 158 of file usb.h.

◆ USB_AF

#define USB_AF   GPIO_AF_OTG1_FS

Definition at line 50 of file usb.h.

◆ USB_CLOCK

#define USB_CLOCK   RCC_AHB2Periph_OTG_FS

Definition at line 51 of file usb.h.

Referenced by usb_periphcfg().

◆ USB_CONFIG_ATTR_BUSPOWERED

#define USB_CONFIG_ATTR_BUSPOWERED   0b10000000

Definition at line 282 of file usb.h.

◆ USB_CONFIG_ATTR_SELF_POWERED

#define USB_CONFIG_ATTR_SELF_POWERED   0b11000000

Definition at line 283 of file usb.h.

◆ USB_DESCRIPTOR_ENDPOINT_IN

#define USB_DESCRIPTOR_ENDPOINT_IN   0x80

Definition at line 288 of file usb.h.

◆ USB_DESCRIPTOR_ENDPOINT_OUT

#define USB_DESCRIPTOR_ENDPOINT_OUT   0x00

Definition at line 289 of file usb.h.

◆ USB_DESCRIPTOR_STRING

#define USB_DESCRIPTOR_STRING (   len)
Value:
struct { \
uint8_t bLength; \
uint8_t bDescriptorType; \
uint16_t bString[len]; \
#define __packed
Definition: hal_types.h:43

Definition at line 218 of file usb.h.

◆ USB_DESCRIPTOR_STRING_LEN

#define USB_DESCRIPTOR_STRING_LEN (   x)    (2 + (x << 1))

Definition at line 216 of file usb.h.

◆ USB_DESCRIPTOR_TYPE_CONFIGURATION

#define USB_DESCRIPTOR_TYPE_CONFIGURATION   0x02

Definition at line 209 of file usb.h.

◆ USB_DESCRIPTOR_TYPE_DEVICE

#define USB_DESCRIPTOR_TYPE_DEVICE   0x01

Definition at line 208 of file usb.h.

◆ USB_DESCRIPTOR_TYPE_ENDPOINT

#define USB_DESCRIPTOR_TYPE_ENDPOINT   0x05

Definition at line 212 of file usb.h.

◆ USB_DESCRIPTOR_TYPE_INTERFACE

#define USB_DESCRIPTOR_TYPE_INTERFACE   0x04

Definition at line 211 of file usb.h.

◆ USB_DESCRIPTOR_TYPE_STRING

#define USB_DESCRIPTOR_TYPE_STRING   0x03

Definition at line 210 of file usb.h.

◆ USB_EP_TYPE_BULK

#define USB_EP_TYPE_BULK   0x02

Definition at line 286 of file usb.h.

◆ USB_EP_TYPE_INTERRUPT

#define USB_EP_TYPE_INTERRUPT   0x03

Definition at line 285 of file usb.h.

◆ USB_IRQ

#define USB_IRQ   OTG_FS_IRQn

Definition at line 49 of file usb.h.

◆ USB_ISR_MSK

#define USB_ISR_MSK   0xBF00

Definition at line 297 of file usb.h.

◆ USB_RXFIFO_SIZE

#define USB_RXFIFO_SIZE   256

Definition at line 44 of file usb.h.

◆ USB_TXFIFO_SIZE

#define USB_TXFIFO_SIZE   256

Definition at line 45 of file usb.h.

◆ USBD_CONFIGURATION_FS_STRING

#define USBD_CONFIGURATION_FS_STRING   "VCP Config"

Definition at line 37 of file usb.h.

Referenced by USBD_USR_ConfigStrDescriptor().

◆ USBD_INTERFACE_FS_STRING

#define USBD_INTERFACE_FS_STRING   "VCP Interface"

Definition at line 38 of file usb.h.

Referenced by USBD_USR_InterfaceStrDescriptor().

◆ USBD_LANGID_STRING

#define USBD_LANGID_STRING   0x409

Definition at line 42 of file usb.h.

◆ USBD_MANUFACTURER_STRING

#define USBD_MANUFACTURER_STRING   "RevoMini"

Definition at line 34 of file usb.h.

Referenced by USBD_USR_ManufacturerStrDescriptor().

◆ USBD_PID

#define USBD_PID   0x0011

Definition at line 41 of file usb.h.

◆ USBD_PRODUCT_FS_STRING

#define USBD_PRODUCT_FS_STRING   "3DR Virtual COM"

Definition at line 35 of file usb.h.

Referenced by USBD_USR_ProductStrDescriptor().

◆ USBD_SERIALNUMBER_FS_STRING

#define USBD_SERIALNUMBER_FS_STRING   "00000000050C"

Definition at line 36 of file usb.h.

Referenced by USBD_USR_SerialStrDescriptor().

◆ USBD_VID

#define USBD_VID   0x26ac

Definition at line 40 of file usb.h.

Typedef Documentation

◆ usb_descriptor_config_header

◆ usb_descriptor_device

◆ usb_descriptor_endpoint

◆ usb_descriptor_interface

◆ usb_descriptor_string

◆ usb_dev_state

Enumeration Type Documentation

◆ usb_dev_state

Enumerator
USB_UNCONNECTED 
USB_ATTACHED 
USB_POWERED 
USB_SUSPENDED 
USB_ADDRESSED 
USB_CONFIGURED 

Definition at line 301 of file usb.h.

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.

◆ 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.

◆ 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_disconnect()

static void usb_disconnect ( )
inlinestatic

Definition at line 133 of file usb.h.

Here is the call graph for this function:

◆ usb_get_dtr()

bool usb_get_dtr ( )

Definition at line 768 of file usb.c.

◆ usb_getc()

static uint8_t usb_getc ( void  )
inlinestatic

Definition at line 127 of file usb.h.

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

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

◆ 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.

◆ 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_OTG_BSP_mDelay()

void USB_OTG_BSP_mDelay ( const uint32_t  msec)

Definition at line 393 of file usb.c.

Referenced by usb_disconnect().

Here is the caller graph for this function:

◆ USB_OTG_BSP_uDelay()

void USB_OTG_BSP_uDelay ( const uint32_t  usec)

Definition at line 751 of file usb.c.

◆ 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_putc()

static uint8_t usb_putc ( uint8_t  b)
inlinestatic

Definition at line 125 of file usb.h.

Here is the call 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.

◆ 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:

◆ 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_DataPtr()

static uint8_t const* VCP_DataPtr ( void  )
inlinestatic

Definition at line 184 of file usb.h.

Referenced by VCP_GetContig().

Here is the caller graph for this function:

◆ VCP_Get()

unsigned VCP_Get ( void *  buff,
unsigned  max_len 
)

◆ 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_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_Put()

unsigned VCP_Put ( void const *  buff,
unsigned  len 
)

◆ 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:

◆ VCP_SpacePtr()

static uint8_t* VCP_SpacePtr ( void  )
inlinestatic

Definition at line 187 of file usb.h.

Referenced by VCP_PutContig().

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

Variable Documentation

◆ USB_OTG_dev

USB_OTG_CORE_HANDLE USB_OTG_dev