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

ref: fd50dee1a73f27372392f528cda343b258e16f99 stm32h747i-disco-usb-image-viewer/include/usb_device.h -rw-r--r-- 1.3 KiB
fd50dee1 — Rutherther feat: receive setup packets 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stm32h747xx.h>
#include "usb.h"

#ifndef USB_DEVICE_H
#define USB_DEVICE_H

typedef enum {
  // error states first so they are lowest
  CONTROL_ERROR = -4,
  UNKNOWN_CONTROL_COMMAND = -4,
  ERROR = -3,
  UNKNOWN_INTERRUPT = -2,
  OTG_ERROR = -1, // shouldn't happen, since otg is not used

  INIT = 0,
  RESET = 1,
  RESET_DONE = 2,
  SET_ADDRESS_RCVD = 3,
  SET_CONFIG_RCVD = 4,
  ENUMERATED = 5,
} usb_device_state_t;

typedef struct {
  volatile uint32_t data[128];
} usb_fifo_t;

typedef struct {
  usb_device_descriptor_t device_descriptor;
  usb_configuration_descriptor_t configuration_descriptor;
  usb_interface_descriptor_t interface_descriptor;
  usb_endpoint_descriptor_t endpoint_descriptors[8];
} usb_class_t;

typedef struct {
  USB_OTG_GlobalTypeDef *core;
  USB_OTG_DeviceTypeDef *device;

  USB_OTG_OUTEndpointTypeDef *out;
  USB_OTG_INEndpointTypeDef *in;

  usb_fifo_t *fifos;

  uint8_t endpoint_count;

  usb_class_t class;

  usb_device_state_t state;
  usb_setup_command_t received_setup_command;
} usb_device_t;

// has configuration etc

#define USB_DEVICE_SIZE sizeof(usb_device_t)

extern usb_device_t* usb1_device;

void* usb_device_init(void* peripheral_address, usb_class_t* class, void* buffer);

void usb_device_setup(void* device);
void usb_device_wait_for_handshake(void* device);

#endif // USB_DEVICE_H
Do not follow this link