74 lines
2.0 KiB
C
74 lines
2.0 KiB
C
#ifndef CORE_USB_CLASS_CDC
|
|
#define CORE_USB_CLASS_CDC
|
|
|
|
#include "../usb_callback_event.h"
|
|
|
|
// CDC request codes
|
|
typedef enum {
|
|
USB_CDC_SET_COMM_FEATURE = 0x2,
|
|
USB_CDC_GET_COMM_FEATURE = 0x3,
|
|
USB_CDC_CLEAR_COMM_FEATURE = 0x4,
|
|
USB_CDC_SET_AUX_LINE_STATE = 0x10,
|
|
USB_CDC_SET_HOOK_STATE = 0x11,
|
|
USB_CDC_PULSE_SETUP = 0x12,
|
|
USB_CDC_SEND_PULSE = 0x13,
|
|
USB_CDC_SET_PULSE_TIME = 0x14,
|
|
USB_CDC_RING_AUX_JACK = 0x15,
|
|
USB_CDC_SET_LINE_CODING = 0x20,
|
|
USB_CDC_GET_LINE_CODING = 0x21,
|
|
USB_CDC_SET_CONTROL_LINE_STATE = 0x22,
|
|
USB_CDC_SEND_BREAK = 0x23,
|
|
USB_CDC_SET_RINGER_PARMS = 0x30,
|
|
USB_CDC_GET_RINGER_PARMS = 0x31,
|
|
USB_CDC_SET_OPERATION_PARMS = 0x32,
|
|
USB_CDC_GET_OPERATION_PARMS = 0x33,
|
|
USB_CDC_SET_LINE_PARMS = 0x34,
|
|
} USB_Cdc_RequestCodes;
|
|
|
|
// CDC line coding structure
|
|
typedef struct {
|
|
uint32_t dwDTERate; // data terminal rate, bits per second
|
|
uint8_t bCharFormat; // character format
|
|
uint8_t bParityType; // parity type
|
|
uint8_t bDataBits; // data bits
|
|
} USB_Cdc_LineCodingStruct;
|
|
|
|
// CDC control line state struct
|
|
typedef struct {
|
|
uint16_t D; // settings word
|
|
} USB_Cdc_ControlLineStateStruct;
|
|
|
|
// ----------------
|
|
|
|
// endpoint assignments
|
|
typedef struct {
|
|
uint8_t control_ep : 4; // control endpoint
|
|
uint8_t data_ep : 4; // data endpoint
|
|
} USB_CdcAssignments;
|
|
|
|
typedef struct {
|
|
USB_CdcAssignments ep_assignments; // endpoint assignments
|
|
USB_Cdc_LineCodingStruct line_coding; // line coding
|
|
USB_Cdc_ControlLineStateStruct control_line_state; // control line state
|
|
bool initialized; // CDC is initialized
|
|
} USB_CdcState;
|
|
|
|
// ----------------
|
|
|
|
#define USB_CDC_DEFAULT_BITRATE (115200)
|
|
#define USB_CDC_DEFAULT_DATA_BITS (8)
|
|
#define USB_CDC_DEFAULT_PARITY_TYPE (0)
|
|
#define USB_CDC_DEFAULT_CHAR_FORMAT (0)
|
|
|
|
// ----------------
|
|
|
|
#define USB_CDC_PCKT_BUFSIZE (120)
|
|
|
|
// ----------------
|
|
|
|
void usb_cdc_init(const USB_CdcAssignments * as);
|
|
int usb_cdc_process_and_return(USB_CallbackEvent * cbevt);
|
|
void usb_cdc_write(const uint8_t * data, uint32_t size);
|
|
|
|
#endif /* CORE_USB_CLASS_CDC */
|