-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathWaspUSB.h
executable file
·389 lines (314 loc) · 8.91 KB
/
WaspUSB.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*! \file WaspUSB.h
\brief Library for managing the USB interface
Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
http://www.libelium.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
This 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Version: 3.0
Design: David Gascón
Implementation: David Cuartielles, Alberto Bielsa, Yuri Carmona
*/
/*! \def WaspUSB_h
\brief The library flag
*/
#ifndef WaspUSB_h
#define WaspUSB_h
/******************************************************************************
* Includes
******************************************************************************/
#include <inttypes.h>
// Header file in order to allow prints from Flash memory
#include "Printable.h"
#include <stdarg.h>
/******************************************************************************
* Definitions & Declarations
******************************************************************************/
/*! \def DEC
\brief The base to print numbers. Decimal Base in this case
*/
/*! \def HEX
\brief The base to print numbers. Hexadecimal Base in this case
*/
/*! \def OCT
\brief The base to print numbers. Octal Base in this case
*/
/*! \def BIN
\brief The base to print numbers. Binary Base in this case
*/
/*! \def BYTE
\brief The base to print numbers. Byte Base in this case
*/
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
#define BYTE 0
/*! \def USB_RATE
\brief USB Baud Rates
*/
#define USB_RATE 115200
/******************************************************************************
* Class
******************************************************************************/
//! WaspUSB Class
/*!
WaspUSB Class defines all the variables and functions used for managing the
USB interface
*/
class WaspUSB
{
private:
//! Variable : specifies the UART where the USB is connected
/*!
*/
uint8_t _uart;
//! backup register attributes
uint8_t _reg_ubrr0h;
uint8_t _reg_ubrr0l;
uint8_t _reg_ucsr0c;
public:
//! class constructor
/*!
It initializes some variables
\param void
\return void
*/
WaspUSB();
//! It opens UART0 to be able to communicate with the FTDI conversor
/*!
It gets the baud rate from 'USB_RATE'
\param void
\return void
*/
void ON();
//! It closes the previously opened UART0
/*!
\param void
\return void
*/
void OFF();
//! It checks if there is available data waiting to be read
/*!
\param void
\return '1' if there is available data, '0' otherwise
*/
uint8_t available();
//! It reads a byte from the UART
/*!
\param void
\return the read byte or '-1' if no data is available
*/
int read();
//! It clears the UART buffer
/*!
\param void
\return void
*/
void flush();
//! It prints a character
/*!
\param char c : the character to print
\return void
*/
void print(char c);
//! It prints a string
/*!
\param const char[] c : the string to print
\return void
*/
void print(const char[]);
//! It prints an unsigned 8-bit integer
/*!
\param uint8_t b : the number to print
\return void
*/
void print(uint8_t b);
//! It prints an unsigned 16-bit integer
/*!
\param uint16_t n : the number to print
\return void
*/
void print(uint16_t n);
//! It prints an integer
/*!
\param int n : the number to print
\return void
*/
void print(int n);
//! It prints a long integer
/*!
\param long n : the number to print
\return void
*/
void print(long n);
//! It prints an unsigned long integer
/*!
\param unsigned long n : the number to print
\return void
*/
void print(unsigned long n);
//! It prints a long number in the specified base
/*!
\param long n : the number to print
\param int base : the base for printing the number
\return void
*/
void print(long n, int base);
//! It prints a byte as a hexadecimal (%2X) format
/*!
\param char n : the byte to print
\return void
*/
void printHex(char n);
//! It prints a double number
/*!
\param double n : the number to print
\return void
*/
void print(double n);
//! It prints a 64-bit number
/*!
\param uint64_t n : the number to print
\return void
*/
void print(uint64_t n);
//! It prints an EOL and a carriage return
/*!
\param void
\return void
*/
void println();
//! It prints a character adding an EOL and a carriage return
/*!
\param char c : the character to print
\return void
*/
void println(char c);
//! It prints a string adding an EOL and a carriage return
/*!
\param const char[] c : the string to print
\return void
*/
void println(const char[]);
//! It prints an unsigned 8-bit integer adding an EOL and a carriage return
/*!
\param uint8_t b : the number to print
\return void
*/
void println(uint8_t b);
//! It prints an unsigned 16-bit integer adding an EOL and a carriage return
/*!
\param uint16_t n : the number to print
\return void
*/
void println(uint16_t n);
//! It prints an integer adding an EOL and a carriage return
/*!
\param int n : the number to print
\return void
*/
void println(int n);
//! It prints a long integer adding an EOL and a carriage return
/*!
\param long n : the number to print
\return void
*/
void println(long n);
//! It prints an unsigned long integer adding an EOL and a carriage return
/*!
\param unsigned long n : the number to print
\return void
*/
void println(unsigned long n);
//! It prints a long number in the specified base adding an EOL and a
//! carriage return
/*!
\param long n : the number to print
\param int base : the base for printing the number
\return void
*/
void println(long n, int base);
//! It prints a double number adding an EOL and a carriage return
/*!
\param double n : the number to print
\return void
*/
void println(double n);
//! It prints a 64-bit number adding an EOL and a carriage return
/*!
\param uint64_t n : the number to print
\return void
*/
void println(uint64_t n);
//! It prints a string from Flash memory
/*!
\param const __FlashStringHelper * : pointer to the string in the flash
\return uint32_t '0'
*/
uint32_t print(const __FlashStringHelper *);
//! It prints a string from Flash memory adding an EOL
/*!
\param __FlashStringHelper
\return uint32_t '0'
*/
uint32_t println(const __FlashStringHelper *);
//! It prints a sequence of data formatted as the format argument specifies
/*!
This function emulates the stdio.h printf() functionality in C and will send
the output to the Serial connection using printByte(). The resulting
string sent over serial is limited to 128 chars.
\param char *fmt : is the format string to be printed
\param ... : additional arguments as specified in format.
\return void
*/
void printf(char *fmt, ... );
//! It prints a 'float' number
/*!
\param double number : the number to print
\param uint8_t digits : the number of non-integer part digits
\return void
*/
void printFloat(double number, uint8_t digits);
//! It prints a buffer specifying the length of the buffer
/*!
\param uint8_t* pointer : pointer to data to be printed
\param uint16_t length : length of data
\return void
*/
void print(uint8_t* pointer, uint16_t length);
//! It prints a buffer specifying the length of the buffer
/*! This function adds an End Of Line after printing the buffer
\param uint8_t* pointer : pointer to data to be printed
\param uint16_t length : length of data
\return void
*/
void println(uint8_t* pointer, uint16_t length);
//! It prints a buffer in HEX format specifying the length of the buffer
/*!
\param uint8_t* pointer : pointer to data to be printed
\param uint16_t length : length of data
\return void
*/
void printHex(uint8_t* pointer, uint16_t length);
//! It prints a buffer in HEX format specifying the length of the buffer
/*! This function adds an End Of Line after printing the buffer
\param uint8_t* pointer : pointer to data to be printed
\param uint16_t length : length of data
\return void
*/
void printHexln(uint8_t* pointer, uint16_t length);
//! It prepares the UART0 for USB port securely
void secureBegin();
//! It sets the UART0 to the previous settings before using USB port
void secureEnd();
};
extern WaspUSB USB;
#endif