-
Notifications
You must be signed in to change notification settings - Fork 2
/
USBTon.h
85 lines (73 loc) · 1.76 KB
/
USBTon.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
85
#ifndef USBTON_H
#define USBTON_H
#include "Stream.h"
#include "usb_user.h"
#include "USBCDC.h"
/**
* USBTon example
*
* @code
* #include "mbed.h"
* #include "USBTon.h"
*
* //Virtual serial port over USB
* USBTon usb;
*
* int main(void) {
*
* while(1)
* {
* usb.printf("I am a virtual serial port\n");
* wait(1);
* }
* }
* @endcode
*/
class USBTon: public Stream {
public:
/**
* Constructor
*
* @param vendor_id Your vendor_id (default: 0x1f00)
* @param product_id Your product_id (default: 0x2012)
* @param product_release Your preoduct_release (default: 0x0001)
* @param connect_blocking define if the connection must be blocked if USB not plugged in
*
*/
USBTon(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true) {
};
/**
* Send a character. You can use puts, printf.
*
* @param c character to be sent
* @returns true if there is no error, false otherwise
*/
virtual int _putc(int c);
/**
* Read a character: blocking
*
* @returns character read
*/
virtual int _getc();
/**
* Check the number of bytes available.
*
* @returns the number of bytes available
*/
uint8_t available();
/** Determine if there is a character available to read
*
* @returns
* 1 if there is a character available to read,
* 0 otherwise
*/
int readable() { return available() ? 1 : 0; }
/** Determine if there is space available to write a character
*
* @returns
* 1 if there is space to write a character,
* 0 otherwise
*/
int writeable() { return 1; } // always return 1, for write operation is blocking
};
#endif