~ruther/stm32h747i-disco-usb-image-viewer

571c4797b5046b1cda0db74748620741f3acceee — Rutherther 9 months ago d10035e
refactor: use usb descriptor common struct header
1 files changed, 22 insertions(+), 23 deletions(-)

M include/usb.h
M include/usb.h => include/usb.h +22 -23
@@ 45,14 45,14 @@ typedef enum {
} usb_setup_request_t;

typedef enum {
  DEVICE = 1,
  CONFIGURATION = 1,
  STRING = 2,
  INTERFACE = 3,
  ENDPOINT = 4,
  DEVICE_QUALIFIER = 5,
  OTHER_SPEED_CONFIGURATION = 6,
  INTERFACE_POWER = 7,
  DESCRIPTOR_DEVICE = 1,
  DESCRIPTOR_CONFIGURATION = 1,
  DESCRIPTOR_STRING = 2,
  DESCRIPTOR_INTERFACE = 3,
  DESCRIPTOR_ENDPOINT = 4,
  DESCRIPTOR_DEVICE_QUALIFIER = 5,
  DESCRIPTOR_OTHER_SPEED_CONFIGURATION = 6,
  DESCRIPTOR_INTERFACE_POWER = 7,
} usb_descriptor_type_t;

#pragma GCC diagnostic error "-Wpadded"


@@ 65,9 65,13 @@ typedef struct {
} usb_setup_command_t;
_Static_assert(sizeof(usb_setup_command_t) == 8, "Size check");

typedef struct {
typedef struct __attribute__((packed)) {
  uint8_t bLength;
  uint8_t bDescriptorType;
} usb_descriptor_t;

typedef struct {
  usb_descriptor_t header;
  uint16_t bcdUSB;
  uint8_t bDeviceClass;
  uint8_t bDeviceSubClass;


@@ 84,8 88,7 @@ typedef struct {
_Static_assert(sizeof(usb_device_descriptor_t) == 18, "Size check");

typedef struct {
  uint8_t bLength;
  uint8_t bDescriptorType;
  usb_descriptor_t header;
  uint16_t bcdUSB;
  uint8_t bDeviceClass;
  uint8_t bDeviceSubClass;


@@ 104,8 107,7 @@ typedef struct {
} usb_configuration_descriptor_attributes;

typedef struct __attribute__((packed)) {
  uint8_t bLength;
  uint8_t bDescriptorType;
  usb_descriptor_t header;
  uint16_t wTotalLength;
  uint8_t bNumInterfaces;
  uint8_t bConfigurationValue;


@@ 118,8 120,7 @@ _Static_assert(sizeof(usb_configuration_descriptor_t) == 9, "Size check");
typedef usb_configuration_descriptor_t usb_other_speed_configuration_t;

typedef struct __attribute__((packed)) {
  uint8_t bLength;
  uint8_t bDescriptorType;
  usb_descriptor_t header;
  uint8_t bInterfaceNumber;
  uint8_t bAlternateSetting;
  uint8_t bNumEndpoints;


@@ 162,7 163,7 @@ typedef enum {
  USB_ENDPOINT_USAGE_RESERVED = 3,
} usb_endpoint_usage_type_t;

typedef struct {
typedef struct __attribute__((packed)) {
  uint8_t reserved_zeros : 2;
  usb_endpoint_usage_type_t usage_type : 2;
  usb_endpoint_synchronization_type_t synchronization_type : 2;


@@ 170,8 171,7 @@ typedef struct {
} usb_endpoint_attributes_t;

typedef struct __attribute__((packed)) {
  uint8_t bLength;
  uint8_t bDescriptorType;
  usb_descriptor_t header;
  usb_endpoint_address_t bEndpointAddress;
  usb_endpoint_attributes_t bmAttributes;
  uint16_t wMaxPacketSize;


@@ 181,15 181,14 @@ _Static_assert(sizeof(usb_endpoint_descriptor_t) == 7, "Size check");

#pragma GCC diagnostic ignored "-Wpadded"
typedef struct {
  uint8_t bLength; // lengto of wLANGID + 2
  uint8_t bDescriptorType;
  // uint8_t bLength; // lengto of wLANGID + 2
  usb_descriptor_t header;
  uint16_t *wLANGID; // should have length equal to bLength - 2
} usb_string_descriptor_zero_t;

typedef struct {
  uint8_t bLength;
  uint8_t bDescriptorType;
  uint8_t *bString; // should have length equal to bLength
  usb_descriptor_t header;
  uint8_t *bString;
} usb_unicode_string_descriptor_t;

#endif // USB_H