forked from cmaglie/ArduinoCore-samd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUart.h
65 lines (53 loc) · 2.07 KB
/
Uart.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
/*
Copyright (c) 2015 Arduino LLC. All right reserved.
This library 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 library 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 library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include "api/HardwareSerial.h"
#include "SERCOM.h"
#include "SafeRingBuffer.h"
#define SERIAL_BUFFER_SIZE 64
class Uart : public arduino::HardwareSerial
{
public:
Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX);
Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX, uint8_t _pinRTS, uint8_t _pinCTS);
void begin(unsigned long baudRate);
void begin(unsigned long baudrate, uint16_t config);
void end();
int available();
int availableForWrite();
int peek();
int read();
void flush();
size_t write(const uint8_t data);
using Print::write; // pull in write(str) and write(buf, size) from Print
void IrqHandler();
operator bool() { return true; }
private:
SERCOM *sercom;
arduino::SafeRingBuffer rxBuffer;
arduino::SafeRingBuffer txBuffer;
uint8_t uc_pinRX;
uint8_t uc_pinTX;
SercomRXPad uc_padRX;
SercomUartTXPad uc_padTX;
uint8_t uc_pinRTS;
volatile uint32_t* pul_outsetRTS;
volatile uint32_t* pul_outclrRTS;
uint32_t ul_pinMaskRTS;
uint8_t uc_pinCTS;
SercomNumberStopBit extractNbStopBit(uint16_t config);
SercomUartCharSize extractCharSize(uint16_t config);
SercomParityMode extractParity(uint16_t config);
};