PER Firmware
Loading...
Searching...
No Matches
usb.h
Go to the documentation of this file.
1
11#ifndef PHAL_G4_USB_H
12#define PHAL_G4_USB_H
13
14#include <stdint.h>
15
17static constexpr uint8_t PHAL_USB_CONTROL_ENDPOINT = 0U;
18
20static constexpr uint8_t PHAL_USB_DATA_ENDPOINT = 1U;
21
23static constexpr uint16_t PHAL_USB_PACKET_SIZE_BYTES = 64U;
24
30
37
39typedef struct {
40 bool transfer;
41 union {
43 };
45
57void PHAL_USB_callback(const PHAL_USB_Event_t *event);
58
70bool PHAL_USB_init(void);
71
77bool PHAL_USB_deinit(void);
78
84bool PHAL_USB_connect(void);
85
96bool PHAL_USB_setAddress(uint8_t address);
97
105bool PHAL_USB_stall(uint8_t endpoint, PHAL_USB_EndpointDirection_t direction);
106
121bool PHAL_USB_write(uint8_t endpoint, const void *source, uint16_t length_bytes);
122
137bool PHAL_USB_read(uint8_t endpoint,
138 void *destination,
139 uint16_t destination_capacity,
140 uint16_t *received_length);
141
150uint16_t PHAL_USB_getFrameNumber(void);
151
152#endif // PHAL_G4_USB_H
Definition usb.h:39
bool transfer
Definition usb.h:40
PHAL_USB_TransferEvent_t transfer_data
Definition usb.h:42
Definition usb.h:32
bool setup
Definition usb.h:35
PHAL_USB_EndpointDirection_t direction
Definition usb.h:34
uint8_t endpoint
Definition usb.h:33
bool PHAL_USB_init(void)
Initialize the USB device hardware and endpoints.
Definition usb.c:22
static constexpr uint16_t PHAL_USB_PACKET_SIZE_BYTES
Definition usb.h:23
uint16_t PHAL_USB_getFrameNumber(void)
Read the USB peripheral's current 11-bit frame number.
Definition usb.c:93
void PHAL_USB_callback(const PHAL_USB_Event_t *event)
Handle USB events.
Definition usb.c:98
bool PHAL_USB_write(uint8_t endpoint, const void *source, uint16_t length_bytes)
Queue one device-to-host packet.
Definition usb.c:70
bool PHAL_USB_setAddress(uint8_t address)
Apply the address assigned by a SET_ADDRESS request.
Definition usb.c:51
PHAL_USB_EndpointDirection_t
Definition usb.h:26
@ PHAL_USB_ENDPOINT_DIRECTION_IN
Definition usb.h:28
@ PHAL_USB_ENDPOINT_DIRECTION_OUT
Definition usb.h:27
static constexpr uint8_t PHAL_USB_DATA_ENDPOINT
Definition usb.h:20
static constexpr uint8_t PHAL_USB_CONTROL_ENDPOINT
Definition usb.h:17
bool PHAL_USB_stall(uint8_t endpoint, PHAL_USB_EndpointDirection_t direction)
Stall one endpoint direction.
Definition usb.c:60
bool PHAL_USB_deinit(void)
Detach and disable the USB peripheral.
Definition usb.c:32
bool PHAL_USB_connect(void)
Attach the initialized USB device to the host.
Definition usb.c:42
bool PHAL_USB_read(uint8_t endpoint, void *destination, uint16_t destination_capacity, uint16_t *received_length)
Consume one host-to-device packet.
Definition usb.c:80