1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00
trezor-firmware/micropython/trezorhal/usb.h

105 lines
2.4 KiB
C
Raw Normal View History

2017-03-07 14:52:19 +00:00
#ifndef __TREZORHAL_USB_H__
#define __TREZORHAL_USB_H__
2017-03-24 13:19:24 +00:00
typedef struct __attribute__((packed)) {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
} usb_device_descriptor_t;
typedef struct __attribute__((packed)) {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wData;
} usb_string_descriptor_t;
typedef struct __attribute__((packed)) {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} usb_config_descriptor_t;
typedef struct __attribute__((packed)) {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
} usb_interface_descriptor_t;
typedef struct __attribute__((packed)) {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
} usb_endpoint_descriptor_t;
typedef enum {
USB_LANGID_ENGLISH_US = 0x409,
} usb_language_id_t;
typedef struct {
const uint8_t *manufacturer_str;
const uint8_t *product_str;
const uint8_t *serial_str;
const uint8_t *config_str;
const uint8_t *interface_str;
} usb_string_table_t;
typedef struct {
uint16_t vendor_id;
uint16_t product_id;
uint16_t release_num;
const uint8_t *product_str;
const uint8_t *manufacturer_str;
const uint8_t *serial_number_str;
const uint8_t *configuration_str;
const uint8_t *interface_str;
} usb_dev_info_t;
typedef enum {
USB_IFACE_TYPE_DISABLED = 0,
2017-03-26 22:59:52 +00:00
USB_IFACE_TYPE_VCP = 1,
2017-03-24 15:38:46 +00:00
// USB_IFACE_TYPE_MSC = 2,
USB_IFACE_TYPE_HID = 3,
2017-03-24 13:19:24 +00:00
} usb_iface_type_t;
#include "usb_hid-defs.h"
2017-03-26 22:59:52 +00:00
#include "usb_vcp-defs.h"
2017-03-24 13:19:24 +00:00
typedef struct {
union {
usb_hid_state_t hid;
2017-03-26 22:59:52 +00:00
usb_vcp_state_t vcp;
2017-03-24 13:19:24 +00:00
};
usb_iface_type_t type;
} usb_iface_t;
int usb_init(const usb_dev_info_t *dev_info);
int usb_start(void);
int usb_stop(void);
2017-03-07 14:52:19 +00:00
#endif