-
Notifications
You must be signed in to change notification settings - Fork 2
/
usb_dev.h
84 lines (67 loc) · 3.04 KB
/
usb_dev.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// papoon_usb: "Not Insane" USB library for STM32F103xx MCUs
// Copyright (C) 2019,2020 Mark R. Rubin
//
// This file is part of papoon_usb.
//
// The papoon_usb program is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// The papoon_usb program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// (LICENSE.txt) along with the papoon_usb program. If not, see
// <https://www.gnu.org/licenses/gpl.html>
#ifndef USB_DEV_H
#define USB_DEV_H
#include <stdint.h>
enum {
CONSTRUCTED = 0,
INITIALIZED ,
RESET ,
ADDRESSED ,
CONFIGURED
} DeviceState;
/* Optional use by client application.
Will copy/format ST "Unique Device ID" value into USB descriptor,
Otherwise value will be default string "000..."
Hardware bug: must be done while main CPU clock at default 8 MHz
before mandatory increase to 48 or 72 MHz for USB peripheral.
*/
void usb_dev_serial_number_init();
int usb_dev_init();
unsigned usb_dev_device_state();
void usb_dev_interrupt_handler();
#ifndef USB_DEV_INTERRUPT_DRIVEN
uint32_t usb_dev_poll();
uint32_t usb_dev_poll_recv_ready(const uint8_t endpoint),
usb_dev_poll_send_ready(const uint8_t endpoint);
#endif
#ifdef USB_DEV_ENDPOINT_CALLBACKS
void usb_dev_register_recv_callback(void (*callback)(const uint8_t,
void* ),
uint8_t endpoint, /* not checked */
void *user_data ),
usb_dev_register_send_callback(void (*callback)(const uint8_t,
void* ),
uint8_t endpoint, /* not checked */
void *user_data );
#endif
uint16_t usb_dev_endpoint_recv_bufsize(const uint8_t endpoint),
usb_dev_endpoint_send_bufsize(const uint8_t endpoint);
uint16_t usb_dev_recv_readys(),
usb_dev_send_readys();
// no checking of params -- caller must guarantee valid
// endpoint_number and buffer
uint16_t usb_dev_recv(const uint8_t endpoint_number,
uint8_t* const buffer );
// no checking of params -- caller must guarantee valid
// endpoint_number, data, and length
int usb_dev_send(const uint8_t endpoint_number,
const uint8_t* const data ,
const uint16_t length );
#endif // ifndef USB_DEV_H