ccNOos  v0.0.0
Build Portable Microcontroller Applications!
io_device.h
Go to the documentation of this file.
1 /** \file io_device.h
2 * \brief <a href="https://www.inmechasol.org/" target="_blank">IMS</a>:
3  <a href="https://github.com/InMechaSol/ccNOos" target="_blank">ccNOos</a>,
4  Declarations for straight C and C++
5 
6  Copyright 2021 <a href="https://www.inmechasol.org/" target="_blank">InMechaSol, Inc</a>
7 
8  Licensed under the Apache License, Version 2.0(the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 Notes:
21  (.c includes .h) - for straight C or
22  (.cpp includes .c which includes .h) - for C++ wrapped straight C
23  *Always compiled to a single compilation unit, either C or CPP, not both
24 
25 */
26 
27 #ifndef __IO_DEVICE__
28 #define __IO_DEVICE__
29 
30 #include "version_config.h"
31 
32 
33 ////////////////////////////////////////////////////////////////////////
34 /// Generic IO Device
35 ////////////////////////////////////////////////////////////////////////
36 
37 /** \enum devicestateenum
38 * \brief enumerates states of the io device
39 */
41 {
49 };
50 /** \union devicebufferunion
51 * \brief char/byte ambiguous container for io data
52 */
54 {
56  unsigned char bytebuff[charBuffMax];
57 };
58 /** \struct devicedatastruct
59 * \brief the common data struct of io devices
60 */
62 {
68 };
70 
71 ////////////////////////////////////////////////////////////////////////
72 /// SPI IO Device
73 ////////////////////////////////////////////////////////////////////////
75 {
80 };
82 {
83  enum SPITypes spitype;
86 
87 };
88 
89 ////////////////////////////////////////////////////////////////////////
90 /// Serial UART IO Device
91 ////////////////////////////////////////////////////////////////////////
93 {
94  stop_none = 0,
95  stop_one = 1,
96  stop_two = 2,
98 };
100 {
105  parity_space = 4
106 };
108 {
113 };
114 
116 {
117  int baudRate;
118  int dataBits;
120  enum portParityEnum parity;
122  struct devicedatastruct devdata;
125 };
126 
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 // C only, struct of function pointers
130 // - not yet using this, may not use it, creates complications when switching from c to c++
131 #ifndef __cplusplus
132 
134 {
135  int (*open)();
136  int (*close)();
137  int (*read)();
138  int (*write)();
139 };
140 
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 // C++, class of virtual methods
144 #else
145 
146 class IODeviceClass
147 {
148 
149 protected:
150  struct devicedatastruct* devdataptr = nullptr;
151  virtual int opendevice() = 0;
152  virtual int closedevice() = 0;
153  virtual int readdevice() = 0;
154  virtual int writedevice() = 0;
155  virtual UI_8 isdeviceopen() = 0;
156 
157 public:
158  IODeviceClass(struct devicedatastruct* devdataptrin);
159  int OpenDev();
160  int CloseDev();
161  int ReadDev();
162  int WriteDev();
163  bool IsDevOpen();
164  void TriggerWriteOperation();
165  bool NewDataReadIn();
166  void ClearNewDataReadInFlag();
167  bool ReadTriggerWriteOperationFlag();
168  struct devicedatastruct* GetDevPtr();
169 };
170 
171 
172 
173 
174 // Abstract SPI IO Device
175 class SPI_DeviceClass : public IODeviceClass
176 {
177 protected:
178  SPIDeviceStruct* spidevptr;
179 public:
180  SPI_DeviceClass(struct SPIDeviceStruct* spidevdataptrin);
181 };
182 
183 
184 
185 // Abstract Serial IO Device
186 class Serial_DeviceClass : public IODeviceClass
187 {
188 protected:
189  SerialDeviceStruct* serialdevptr;
190 public:
191  Serial_DeviceClass(struct SerialDeviceStruct* serialdevdataptrin);
192 };
193 
194 
195 
196 #endif // !__cplusplus
197 #endif // !__IO_DEVICE__
charBuffMax
#define charBuffMax
Definition: version_config.h:78
devstate_reading
@ devstate_reading
Definition: io_device.h:45
SPIDeviceStruct::chipSelectEnabled
UI_8 chipSelectEnabled
Definition: io_device.h:85
devicedatastruct::outbuff
union devicebufferunion outbuff
Definition: io_device.h:64
stop_onepointfive
@ stop_onepointfive
Definition: io_device.h:97
SPIDeviceStruct
Definition: io_device.h:82
parity_mark
@ parity_mark
Definition: io_device.h:104
parity_none
@ parity_none
Definition: io_device.h:101
devstate_writedone
@ devstate_writedone
Definition: io_device.h:48
devicestateenum
devicestateenum
Generic IO Device.
Definition: io_device.h:41
ioDeviceStruct::open
int(* open)()
Definition: io_device.h:135
portParityEnum
portParityEnum
Definition: io_device.h:100
devstate_readdone
@ devstate_readdone
Definition: io_device.h:46
parity_even
@ parity_even
Definition: io_device.h:102
SerialDeviceStruct::parity
enum portParityEnum parity
Definition: io_device.h:120
stop_none
@ stop_none
Definition: io_device.h:94
parity_space
@ parity_space
Definition: io_device.h:105
SPIDeviceStruct::spitype
enum SPITypes spitype
Definition: io_device.h:83
SPIDeviceStruct::devdata
struct devicedatastruct devdata
Definition: io_device.h:84
SerialDeviceStruct::readIndex
int readIndex
Definition: io_device.h:124
ioDeviceStruct::close
int(* close)()
Definition: io_device.h:136
handshake_requesttosend
@ handshake_requesttosend
Definition: io_device.h:110
portHandshakeEnum
portHandshakeEnum
Definition: io_device.h:108
devicedatastruct::newDataReadIn
UI_8 newDataReadIn
Definition: io_device.h:66
devicebufferunion::charbuff
char charbuff[charBuffMax]
Definition: io_device.h:55
parity_odd
@ parity_odd
Definition: io_device.h:103
ioDeviceStruct::write
int(* write)()
Definition: io_device.h:138
SerialDeviceStruct::numBytes2Read
int numBytes2Read
Definition: io_device.h:123
handshake_xonxoff
@ handshake_xonxoff
Definition: io_device.h:112
devicebufferunion::bytebuff
unsigned char bytebuff[charBuffMax]
Definition: io_device.h:56
devstate_open
@ devstate_open
Definition: io_device.h:44
SerialDeviceStruct
Definition: io_device.h:116
SPIType_two
@ SPIType_two
Definition: io_device.h:77
devstate_writing
@ devstate_writing
Definition: io_device.h:47
SPITypes
SPITypes
SPI IO Device.
Definition: io_device.h:75
stop_two
@ stop_two
Definition: io_device.h:96
devicedatastruct
the common data struct of io devices
Definition: io_device.h:62
ioDeviceStruct::read
int(* read)()
Definition: io_device.h:137
SPIType_one
@ SPIType_one
Definition: io_device.h:76
SPIType_four
@ SPIType_four
Definition: io_device.h:79
SerialDeviceStruct::stopBits
enum portStopBitsEnum stopBits
Definition: io_device.h:119
SPIType_three
@ SPIType_three
Definition: io_device.h:78
devstate_opening
@ devstate_opening
Definition: io_device.h:43
devicedatastruct::triggerWriteOperation
UI_8 triggerWriteOperation
Definition: io_device.h:67
SerialDeviceStruct::handshake
enum portHandshakeEnum handshake
Definition: io_device.h:121
portStopBitsEnum
portStopBitsEnum
Serial UART IO Device.
Definition: io_device.h:93
devicedatastruct::inbuff
union devicebufferunion inbuff
Definition: io_device.h:63
createDeviceStruct
struct devicedatastruct createDeviceStruct()
Definition: io_device.c:31
version_config.h
IMS: ccNOos, Declarations for straight C and C++
SerialDeviceStruct::devdata
struct devicedatastruct devdata
Definition: io_device.h:122
devicebufferunion
char/byte ambiguous container for io data
Definition: io_device.h:54
SerialDeviceStruct::baudRate
int baudRate
Definition: io_device.h:117
handshake_requesttosendxonxoff
@ handshake_requesttosendxonxoff
Definition: io_device.h:111
devstate_init
@ devstate_init
Definition: io_device.h:42
handshake_none
@ handshake_none
Definition: io_device.h:109
devicedatastruct::devstate
enum devicestateenum devstate
Definition: io_device.h:65
SerialDeviceStruct::dataBits
int dataBits
Definition: io_device.h:118
ioDeviceStruct
Definition: io_device.h:134
stop_one
@ stop_one
Definition: io_device.h:95