GM6000 Digital Heater Controller Branch: main
SDX-1330
InputOutput.h
Go to the documentation of this file.
1#ifndef Cpl_Io_Serial_Adafruit_Nrf5_InputOutput_h
2#define Cpl_Io_Serial_Adafruit_Nrf5_InputOutput_h
3/*-----------------------------------------------------------------------------
4* This file is part of the Colony.Core Project. The Colony.Core Project is an
5* open source project with a BSD type of licensing agreement. See the license
6* agreement (license.txt) in the top/ directory or on the Internet at
7* http://integerfox.com/colony.core/license.txt
8*
9* Copyright (c) 2017-2020 John T. Taylor
10*
11* Redistributions of the source code must retain the above copyright notice.
12*----------------------------------------------------------------------------*/
13/** @file */
14
15#include "Cpl/Io/InputOutput.h"
16#include "cores/nRF5/Uart.h"
17
18///
19namespace Cpl {
20///
21namespace Io {
22///
23namespace Serial {
24///
25namespace Adafruit {
26///
27namespace Nrf5 {
28
29
30/** This concrete class implements the InputOutput stream interface
31 as a wrapper around Adafruit's Arduino UART class.
32
33 NOTES:
34 1) The read() methods are non-blocking, i.e. if there is no data
35 available - the methods will return 'true' but no data will be
36 read in.
37 2) The write() methods are blocking in the sense that they will
38 not return until all of the specified data has been sent to
39 the UART Hardware peripheral, BUT it is non-blocking in the sense
40 the it does a busy-wait on the UART Hardware instead of thread
41 yielding.
42 3) As of the nrf52 BSP version 0.6.0 only ONE instance - UART0 -
43 is supported by the Adafruit's Uart class.
44
45 USAGE:
46 // Create an instance using the Arduino primary serial port for 'stdio'
47 static Cpl::Io::Serial::Adafruit::Nrf5 myStdio( Serial );
48
49 // The above line IS equivalent to:
50 static Uart actualSerialPort( NRF_UART0, NRF_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
51 static Cpl::Io::Serial::Adafruit::Nrf5 myStdio( actualSerialPort );
52
53 */
54
56{
57protected:
58 /// Adafruit's UART driver
60
61 /// Flag to keep track of started/stopped state
63
64
65public:
66 /** Constructor.
67 */
68 InputOutput( Uart& serialPort ); //!< Reference to an Arduino 'UART' that provides the actual transfer of data
69
70 /// Destructor
71 virtual ~InputOutput( void );
72
73
74public:
75 /** This method starts UART and must be called BEFORE any of
76 InputOutput methods are called. This allows the instance to
77 be statically created and the initialized/started once the
78 'system is running' (aka in the Arduino setup() method). It
79 is the same as calling 'Serial.begin();
80
81 Note: See the cores/nRF5/HardwareSerial.h head file for
82 valid 'config' settings.
83
84 Note: If using an instance of this class for CPL Tracing logging, then
85 the start() method MUST be called BEFORE the Cpl::System::Initialize()
86 method is called.
87 */
88 void start( unsigned long baudrate=115200, uint16_t config = SERIAL_8N1 ) noexcept;
89
90 /** This method return true when UART is 'ready'
91 */
92 bool isReady( void );
93
94public:
95 /// Pull in overloaded methods from base class
97
98 /// See Cpl::Io::Input
99 bool read( void* buffer, int numBytes, int& bytesRead );
100
101 /// See Cpl::Io::Input
102 bool available();
103
104
105public:
106 /// Pull in overloaded methods from base class
108
109 /// See Cpl::Io::Output
110 bool write( const void* buffer, int maxBytes, int& bytesWritten );
111
112 /// See Cpl::Io::Output. This method does nothing. See comments about the semantics of the write() methods
113 void flush();
114
115 /// See Cpl::Io::IsEos.
116 bool isEos();
117
118 /// See Cpl::Io::Output. Note: An can be 're-opened' by calling the start() method.
119 void close();
120
121};
122
123}; // end namespaces
124};
125};
126};
127};
128#endif // end header latch
virtual bool read(char &c)
Reads a single byte from the stream.
This abstract class defines a interface for operating on an input-output stream (example of a stream ...
Definition InputOutput.h:30
virtual bool write(char c)
Writes a single byte to the stream.
This concrete class implements the InputOutput stream interface as a wrapper around Adafruit's Arduin...
Definition InputOutput.h:56
void close()
See Cpl::Io::Output. Note: An can be 're-opened' by calling the start() method.
void start(unsigned long baudrate=115200, uint16_t config=SERIAL_8N1) noexcept
This method starts UART and must be called BEFORE any of InputOutput methods are called.
Uart & m_serialPort
Adafruit's UART driver.
Definition InputOutput.h:59
bool write(const void *buffer, int maxBytes, int &bytesWritten)
See Cpl::Io::Output.
bool read(void *buffer, int numBytes, int &bytesRead)
See Cpl::Io::Input.
InputOutput(Uart &serialPort)
Constructor.
void flush()
See Cpl::Io::Output. This method does nothing. See comments about the semantics of the write() method...
bool isReady(void)
This method return true when UART is 'ready'.
bool m_started
Flag to keep track of started/stopped state.
Definition InputOutput.h:62
The 'Cpl' namespace is the root name space for the Colony.
Definition Api16.h:20