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,
219  CONFIGURE_PIN_MODE0 = 200,
220  CONFIGURE_PIN_MODE1 = 201,
221  CONFIGURE_PIN_MODE2 = 202,
222  CONFIGURE_PIN_MODE3 = 203,
223  CONFIGURE_PIN_MODE4 = 204,
224  CONFIGURE_PIN_MODE5 = 205,
225  CONFIGURE_PIN_MODE6 = 206,
226  CONFIGURE_PIN_MODE7 = 207,
227  CONFIGURE_PIN_MODE8 = 208,
228  CONFIGURE_PIN_MODE9 = 209,
229  CONFIGURE_PIN_MODE10 = 210,
237 
238 };
239 
240 
241 typedef enum {
273 
274 class SerialWombatChip;
275 
276 typedef void (*SerialWombatErrorHandler_t) (uint16_t errorNumber, SerialWombatChip* sw);
277 
284 {
285 private:
286 
287  char version[8] = { 0 };
288  HardwareSerial * Serial = NULL;
289  TwoWire* i2cInterface = NULL;
290  uint8_t _pinmode[WOMBAT_MAXIMUM_PINS]={}; // Includes Pullup
291  bool _pullDown[WOMBAT_MAXIMUM_PINS]={};
292  bool _openDrain[WOMBAT_MAXIMUM_PINS]={};
293  bool _highLow[WOMBAT_MAXIMUM_PINS] = {};
294  bool _asleep = false;
295  SerialWombatErrorHandler_t errorHandler = NULL;
296  bool _currentlyCommunicating = false;
297 public:
304  uint16_t _supplyVoltagemV = 0;
305 
307  uint8_t model[4] = { 0 };
308 
310  uint8_t fwVersion[4] = { 0 };
311 
317  uint8_t uniqueIdentifier[16];
318 
324 
330 
335  uint16_t deviceRevision;
337  uint16_t errorCount = 0;
338 
340  bool inBoot = false;
341 
343  int16_t lastErrorCode = 0;
344 
345  void configureDigitalPin(uint8_t pin, uint8_t highLow)
346  {
347  uint8_t tx[8] = { 200,pin,0,0,0,0,0,0x55 };
348  uint8_t rx[8];
349  switch (_pinmode[pin])
350  {
351  case INPUT: // Arduino input
352  {
353  tx[3] = 2; //Input
354  }
355  break;
356  case OUTPUT:
357  {
358  if (highLow == LOW)
359  {
360  tx[3] = 0;
361  }
362  else if (highLow == HIGH)
363  {
364  tx[3] = 1;
365  }
366  else
367  {
368  return;
369  }
370  }
371  break;
372  case INPUT_PULLUP:
373  {
374  tx[3] = 2; //Input
375  tx[4] = 1; //Pullup on
376  }
377  break;
378  default:
379  {
380  return;
381  }
382  }
383  tx[6] = _openDrain[pin];
384  tx[5] = _pullDown[pin];
385  sendPacket(tx, rx, true);
386  }
387  uint32_t sendReadyTime = 0;
388  int16_t initialize()
389  {
390  int16_t retvalue = -1;
391  lastErrorCode = 0;
392  readVersion();
396  return(lastErrorCode);
397  }
398 
400  {
402  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
403  { //16F15214
404  for (uint32_t address = 0x8100; address <= 0x8108; ++address)
405  {
406  uint32_t data = readFlashAddress(address);
407  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)data;
409  /* Always zero... leave out
410  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)(data>>8);
411  ++uniqueIdentifierLength;
412  */
413  }
414  }
415  else if (isSW18())
416  {
417  for (uint32_t address = 0x801600; address <= 0x801608; address += 2)
418  {
419  uint32_t data = readFlashAddress(address);
426  }
427  }
428  }
429 
431  {
432  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
433  { //16F15214
434 
435  uint32_t data = readFlashAddress(0x8006);
436  deviceIdentifier = (uint16_t)data;
437  data = readFlashAddress(0x8005);
438  deviceRevision = (uint16_t)data;
439  }
440  else if (isSW18())
441  {
442  uint32_t data = readFlashAddress(0xFF0000);
443  deviceIdentifier = (uint16_t)data;
444  data = readFlashAddress(0xFF0002);
445  deviceRevision = (uint16_t)data & 0xF;
446  }
447  }
448 
449  uint16_t returnErrorCode(uint8_t* rx)
450  {
451  uint16_t result = rx[1] - '0';
452  result *= 10;
453  result += rx[2] - '0';
454  result *= 10;
455  result += rx[3] - '0';
456  result *= 10;
457  result += rx[4] - '0';
458  result *= 10;
459  result += rx[5] - '0';
460  return(result);
461  }
462 
463 
464 
465 public:
480  int16_t begin(HardwareSerial& serial, bool reset = true)
481  {
482  Serial = &serial;
483  Serial->begin(115200);
484  Serial->setTimeout(2);
485  Serial->write((uint8_t*)"UUUUUUUU", 8);
486  delay(5);
487  while (Serial->read() >= 0);
488  if (reset)
489  {
490  hardwareReset();
491  sendReadyTime = millis() + 1000;
492  return(1);
493  }
494  else
495  {
496  return initialize();
497  }
498 
499 
500  }
501 
511  int16_t begin(uint8_t i2cAddress);
512 
526  int16_t begin(TwoWire& wire, uint8_t i2cAddress, bool reset = true)
527  {
528  i2cInterface = &wire;
529  address = i2cAddress;
530 
531  Wire.beginTransmission(i2cAddress);
532  int error = Wire.endTransmission();
533 
534 
535  if (error != 0)
536  {
537  return(-1);
538  }
539 
540  if (reset)
541  {
542  hardwareReset();
543  sendReadyTime = millis() + 1000;
544  return(1);
545  }
546  else
547  {
548  sendReadyTime = 0;
549  return initialize();
550 
551  }
552  }
553 
555 
566  int sendPacket( uint8_t tx[], uint8_t rx[]);
567 
577  int sendPacket(uint8_t tx[]);
578 
589  int sendPacket(uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch = 8, uint8_t endBytesToMatch = 0);
599  int sendPacket(uint8_t tx[], bool retryIfEchoDoesntMatch);
600 
610  int sendPacketNoResponse(uint8_t tx[]);
611 
620  char* readVersion(void)
621  {
622  uint8_t tx[] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
623  uint8_t rx[8];
624  sendPacket(tx, rx);
625  memcpy(version, &rx[1], 7);
626  version[7] = '\0';
627  memcpy(model, &rx[1], 3);
628  model[3] = '\0';
629  fwVersion[0] = rx[5];
630  fwVersion[1] = rx[6];
631  fwVersion[2] = rx[7];
632  return (version);
633  }
634 
641  uint32_t readVersion_uint32(void)
642  {
643  readVersion();
644  return ((((uint32_t)fwVersion[0]) << 16) |
645  (((uint32_t)fwVersion[1]) << 8) |
646  fwVersion[2]);
647  }
648 
658  uint16_t readPublicData(uint8_t pin)
659  {
660  uint8_t tx[] = { 0x81,pin,255,255,0x55,0x55,0x55,0x55 };
661  uint8_t rx[8];
662  sendPacket(tx, rx);
663  return(rx[2] + (uint16_t)rx[3] * 256);
664  }
665 
676  {
677  return (readPublicData((uint8_t)dataSource));
678  }
679 
685  uint16_t writePublicData(uint8_t pin, uint16_t value)
686  {
687  uint8_t tx[] = { 0x82,pin,(uint8_t)(value & 0xFF),(uint8_t)(value >> 8) ,255,0x55,0x55,0x55 };
688  uint8_t rx[8];
689  sendPacket(tx, rx);
690  return (rx[2] + rx[3] * 256);
691  }
692 
703  uint16_t readSupplyVoltage_mV(void)
704  {
705  if (isSW18())
706  {
708  }
709  else
710  {
711  int32_t counts = readPublicData(66); // Get FVR counts (1.024 v)
712  if (counts > 0)
713  {
714  uint32_t mv = 1024 * 65536 / counts;
715  _supplyVoltagemV = (uint16_t)mv;
716  }
717  else
718  {
719  _supplyVoltagemV = 0;
720  }
721  }
722  return(_supplyVoltagemV);
723  }
724 
725 
737  {
738  if (isSW18())
739  {
740  int32_t result = readPublicData(70);
741  if (result >= 32768)
742  {
743  result = result - 65536;
744  }
745  return ((int16_t)result);
746  }
747  else
748  {
749  return 2500;
750  }
751  }
752 
760  {
761  uint8_t tx[9] = "ReSeT!#*";
762  uint8_t rx[8];
763  sendPacket(tx, rx);
764  }
765 
774  void pinMode(uint8_t pin, uint8_t mode, bool pullDown = false, bool openDrain = false)
775  {
776  if (pin >= WOMBAT_MAXIMUM_PINS)
777  {
778  return;
779  }
780  _pullDown[pin] = openDrain;
781  _openDrain[pin] = openDrain;
782  _pinmode[pin] = mode;
783  configureDigitalPin(pin, mode);
784  }
785 
793  void digitalWrite(uint8_t pin, uint8_t val)
794  {
795  configureDigitalPin(pin, val);
796  }
797 
803  int digitalRead(uint8_t pin)
804  {
805  if (readPublicData(pin) > 0)
806  {
807  return (HIGH);
808  }
809  else
810  {
811  return (LOW);
812  }
813  }
814 
824  int analogRead(uint8_t pin)
825  {
826  uint8_t tx[] = { 200,pin,PIN_MODE_ANALOGINPUT,0,0,0,0,0 };
827  uint8_t rx[8];
828  sendPacket(tx, rx);
829  return (readPublicData(pin) >> 6); // Scale from 16 bit value to 10 bit value.
830  }
831 
843  void analogWrite(uint8_t pin, int val)
844  {
845  uint8_t dutyCycleLow = 0;
846  if (val == 255)
847  {
848  dutyCycleLow = 255;
849  }
850  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_PWM,pin,dutyCycleLow,(uint8_t) val,false,0x55 };
851  uint8_t rx[8];
852  sendPacket(tx, rx);
853  }
854 
866  {
867  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
868  uint8_t rx[8];
869  sendPacket(tx, rx);
870  if (rx[0] == 'V' && (rx[1] == 'S' || rx[1] == 'B'))
871  {
872  model[0] = rx[1];
873  model[1] = rx[2];
874  model[2] = rx[3];
875  model[3] = 0;
876  fwVersion[0] = rx[5];
877  fwVersion[1] = rx[6];
878  fwVersion[2] = rx[7];
879  fwVersion[3] = 0;
880 
881  inBoot = (rx[1] == 'B');
882  return (true);
883  }
884  return (false);
885  }
886 
894  {
895  uint8_t tx[8] = { 0x81,67,68,0x55,0x55,0x55,0x55,0x55 };
896  uint8_t rx[8];
897  sendPacket(tx, rx);
898  uint32_t returnval = rx[2] + (((uint32_t)rx[3]) << 8) + (((uint32_t)rx[4]) << 16) + (((uint32_t)rx[5]) << 24);
899  return (returnval);
900  }
901 
911  {
912  return readPublicData(69);
913  }
914 
924  void jumpToBoot()
925  {
926  uint8_t tx[] = "BoOtLoAd";
927  sendPacket(tx);
928  }
929 
950  uint8_t readRamAddress(uint16_t address)
951  {
952  uint8_t tx[8] = { 0xA0,SW_LE16(address),0x55,0x55,0x55,0x55,0x55 };
953  uint8_t rx[8];
954  sendPacket(tx, rx);
955  return(rx[3]);
956  }
957 
978  int16_t writeRamAddress(uint16_t address, uint8_t value)
979  {
980  uint8_t tx[8] = { 0xA3,SW_LE16(address),0,0,value,0x55,0x55};
981  return sendPacket(tx);
982  }
983 
999  uint32_t readFlashAddress(uint32_t address)
1000  {
1001  uint8_t tx[8] = { 0xA1,SW_LE32(address),0x55,0x55,0x55 };
1002  uint8_t rx[8];
1003  sendPacket(tx, rx);
1004  return(((uint32_t)rx[4]) + (((uint32_t)rx[5]) <<8) + (((uint32_t)rx[6]) <<16) + (((uint32_t)rx[7]) <<24));
1005  }
1006 
1018  int16_t readUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1019  {
1020  uint16_t bytesRead = 0;
1021  while (bytesRead < count)
1022  {
1023  byte tx[] = {(byte)SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER, (byte)(index & 0xFF), (byte)(index >> 8), 0x55, 0x55, 0x55, 0x55, 0x55};
1024  byte rx[8];
1025  int16_t result = sendPacket(tx, rx);
1026  if (result >= 0)
1027  {
1028  for (int i = 1; i < 8; ++i)
1029  {
1030  buffer[bytesRead] = rx[i];
1031  ++bytesRead;
1032  ++index;
1033  if (bytesRead >= count)
1034  {
1035  break;
1036  }
1037  }
1038  }
1039  else
1040  {
1041  return (bytesRead);
1042  }
1043  }
1044  return (bytesRead);
1045  }
1056  void sleep()
1057  {
1058  uint8_t tx[8] = { 'S','l','E','e','P','!','#','*'};
1059  sendPacket(tx);
1060  _asleep = true;
1061  }
1062 
1064  void wake()
1065  {
1066  uint8_t tx[8] = { '!','!','!','!','!','!','!','!' };
1067  sendPacket(tx);
1068  }
1069 
1071  bool isSW18()
1072  {
1073  return ( model[1] == '1' && model[2] == '8');
1074  }
1075 
1077  int16_t eraseFlashPage(uint32_t address)
1078  {
1079  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1080  0, //Erase Page
1081  SW_LE32(address),
1082  0x55,0x55 };
1083  return sendPacket(tx);
1084  }
1085 
1086 
1088  int16_t writeFlashRow(uint32_t address)
1089  {
1090  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1091  1, // Write entire row
1092  SW_LE32(address),0x55,0x55 };
1093  return sendPacket(tx);
1094  }
1095 
1096 
1097 
1098 
1108  int16_t setThroughputPin(uint8_t pin)
1109  {
1110  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1111  return sendPacket(tx);
1112  }
1113 
1121  int writeUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1122  {
1123  uint16_t bytesSent = 0;
1124  if (count == 0)
1125  {
1126  return 0;
1127  }
1128 
1129  { // Send first packet of up to 4 bytes
1130  uint8_t bytesToSend = 4;
1131  if (count < 4)
1132  {
1133  bytesToSend = (uint8_t)count;
1134  count = 0;
1135  }
1136  else
1137  {
1138  count -= 4;
1139  }
1140 
1141  uint8_t tx[8] = { 0x84,SW_LE16(index), bytesToSend,0x55,0x55,0x55,0x55 };
1142  uint8_t rx[8];
1143 
1144  uint8_t i;
1145  for (i = 0; i < bytesToSend; ++i)
1146  {
1147  tx[4 + i] = buffer[i];
1148  }
1149  int result = sendPacket(tx, rx);
1150  if (rx[0] == 'E')
1151  {
1152  return (result);
1153  }
1154  bytesSent = bytesToSend;
1155  }
1156  while (count >= 7) // Continue sending
1157  {
1158 
1159  count -= 7;
1160  uint8_t tx[8] = { 0x85,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1161  uint8_t rx[8];
1162  uint8_t i;
1163  for (i = 0; i < 7; ++i)
1164  {
1165  tx[1 + i] = buffer[bytesSent + i];
1166  }
1167  int result = sendPacket(tx, rx);
1168  if (rx[0] == 'E')
1169  {
1170  return (result);
1171  }
1172  bytesSent += 7;
1173  }
1174  while (count > 0)
1175  {
1176 
1177  { // Send first packet of up to 4 bytes
1178  uint8_t bytesToSend = 4;
1179  if (count < 4)
1180  {
1181  bytesToSend = (uint8_t)count;
1182  count = 0;
1183  }
1184  else
1185  {
1186  count -= 4;
1187  }
1188 
1189  uint8_t tx[8] = { 0x84,SW_LE16(index + bytesSent), bytesToSend,0x55,0x55,0x55,0x55 };
1190  uint8_t rx[8];
1191 
1192  uint8_t i;
1193  for (i = 0; i < bytesToSend; ++i)
1194  {
1195  tx[4 + i] = buffer[i + bytesSent];
1196  }
1197  int result = sendPacket(tx, rx);
1198  if (rx[0] == 'E')
1199  {
1200  return (result);
1201  }
1202  bytesSent += bytesToSend;
1203  }
1204  }
1205  return(bytesSent);
1206 
1207 
1208  }
1209 
1217  int writeUserBuffer(uint16_t index, char* s)
1218  {
1219  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1220  }
1221 
1229  int writeUserBuffer(uint16_t index, const char s[])
1230  {
1231  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1232  }
1233 
1234 
1235 
1247  int16_t writeFrameTimerPin(uint8_t pin)
1248 {
1249  uint8_t tx[] = { 0xC8 ,pin,(uint8_t)PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1250  return sendPacket(tx);
1251 }
1252 
1253 
1261  static uint8_t find(bool keepTrying = false)
1262  {
1263  do
1264  {
1265  for (int i2cAddress = 0x68; i2cAddress <= 0x6F; ++i2cAddress)
1266  {
1267  Wire.beginTransmission(i2cAddress);
1268  int error = Wire.endTransmission();
1269 
1270 
1271  if (error == 0)
1272  {
1273  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1274  uint8_t rx[8];
1275  Wire.beginTransmission(i2cAddress);
1276  Wire.write(tx, 8);
1277  Wire.endTransmission();
1278  Wire.requestFrom((uint8_t)i2cAddress, (uint8_t)8);
1279 
1280  int count = 0;
1281  while (Wire.available() && count < 8)
1282  {
1283  rx[count] = Wire.read();
1284  ++count;
1285  }
1286  if (count == 8)
1287  {
1288  if (rx[0] == 'V' && rx[1] == 'S')
1289  {
1290  return(i2cAddress); // Found one.
1291  }
1292  }
1293  }
1294  }
1295  delay(0);
1296  }while (keepTrying);
1297  return(0); // Didn't find one.
1298  }
1299 
1300 
1307  int16_t readLastErrorCommand(uint8_t* cmd)
1308 {
1309  //TODO this doen't look like it returns the error
1310  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET, 0,0x55,0x55,0x55,0x55,0x55,0x55 };
1311  uint8_t rx[8];
1312  if (sendPacket(tx, rx) >= 0)
1313  {
1314  for (int i = 1; i < 8; ++i)
1315  {
1316  cmd[i - 1] = rx[i];
1317  }
1318  }
1319  else
1320  {
1321  return (lastErrorCode);
1322  }
1323  tx[1] = 7;
1324  if (sendPacket(tx, rx) >= 0)
1325  {
1326  cmd[7] = rx[1];
1327  }
1328  return(lastErrorCode);
1329 }
1330 
1336  {
1337  errorHandler = handler;
1338  }
1339 
1341  uint8_t address = 0;
1342 
1345 
1346  int16_t echo(uint8_t data[], uint8_t count = 7)
1347  {
1348  uint8_t tx[] = "!UUUUUUU";
1349  for (int i = 0; i < 7 && i < count; ++i)
1350  {
1351  tx[i + 1] = (uint8_t)data[i];
1352  }
1353  return sendPacket(tx);
1354  }
1355 
1356 
1357  int16_t echo(char* data)
1358  {
1359  int length = strlen(data);
1360  uint8_t tx[] = "!UUUUUUU";
1361  for (int i = 0; i < 7 && i < length; ++i)
1362  {
1363  tx[i + 1] = (uint8_t)data[i];
1364  }
1365  return sendPacket(tx);
1366  }
1367 
1368  uint32_t readBirthday()
1369  {
1370  if (isSW18())
1371  {
1372  uint32_t birthday = (readFlashAddress(0x2A00C) >> 8) & 0xFF;
1373  birthday *= 100;
1374  birthday += (readFlashAddress(0x2A00C)) & 0xFF;
1375  birthday *= 100;
1376  birthday += readFlashAddress(0x2A00E) & 0xFF;
1377  birthday *= 100;
1378  birthday += readFlashAddress(0x2A010) & 0xFF;
1379  return (birthday);
1380  }
1381  return 0;
1382  }
1383 
1384  int16_t readBrand(char* data)
1385  {
1386  uint8_t length = 0;
1387  if (isSW18())
1388  {
1389  for (int i = 0; i < 32; ++i)
1390  {
1391  uint32_t val = readFlashAddress(0x2A020 + i * 2) ;
1392  if ((val & 0xFF) != 0xFF)
1393  {
1394  data[i ] = (char)(val & 0xFF);
1395  ++length;
1396  }
1397  else
1398  {
1399  data[length] = 0;
1400  return (length);
1401  }
1402  }
1403  data[length] = 0;
1404  return (length);
1405  }
1406 
1407  data[0] = 0;
1408  return 0 ;
1409  }
1410 
1411 };
1412 
1427 {
1428 private:
1429  SerialWombatChip& _sw;
1430  uint32_t lastMillis = 0;
1431  uint32_t lastFrames = 0;
1432 public:
1437  SerialWombat18ABOscillatorTuner(SerialWombatChip& serialWombatChip) : _sw(serialWombatChip) { }
1438 
1442  void update() {
1443  uint32_t m = millis();
1444  if (lastMillis == 0)
1445  {
1446  lastMillis = m;
1450  {
1453  }
1454  frames <<= 16;
1455  frames += frameslsb;
1456  lastFrames = frames;
1457 
1458  }
1459  else if ((m - lastMillis) < 10000)
1460  {
1461  //Do nothing
1462  }
1463  else if (m < lastMillis)
1464  {
1465  //Has it been 47 days already?
1466  lastMillis = 0;
1467  }
1468  else
1469  {
1470  uint32_t diff = m - lastMillis;
1471 
1474 
1476  {
1479  }
1480  frames <<= 16;
1481  frames += frameslsb;
1482  uint32_t framesDif = frames - lastFrames;
1483 
1484  if (diff > framesDif )
1485  {
1486  // Running slow
1487  uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1488  SW_LE16(1),//Counts to increment
1489  SW_LE16(0), // Counts to decrement
1490  0x55,0x55,0x55};
1491  _sw.sendPacket(tx);
1492  }
1493  else if (diff < framesDif)
1494  {
1495  // Running mfast
1496  uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1497  SW_LE16(0),//Counts to increment
1498  SW_LE16(1), // Counts to decrement
1499  0x55,0x55,0x55 };
1500  _sw.sendPacket(tx);
1501 
1502  }
1503 
1504  lastMillis = m;
1505  lastFrames = frames;
1506 
1507  }
1508 
1509  }
1510 
1511 };
1512 
1513 /*
1514 End of cross platform code synchronization. Random string to help the compare tool sync lines:
1515 asdkj38vjn1nasdnvuwlamafdjiivnowalskive
1516 */
1517 
1519 class SerialWombat : public SerialWombatChip {};
1520 
1521 
1522 
1523 
1524 
1532 void SerialWombatSerialErrorHandlerBrief(uint16_t error, SerialWombatChip* sw);
1534 
1535 #include "SerialWombatPin.h"
1536 #include "SerialWombatErrors.h"
1537 #include "SerialWombatQueue.h"
1541 #include "SerialWombat18CapTouch.h"
1542 #include "SerialWombat18ABVGA.h"
1543 #include "SerialWombatAnalogInput.h"
1545 #include "SerialWombatHSClock.h"
1546 #include "SerialWombatHSCounter.h"
1547 #include "SerialWombatLiquidCrystal.h"
1548 #include "SerialWombatMatrixKeypad.h"
1551 #include "SerialWombatPS2Keyboard.h"
1552 #include "SerialWombatPulseOnChange.h"
1553 #include "SerialWombatPulseTimer.h"
1554 #include "SerialWombatPWM.h"
1555 #include "SerialWombatQuadEnc.h"
1557 #include "SerialWombatServo.h"
1558 #include "SerialWombatTM1637.h"
1559 #include "SerialWombatUART.h"
1561 #include "SerialWombatWatchdog.h"
1562 #include "SerialWombatWS2812.h"
1564 
1565 #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:1247
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:283
PIN_MODE_ANALOGINPUT
@ PIN_MODE_ANALOGINPUT
(2)
Definition: SerialWombat.h:244
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:924
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:1217
PIN_MODE_PULSE_ON_CHANGE
@ PIN_MODE_PULSE_ON_CHANGE
(25)
Definition: SerialWombat.h:263
PIN_MODE_SW18AB_CAPTOUCH
@ PIN_MODE_SW18AB_CAPTOUCH
(22)
Definition: SerialWombat.h:260
SerialWombatHSClock.h
PIN_MODE_HS_CLOCK
@ PIN_MODE_HS_CLOCK
Definition: SerialWombat.h:267
PIN_MODE_UART1_RX_TX
@ PIN_MODE_UART1_RX_TX
(23)
Definition: SerialWombat.h:261
SerialWombatCommands::COMMAND_BINARY_QUEUE_INFORMATION
@ COMMAND_BINARY_QUEUE_INFORMATION
(0x94)
SerialWombatWS2812.h
PIN_MODE_DEBOUNCE
@ PIN_MODE_DEBOUNCE
(10)
Definition: SerialWombat.h:250
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:276
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:343
SerialWombatChip::readPublicData
uint16_t readPublicData(SerialWombatDataSource dataSource)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:675
SerialWombatDataSource::SW_DATA_SOURCE_PIN_9
@ SW_DATA_SOURCE_PIN_9
(9) 16 bit public data provided by Pin 9
SerialWombatChip::sendReadyTime
uint32_t sendReadyTime
Definition: SerialWombat.h:387
SerialWombatChip::digitalRead
int digitalRead(uint8_t pin)
Reads the state of a Pin.
Definition: SerialWombat.h:803
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:290
SerialWombatPinMode_t
SerialWombatPinMode_t
Definition: SerialWombat.h:241
SerialWombatAnalogInput.h
SerialWombatChip::analogRead
int analogRead(uint8_t pin)
Configures pin as analog input and does an immediate A/D conversion.
Definition: SerialWombat.h:824
SerialWombatCommands::COMMAND_BINARY_RW_PIN_MEMORY
@ COMMAND_BINARY_RW_PIN_MEMORY
(0xB5)
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
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:843
SerialWombat18ABOscillatorTuner::SerialWombat18ABOscillatorTuner
SerialWombat18ABOscillatorTuner(SerialWombatChip &serialWombatChip)
Class constructor for SerialWombat18OscillatorTuner.
Definition: SerialWombat.h:1437
PIN_MODE_WATCHDOG
@ PIN_MODE_WATCHDOG
(7)
Definition: SerialWombat.h:248
SerialWombatChip::returnErrorCode
uint16_t returnErrorCode(uint8_t *rx)
Definition: SerialWombat.h:449
PIN_MODE_CONTROLLED
@ PIN_MODE_CONTROLLED
(1)
Definition: SerialWombat.h:243
PIN_MODE_SW_UART
@ PIN_MODE_SW_UART
(13)
Definition: SerialWombat.h:253
SerialWombatChip::queryVersion
bool queryVersion()
Send a version request to the Serial Wombat chip.
Definition: SerialWombat.h:865
SerialWombatCommands::COMMAND_BINARY_TEST_SEQUENCE
@ COMMAND_BINARY_TEST_SEQUENCE
(0xB4)
SerialWombatChip::setThroughputPin
int16_t setThroughputPin(uint8_t pin)
Set a pin to be a throughput monitoring pin.
Definition: SerialWombat.h:1108
PIN_MODE_PS2KEYBOARD
@ PIN_MODE_PS2KEYBOARD
(32)
Definition: SerialWombat.h:270
SerialWombatLiquidCrystal.h
SerialWombatChip::readSupplyVoltage_mV
uint16_t readSupplyVoltage_mV(void)
Measure the Serial Wombat chip's Supply voltage.
Definition: SerialWombat.h:703
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:340
SerialWombatChip::_supplyVoltagemV
uint16_t _supplyVoltagemV
Definition: SerialWombat.h:304
SerialWombat18ABVGA.h
SerialWombat18CapTouch.h
PIN_MODE_RESISTANCEINPUT
@ PIN_MODE_RESISTANCEINPUT
(24)
Definition: SerialWombat.h:262
SerialWombatChip::readFramesExecuted
uint32_t readFramesExecuted()
Get the number of 1mS frames that have been executed since Serial Wombat chip reset.
Definition: SerialWombat.h:893
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:251
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:1064
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:774
PIN_MODE_PWM
@ PIN_MODE_PWM
(16)
Definition: SerialWombat.h:256
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)
SerialWombatChip::begin
int16_t begin(HardwareSerial &serial, bool reset=true)
initialize a Serial Wombat chip to use a Serial Interface.
Definition: SerialWombat.h:480
SerialWombatCommands::COMMAND_UART1_TX_7BYTES
@ COMMAND_UART1_TX_7BYTES
(0xB2)
SerialWombatChip::begin
int16_t begin(TwoWire &wire, uint8_t i2cAddress, bool reset=true)
initialize a Serial Wombat chip to use a specified I2C Interface and address.
Definition: SerialWombat.h:526
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:245
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 ...
SerialWombatChip::initialize
int16_t initialize()
Definition: SerialWombat.h:388
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:360
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:759
PIN_MODE_PULSETIMER
@ PIN_MODE_PULSETIMER
(18)
Definition: SerialWombat.h:258
SerialWombatChip::uniqueIdentifierLength
uint8_t uniqueIdentifierLength
Definition: SerialWombat.h:323
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:1077
SerialWombatChip::readLastErrorCommand
int16_t readLastErrorCommand(uint8_t *cmd)
Returns the last Serial Wombat command that produced a protocol error.
Definition: SerialWombat.h:1307
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:793
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')
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:255
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::readOverflowFrames
uint16_t readOverflowFrames()
Get the number of times an overflow Frame has occured.
Definition: SerialWombat.h:910
SerialWombatCommands::CONFIGURE_PIN_MODE9
@ CONFIGURE_PIN_MODE9
(209)
SerialWombatChip::deviceIdentifier
uint16_t deviceIdentifier
Definition: SerialWombat.h:329
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:1261
SerialWombatChip::readPublicData
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:658
SerialWombatUART.h
SerialWombatDataSource::SW_DATA_SOURCE_PIN_0
@ SW_DATA_SOURCE_PIN_0
(0) 16 bit public data provided by Pin 0
SerialWombatChip::readUniqueIdentifier
void readUniqueIdentifier()
Definition: SerialWombat.h:399
PIN_MODE_HS_COUNTER
@ PIN_MODE_HS_COUNTER
< (29)
Definition: SerialWombat.h:268
SerialWombat18ABOscillatorTuner
A class which tunes the oscillator on a Serial Wombat 18AB chip.
Definition: SerialWombat.h:1426
SerialWombatChip::readFlashAddress
uint32_t readFlashAddress(uint32_t address)
Read Address from Flash based on 32 bit address.
Definition: SerialWombat.h:999
SerialWombatChip::readTemperature_100thsDegC
int16_t readTemperature_100thsDegC(void)
Measure the Serial Wombat chip's internal temperature.
Definition: SerialWombat.h:736
SerialWombatChip::uniqueIdentifier
uint8_t uniqueIdentifier[16]
Definition: SerialWombat.h:317
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:1088
SerialWombatChip::errorCount
uint16_t errorCount
Incremented every time a communication or command error is detected.
Definition: SerialWombat.h:337
SerialWombatChip::readRamAddress
uint8_t readRamAddress(uint16_t address)
Read Address from RAM based on 16 bit address.
Definition: SerialWombat.h:950
SerialWombatChip::readBirthday
uint32_t readBirthday()
Definition: SerialWombat.h:1368
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:978
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:114
SerialWombatCommands::CONFIGURE_PIN_MODE_HW_0
@ CONFIGURE_PIN_MODE_HW_0
(220)
PIN_MODE_WS2812
@ PIN_MODE_WS2812
(12)
Definition: SerialWombat.h:252
PIN_MODE_UNKNOWN
@ PIN_MODE_UNKNOWN
(0xFF)
Definition: SerialWombat.h:271
SerialWombatCommands::COMMAND_CALIBRATE_ANALOG
@ COMMAND_CALIBRATE_ANALOG
(0xA5)
SerialWombatChip::configureDigitalPin
void configureDigitalPin(uint8_t pin, uint8_t highLow)
Definition: SerialWombat.h:345
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:335
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:1056
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:685
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:1121
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)
SerialWombatCommands::COMMAND_ADJUST_FREQUENCY
@ COMMAND_ADJUST_FREQUENCY
(0xB7)
SerialWombatPin.h
SerialWombatChip::readVersion
char * readVersion(void)
Request version string (combined model and firmware) and return pointer to it.
Definition: SerialWombat.h:620
SerialWombatCommands::COMMAND_BINARY_CONFIGURE
@ COMMAND_BINARY_CONFIGURE
(0x9F)
SerialWombatChip::readVersion_uint32
uint32_t readVersion_uint32(void)
Request version as a uint32.
Definition: SerialWombat.h:641
SerialWombatChip::fwVersion
uint8_t fwVersion[4]
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:310
SW_INPUT
@ SW_INPUT
Definition: SerialWombat.h:51
SerialWombatChip::~SerialWombatChip
~SerialWombatChip()
Definition: SerialWombat.cpp:36
SerialWombatChip::echo
int16_t echo(char *data)
Definition: SerialWombat.h:1357
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:1519
SerialWombat18ABOscillatorTuner::update
void update()
Call periodically to tune the SW18AB oscillator to reported millis.
Definition: SerialWombat.h:1442
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:246
SerialWombatMatrixKeypad.h
SerialWombatCommands::CMD_RESYNC
@ CMD_RESYNC
('U')
SerialWombatChip::readDeviceIdentifier
void readDeviceIdentifier()
Definition: SerialWombat.h:430
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:254
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:1346
SerialWombatDataSource::SW_DATA_SOURCE_PIN_13
@ SW_DATA_SOURCE_PIN_13
(13) 16 bit public data provided by Pin 13
SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER
@ COMMAND_BINARY_READ_USER_BUFFER
(0x83)
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:247
SerialWombatThroughputConsumer.h
SerialWombatChip::communicationErrorRetries
uint8_t communicationErrorRetries
How many times to retry a packet if communcation bus (such as I2C) error.
Definition: SerialWombat.h:1344
SerialWombatCommands::CONFIGURE_PIN_MODE2
@ CONFIGURE_PIN_MODE2
(202)
SerialWombatChip::readUserBuffer
int16_t readUserBuffer(uint16_t index, uint8_t *buffer, uint16_t count)
Read data from the Serial Wombat 18AB's internal RAM buffer.
Definition: SerialWombat.h:1018
SerialWombatCommands::CMD_RESET
@ CMD_RESET
('R')
SerialWombatDebouncedInput.h
PIN_MODE_FRAME_TIMER
@ PIN_MODE_FRAME_TIMER
(21)
Definition: SerialWombat.h:259
SerialWombatCommands::CONFIGURE_PIN_INPUTPROCESS
@ CONFIGURE_PIN_INPUTPROCESS
(211)
PIN_MODE_LIQUIDCRYSTAL
@ PIN_MODE_LIQUIDCRYSTAL
(28)
Definition: SerialWombat.h:266
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:249
SerialWombatChip::model
uint8_t model[4]
Contains the last model retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:307
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)
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:1229
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:1335
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:1071
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:265
PIN_MODE_DIGITALIO
@ PIN_MODE_DIGITALIO
(0)
Definition: SerialWombat.h:242
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::COMMAND_CAPTURE_STARTUP_SEQUENCE
@ COMMAND_CAPTURE_STARTUP_SEQUENCE
(0xB6)
SerialWombatCommands::CMD_SUPPLYVOLTAGE
@ CMD_SUPPLYVOLTAGE
('v')
SerialWombatChip::readBrand
int16_t readBrand(char *data)
Definition: SerialWombat.h:1384
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)
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:257
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:264
PIN_MODE_VGA
@ PIN_MODE_VGA
(31)
Definition: SerialWombat.h:269
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:1341
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