Serial Wombat Arduino Library
SerialWombat.h
Go to the documentation of this file.
1 #ifndef SERIAL_WOMBAT_H__
2 #define SERIAL_WOMBAT_H__
3 
4 /*
5 Copyright 2020-2023 Broadwell Consulting Inc.
6 
7 "Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
8 the United States. See SerialWombat.com for usage guidance.
9 
10 Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27 */
28 
29 #include <stdint.h>
30 #include "Stream.h"
31 //#include "Serial.h" // Using "" rather than <> for compatibility with Visual C++ simulation project
32 #include "Wire.h"// Using "" rather than <> for compatibility with Visual C++ simulation project
33 #include "Arduino.h"
34 
35 
36 
40 #define SW_LE16(_a) (uint8_t)((_a) & 0xFF), (uint8_t)((_a) >>8)
42 
44 #define SW_LE32(_a) (uint8_t)((_a) & 0xFF), (uint8_t)((_a) >>8) , (uint8_t)((_a) >>16), (uint8_t)((_a) >>24)
45 
46 
47 typedef enum
48 {
49  SW_LOW = 0,
50  SW_HIGH = 1,
51  SW_INPUT = 2,
53 
54 
57 
78 // SW_DATA_SOURCE_PIN_20 = 20,
79 // SW_DATA_SOURCE_PIN_21 = 21,
80 // SW_DATA_SOURCE_PIN_22 = 22,
81 // SW_DATA_SOURCE_PIN_23 = 23,
82 // SW_DATA_SOURCE_PIN_24 = 24,
83 // SW_DATA_SOURCE_PIN_25 = 25,
84 // SW_DATA_SOURCE_PIN_26 = 26,
85 // SW_DATA_SOURCE_PIN_27 = 27,
86 // SW_DATA_SOURCE_PIN_28 = 28,
87 // SW_DATA_SOURCE_PIN_29 = 29,
88 // SW_DATA_SOURCE_PIN_30 = 30,
89 // SW_DATA_SOURCE_PIN_31 = 31,
90 // SW_DATA_SOURCE_PIN_32 = 32,
91 // SW_DATA_SOURCE_PIN_33 = 33,
92 // SW_DATA_SOURCE_PIN_34 = 34,
93 // SW_DATA_SOURCE_PIN_35 = 35,
94 // SW_DATA_SOURCE_PIN_36 = 36,
95 // SW_DATA_SOURCE_PIN_37 = 37,
96 // SW_DATA_SOURCE_PIN_38 = 38,
97 // SW_DATA_SOURCE_PIN_39 = 39,
98 // SW_DATA_SOURCE_PIN_40 = 40,
99 // SW_DATA_SOURCE_PIN_41 = 41,
100 // SW_DATA_SOURCE_PIN_42 = 42,
101 // SW_DATA_SOURCE_PIN_43 = 43,
102 // SW_DATA_SOURCE_PIN_44 = 44,
103 // SW_DATA_SOURCE_PIN_45 = 45,
104 // SW_DATA_SOURCE_PIN_46 = 46,
105 // SW_DATA_SOURCE_PIN_47 = 47,
106 // SW_DATA_SOURCE_PIN_48 = 48,
107 // SW_DATA_SOURCE_PIN_49 = 49,
108 // SW_DATA_SOURCE_PIN_50 = 50,
109 // SW_DATA_SOURCE_PIN_51 = 51,
110 // SW_DATA_SOURCE_PIN_52 = 52,
111 // SW_DATA_SOURCE_PIN_53 = 53,
112 // SW_DATA_SOURCE_PIN_54 = 54,
113 // SW_DATA_SOURCE_PIN_55 = 55,
114 // SW_DATA_SOURCE_PIN_56 = 56,
115 // SW_DATA_SOURCE_PIN_57 = 57,
116 // SW_DATA_SOURCE_PIN_58 = 58,
117 // SW_DATA_SOURCE_PIN_59 = 59,
118 // SW_DATA_SOURCE_PIN_60 = 60,
119 // SW_DATA_SOURCE_PIN_61 = 61,
120 // SW_DATA_SOURCE_PIN_62 = 62,
121 // SW_DATA_SOURCE_PIN_63 = 63,
129  SW_DATA_SOURCE_ERRORS = 72,
134  SW_DATA_SOURCE_LFSR = 78,
135  SW_DATA_SOURCE_0x55 = 85,
141  //NOT ANALOG SW_DATA_SOURCE_PIN_5_MV = 105,
142  //NOT ANALOG SW_DATA_SOURCE_PIN_6_MV = 106,
143  //NOT ANALOG SW_DATA_SOURCE_PIN_7_MV = 107,
144  //NOT ANALOG SW_DATA_SOURCE_PIN_8_MV = 108,
145  //NOT ANALOG SW_DATA_SOURCE_PIN_9_MV = 109,
146  //NOT ANALOG SW_DATA_SOURCE_PIN_10_MV = 110,
147  //NOT ANALOG SW_DATA_SOURCE_PIN_11_MV = 111,
148  //NOT ANALOG SW_DATA_SOURCE_PIN_12_MV = 112,
149  //NOT ANALOG SW_DATA_SOURCE_PIN_13_MV = 113,
150  //NOT ANALOG SW_DATA_SOURCE_PIN_14_MV = 114,
151  //NOT ANALOG SW_DATA_SOURCE_PIN_15_MV = 115,
158 // SW_DATA_SOURCE_2HZ_SIN = 166,
161 // SW_DATA_SOURCE_1HZ_SIN = 169,
164 // SW_DATA_SOURCE_2SEC_SIN = 172,
167 // SW_DATA_SOURCE_8SEC_SIN = 175,
170 // SW_DATA_SOURCE_65SEC_SIN = 178,
171  SW_DATA_SOURCE_NONE = 255,
172 };
173 
174 #define ERROR_HOST_INCORRECT_NUMBER_BYTES_WRITTEN 0x10000
175 #define ERROR_HOST_DATA_TOO_LONG 0x10001
176 #define ERROR_HOST_NACK_ADDRESS 0x10002
177 #define ERROR_HOST_NACK_DATA 0x10003
178 #define ERROR_HOST_OTHER_I2C_ERROR 0x10004
179 
180 #define WOMBAT_MAXIMUM_PINS 20
181 
183 {
184  CMD_ECHO ='!',
185  CMD_READ_BUFFER_ASCII = 'G',
186  CMD_ASCII_SET_PIN ='P',
187  CMD_RESET = 'R',
188  CMD_SET_BUFFER_ASCII = 'S',
189  CMD_RESYNC = 'U',
190  CMD_VERSION = 'V',
191  CMD_SUPPLYVOLTAGE = 'v',
202  COMMAND_BINARY_CONFIGURE = 0x9F,
203  COMMAND_BINARY_READ_RAM = 0xA0,
206  COMMAND_BINARY_WRITE_RAM = 0xA3,
208  COMMAND_CALIBRATE_ANALOG = 0xA5,
209  COMMAND_ENABLE_2ND_UART = 0xA6,
211  COMMAND_UART0_TX_7BYTES = 0xB0,
212  COMMAND_UART0_RX_7BYTES = 0xB1,
213  COMMAND_UART1_TX_7BYTES = 0xB2,
214  COMMAND_UART1_RX_7BYTES = 0xB3,
215  CONFIGURE_PIN_MODE0 = 200,
216  CONFIGURE_PIN_MODE1 = 201,
217  CONFIGURE_PIN_MODE2 = 202,
218  CONFIGURE_PIN_MODE3 = 203,
219  CONFIGURE_PIN_MODE4 = 204,
220  CONFIGURE_PIN_MODE5 = 205,
221  CONFIGURE_PIN_MODE6 = 206,
222  CONFIGURE_PIN_MODE7 = 207,
223  CONFIGURE_PIN_MODE8 = 208,
224  CONFIGURE_PIN_MODE9 = 209,
225  CONFIGURE_PIN_MODE10 = 210,
233 
234 };
235 
236 
237 typedef enum {
269 
270 class SerialWombatChip;
271 
272 typedef void (*SerialWombatErrorHandler_t) (uint16_t errorNumber, SerialWombatChip* sw);
273 
280 {
281 
282 private:
283 
284 
285  char version[8] = { 0 };
286  HardwareSerial * Serial = NULL;
287  TwoWire* i2cInterface = NULL;
288  uint8_t _pinmode[WOMBAT_MAXIMUM_PINS]={}; // Includes Pullup
289  bool _pullDown[WOMBAT_MAXIMUM_PINS]={};
290  bool _openDrain[WOMBAT_MAXIMUM_PINS]={};
291  bool _highLow[WOMBAT_MAXIMUM_PINS] = {};
292  bool _asleep = false;
293  void configureDigitalPin(uint8_t pin, uint8_t highLow)
294  {
295  uint8_t tx[8] = { 200,pin,0,0,0,0,0,0x55 };
296  uint8_t rx[8];
297  switch (_pinmode[pin])
298  {
299  case INPUT: // Arduino input
300  {
301  tx[3] = 2; //Input
302  }
303  break;
304  case OUTPUT:
305  {
306  if (highLow == LOW)
307  {
308  tx[3] = 0;
309  }
310  else if (highLow == HIGH)
311  {
312  tx[3] = 1;
313  }
314  else
315  {
316  return;
317  }
318  }
319  break;
320  case INPUT_PULLUP:
321  {
322  tx[3] = 2; //Input
323  tx[4] = 1; //Pullup on
324  }
325  break;
326  default:
327  {
328  return;
329  }
330  }
331  tx[6] = _openDrain[pin];
332  tx[5] = _pullDown[pin];
333  sendPacket(tx, rx, true);
334  }
335  uint32_t sendReadyTime = 0;
336  int16_t initialize()
337  {
338  int16_t retvalue = -1;
339  lastErrorCode = 0;
340  readVersion();
342  readUniqueIdentifier();
343  readDeviceIdentifier();
344  return(lastErrorCode);
345  }
346 
347  void readUniqueIdentifier()
348  {
350  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
351  { //16F15214
352  for (uint32_t address = 0x8100; address <= 0x8108; ++address)
353  {
354  uint32_t data = readFlashAddress(address);
355  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)data;
357  /* Always zero... leave out
358  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)(data>>8);
359  ++uniqueIdentifierLength;
360  */
361  }
362  }
363  else if (isSW18())
364  {
365  for (uint32_t address = 0x801600; address <= 0x801608; address += 2)
366  {
367  uint32_t data = readFlashAddress(address);
374  }
375  }
376  }
377 
378  void readDeviceIdentifier()
379  {
380  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
381  { //16F15214
382 
383  uint32_t data = readFlashAddress(0x8006);
384  deviceIdentifier = (uint16_t)data;
385  data = readFlashAddress(0x8005);
386  deviceRevision = (uint16_t)data;
387  }
388  else if (isSW18())
389  {
390  uint32_t data = readFlashAddress(0xFF0000);
391  deviceIdentifier = (uint16_t)data;
392  data = readFlashAddress(0xFF0002);
393  deviceRevision = (uint16_t)data & 0xF;
394  }
395  }
396 
397  uint16_t returnErrorCode(uint8_t* rx)
398  {
399  uint16_t result = rx[1] - '0';
400  result *= 10;
401  result += rx[2] - '0';
402  result *= 10;
403  result += rx[3] - '0';
404  result *= 10;
405  result += rx[4] - '0';
406  result *= 10;
407  result += rx[5] - '0';
408  return(result);
409  }
410 
411 
412  SerialWombatErrorHandler_t errorHandler = NULL;
413  bool _currentlyCommunicating = false;
414 
415 public:
426  int16_t begin(HardwareSerial &serial);
440  int16_t begin(HardwareSerial& serial, bool reset);
441 
451  int16_t begin(uint8_t i2cAddress);
452 
466  auto begin(TwoWire& wire, uint8_t i2cAddress, bool reset = true) ->
467  int16_t{
468  i2cInterface = &wire;
469  address = i2cAddress;
470 
471  Wire.beginTransmission(i2cAddress);
472  int error = Wire.endTransmission();
473 
474 
475  if (error != 0)
476  {
477  return(-1);
478  }
479 
480  if (reset)
481  {
482  hardwareReset();
483  sendReadyTime = millis() + 1000;
484  return(1);
485  }
486  else
487  {
488  sendReadyTime = 0;
489  return initialize();
490 
491  }
492  }
493 
495 
506  int sendPacket( uint8_t tx[], uint8_t rx[]);
507 
517  int sendPacket(uint8_t tx[]);
518 
529  int sendPacket(uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch = 8, uint8_t endBytesToMatch = 0);
539  int sendPacket(uint8_t tx[], bool retryIfEchoDoesntMatch);
540 
550  int sendPacketNoResponse(uint8_t tx[]);
551 
560  char* readVersion(void)
561  {
562  uint8_t tx[] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
563  uint8_t rx[8];
564  sendPacket(tx, rx);
565  memcpy(version, &rx[1], 7);
566  version[7] = '\0';
567  memcpy(model, &rx[1], 3);
568  model[3] = '\0';
569  fwVersion[0] = rx[5];
570  fwVersion[1] = rx[6];
571  fwVersion[2] = rx[7];
572  return (version);
573  }
574 
581  uint32_t readVersion_uint32(void)
582  {
583  readVersion();
584  return ((((uint32_t)fwVersion[0]) << 16) |
585  (((uint32_t)fwVersion[1]) << 8) |
586  fwVersion[2]);
587  }
588 
598  uint16_t readPublicData(uint8_t pin)
599  {
600  uint8_t tx[] = { 0x81,pin,255,255,0x55,0x55,0x55,0x55 };
601  uint8_t rx[8];
602  sendPacket(tx, rx);
603  return(rx[2] + (uint16_t)rx[3] * 256);
604  }
605 
616  {
617  return (readPublicData((uint8_t)dataSource));
618  }
619 
625  uint16_t writePublicData(uint8_t pin, uint16_t value)
626  {
627  uint8_t tx[] = { 0x82,pin,(uint8_t)(value & 0xFF),(uint8_t)(value >> 8) ,255,0x55,0x55,0x55 };
628  uint8_t rx[8];
629  sendPacket(tx, rx);
630  return (rx[2] + rx[3] * 256);
631  }
632 
643  uint16_t readSupplyVoltage_mV(void)
644  {
645  if (isSW18())
646  {
648  }
649  else
650  {
651  int32_t counts = readPublicData(66); // Get FVR counts (1.024 v)
652  if (counts > 0)
653  {
654  uint32_t mv = 1024 * 65536 / counts;
655  _supplyVoltagemV = (uint16_t)mv;
656  }
657  else
658  {
659  _supplyVoltagemV = 0;
660  }
661  }
662  return(_supplyVoltagemV);
663  }
664 
665 
677  {
678  if (isSW18())
679  {
680  int32_t result = readPublicData(70);
681  if (result >= 32768)
682  {
683  result = result - 65536;
684  }
685  return ((int16_t)result);
686  }
687  else
688  {
689  return 2500;
690  }
691  }
692 
700  {
701  uint8_t tx[9] = "ReSeT!#*";
702  uint8_t rx[8];
703  sendPacket(tx, rx);
704  }
705 
714  void pinMode(uint8_t pin, uint8_t mode, bool pullDown = false, bool openDrain = false)
715  {
716  if (pin >= WOMBAT_MAXIMUM_PINS)
717  {
718  return;
719  }
720  _pullDown[pin] = openDrain;
721  _openDrain[pin] = openDrain;
722  _pinmode[pin] = mode;
723  configureDigitalPin(pin, mode);
724  }
725 
733  void digitalWrite(uint8_t pin, uint8_t val)
734  {
735  configureDigitalPin(pin, val);
736  }
737 
742 
743  int digitalRead(uint8_t pin)
744  {
745  if (readPublicData(pin) > 0)
746  {
747  return (HIGH);
748  }
749  else
750  {
751  return (LOW);
752  }
753  }
754 
764  int analogRead(uint8_t pin)
765  {
766  uint8_t tx[] = { 200,pin,PIN_MODE_ANALOGINPUT,0,0,0,0,0 };
767  uint8_t rx[8];
768  sendPacket(tx, rx);
769  return (readPublicData(pin) >> 6); // Scale from 16 bit value to 10 bit value.
770  }
771 
783  void analogWrite(uint8_t pin, int val)
784  {
785  uint8_t dutyCycleLow = 0;
786  if (val == 255)
787  {
788  dutyCycleLow = 255;
789  }
790  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_PWM,pin,dutyCycleLow,(uint8_t) val,false,0x55 };
791  uint8_t rx[8];
792  sendPacket(tx, rx);
793  }
794 
806  {
807  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
808  uint8_t rx[8];
809  sendPacket(tx, rx);
810  if (rx[0] == 'V' && (rx[1] == 'S' || rx[1] == 'B'))
811  {
812  model[0] = rx[1];
813  model[1] = rx[2];
814  model[2] = rx[3];
815  model[3] = 0;
816  fwVersion[0] = rx[5];
817  fwVersion[1] = rx[6];
818  fwVersion[2] = rx[7];
819  fwVersion[3] = 0;
820 
821  inBoot = (rx[1] == 'B');
822  return (true);
823  }
824  return (false);
825  }
826 
834  {
835  uint8_t tx[8] = { 0x81,67,68,0x55,0x55,0x55,0x55,0x55 };
836  uint8_t rx[8];
837  sendPacket(tx, rx);
838  uint32_t returnval = rx[2] + (((uint32_t)rx[3]) << 8) + (((uint32_t)rx[4]) << 16) + (((uint32_t)rx[5]) << 24);
839  return (returnval);
840  }
841 
851  {
852  return readPublicData(69);
853  }
854 
864  void jumpToBoot()
865  {
866  uint8_t tx[] = "BoOtLoAd";
867  sendPacket(tx);
868  }
869 
890  uint8_t readRamAddress(uint16_t address)
891  {
892  uint8_t tx[8] = { 0xA0,SW_LE16(address),0x55,0x55,0x55,0x55,0x55 };
893  uint8_t rx[8];
894  sendPacket(tx, rx);
895  return(rx[3]);
896  }
897 
918  int16_t writeRamAddress(uint16_t address, uint8_t value)
919  {
920  uint8_t tx[8] = { 0xA3,SW_LE16(address),0,0,value,0x55,0x55};
921  return sendPacket(tx);
922  }
923 
939  uint32_t readFlashAddress(uint32_t address)
940  {
941  uint8_t tx[8] = { 0xA1,SW_LE32(address),0x55,0x55,0x55 };
942  uint8_t rx[8];
943  sendPacket(tx, rx);
944  return(((uint32_t)rx[4]) + (((uint32_t)rx[5]) <<8) + (((uint32_t)rx[6]) <<16) + (((uint32_t)rx[7]) <<24));
945  }
946 
957  void sleep()
958  {
959  uint8_t tx[8] = { 'S','l','E','e','P','!','#','*'};
960  sendPacket(tx);
961  _asleep = true;
962  }
963 
965  void wake()
966  {
967  uint8_t tx[8] = { '!','!','!','!','!','!','!','!' };
968  sendPacket(tx);
969  }
970 
972  bool isSW18()
973  {
974  return ( model[1] == '1' && model[2] == '8');
975  }
976 
978  int16_t eraseFlashPage(uint32_t address)
979  {
980  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
981  0, //Erase Page
982  SW_LE32(address),
983  0x55,0x55 };
984  return sendPacket(tx);
985  }
986 
987 
989  int16_t writeFlashRow(uint32_t address)
990  {
991  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
992  1, // Write entire row
993  SW_LE32(address),0x55,0x55 };
994  return sendPacket(tx);
995  }
996 
997 
1004  uint16_t _supplyVoltagemV = 0;
1005 
1007  uint8_t model[4] = { 0 };
1008 
1010  uint8_t fwVersion[4] = { 0 };
1011 
1017  uint8_t uniqueIdentifier[16];
1018 
1024 
1030 
1035  uint16_t deviceRevision;
1037  uint16_t errorCount = 0;
1038 
1040  bool inBoot = false;
1041 
1051  int16_t setThroughputPin(uint8_t pin)
1052  {
1053  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1054  return sendPacket(tx);
1055  }
1056 
1064  int writeUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1065  {
1066  uint16_t bytesSent = 0;
1067  if (count == 0)
1068  {
1069  return 0;
1070  }
1071 
1072  { // Send first packet of up to 4 bytes
1073  uint8_t bytesToSend = 4;
1074  if (count < 4)
1075  {
1076  bytesToSend = (uint8_t)count;
1077  count = 0;
1078  }
1079  else
1080  {
1081  count -= 4;
1082  }
1083 
1084  uint8_t tx[8] = { 0x84,SW_LE16(index), bytesToSend,0x55,0x55,0x55,0x55 };
1085  uint8_t rx[8];
1086 
1087  uint8_t i;
1088  for (i = 0; i < bytesToSend; ++i)
1089  {
1090  tx[4 + i] = buffer[i];
1091  }
1092  int result = sendPacket(tx, rx);
1093  if (rx[0] == 'E')
1094  {
1095  return (result);
1096  }
1097  bytesSent = bytesToSend;
1098  }
1099  while (count >= 7) // Continue sending
1100  {
1101 
1102  count -= 7;
1103  uint8_t tx[8] = { 0x85,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1104  uint8_t rx[8];
1105  uint8_t i;
1106  for (i = 0; i < 7; ++i)
1107  {
1108  tx[1 + i] = buffer[bytesSent + i];
1109  }
1110  int result = sendPacket(tx, rx);
1111  if (rx[0] == 'E')
1112  {
1113  return (result);
1114  }
1115  bytesSent += 7;
1116  }
1117  while (count > 0)
1118  {
1119 
1120  { // Send first packet of up to 4 bytes
1121  uint8_t bytesToSend = 4;
1122  if (count < 4)
1123  {
1124  bytesToSend = (uint8_t)count;
1125  count = 0;
1126  }
1127  else
1128  {
1129  count -= 4;
1130  }
1131 
1132  uint8_t tx[8] = { 0x84,SW_LE16(index + bytesSent), bytesToSend,0x55,0x55,0x55,0x55 };
1133  uint8_t rx[8];
1134 
1135  uint8_t i;
1136  for (i = 0; i < bytesToSend; ++i)
1137  {
1138  tx[4 + i] = buffer[i + bytesSent];
1139  }
1140  int result = sendPacket(tx, rx);
1141  if (rx[0] == 'E')
1142  {
1143  return (result);
1144  }
1145  bytesSent += bytesToSend;
1146  }
1147  }
1148  return(bytesSent);
1149 
1150 
1151  }
1152 
1160  int writeUserBuffer(uint16_t index, char* s)
1161  {
1162  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1163  }
1164 
1172  int writeUserBuffer(uint16_t index, const char s[])
1173  {
1174  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1175  }
1176 
1185  int readUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1186  {
1187  uint16_t bytesRead = 0;
1188  while (bytesRead < count)
1189  {
1190  uint8_t tx[] = {(uint8_t) SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER, SW_LE16(index),0x55,0x55,0x55,0x55,0x55 };
1191  uint8_t rx[8];
1192  int16_t result = sendPacket(tx, rx);
1193  if (result >= 0)
1194  {
1195  for (int i = 1; i < 8; ++i)
1196  {
1197  buffer[bytesRead] = rx[i];
1198  ++bytesRead;
1199  if (bytesRead >= count)
1200  {
1201  break;
1202  }
1203  }
1204  }
1205  else
1206  {
1207  return (bytesRead);
1208  }
1209  }
1210  return (bytesRead);
1211  }
1218  int16_t enable2ndCommandInterface(bool enabled = true)
1219  {
1220  uint8_t tx[] = { 0xA6,0,0xB2, 0xA5, 0x61, 0x73, 0xF8 ,0xA2 };
1221  if (enabled)
1222  {
1223  tx[1] = 1;
1224  }
1225  return sendPacket(tx);
1226  }
1227 
1238  {
1239  uint8_t tx[] = { 0xB3,0,(uint8_t)'C', (uint8_t)'A', (uint8_t)'P',(uint8_t)'T',(uint8_t)'U',(uint8_t)'R' };
1240  return sendPacket(tx);
1241  }
1242 
1248  {
1249  uint8_t tx[] = { 0xB3,1,(uint8_t)'C', (uint8_t)'A', (uint8_t)'P',(uint8_t)'T',(uint8_t)'U',(uint8_t)'R' };
1250  return sendPacket(tx);
1251  }
1252 
1253 
1266  {
1267  uint8_t tx[] = { 0xB3,2,(uint8_t)'C', (uint8_t)'A', (uint8_t)'P',(uint8_t)'T',(uint8_t)'U',(uint8_t)'R' };
1268  return sendPacket(tx);
1269  }
1270 
1271 
1283  int16_t writeFrameTimerPin(uint8_t pin)
1284 {
1285  uint8_t tx[] = { 0xC8 ,pin,(uint8_t)PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1286  return sendPacket(tx);
1287 }
1288 
1289 
1297  static uint8_t find(bool keepTrying = false)
1298  {
1299  do
1300  {
1301  for (int i2cAddress = 0x68; i2cAddress <= 0x6F; ++i2cAddress)
1302  {
1303  Wire.beginTransmission(i2cAddress);
1304  int error = Wire.endTransmission();
1305 
1306 
1307  if (error == 0)
1308  {
1309  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1310  uint8_t rx[8];
1311  Wire.beginTransmission(i2cAddress);
1312  Wire.write(tx, 8);
1313  Wire.endTransmission();
1314  Wire.requestFrom((uint8_t)i2cAddress, (uint8_t)8);
1315 
1316  int count = 0;
1317  while (Wire.available() && count < 8)
1318  {
1319  rx[count] = Wire.read();
1320  ++count;
1321  }
1322  if (count == 8)
1323  {
1324  if (rx[0] == 'V' && rx[1] == 'S')
1325  {
1326  return(i2cAddress); // Found one.
1327  }
1328  }
1329  }
1330  }
1331  delay(0);
1332  }while (keepTrying);
1333  return(0); // Didn't find one.
1334  }
1335 
1337  int16_t lastErrorCode = 0;
1338 
1345  int16_t readLastErrorCommand(uint8_t* cmd)
1346 {
1347  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET, 0,0x55,0x55,0x55,0x55,0x55,0x55 };
1348  uint8_t rx[8];
1349  if (sendPacket(tx, rx) >= 0)
1350  {
1351  for (int i = 1; i < 8; ++i)
1352  {
1353  cmd[i - 1] = rx[i];
1354  }
1355  }
1356  else
1357  {
1358  return (-1);
1359  }
1360  tx[1] = 7;
1361  if (sendPacket(tx, rx) >= 0)
1362  {
1363  cmd[7] = rx[1];
1364  return(0);
1365  }
1366  else
1367  {
1368  return (-1);
1369  }
1370 }
1371 
1377  {
1378  errorHandler = handler;
1379  }
1380 
1382  uint8_t address = 0;
1383 
1386 
1387  int16_t echo(uint8_t data[], uint8_t count = 7)
1388  {
1389  uint8_t tx[] = "!UUUUUUU";
1390  for (int i = 0; i < 7 && i < count; ++i)
1391  {
1392  tx[i + 1] = (uint8_t)data[i];
1393  }
1394  return sendPacket(tx);
1395  }
1396 
1397 
1398  int16_t echo(char* data)
1399  {
1400  int length = strlen(data);
1401  uint8_t tx[] = "!UUUUUUU";
1402  for (int i = 0; i < 7 && i < length; ++i)
1403  {
1404  tx[i + 1] = (uint8_t)data[i];
1405  }
1406  return sendPacket(tx);
1407  }
1408 
1409  uint32_t readBirthday()
1410  {
1411  if (isSW18())
1412  {
1413  uint32_t birthday = (readFlashAddress(0x2A00C) >> 8) & 0xFF;
1414  birthday *= 100;
1415  birthday += (readFlashAddress(0x2A00C)) & 0xFF;
1416  birthday *= 100;
1417  birthday += readFlashAddress(0x2A00E) & 0xFF;
1418  birthday *= 100;
1419  birthday += readFlashAddress(0x2A010) & 0xFF;
1420  return (birthday);
1421  }
1422  return 0;
1423  }
1424 
1425  int16_t readBrand(char* data)
1426  {
1427  uint8_t length = 0;
1428  if (isSW18())
1429  {
1430  for (int i = 0; i < 32; ++i)
1431  {
1432  uint32_t val = readFlashAddress(0x2A020 + i * 2) ;
1433  if ((val & 0xFF) != 0xFF)
1434  {
1435  data[i ] = (char)(val & 0xFF);
1436  ++length;
1437  }
1438  else
1439  {
1440  data[length] = 0;
1441  return (length);
1442  }
1443  }
1444  data[length] = 0;
1445  return (length);
1446  }
1447 
1448  data[0] = 0;
1449  return 0 ;
1450  }
1451 
1452 };
1453 
1455 class SerialWombat : public SerialWombatChip {};
1456 
1457 
1458 
1471 {
1472 public:
1477  SerialWombatPin(SerialWombatChip& serialWombatChip): _sw(serialWombatChip)
1478  {
1479  }
1480 
1486  SerialWombatPin(SerialWombatChip& serialWombatChip, uint8_t pin): _sw(serialWombatChip)
1487  {
1488  _pin = pin;
1489  }
1490 
1497  uint16_t readPublicData()
1498  {
1499  return _sw.readPublicData(_pin);
1500  };
1501 
1502 
1511  void pinMode(uint8_t mode, bool pullDown = false, bool openDrain = false)
1512  {
1513  _sw.pinMode(_pin, mode, pullDown, openDrain);
1514  }
1515 
1524  void digitalWrite(uint8_t val)
1525  {
1526  _sw.digitalWrite(_pin, val);
1527  }
1528 
1537  {
1538  return (_sw.digitalRead(_pin));
1539  }
1540 
1541 
1546  uint16_t writePublicData(uint16_t value)
1547  { return _sw.writePublicData(_pin, value); }
1548 
1553  uint8_t pin() {return _pin;}
1554 
1559  uint8_t swPinModeNumber() { return _pinMode; }
1560 
1561 
1562 
1563 
1564 protected:
1565  uint8_t _pin = 255;
1567  uint8_t _pinMode = 0;
1568 
1569 };
1570 
1571 
1579 void SerialWombatSerialErrorHandlerBrief(uint16_t error, SerialWombatChip* sw);
1581 
1582 #include "SerialWombatErrors.h"
1583 #include "SerialWombatQueue.h"
1587 #include "SerialWombat18CapTouch.h"
1588 #include "SerialWombat18ABVGA.h"
1589 #include "SerialWombatAnalogInput.h"
1591 #include "SerialWombatHSClock.h"
1592 #include "SerialWombatHSCounter.h"
1593 #include "SerialWombatLiquidCrystal.h"
1594 #include "SerialWombatMatrixKeypad.h"
1597 #include "SerialWombatPS2Keyboard.h"
1598 #include "SerialWombatPulseOnChange.h"
1599 #include "SerialWombatPulseTimer.h"
1600 #include "SerialWombatPWM.h"
1601 #include "SerialWombatQuadEnc.h"
1603 #include "SerialWombatServo.h"
1604 #include "SerialWombatTM1637.h"
1605 #include "SerialWombatUART.h"
1607 #include "SerialWombatWatchdog.h"
1608 #include "SerialWombatWS2812.h"
1610 
1611 #endif
SerialWombatPulseOnChange.h
SerialWombatDataSource::SW_DATA_SOURCE_1HZ_SAW
@ SW_DATA_SOURCE_1HZ_SAW
(168) Sawtooth wave that goes from 0 to 65535 to 0 every 1024 frames
SerialWombatCommands::CONFIGURE_PIN_MODE10
@ CONFIGURE_PIN_MODE10
(210)
SerialWombatCommands::CMD_READ_BUFFER_ASCII
@ CMD_READ_BUFFER_ASCII
('G')
SerialWombatChip::writeFrameTimerPin
int16_t writeFrameTimerPin(uint8_t pin)
Set a pin to be a frame timer for system utilization (SW18AB Only)
Definition: SerialWombat.h:1283
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:279
SerialWombatChip::begin
int16_t begin(HardwareSerial &serial)
initialize a Serial Wombat chip to use a Serial Interface.
Definition: SerialWombat.cpp:41
PIN_MODE_ANALOGINPUT
@ PIN_MODE_ANALOGINPUT
(2)
Definition: SerialWombat.h:240
SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET
@ COMMAND_READ_LAST_ERROR_PACKET
(0xA7)
SerialWombatCommands::COMMAND_ENABLE_2ND_UART
@ COMMAND_ENABLE_2ND_UART
(0xA6)
SerialWombatChip::jumpToBoot
void jumpToBoot()
Jump to Bootloader and wait for a UART download of new firmware.
Definition: SerialWombat.h:864
SerialWombatQuadEnc.h
SerialWombatCommands::CMD_VERSION
@ CMD_VERSION
('V')
SerialWombatDataSource::SW_DATA_SOURCE_PIN_8
@ SW_DATA_SOURCE_PIN_8
(8) 16 bit public data provided by Pin 8
SerialWombatWatchdog.h
SerialWombatChip::writeUserBuffer
int writeUserBuffer(uint16_t index, char *s)
Write bytes to the User Memory Buffer in the Serial Wombat chip.
Definition: SerialWombat.h:1160
PIN_MODE_PULSE_ON_CHANGE
@ PIN_MODE_PULSE_ON_CHANGE
(25)
Definition: SerialWombat.h:259
PIN_MODE_SW18AB_CAPTOUCH
@ PIN_MODE_SW18AB_CAPTOUCH
(22)
Definition: SerialWombat.h:256
SerialWombatHSClock.h
PIN_MODE_HS_CLOCK
@ PIN_MODE_HS_CLOCK
Definition: SerialWombat.h:263
PIN_MODE_UART1_RX_TX
@ PIN_MODE_UART1_RX_TX
(23)
Definition: SerialWombat.h:257
SerialWombatCommands::COMMAND_BINARY_QUEUE_INFORMATION
@ COMMAND_BINARY_QUEUE_INFORMATION
(0x94)
SerialWombatWS2812.h
PIN_MODE_DEBOUNCE
@ PIN_MODE_DEBOUNCE
(10)
Definition: SerialWombat.h:246
SerialWombatDataSource::SW_DATA_SOURCE_1024mvCounts
@ SW_DATA_SOURCE_1024mvCounts
(66) The number of ADC counts that result from a 1.024V reading
SerialWombatCommands::CONFIGURE_PIN_MODE0
@ CONFIGURE_PIN_MODE0
(200)
SerialWombatErrorHandler_t
void(* SerialWombatErrorHandler_t)(uint16_t errorNumber, SerialWombatChip *sw)
Definition: SerialWombat.h:272
SerialWombatCommands::COMMAND_UART0_RX_7BYTES
@ COMMAND_UART0_RX_7BYTES
(0xB1)
SerialWombatChip::lastErrorCode
int16_t lastErrorCode
The last error code returned as part of a protocol error message expressed as a positive integer.
Definition: SerialWombat.h:1337
SerialWombatChip::readPublicData
uint16_t readPublicData(SerialWombatDataSource dataSource)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:615
SerialWombatDataSource::SW_DATA_SOURCE_PIN_9
@ SW_DATA_SOURCE_PIN_9
(9) 16 bit public data provided by Pin 9
SerialWombatChip::digitalRead
int digitalRead(uint8_t pin)
Reads the state of a Pin / /.
Definition: SerialWombat.h:743
SerialWombatChip::sendPacketNoResponse
int sendPacketNoResponse(uint8_t tx[])
Send an 8 byte packet to the Serial Wombat chip, don't wait for a response.
Definition: SerialWombat.cpp:315
SerialWombatPinMode_t
SerialWombatPinMode_t
Definition: SerialWombat.h:237
SerialWombatAnalogInput.h
SerialWombatChip::analogRead
int analogRead(uint8_t pin)
Configures pin as analog input and does an immediate A/D conversion.
Definition: SerialWombat.h:764
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition: SerialWombat.h:1477
SerialWombatPin::swPinModeNumber
uint8_t swPinModeNumber()
Returns the Mode number. Used primarily by derived classes to populate packet data.
Definition: SerialWombat.h:1559
SerialWombatAbstractButton.h
SerialWombatDataSource::SW_DATA_SOURCE_LFSR
@ SW_DATA_SOURCE_LFSR
(78) A Linear Feedback Shift Register that produces a Pseudo random sequence of 16 bit values
SerialWombatDataSource::SW_DATA_SOURCE_PIN_15
@ SW_DATA_SOURCE_PIN_15
(15) 16 bit public data provided by Pin 15
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition: SerialWombat.h:1566
SerialWombatDataSource::SW_DATA_SOURCE_PIN_16_MV
@ SW_DATA_SOURCE_PIN_16_MV
(116) Pin 16 public output expressed in mV (for analog modes only)
SerialWombatCommands::CONFIGURE_PIN_MODE7
@ CONFIGURE_PIN_MODE7
(207)
SerialWombatChip::analogWrite
void analogWrite(uint8_t pin, int val)
Set a pin to PWM output.
Definition: SerialWombat.h:783
PIN_MODE_WATCHDOG
@ PIN_MODE_WATCHDOG
(7)
Definition: SerialWombat.h:244
PIN_MODE_CONTROLLED
@ PIN_MODE_CONTROLLED
(1)
Definition: SerialWombat.h:239
PIN_MODE_SW_UART
@ PIN_MODE_SW_UART
(13)
Definition: SerialWombat.h:249
SerialWombatChip::queryVersion
bool queryVersion()
Send a version request to the Serial Wombat chip.
Definition: SerialWombat.h:805
SerialWombatChip::setThroughputPin
int16_t setThroughputPin(uint8_t pin)
Set a pin to be a throughput monitoring pin.
Definition: SerialWombat.h:1051
SerialWombatChip::enable2ndCommandInterface
int16_t enable2ndCommandInterface(bool enabled=true)
Enable UART command interface in addition to I2C (SW18AB Only)
Definition: SerialWombat.h:1218
PIN_MODE_PS2KEYBOARD
@ PIN_MODE_PS2KEYBOARD
(32)
Definition: SerialWombat.h:266
SerialWombatPin::writePublicData
uint16_t writePublicData(uint16_t value)
Write a 16 bit value to this pin.
Definition: SerialWombat.h:1546
SerialWombatLiquidCrystal.h
SerialWombatChip::readSupplyVoltage_mV
uint16_t readSupplyVoltage_mV(void)
Measure the Serial Wombat chip's Supply voltage.
Definition: SerialWombat.h:643
SerialWombatCommands::CONFIGURE_PIN_MODE3
@ CONFIGURE_PIN_MODE3
(203)
SerialWombatChip::inBoot
bool inBoot
Set to true if boot mode is indicated by a version query.
Definition: SerialWombat.h:1040
SerialWombatChip::_supplyVoltagemV
uint16_t _supplyVoltagemV
Definition: SerialWombat.h:1004
SerialWombat18ABVGA.h
SerialWombat18CapTouch.h
PIN_MODE_RESISTANCEINPUT
@ PIN_MODE_RESISTANCEINPUT
(24)
Definition: SerialWombat.h:258
SerialWombatChip::readFramesExecuted
uint32_t readFramesExecuted()
Get the number of 1mS frames that have been executed since Serial Wombat chip reset.
Definition: SerialWombat.h:833
SerialWombatDataSource::SW_DATA_SOURCE_2SEC_SAW
@ SW_DATA_SOURCE_2SEC_SAW
(171)Sawtooth wave that goes from 0 to 65535 to 0 every 2048 frames
SerialWombatDataSource::SW_DATA_SOURCE_VBG_COUNTS_VS_VREF
@ SW_DATA_SOURCE_VBG_COUNTS_VS_VREF
(76) A/D conversion of VBG against VRef . Used for mfg calibration
PIN_MODE_TM1637
@ PIN_MODE_TM1637
(11)
Definition: SerialWombat.h:247
SerialWombatChip::wake
void wake()
Called to send a dummy packet to the Serial Wombat chip to wake it from sleep and ready it for other ...
Definition: SerialWombat.h:965
SerialWombatDataSource::SW_DATA_SOURCE_PIN_17_MV
@ SW_DATA_SOURCE_PIN_17_MV
(117) Pin 17 public output expressed in mV (for analog modes only)
SerialWombatChip::pinMode
void pinMode(uint8_t pin, uint8_t mode, bool pullDown=false, bool openDrain=false)
Set a pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
Definition: SerialWombat.h:714
PIN_MODE_PWM
@ PIN_MODE_PWM
(16)
Definition: SerialWombat.h:252
SerialWombatHSCounter.h
SerialWombatDataSource::SW_DATA_SOURCE_2HZ_SAW
@ SW_DATA_SOURCE_2HZ_SAW
(165) Sawtooth wave that goes from 0 to 65535 to 0 every 512 frames
SerialWombatCommands::COMMAND_BINARY_WRITE_RAM
@ COMMAND_BINARY_WRITE_RAM
(0xA3)
SerialWombatServo.h
SerialWombatCommands::COMMAND_BINARY_WRITE_USER_BUFFER
@ COMMAND_BINARY_WRITE_USER_BUFFER
(0x84)
SerialWombatProtectedOutput.h
SerialWombatCommands::CONFIGURE_PIN_MODE8
@ CONFIGURE_PIN_MODE8
(208)
SerialWombatCommands::COMMAND_UART1_TX_7BYTES
@ COMMAND_UART1_TX_7BYTES
(0xB2)
SerialWombatDataSource::SW_DATA_SOURCE_PIN_4_MV
@ SW_DATA_SOURCE_PIN_4_MV
(104) Pin 4 public output expressed in mV (for analog modes only)
PIN_MODE_SERVO
@ PIN_MODE_SERVO
(3)
Definition: SerialWombat.h:241
SerialWombatDataSource::SW_DATA_SOURCE_SYSTEM_UTILIZATION
@ SW_DATA_SOURCE_SYSTEM_UTILIZATION
(74) A number between 0 and 65535 that scales to the average length of pin processing frames between ...
SerialWombatCommands::COMMAND_BINARY_QUEUE_READ_BYTES
@ COMMAND_BINARY_QUEUE_READ_BYTES
(0x93)
SerialWombatPWM.h
SerialWombatCommands::CONFIGURE_PIN_MODE4
@ CONFIGURE_PIN_MODE4
(204)
SerialWombatSerialErrorHandlerBrief
void SerialWombatSerialErrorHandlerBrief(uint16_t error, SerialWombatChip *sw)
a sample error handler that can be registered with registerErrorHandler to report protocol errors on ...
Definition: SerialWombat.cpp:385
SerialWombatChip::SerialWombatChip
SerialWombatChip()
Definition: SerialWombat.cpp:30
SerialWombatDataSource::SW_DATA_SOURCE_65SEC_SAW
@ SW_DATA_SOURCE_65SEC_SAW
(177 )Sawtooth wave that goes from 0 to 65535 to 0 every 65536 frames
SerialWombatQueue.h
SerialWombatChip::hardwareReset
void hardwareReset()
Send a reset command to the Serial Wombat chip.
Definition: SerialWombat.h:699
PIN_MODE_PULSETIMER
@ PIN_MODE_PULSETIMER
(18)
Definition: SerialWombat.h:254
SerialWombatChip::uniqueIdentifierLength
uint8_t uniqueIdentifierLength
Definition: SerialWombat.h:1023
SerialWombatPin::digitalRead
int digitalRead()
Reads the state of the Pin.
Definition: SerialWombat.h:1536
SerialWombatChip::eraseFlashPage
int16_t eraseFlashPage(uint32_t address)
Erases a page in flash. Intended for use with the Bootloader, not by end users outside of bootloading...
Definition: SerialWombat.h:978
SerialWombatChip::readLastErrorCommand
int16_t readLastErrorCommand(uint8_t *cmd)
Returns the last Serial Wombat command that produced a protocol error.
Definition: SerialWombat.h:1345
SerialWombatDataSource::SW_DATA_SOURCE_NONE
@ SW_DATA_SOURCE_NONE
(255 ) Used to mean "No Source Selected"
SW_HIGH
@ SW_HIGH
Definition: SerialWombat.h:50
SerialWombatTM1637.h
SerialWombatDataSource::SW_DATA_SOURCE_PIN_2
@ SW_DATA_SOURCE_PIN_2
(2) 16 bit public data provided by Pin 2
SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW
@ SW_DATA_SOURCE_FRAMES_RUN_LSW
(67) The number of frames run since reset, least significant 16 bits
SerialWombatAbstractProcessedInput.h
SerialWombatDataSource::SW_DATA_SOURCE_DROPPED_FRAMES
@ SW_DATA_SOURCE_DROPPED_FRAMES
(73) The number of times since reset that a frame ran so far behind that it crossed two subsequent 1m...
SerialWombatCommands::COMMAND_BINARY_WRITE_USER_BUFFER_CONTINUE
@ COMMAND_BINARY_WRITE_USER_BUFFER_CONTINUE
(0x85)
SerialWombatDataSource::SW_DATA_SOURCE_VCC_mVOLTS
@ SW_DATA_SOURCE_VCC_mVOLTS
(75) The system source voltage in mV
SerialWombatChip::digitalWrite
void digitalWrite(uint8_t pin, uint8_t val)
Set an output pin High or Low.
Definition: SerialWombat.h:733
SerialWombatDataSource::SW_DATA_SOURCE_TEMPERATURE
@ SW_DATA_SOURCE_TEMPERATURE
(70)The internal core temperature expressed in 100ths deg C
SerialWombatCommands::CMD_SET_BUFFER_ASCII
@ CMD_SET_BUFFER_ASCII
('S')
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip, uint8_t pin)
Instantiates a Serial Wombat Pin.
Definition: SerialWombat.h:1486
SerialWombatDataSource::SW_DATA_SOURCE_PIN_14
@ SW_DATA_SOURCE_PIN_14
(14) 16 bit public data provided by Pin 14
PIN_MODE_MATRIX_KEYPAD
@ PIN_MODE_MATRIX_KEYPAD
(15)
Definition: SerialWombat.h:251
SerialWombatDataSource::SW_DATA_SOURCE_PIN_0_MV
@ SW_DATA_SOURCE_PIN_0_MV
(100) Pin 0 public output expressed in mV (for analog modes only)
SerialWombatChip::readUserBuffer
int readUserBuffer(uint16_t index, uint8_t *buffer, uint16_t count)
Read bytes from the User Memory Buffer in the Serial Wombat chip.
Definition: SerialWombat.h:1185
SerialWombatChip::readOverflowFrames
uint16_t readOverflowFrames()
Get the number of times an overflow Frame has occured.
Definition: SerialWombat.h:850
SerialWombatCommands::CONFIGURE_PIN_MODE9
@ CONFIGURE_PIN_MODE9
(209)
SerialWombatChip::deviceIdentifier
uint16_t deviceIdentifier
Definition: SerialWombat.h:1029
SerialWombatDataSource::SW_DATA_SOURCE_8SEC_SAW
@ SW_DATA_SOURCE_8SEC_SAW
(174)Sawtooth wave that goes from 0 to 65535 to 0 every 8192 frames
SerialWombatCommands
SerialWombatCommands
Definition: SerialWombat.h:182
SW_LE32
#define SW_LE32(_a)
Convert a uint32_t to four bytes in little endian format for array initialization.
Definition: SerialWombat.h:44
SerialWombatChip::find
static uint8_t find(bool keepTrying=false)
Search the I2C Bus addresses 0x68 to 0x6F for I2C devices, and test to see if they respond to Serial ...
Definition: SerialWombat.h:1297
SerialWombatChip::readPublicData
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:598
SerialWombatUART.h
SerialWombatPin
Describes a Serial Wombat Pin. Is base class for other pin modes.
Definition: SerialWombat.h:1470
SerialWombatDataSource::SW_DATA_SOURCE_PIN_0
@ SW_DATA_SOURCE_PIN_0
(0) 16 bit public data provided by Pin 0
PIN_MODE_HS_COUNTER
@ PIN_MODE_HS_COUNTER
< (29)
Definition: SerialWombat.h:264
SerialWombatChip::readFlashAddress
uint32_t readFlashAddress(uint32_t address)
Read Address from Flash based on 32 bit address.
Definition: SerialWombat.h:939
SerialWombatChip::readTemperature_100thsDegC
int16_t readTemperature_100thsDegC(void)
Measure the Serial Wombat chip's internal temperature.
Definition: SerialWombat.h:676
SerialWombatChip::uniqueIdentifier
uint8_t uniqueIdentifier[16]
Definition: SerialWombat.h:1017
WOMBAT_MAXIMUM_PINS
#define WOMBAT_MAXIMUM_PINS
Definition: SerialWombat.h:180
SerialWombatCommands::CONFIGURE_CHANNEL_MODE_HW_3
@ CONFIGURE_CHANNEL_MODE_HW_3
(223)
SerialWombatChip::writeFlashRow
int16_t writeFlashRow(uint32_t address)
Writes a row in flash. Intended for use with the Bootloader, not by end users outside of bootloading ...
Definition: SerialWombat.h:989
SerialWombatChip::errorCount
uint16_t errorCount
Incremented every time a communication or command error is detected.
Definition: SerialWombat.h:1037
SerialWombatChip::readRamAddress
uint8_t readRamAddress(uint16_t address)
Read Address from RAM based on 16 bit address.
Definition: SerialWombat.h:890
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition: SerialWombat.h:1567
SerialWombatChip::readBirthday
uint32_t readBirthday()
Definition: SerialWombat.h:1409
SerialWombatDataSource::SW_DATA_SOURCE_PIN_3
@ SW_DATA_SOURCE_PIN_3
(3) 16 bit public data provided by Pin 3
SerialWombatChip::writeRamAddress
int16_t writeRamAddress(uint16_t address, uint8_t value)
Write byte to Address in RAM based on 16 bit address.
Definition: SerialWombat.h:918
SerialWombatCommands::COMMAND_BINARY_READ_FLASH
@ COMMAND_BINARY_READ_FLASH
(0xA1)
SerialWombatCommands::CMD_ASCII_SET_PIN
@ CMD_ASCII_SET_PIN
('P')
SerialWombatDataSource::SW_DATA_SOURCE_PACKETS_RECEIVED
@ SW_DATA_SOURCE_PACKETS_RECEIVED
(71) The nubmer of incoming command packets that have been processed since reset (rolls over at 65535...
SerialWombatCommands::CONFIGURE_CHANNEL_MODE_HW_2
@ CONFIGURE_CHANNEL_MODE_HW_2
(222)
SerialWombatChip::sendPacket
int sendPacket(uint8_t tx[], uint8_t rx[])
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
Definition: SerialWombat.cpp:139
SerialWombatChip::begin
auto begin(TwoWire &wire, uint8_t i2cAddress, bool reset=true) -> int16_t
initialize a Serial Wombat chip to use a specified I2C Interface and address.
Definition: SerialWombat.h:466
SerialWombatCommands::CONFIGURE_PIN_MODE_HW_0
@ CONFIGURE_PIN_MODE_HW_0
(220)
PIN_MODE_WS2812
@ PIN_MODE_WS2812
(12)
Definition: SerialWombat.h:248
PIN_MODE_UNKNOWN
@ PIN_MODE_UNKNOWN
(0xFF)
Definition: SerialWombat.h:267
SerialWombatCommands::COMMAND_CALIBRATE_ANALOG
@ COMMAND_CALIBRATE_ANALOG
(0xA5)
SerialWombatDataSource::SW_DATA_SOURCE_PIN_10
@ SW_DATA_SOURCE_PIN_10
(10) 16 bit public data provided by Pin 10
SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH
@ COMMAND_BINARY_WRITE_FLASH
(0xA4)
SerialWombatChip::deviceRevision
uint16_t deviceRevision
Definition: SerialWombat.h:1035
SerialWombatPin::readPublicData
uint16_t readPublicData()
Read the 16 Bit public data associated with this pin.
Definition: SerialWombat.h:1497
SerialWombatDataSource::SW_DATA_SOURCE_PIN_16
@ SW_DATA_SOURCE_PIN_16
(16) 16 bit public data provided by Pin 16
SerialWombatDataSource::SW_DATA_SOURCE_PIN_1
@ SW_DATA_SOURCE_PIN_1
(1) 16 bit public data provided by Pin 1
SerialWombatDataSource::SW_DATA_SOURCE_2SEC_SQUARE
@ SW_DATA_SOURCE_2SEC_SQUARE
(170)Square wave that alternates between 0 and 65535 every 1024 frames
SerialWombatChip::sleep
void sleep()
Shuts down most functions of the Serial Wombat chip reducing power consumption.
Definition: SerialWombat.h:957
SerialWombatChip::writePublicData
uint16_t writePublicData(uint8_t pin, uint16_t value)
Write a 16 bit value to a Serial Wombat pin Mode.
Definition: SerialWombat.h:625
SerialWombatErrors.h
SerialWombatPS2Keyboard.h
SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW
@ SW_DATA_SOURCE_FRAMES_RUN_MSW
(68) The number of frames run since reset, most significant 16 bits
SerialWombatUltrasonicDistanceSensor.h
SerialWombatChip::writeUserBuffer
int writeUserBuffer(uint16_t index, uint8_t *buffer, uint16_t count)
Write bytes to the User Memory Buffer in the Serial Wombat chip.
Definition: SerialWombat.h:1064
SerialWombatDataSource::SW_DATA_SOURCE_PIN_3_MV
@ SW_DATA_SOURCE_PIN_3_MV
(103) Pin 3 public output expressed in mV (for analog modes only)
SerialWombatPinState_t
SerialWombatPinState_t
Definition: SerialWombat.h:47
SerialWombatCommands::CONFIGURE_PIN_OUTPUTSCALE
@ CONFIGURE_PIN_OUTPUTSCALE
(210)
SerialWombatChip::readVersion
char * readVersion(void)
Request version string (combined model and firmware) and return pointer to it.
Definition: SerialWombat.h:560
SerialWombatCommands::COMMAND_BINARY_CONFIGURE
@ COMMAND_BINARY_CONFIGURE
(0x9F)
SerialWombatChip::readVersion_uint32
uint32_t readVersion_uint32(void)
Request version as a uint32.
Definition: SerialWombat.h:581
SerialWombatChip::fwVersion
uint8_t fwVersion[4]
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:1010
SW_INPUT
@ SW_INPUT
Definition: SerialWombat.h:51
SerialWombatChip::~SerialWombatChip
~SerialWombatChip()
Definition: SerialWombat.cpp:36
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition: SerialWombat.h:1553
SerialWombatChip::echo
int16_t echo(char *data)
Definition: SerialWombat.h:1398
SerialWombatDataSource::SW_DATA_SOURCE_INCREMENTING_NUMBER
@ SW_DATA_SOURCE_INCREMENTING_NUMBER
(65) An number that increments each time it is accessed.
SerialWombat
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.
Definition: SerialWombat.h:1455
SerialWombatCommands::CONFIGURE_CHANNEL_MODE_HW_1
@ CONFIGURE_CHANNEL_MODE_HW_1
(221)
SW_LOW
@ SW_LOW
Definition: SerialWombat.h:49
PIN_MODE_THROUGHPUT_CONSUMER
@ PIN_MODE_THROUGHPUT_CONSUMER
(4)
Definition: SerialWombat.h:242
SerialWombatMatrixKeypad.h
SerialWombatCommands::CMD_RESYNC
@ CMD_RESYNC
('U')
SerialWombatDataSource::SW_DATA_SOURCE_PIN_18
@ SW_DATA_SOURCE_PIN_18
(18) 16 bit public data provided by Pin 18
SerialWombatDataSource::SW_DATA_SOURCE_PIN_4
@ SW_DATA_SOURCE_PIN_4
(4) 16 bit public data provided by Pin 4
SerialWombatDataSource
SerialWombatDataSource
A list of Serial Wombat public data sources.
Definition: SerialWombat.h:56
PIN_MODE_INPUT_PROCESSOR
@ PIN_MODE_INPUT_PROCESSOR
(14)
Definition: SerialWombat.h:250
SerialWombatCommands::COMMAND_UART1_RX_7BYTES
@ COMMAND_UART1_RX_7BYTES
(0xB3)
SerialWombatChip::echo
int16_t echo(uint8_t data[], uint8_t count=7)
Definition: SerialWombat.h:1387
SerialWombatDataSource::SW_DATA_SOURCE_PIN_13
@ SW_DATA_SOURCE_PIN_13
(13) 16 bit public data provided by Pin 13
SerialWombatPin::_pin
uint8_t _pin
Definition: SerialWombat.h:1565
SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER
@ COMMAND_BINARY_READ_USER_BUFFER
(0x83)
SerialWombatChip::startStartupCommandCapture
int16_t startStartupCommandCapture()
Start capture of startup commands (SW18AB Only)
Definition: SerialWombat.h:1237
SerialWombatProcessedInputPin.h
SerialWombatDataSource::SW_DATA_SOURCE_PIN_1_MV
@ SW_DATA_SOURCE_PIN_1_MV
(101) Pin 1 public output expressed in mV (for analog modes only)
SerialWombatDataSource::SW_DATA_SOURCE_PIN_17
@ SW_DATA_SOURCE_PIN_17
(17) 16 bit public data provided by Pin 17
SerialWombatDataSource::SW_DATA_SOURCE_PIN_19_MV
@ SW_DATA_SOURCE_PIN_19_MV
(119) Pin 19 public output expressed in mV (for analog modes only)
PIN_MODE_QUADRATUREENCODER
@ PIN_MODE_QUADRATUREENCODER
(5)
Definition: SerialWombat.h:243
SerialWombatThroughputConsumer.h
SerialWombatChip::stopStartupCommandCapture
int16_t stopStartupCommandCapture()
Stop capture of startup commands (SW18AB Only)
Definition: SerialWombat.h:1247
SerialWombatChip::communicationErrorRetries
uint8_t communicationErrorRetries
How many times to retry a packet if communcation bus (such as I2C) error.
Definition: SerialWombat.h:1385
SerialWombatCommands::CONFIGURE_PIN_MODE2
@ CONFIGURE_PIN_MODE2
(202)
SerialWombatCommands::CMD_RESET
@ CMD_RESET
('R')
SerialWombatDebouncedInput.h
PIN_MODE_FRAME_TIMER
@ PIN_MODE_FRAME_TIMER
(21)
Definition: SerialWombat.h:255
SerialWombatCommands::CONFIGURE_PIN_INPUTPROCESS
@ CONFIGURE_PIN_INPUTPROCESS
(211)
PIN_MODE_LIQUIDCRYSTAL
@ PIN_MODE_LIQUIDCRYSTAL
(28)
Definition: SerialWombat.h:262
SerialWombatCommands::COMMAND_BINARY_READ_PIN_BUFFFER
@ COMMAND_BINARY_READ_PIN_BUFFFER
(0x81)
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition: SerialWombat.h:41
SerialWombatAbstractScaledOutput.h
PIN_MODE_PROTECTED_OUTPUT
@ PIN_MODE_PROTECTED_OUTPUT
(8)
Definition: SerialWombat.h:245
SerialWombatChip::model
uint8_t model[4]
Contains the last model retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:1007
SerialWombatDataSource::SW_DATA_SOURCE_ERRORS
@ SW_DATA_SOURCE_ERRORS
(72)The number of incoming packets that have caused errors since reset (rolls over at 65535)
SerialWombatPin::digitalWrite
void digitalWrite(uint8_t val)
Set output pin High or Low.
Definition: SerialWombat.h:1524
SerialWombatChip::writeUserBuffer
int writeUserBuffer(uint16_t index, const char s[])
Write bytes to the User Memory Buffer in the Serial Wombat chip.
Definition: SerialWombat.h:1172
SerialWombatDataSource::SW_DATA_SOURCE_65SEC_SQUARE
@ SW_DATA_SOURCE_65SEC_SQUARE
(176) Square wave that alternates between 0 and 65535 every 32768 frames
SerialWombatDataSource::SW_DATA_SOURCE_0x55
@ SW_DATA_SOURCE_0x55
(85) 0x55 is a reserved value for resyncing. Returns 0x55 0x55
SerialWombatDataSource::SW_DATA_SOURCE_PIN_7
@ SW_DATA_SOURCE_PIN_7
(7) 16 bit public data provided by Pin 7
SerialWombatChip::registerErrorHandler
void registerErrorHandler(SerialWombatErrorHandler_t handler)
Registers an error handler that is called by the SerialWombatChip sendPacket() command when a protoco...
Definition: SerialWombat.h:1376
SerialWombatDataSource::SW_DATA_SOURCE_2HZ_SQUARE
@ SW_DATA_SOURCE_2HZ_SQUARE
(164) Square wave that alternates between 0 and 65535 every 256 frames
SerialWombatChip::isSW18
bool isSW18()
Returns true if the instance received a model number corresponding to the Serial Wombat 18 series of ...
Definition: SerialWombat.h:972
SerialWombatPin::pinMode
void pinMode(uint8_t mode, bool pullDown=false, bool openDrain=false)
Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
Definition: SerialWombat.h:1511
SerialWombatDataSource::SW_DATA_SOURCE_PIN_5
@ SW_DATA_SOURCE_PIN_5
(5) 16 bit public data provided by Pin 5
SerialWombatCommands::CONFIGURE_PIN_MODE5
@ CONFIGURE_PIN_MODE5
(205)
SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE
@ CONFIGURE_PIN_MODE_DISABLE
(219)
PIN_MODE_ULTRASONIC_DISTANCE
@ PIN_MODE_ULTRASONIC_DISTANCE
(27)
Definition: SerialWombat.h:261
PIN_MODE_DIGITALIO
@ PIN_MODE_DIGITALIO
(0)
Definition: SerialWombat.h:238
SerialWombatDataSource::SW_DATA_SOURCE_PIN_19
@ SW_DATA_SOURCE_PIN_19
(19) 16 bit public data provided by Pin 19
SerialWombatDataSource::SW_DATA_SOURCE_8SEC_SQUARE
@ SW_DATA_SOURCE_8SEC_SQUARE
(173)Square wave that alternates between 0 and 65535 every 4096 frames
SerialWombatCommands::CMD_SUPPLYVOLTAGE
@ CMD_SUPPLYVOLTAGE
('v')
SerialWombatChip::readBrand
int16_t readBrand(char *data)
Definition: SerialWombat.h:1425
SerialWombatCommands::CONFIGURE_PIN_MODE1
@ CONFIGURE_PIN_MODE1
(201)
SerialWombatCommands::COMMAND_BINARY_READ_RAM
@ COMMAND_BINARY_READ_RAM
(0xA0)
SerialWombatCommands::CONFIGURE_PIN_MODE6
@ CONFIGURE_PIN_MODE6
(206)
SerialWombatDataSource::SW_DATA_SOURCE_PIN_6
@ SW_DATA_SOURCE_PIN_6
(6) 16 bit public data provided by Pin 6
SerialWombatSerialErrorHandlerVerbose
void SerialWombatSerialErrorHandlerVerbose(uint16_t error, SerialWombatChip *sw)
SerialWombatCommands::CMD_ECHO
@ CMD_ECHO
('!')
SerialWombatCommands::COMMAND_BINARY_QUEUE_ADD_7BYTES
@ COMMAND_BINARY_QUEUE_ADD_7BYTES
(0x92)
SerialWombatDataSource::SW_DATA_SOURCE_PIN_12
@ SW_DATA_SOURCE_PIN_12
(12) 16 bit public data provided by Pin 12
SerialWombatDataSource::SW_DATA_SOURCE_PIN_2_MV
@ SW_DATA_SOURCE_PIN_2_MV
(102) Pin 2 public output expressed in mV (for analog modes only)
SerialWombatChip::writeStartupCommandCapture
int16_t writeStartupCommandCapture()
Write captured startup commands to flash (SW18AB Only)
Definition: SerialWombat.h:1265
SerialWombatCommands::COMMAND_BINARY_SET_PIN_BUFFFER
@ COMMAND_BINARY_SET_PIN_BUFFFER
(0x82)
PIN_MODE_UART_RX_TX
@ PIN_MODE_UART_RX_TX
(17)
Definition: SerialWombat.h:253
SerialWombatDataSource::SW_DATA_SOURCE_1HZ_SQUARE
@ SW_DATA_SOURCE_1HZ_SQUARE
(167) Square wave that alternates between 0 and 65535 every 512 frames
SerialWombatDataSource::SW_DATA_SOURCE_PIN_18_MV
@ SW_DATA_SOURCE_PIN_18_MV
(118) Pin 18 public output expressed in mV (for analog modes only)
PIN_MODE_HS_SERVO
@ PIN_MODE_HS_SERVO
(26)
Definition: SerialWombat.h:260
PIN_MODE_VGA
@ PIN_MODE_VGA
(31)
Definition: SerialWombat.h:265
SerialWombatPulseTimer.h
SerialWombatResistanceInput.h
SerialWombatCommands::COMMAND_BINARY_QUEUE_INITIALIZE
@ COMMAND_BINARY_QUEUE_INITIALIZE
(0x90)
SerialWombatChip::address
uint8_t address
The I2C address of the SerialWombatChip instance.
Definition: SerialWombat.h:1382
SerialWombatCommands::COMMAND_BINARY_READ_EEPROM
@ COMMAND_BINARY_READ_EEPROM
(0xA2)
SerialWombatCommands::COMMAND_UART0_TX_7BYTES
@ COMMAND_UART0_TX_7BYTES
(0xB0)
SerialWombatDataSource::SW_DATA_SOURCE_OVERRUN_FRAMES
@ SW_DATA_SOURCE_OVERRUN_FRAMES
(69) The number of frames that ran more than 1mS
SerialWombatCommands::COMMAND_BINARY_QUEUE_ADD_BYTES
@ COMMAND_BINARY_QUEUE_ADD_BYTES
(0x91)
SerialWombatDataSource::SW_DATA_SOURCE_PIN_11
@ SW_DATA_SOURCE_PIN_11
(11) 16 bit public data provided by Pin 11