LINXx firmware
Extensions to LINX toolkit
device/utility/LinxDevice.h
1/****************************************************************************************
2** LINX header for generic LINX Device.
3**
4** For more information see: www.labviewmakerhub.com/linx
5** For support visit the forums at: www.labviewmakerhub.com/forums/linx
6**
7** Written By Sam Kristoff, modified by CBC Girard
8**
9** BSD2 License.
10****************************************************************************************/
11
12#ifndef LINX_DEVICE_H
13#define LINX_DEVICE_H
14
15/****************************************************************************************
16** Includes
17****************************************************************************************/
18#ifndef LINX_CONFIG
19#include "../config/LinxConfig.h"
20#endif
21
22/****************************************************************************************
23** Defines
24****************************************************************************************/
25//GPIO
26#ifndef INPUT
27 #define INPUT 0x00
28#endif
29
30#ifndef OUTPUT
31 #define OUTPUT 0x01
32#endif
33
34#ifndef HIGH
35 #define HIGH 0x01
36#endif
37
38#ifndef LOW
39 #define LOW 0x00
40#endif
41
42//SPI
43#ifndef IS_M0
44
45#ifndef LSBFIRST
46 #define LSBFIRST 0
47#endif
48
49#ifndef MSBFIRST
50 #define MSBFIRST 1
51#endif
52
53#endif
54
55//I2C
56#define EOF_STOP 0
57#define EOF_RESTART 1
58#define EOF_RESTART_NOSTOP 2
59#define EOF_NOSTOP 3
60
61//UART
62#ifndef BIN
63 #define BIN 2
64#endif
65#ifndef OCT
66 #define OCT 8
67#endif
68#ifndef DEC
69 #define DEC 10
70#endif
71#ifndef HEX
72 #define HEX 16
73#endif
74
75//Non-Volatile Storage Addresses
76#define NVS_USERID 0x00
77#define NVS_ETHERNET_IP 0x02
78#define NVS_ETHERNET_PORT 0x06
79#define NVS_WIFI_IP 0x08
80#define NVS_WIFI_PORT 0x0C
81#define NVS_WIFI_SSID_SIZE 0x0E
82#define NVS_WIFI_SSID 0x0F
83#define NVS_WIFI_SECURITY_TYPE 0x30
84#define NVS_WIFI_PW_SIZE 0x31
85#define NVS_WIFI_PW 0x32
86#define NVS_SERIAL_INTERFACE_MAX_BAUD 0x72
87
88//DEBUG
89#define TX 0
90#define RX 1
91
92/****************************************************************************************
93** Typedefs
94****************************************************************************************/
98typedef enum LinxStatus
99{
100 L_OK = 0,
101 L_FUNCTION_NOT_SUPPORTED,
102 L_REQUEST_RESEND,
103 L_UNKNOWN_ERROR,
104 L_DISCONNECT
105}LinxStatus;
106
107typedef enum AioStatus
108{
109 LANALOG_REF_MODE_ERROR=129,
110 LANALOG_REF_VAL_ERROR=130
111}AioStatus;
112
113typedef enum DioStatus
114{
115 LDIGITAL_PIN_DNE=128,
116}DioStatus;
117
118
119typedef enum SPIStatus
120{
121 LSPI_OPEN_FAIL = 128,
122 LSPI_TRANSFER_FAIL
123}SPIStatus;
124
125typedef enum I2CStatus
126{
127 LI2C_SADDR=128,
128 LI2C_EOF,
129 LI2C_WRITE_FAIL,
130 LI2C_READ_FAIL,
131 LI2C_CLOSE_FAIL,
132 LI2C_OPEN_FAIL
133}I2CStatus;
134
135typedef enum UartStatus
136{
137 LUART_OPEN_FAIL=128,
138 LUART_SET_BAUD_FAIL,
139 LUART_AVAILABLE_FAIL,
140 LUART_READ_FAIL,
141 LUART_WRITE_FAIL,
142 LUART_CLOSE_FAIL
143}UartStatus;
144
149typedef enum ResetWhat
150{
151 LRESET_NONE,
152 LRESET_SERIAL,
153 LRESET_TCP,
154 LRESET_ALL
155}ResetWhat;
156
157
163{
164 public:
165 /****************************************************************************************
166 ** Member Variables
167 ****************************************************************************************/
170 unsigned char DeviceFamily;
171 unsigned char DeviceId;
172 unsigned char DeviceNameLen;
173 const unsigned char* DeviceName;
174 unsigned char ListenerBufferSize;
176
180 unsigned char LinxApiMajor;
181 unsigned char LinxApiMinor;
182 unsigned char LinxApiSubminor;
184
185 //----Peripherals----
186
189 unsigned char NumDigitalChans;
190 const unsigned char* DigitalChans;
192
195 unsigned char NumAiChans;
196 const unsigned char* AiChans;
197 unsigned char AiResolution;
198 unsigned long AiRefDefault;
199 unsigned long AiRefSet;
200
201 unsigned char NumAoChans;
202 const unsigned char* AoChans;
203 unsigned char AoResolution;
204 unsigned long AoRefDefault;
205 unsigned long AoRefSet;
207
211 unsigned char NumPwmChans;
212 const unsigned char* PwmChans;
214
218 unsigned char NumQeChans;
219 const unsigned char* QeChans;
221
225 unsigned char NumUartChans;
226 const unsigned char* UartChans;
227 unsigned long UartMaxBaud;
229
233 unsigned char NumI2cChans;
234 const unsigned char* I2cChans;
236
240 unsigned char NumSpiChans;
241 const unsigned char* SpiChans;
243
247 unsigned char NumCanChans;
248 const unsigned char* CanChans;
250
254 unsigned char NumServoChans;
255 const unsigned char* ServoChans;
257
260 unsigned short userId;
261
262 unsigned long ethernetIp;
263 unsigned short ethernetPort;
264
265
266 unsigned long WifiIp;
267 unsigned short WifiPort;
268 unsigned char WifiSsidSize;
269 char WifiSsid[32];
270 unsigned char WifiSecurity;
271 unsigned char WifiPwSize;
272 char WifiPw[64];
274
275
276 unsigned long serialInterfaceMaxBaud;
277
281 ResetWhat ResetTarget=LRESET_NONE;
282 unsigned char WifiStatus=0xFF;
284
285 /****************************************************************************************
286 ** Constructors/Destructor
287 ****************************************************************************************/
288 LinxDevice();
289 virtual ~LinxDevice();
290
291 /****************************************************************************************
292 ** Functions
293 ****************************************************************************************/
294
297 virtual int AnalogRead(unsigned char numChans, unsigned char* channels, unsigned char* values) = 0;
298 virtual int AnalogReadNoPacking(unsigned char numChans, unsigned char* channels, unsigned long* values); //Values Are ADC Ticks And Not Bit Packed
299 virtual int AnalogSetRef(unsigned char mode, unsigned long voltage) = 0;
300
301 virtual int AnalogWrite(unsigned char numChans, unsigned char* channels, unsigned char* values) = 0; //Values Are Bit Packed
302 virtual int AnalogWriteNoPacking(unsigned char numChans, unsigned char* channels, unsigned long* values); //Values Are Not Bit Packed
304
307 virtual int DigitalWrite(unsigned char numChans, unsigned char* channels, unsigned char* values) = 0; //Values Are Bit Packed
308 virtual int DigitalWriteNoPacking(unsigned char numChans, unsigned char* channels, unsigned char* values); //Values Are Not Bit Packed
309 virtual int DigitalRead(unsigned char numChans, unsigned char* channels, unsigned char* values) = 0;
310 virtual int DigitalReadNoPacking(unsigned char numChans, unsigned char* channels, unsigned char* values); //Response Not Bit Packed
311 virtual int DigitalWriteSquareWave(unsigned char channel, unsigned long freq, unsigned long duration) = 0;
312 virtual int DigitalReadPulseWidth(unsigned char stimChan, unsigned char stimType, unsigned char respChan, unsigned char respType, unsigned long timeout, unsigned long* width) = 0;
317 virtual int PwmSetDutyCycle(unsigned char numChans, unsigned char* channels, unsigned char* values) = 0;
318 virtual int PwmSetFrequency(unsigned char numChans, unsigned char* channels, unsigned long* values);
320
323 virtual int SpiOpenMaster(unsigned char channel) = 0;
324 virtual int SpiSetBitOrder(unsigned char channel, unsigned char bitOrder) = 0;
325 virtual int SpiSetMode(unsigned char channel, unsigned char mode) = 0;
326 virtual int SpiSetSpeed(unsigned char channel, unsigned long speed, unsigned long* actualSpeed) = 0;
327 virtual int SpiWriteRead(unsigned char channel, unsigned char frameSize, unsigned char numFrames, unsigned char csChan, unsigned char csLL, unsigned char* sendBuffer, unsigned char* recBuffer) = 0;
329
332 virtual int I2cOpenMaster(unsigned char channel) = 0;
333 virtual int I2cSetSpeed(unsigned char channel, unsigned long speed, unsigned long* actualSpeed) = 0;
334 virtual int I2cWrite(unsigned char channel, unsigned char slaveAddress, unsigned char eofConfig, unsigned char numBytes, unsigned char* sendBuffer) = 0;
335 virtual int I2cRead(unsigned char channel, unsigned char slaveAddress, unsigned char eofConfig, unsigned char numBytes, unsigned int timeout, unsigned char* recBuffer) = 0;
336 virtual int I2cClose(unsigned char channel) = 0;
338
341 virtual int UartOpen(unsigned char channel, unsigned long baudRate, unsigned long* actualBaud) = 0;
342 virtual int UartSetBaudRate(unsigned char channel, unsigned long baudRate, unsigned long* actualBaud) = 0;
343 virtual int UartGetBytesAvailable(unsigned char channel, unsigned char *numBytes) = 0;
344 virtual int UartRead(unsigned char channel, unsigned char numBytes, unsigned char* recBuffer, unsigned char* numBytesRead) = 0;
345 virtual int UartWrite(unsigned char channel, unsigned char numBytes, unsigned char* sendBuffer) = 0;
346 virtual void UartWrite(unsigned char channel, char c);
347 virtual void UartWrite(unsigned char channel, const char s[]);
348 virtual void UartWrite(unsigned char channel, unsigned char c);
349 virtual void UartWrite(unsigned char channel, int n);
350 virtual void UartWrite(unsigned char channel, unsigned int n);
351 virtual void UartWrite(unsigned char channel, long n);
352 virtual void UartWrite(unsigned char channel, unsigned long n);
353 virtual void UartWrite(unsigned char channel, long n, int base);
354 virtual void UartWriteln(unsigned char channel);
355 virtual void UartWriteln(unsigned char channel, char c);
356 virtual void UartWriteln(unsigned char channel, const char s[]);
357 virtual void UartWriteln(unsigned char channel, unsigned char c);
358 virtual void UartWriteln(unsigned char channel, int n);
359 virtual void UartWriteln(unsigned char channel, long n);
360 virtual void UartWriteln(unsigned char channel, unsigned long n);
361 virtual void UartWriteln(unsigned char channel, long n, int base);
362 virtual int UartClose(unsigned char channel) = 0;
364
367 virtual int ServoOpen(unsigned char numChans, unsigned char* channels) = 0;
368 virtual int ServoSetPulseWidth(unsigned char numChans, unsigned char* channels, unsigned short* pulseWidths) = 0;
369 virtual int ServoClose(unsigned char numChans, unsigned char* channels) = 0;
371
374 virtual int Ws2812Open(unsigned short numLeds, unsigned char dataChan);
375 virtual int Ws2812WriteOnePixel(unsigned short pixelIndex, unsigned char red, unsigned char green, unsigned char blue, unsigned char refresh);
376 virtual int Ws2812WriteNPixels(unsigned short startPixel, unsigned short numPixels, unsigned char* data, unsigned char refresh);
377 virtual int Ws2812Refresh();
378 virtual int Ws2812Close();
380
383 unsigned char ReverseBits(unsigned char b);
384 virtual unsigned long GetMilliSeconds() = 0;
385 virtual unsigned long GetSeconds() = 0;
386 virtual void DelayMs(unsigned long ms);
387 virtual void NonVolatileWrite(int address, unsigned char data) = 0;
388 virtual unsigned char NonVolatileRead(int address) = 0;
390
393 virtual void EnableDebug(unsigned char channel);
394
395 virtual void DebugPrint(char c);
396 virtual void DebugPrint(const char s[]);
397 virtual void DebugPrint(unsigned char c);
398 virtual void DebugPrint(int n);
399 virtual void DebugPrint(unsigned int n);
400 virtual void DebugPrint(long n);
401 virtual void DebugPrint(unsigned long n);
402 virtual void DebugPrint(long n, int base);
403
404 virtual void DebugPrintln();
405 virtual void DebugPrintln(char c);
406 virtual void DebugPrintln(const char s[]);
407 virtual void DebugPrintln(unsigned char c);
408 virtual void DebugPrintln(int n);
409 virtual void DebugPrintln(long n);
410 virtual void DebugPrintln(unsigned long n);
411 virtual void DebugPrintln(long n, int base);
412
413 virtual void DebugPrintPacket(unsigned char direction, const unsigned char* packetBuffer);
415
418 virtual int BoardCommands(unsigned char command, unsigned char numInputBytes, unsigned char* input, unsigned char* numResponseBytes, unsigned char* response);
419 virtual int Reset(ResetWhat target);
421
422
423 private:
424 /****************************************************************************************
425 ** Variables
426 ****************************************************************************************/
427 virtual void UartWriteNumber(unsigned char channel, unsigned long n, unsigned char bases);
428
429 /****************************************************************************************
430 ** Functions
431 ****************************************************************************************/
432};
433#endif //LINX_DEVICE_H
Base class for board functionality; extended by family and board-specific code.
Definition: device/utility/LinxDevice.h:163