-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNeoICSerial.h
84 lines (75 loc) · 2.83 KB
/
NeoICSerial.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
/* An Alternative Software Serial Library which uses Input Capture pins
* Based on:
* http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
* Copyright (c) 2014 PJRC.COM, LLC, Paul Stoffregen, [email protected]
*
* Modified November 2015 by SlashDev
*
* NeoICSerial always uses these pins:
*
* Board Transmit Receive PWM Unusable
* ----- -------- ------- ------------
* Teensy 3.0 & 3.1 21 20 22
* Teensy 2.0 9 10 (none)
* Teensy++ 2.0 25 4 26, 27
* Arduino Uno 9 8 10
* Arduino Leonardo 5 13 (none)
* Arduino Mega 46 48 44, 45
* Wiring-S 5 6 4
* Sanguino 13 14 12
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef NeoICSerial_h
#define NeoICSerial_h
#include <inttypes.h>
#include "Arduino.h"
#if defined(__arm__) && defined(CORE_TEENSY)
#define ALTSS_BASE_FREQ F_BUS
#else
#define ALTSS_BASE_FREQ F_CPU
#endif
class NeoICSerial : public Stream
{
public:
NeoICSerial() { }
~NeoICSerial() { end(); }
static void begin(uint32_t baud) { init((ALTSS_BASE_FREQ + baud / 2) / baud); }
static void end();
int peek();
int read();
int available();
size_t write(uint8_t byte) { writeByte(byte); return 1; }
void flush() { flushOutput(); }
using Print::write;
static void flushInput();
static void flushOutput();
typedef void (* isr_t)( uint8_t );
static void attachInterrupt( isr_t fn );
static void detachInterrupt()
{ attachInterrupt( nullptr ); };
typedef void (* TXCisr_t)();
static void attachTxCompleteInterrupt( TXCisr_t fn );
static void detachTxCompleteInterrupt()
{ attachTxCompleteInterrupt( nullptr ); };
private:
static void init(uint32_t cycles_per_bit);
static void writeByte(uint8_t byte);
};
#endif