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',
204  COMMAND_BINARY_CONFIGURE = 0x9F,
205  COMMAND_BINARY_READ_RAM = 0xA0,
208  COMMAND_BINARY_WRITE_RAM = 0xA3,
210  COMMAND_CALIBRATE_ANALOG = 0xA5,
211  COMMAND_ENABLE_2ND_UART = 0xA6,
213  COMMAND_UART0_TX_7BYTES = 0xB0,
214  COMMAND_UART0_RX_7BYTES = 0xB1,
215  COMMAND_UART1_TX_7BYTES = 0xB2,
216  COMMAND_UART1_RX_7BYTES = 0xB3,
221  CONFIGURE_PIN_MODE0 = 200,
222  CONFIGURE_PIN_MODE1 = 201,
223  CONFIGURE_PIN_MODE2 = 202,
224  CONFIGURE_PIN_MODE3 = 203,
225  CONFIGURE_PIN_MODE4 = 204,
226  CONFIGURE_PIN_MODE5 = 205,
227  CONFIGURE_PIN_MODE6 = 206,
228  CONFIGURE_PIN_MODE7 = 207,
229  CONFIGURE_PIN_MODE8 = 208,
230  CONFIGURE_PIN_MODE9 = 209,
231  CONFIGURE_PIN_MODE10 = 210,
239 
240 };
241 
242 
243 typedef enum {
279 
280 class SerialWombatChip;
281 
282 typedef void (*SerialWombatErrorHandler_t) (uint16_t errorNumber, SerialWombatChip* sw);
283 
290 {
291 private:
292 
293  char version[8] = { 0 };
294  HardwareSerial * Serial = NULL;
295  TwoWire* i2cInterface = NULL;
296  uint8_t _pinmode[WOMBAT_MAXIMUM_PINS]={}; // Includes Pullup
297  bool _pullDown[WOMBAT_MAXIMUM_PINS]={};
298  bool _openDrain[WOMBAT_MAXIMUM_PINS]={};
299  bool _highLow[WOMBAT_MAXIMUM_PINS] = {};
300  bool _asleep = false;
301  SerialWombatErrorHandler_t errorHandler = NULL;
302  bool _currentlyCommunicating = false;
303 public:
310  uint16_t _supplyVoltagemV = 0;
311 
313  uint8_t model[4] = { 0 };
314 
316  uint8_t fwVersion[4] = { 0 };
317 
323  uint8_t uniqueIdentifier[16];
324 
330 
336 
341  uint16_t deviceRevision;
343  uint16_t errorCount = 0;
344 
346  bool inBoot = false;
347 
349  int16_t lastErrorCode = 0;
350 
351  void configureDigitalPin(uint8_t pin, uint8_t highLow)
352  {
353  uint8_t tx[8] = { 200,pin,0,0,0,0,0,0x55 };
354  uint8_t rx[8];
355  switch (_pinmode[pin])
356  {
357  case INPUT: // Arduino input
358  {
359  tx[3] = 2; //Input
360  }
361  break;
362  case OUTPUT:
363  {
364  if (highLow == LOW)
365  {
366  tx[3] = 0;
367  }
368  else if (highLow == HIGH)
369  {
370  tx[3] = 1;
371  }
372  else
373  {
374  return;
375  }
376  }
377  break;
378  case INPUT_PULLUP:
379  {
380  tx[3] = 2; //Input
381  tx[4] = 1; //Pullup on
382  }
383  break;
384  default:
385  {
386  return;
387  }
388  }
389  tx[6] = _openDrain[pin];
390  tx[5] = _pullDown[pin];
391  sendPacket(tx, rx, true);
392  }
393  uint32_t sendReadyTime = 0;
394  int16_t initialize()
395  {
396  int16_t retvalue = -1;
397  lastErrorCode = 0;
398  readVersion();
402  return(lastErrorCode);
403  }
404 
406  {
408  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
409  { //16F15214
410  for (uint32_t address = 0x8100; address <= 0x8108; ++address)
411  {
412  uint32_t data = readFlashAddress(address);
413  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)data;
415  /* Always zero... leave out
416  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)(data>>8);
417  ++uniqueIdentifierLength;
418  */
419  }
420  }
421  else if (isSW18())
422  {
423  for (uint32_t address = 0x801600; address <= 0x801608; address += 2)
424  {
425  uint32_t data = readFlashAddress(address);
432  }
433  }
434  }
435 
437  {
438  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
439  { //16F15214
440 
441  uint32_t data = readFlashAddress(0x8006);
442  deviceIdentifier = (uint16_t)data;
443  data = readFlashAddress(0x8005);
444  deviceRevision = (uint16_t)data;
445  }
446  else if (isSW18())
447  {
448  uint32_t data = readFlashAddress(0xFF0000);
449  deviceIdentifier = (uint16_t)data;
450  data = readFlashAddress(0xFF0002);
451  deviceRevision = (uint16_t)data & 0xF;
452  }
453  }
454 
455  uint16_t returnErrorCode(uint8_t* rx)
456  {
457  uint16_t result = rx[1] - '0';
458  result *= 10;
459  result += rx[2] - '0';
460  result *= 10;
461  result += rx[3] - '0';
462  result *= 10;
463  result += rx[4] - '0';
464  result *= 10;
465  result += rx[5] - '0';
466  return(result);
467  }
468 
469 
470 
471 public:
486  int16_t begin(HardwareSerial& serial, bool reset = true)
487  {
488  Serial = &serial;
489  Serial->begin(115200);
490  Serial->setTimeout(2);
491  Serial->write((uint8_t*)"UUUUUUUU", 8);
492  delay(5);
493  while (Serial->read() >= 0);
494  if (reset)
495  {
496  hardwareReset();
497  sendReadyTime = millis() + 1000;
498  return(1);
499  }
500  else
501  {
502  return initialize();
503  }
504 
505 
506  }
507 
517  int16_t begin(uint8_t i2cAddress);
518 
532  int16_t begin(TwoWire& wire, uint8_t i2cAddress, bool reset = true)
533  {
534  i2cInterface = &wire;
535  address = i2cAddress;
536 
537  Wire.beginTransmission(i2cAddress);
538  int error = Wire.endTransmission();
539 
540 
541  if (error != 0)
542  {
543  return(-1);
544  }
545 
546  if (reset)
547  {
548  hardwareReset();
549  sendReadyTime = millis() + 1000;
550  return(1);
551  }
552  else
553  {
554  sendReadyTime = 0;
555  return initialize();
556 
557  }
558  }
559 
561 
572  int sendPacket( uint8_t tx[], uint8_t rx[]);
573 
583  int sendPacket(uint8_t tx[]);
584 
595  int sendPacket(uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch = 8, uint8_t endBytesToMatch = 0);
605  int sendPacket(uint8_t tx[], bool retryIfEchoDoesntMatch);
606 
616  int sendPacketNoResponse(uint8_t tx[]);
617 
626  char* readVersion(void)
627  {
628  uint8_t tx[] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
629  uint8_t rx[8];
630  sendPacket(tx, rx);
631  memcpy(version, &rx[1], 7);
632  version[7] = '\0';
633  memcpy(model, &rx[1], 3);
634  model[3] = '\0';
635  fwVersion[0] = rx[5];
636  fwVersion[1] = rx[6];
637  fwVersion[2] = rx[7];
638  return (version);
639  }
640 
647  uint32_t readVersion_uint32(void)
648  {
649  readVersion();
650  return ((((uint32_t)fwVersion[0]) << 16) |
651  (((uint32_t)fwVersion[1]) << 8) |
652  fwVersion[2]);
653  }
654 
664  uint16_t readPublicData(uint8_t pin)
665  {
666  uint8_t tx[] = { 0x81,pin,255,255,0x55,0x55,0x55,0x55 };
667  uint8_t rx[8];
668  sendPacket(tx, rx);
669  return(rx[2] + (uint16_t)rx[3] * 256);
670  }
671 
682  {
683  return (readPublicData((uint8_t)dataSource));
684  }
685 
691  uint16_t writePublicData(uint8_t pin, uint16_t value)
692  {
693  uint8_t tx[] = { 0x82,pin,(uint8_t)(value & 0xFF),(uint8_t)(value >> 8) ,255,0x55,0x55,0x55 };
694  uint8_t rx[8];
695  sendPacket(tx, rx);
696  return (rx[2] + rx[3] * 256);
697  }
698 
709  uint16_t readSupplyVoltage_mV(void)
710  {
711  if (isSW18())
712  {
714  }
715  else
716  {
717  int32_t counts = readPublicData(66); // Get FVR counts (1.024 v)
718  if (counts > 0)
719  {
720  uint32_t mv = 1024 * 65536 / counts;
721  _supplyVoltagemV = (uint16_t)mv;
722  }
723  else
724  {
725  _supplyVoltagemV = 0;
726  }
727  }
728  return(_supplyVoltagemV);
729  }
730 
731 
743  {
744  if (isSW18())
745  {
746  int32_t result = readPublicData(70);
747  if (result >= 32768)
748  {
749  result = result - 65536;
750  }
751  return ((int16_t)result);
752  }
753  else
754  {
755  return 2500;
756  }
757  }
758 
766  {
767  uint8_t tx[9] = "ReSeT!#*";
768  uint8_t rx[8];
769  sendPacket(tx, rx);
770  }
771 
780  void pinMode(uint8_t pin, uint8_t mode, bool pullDown = false, bool openDrain = false)
781  {
782  if (pin >= WOMBAT_MAXIMUM_PINS)
783  {
784  return;
785  }
786  _pullDown[pin] = openDrain;
787  _openDrain[pin] = openDrain;
788  _pinmode[pin] = mode;
789  configureDigitalPin(pin, mode);
790  }
791 
799  void digitalWrite(uint8_t pin, uint8_t val)
800  {
801  configureDigitalPin(pin, val);
802  }
803 
809  int digitalRead(uint8_t pin)
810  {
811  if (readPublicData(pin) > 0)
812  {
813  return (HIGH);
814  }
815  else
816  {
817  return (LOW);
818  }
819  }
820 
830  int analogRead(uint8_t pin)
831  {
832  uint8_t tx[] = { 200,pin,PIN_MODE_ANALOGINPUT,0,0,0,0,0 };
833  uint8_t rx[8];
834  sendPacket(tx, rx);
835  return (readPublicData(pin) >> 6); // Scale from 16 bit value to 10 bit value.
836  }
837 
849  void analogWrite(uint8_t pin, int val)
850  {
851  uint8_t dutyCycleLow = 0;
852  if (val == 255)
853  {
854  dutyCycleLow = 255;
855  }
856  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_PWM,pin,dutyCycleLow,(uint8_t) val,false,0x55 };
857  uint8_t rx[8];
858  sendPacket(tx, rx);
859  }
860 
872  {
873  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
874  uint8_t rx[8];
875  sendPacket(tx, rx);
876  if (rx[0] == 'V' && (rx[1] == 'S' || rx[1] == 'B'))
877  {
878  model[0] = rx[1];
879  model[1] = rx[2];
880  model[2] = rx[3];
881  model[3] = 0;
882  fwVersion[0] = rx[5];
883  fwVersion[1] = rx[6];
884  fwVersion[2] = rx[7];
885  fwVersion[3] = 0;
886 
887  inBoot = (rx[1] == 'B');
888  return (true);
889  }
890  return (false);
891  }
892 
900  {
901  uint8_t tx[8] = { 0x81,67,68,0x55,0x55,0x55,0x55,0x55 };
902  uint8_t rx[8];
903  sendPacket(tx, rx);
904  uint32_t returnval = rx[2] + (((uint32_t)rx[3]) << 8) + (((uint32_t)rx[4]) << 16) + (((uint32_t)rx[5]) << 24);
905  return (returnval);
906  }
907 
917  {
918  return readPublicData(69);
919  }
920 
930  void jumpToBoot()
931  {
932  uint8_t tx[] = "BoOtLoAd";
933  sendPacket(tx);
934  }
935 
956  uint8_t readRamAddress(uint16_t address)
957  {
958  uint8_t tx[8] = { 0xA0,SW_LE16(address),0x55,0x55,0x55,0x55,0x55 };
959  uint8_t rx[8];
960  sendPacket(tx, rx);
961  return(rx[3]);
962  }
963 
984  int16_t writeRamAddress(uint16_t address, uint8_t value)
985  {
986  uint8_t tx[8] = { 0xA3,SW_LE16(address),0,0,value,0x55,0x55};
987  return sendPacket(tx);
988  }
989 
1005  uint32_t readFlashAddress(uint32_t address)
1006  {
1007  uint8_t tx[8] = { 0xA1,SW_LE32(address),0x55,0x55,0x55 };
1008  uint8_t rx[8];
1009  sendPacket(tx, rx);
1010  return(((uint32_t)rx[4]) + (((uint32_t)rx[5]) <<8) + (((uint32_t)rx[6]) <<16) + (((uint32_t)rx[7]) <<24));
1011  }
1012 
1024  int16_t readUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1025  {
1026  uint16_t bytesRead = 0;
1027  while (bytesRead < count)
1028  {
1029  byte tx[] = {(byte)SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER, (byte)(index & 0xFF), (byte)(index >> 8), 0x55, 0x55, 0x55, 0x55, 0x55};
1030  byte rx[8];
1031  int16_t result = sendPacket(tx, rx);
1032  if (result >= 0)
1033  {
1034  for (int i = 1; i < 8; ++i)
1035  {
1036  buffer[bytesRead] = rx[i];
1037  ++bytesRead;
1038  ++index;
1039  if (bytesRead >= count)
1040  {
1041  break;
1042  }
1043  }
1044  }
1045  else
1046  {
1047  return (bytesRead);
1048  }
1049  }
1050  return (bytesRead);
1051  }
1062  void sleep()
1063  {
1064  uint8_t tx[8] = { 'S','l','E','e','P','!','#','*'};
1065  sendPacket(tx);
1066  _asleep = true;
1067  }
1068 
1070  void wake()
1071  {
1072  uint8_t tx[8] = { '!','!','!','!','!','!','!','!' };
1073  sendPacket(tx);
1074  }
1075 
1077  bool isSW18()
1078  {
1079  return ( model[1] == '1' && model[2] == '8');
1080  }
1081 
1083  int16_t eraseFlashPage(uint32_t address)
1084  {
1085  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1086  0, //Erase Page
1087  SW_LE32(address),
1088  0x55,0x55 };
1089  return sendPacket(tx);
1090  }
1091 
1092 
1094  int16_t writeFlashRow(uint32_t address)
1095  {
1096  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1097  1, // Write entire row
1098  SW_LE32(address),0x55,0x55 };
1099  return sendPacket(tx);
1100  }
1101 
1102 
1103 
1104 
1114  int16_t setThroughputPin(uint8_t pin)
1115  {
1116  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1117  return sendPacket(tx);
1118  }
1119 
1127  int writeUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1128  {
1129  uint16_t bytesSent = 0;
1130  if (count == 0)
1131  {
1132  return 0;
1133  }
1134 
1135  { // Send first packet of up to 4 bytes
1136  uint8_t bytesToSend = 4;
1137  if (count < 4)
1138  {
1139  bytesToSend = (uint8_t)count;
1140  count = 0;
1141  }
1142  else
1143  {
1144  count -= 4;
1145  }
1146 
1147  uint8_t tx[8] = { 0x84,SW_LE16(index), bytesToSend,0x55,0x55,0x55,0x55 };
1148  uint8_t rx[8];
1149 
1150  uint8_t i;
1151  for (i = 0; i < bytesToSend; ++i)
1152  {
1153  tx[4 + i] = buffer[i];
1154  }
1155  int result = sendPacket(tx, rx);
1156  if (rx[0] == 'E')
1157  {
1158  return (result);
1159  }
1160  bytesSent = bytesToSend;
1161  }
1162  while (count >= 7) // Continue sending
1163  {
1164 
1165  count -= 7;
1166  uint8_t tx[8] = { 0x85,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1167  uint8_t rx[8];
1168  uint8_t i;
1169  for (i = 0; i < 7; ++i)
1170  {
1171  tx[1 + i] = buffer[bytesSent + i];
1172  }
1173  int result = sendPacket(tx, rx);
1174  if (rx[0] == 'E')
1175  {
1176  return (result);
1177  }
1178  bytesSent += 7;
1179  }
1180  while (count > 0)
1181  {
1182 
1183  { // Send first packet of up to 4 bytes
1184  uint8_t bytesToSend = 4;
1185  if (count < 4)
1186  {
1187  bytesToSend = (uint8_t)count;
1188  count = 0;
1189  }
1190  else
1191  {
1192  count -= 4;
1193  }
1194 
1195  uint8_t tx[8] = { 0x84,SW_LE16(index + bytesSent), bytesToSend,0x55,0x55,0x55,0x55 };
1196  uint8_t rx[8];
1197 
1198  uint8_t i;
1199  for (i = 0; i < bytesToSend; ++i)
1200  {
1201  tx[4 + i] = buffer[i + bytesSent];
1202  }
1203  int result = sendPacket(tx, rx);
1204  if (rx[0] == 'E')
1205  {
1206  return (result);
1207  }
1208  bytesSent += bytesToSend;
1209  }
1210  }
1211  return(bytesSent);
1212 
1213 
1214  }
1215 
1223  int writeUserBuffer(uint16_t index, char* s)
1224  {
1225  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1226  }
1227 
1235  int writeUserBuffer(uint16_t index, const char s[])
1236  {
1237  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1238  }
1239 
1240 
1241 
1253  int16_t writeFrameTimerPin(uint8_t pin)
1254 {
1255  uint8_t tx[] = { 0xC8 ,pin,(uint8_t)PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1256  return sendPacket(tx);
1257 }
1258 
1259 
1267  static uint8_t find(bool keepTrying = false)
1268  {
1269  do
1270  {
1271  for (int i2cAddress = 0x68; i2cAddress <= 0x6F; ++i2cAddress)
1272  {
1273  Wire.beginTransmission(i2cAddress);
1274  int error = Wire.endTransmission();
1275 
1276 
1277  if (error == 0)
1278  {
1279  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1280  uint8_t rx[8];
1281  Wire.beginTransmission(i2cAddress);
1282  Wire.write(tx, 8);
1283  Wire.endTransmission();
1284  Wire.requestFrom((uint8_t)i2cAddress, (uint8_t)8);
1285 
1286  int count = 0;
1287  while (Wire.available() && count < 8)
1288  {
1289  rx[count] = Wire.read();
1290  ++count;
1291  }
1292  if (count == 8)
1293  {
1294  if (rx[0] == 'V' && rx[1] == 'S')
1295  {
1296  return(i2cAddress); // Found one.
1297  }
1298  }
1299  }
1300  }
1301  delay(0);
1302  }while (keepTrying);
1303  return(0); // Didn't find one.
1304  }
1305 
1306 
1313  int16_t readLastErrorCommand(uint8_t* cmd)
1314 {
1315  //TODO this doen't look like it returns the error
1316  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET, 0,0x55,0x55,0x55,0x55,0x55,0x55 };
1317  uint8_t rx[8];
1318  if (sendPacket(tx, rx) >= 0)
1319  {
1320  for (int i = 1; i < 8; ++i)
1321  {
1322  cmd[i - 1] = rx[i];
1323  }
1324  }
1325  else
1326  {
1327  return (lastErrorCode);
1328  }
1329  tx[1] = 7;
1330  if (sendPacket(tx, rx) >= 0)
1331  {
1332  cmd[7] = rx[1];
1333  }
1334  return(lastErrorCode);
1335 }
1336 
1342  {
1343  errorHandler = handler;
1344  }
1345 
1347  uint8_t address = 0;
1348 
1351 
1352  int16_t echo(uint8_t data[], uint8_t count = 7)
1353  {
1354  uint8_t tx[] = "!UUUUUUU";
1355  for (int i = 0; i < 7 && i < count; ++i)
1356  {
1357  tx[i + 1] = (uint8_t)data[i];
1358  }
1359  return sendPacket(tx);
1360  }
1361 
1362 
1363  int16_t echo(char* data)
1364  {
1365  int length = strlen(data);
1366  uint8_t tx[] = "!UUUUUUU";
1367  for (int i = 0; i < 7 && i < length; ++i)
1368  {
1369  tx[i + 1] = (uint8_t)data[i];
1370  }
1371  return sendPacket(tx);
1372  }
1373 
1374  uint32_t readBirthday()
1375  {
1376  if (isSW18())
1377  {
1378  uint32_t birthday = (readFlashAddress(0x2A00C) >> 8) & 0xFF;
1379  birthday *= 100;
1380  birthday += (readFlashAddress(0x2A00C)) & 0xFF;
1381  birthday *= 100;
1382  birthday += readFlashAddress(0x2A00E) & 0xFF;
1383  birthday *= 100;
1384  birthday += readFlashAddress(0x2A010) & 0xFF;
1385  return (birthday);
1386  }
1387  return 0;
1388  }
1389 
1390  int16_t readBrand(char* data)
1391  {
1392  uint8_t length = 0;
1393  if (isSW18())
1394  {
1395  for (int i = 0; i < 32; ++i)
1396  {
1397  uint32_t val = readFlashAddress(0x2A020 + i * 2) ;
1398  if ((val & 0xFF) != 0xFF)
1399  {
1400  data[i ] = (char)(val & 0xFF);
1401  ++length;
1402  }
1403  else
1404  {
1405  data[length] = 0;
1406  return (length);
1407  }
1408  }
1409  data[length] = 0;
1410  return (length);
1411  }
1412 
1413  data[0] = 0;
1414  return 0 ;
1415  }
1416 
1417 };
1418 
1433 {
1434 private:
1435  SerialWombatChip& _sw;
1436  uint32_t lastMillis = 0;
1437  uint32_t lastFrames = 0;
1438 public:
1443  SerialWombat18ABOscillatorTuner(SerialWombatChip& serialWombatChip) : _sw(serialWombatChip) { }
1444 
1448  void update() {
1449  uint32_t m = millis();
1450  if (lastMillis == 0)
1451  {
1452  lastMillis = m;
1456  {
1459  }
1460  frames <<= 16;
1461  frames += frameslsb;
1462  lastFrames = frames;
1463 
1464  }
1465  else if ((m - lastMillis) < 10000)
1466  {
1467  //Do nothing
1468  }
1469  else if (m < lastMillis)
1470  {
1471  //Has it been 47 days already?
1472  lastMillis = 0;
1473  }
1474  else
1475  {
1476  uint32_t diff = m - lastMillis;
1477 
1480 
1482  {
1485  }
1486  frames <<= 16;
1487  frames += frameslsb;
1488  uint32_t framesDif = frames - lastFrames;
1489 
1490  if (diff > framesDif )
1491  {
1492  // Running slow
1493  uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1494  SW_LE16(1),//Counts to increment
1495  SW_LE16(0), // Counts to decrement
1496  0x55,0x55,0x55};
1497  _sw.sendPacket(tx);
1498  }
1499  else if (diff < framesDif)
1500  {
1501  // Running mfast
1502  uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1503  SW_LE16(0),//Counts to increment
1504  SW_LE16(1), // Counts to decrement
1505  0x55,0x55,0x55 };
1506  _sw.sendPacket(tx);
1507 
1508  }
1509 
1510  lastMillis = m;
1511  lastFrames = frames;
1512 
1513  }
1514 
1515  }
1516 
1517 };
1518 
1519 /*
1520 End of cross platform code synchronization. Random string to help the compare tool sync lines:
1521 asdkj38vjn1nasdnvuwlamafdjiivnowalskive
1522 */
1523 
1525 class SerialWombat : public SerialWombatChip {};
1526 
1527 
1528 
1529 
1530 
1538 void SerialWombatSerialErrorHandlerBrief(uint16_t error, SerialWombatChip* sw);
1540 
1541 #include "SerialWombatPin.h"
1542 #include "SerialWombatErrors.h"
1543 #include "SerialWombatQueue.h"
1548 #include "SerialWombat18CapTouch.h"
1549 #include "SerialWombat18ABVGA.h"
1550 #include "SerialWombatAnalogInput.h"
1553 #include "SerialWombatHBridge.h"
1554 #include "SerialWombatHSClock.h"
1555 #include "SerialWombatHSCounter.h"
1556 #include "SerialWombatLiquidCrystal.h"
1557 #include "SerialWombatMatrixKeypad.h"
1560 #include "SerialWombatPS2Keyboard.h"
1561 #include "SerialWombatPulseOnChange.h"
1562 #include "SerialWombatPulseTimer.h"
1563 #include "SerialWombatPWM.h"
1564 #include "SerialWombatQuadEnc.h"
1567 #include "SerialWombatServo.h"
1568 #include "SerialWombatTM1637.h"
1569 #include "SerialWombatUART.h"
1571 #include "SerialWombatWatchdog.h"
1572 #include "SerialWombatWS2812.h"
1574 
1575 #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:1253
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:289
PIN_MODE_ANALOGINPUT
@ PIN_MODE_ANALOGINPUT
(2)
Definition: SerialWombat.h:246
SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET
@ COMMAND_READ_LAST_ERROR_PACKET
(0xA7)
SerialWombatCommands::COMMAND_ENABLE_2ND_UART
@ COMMAND_ENABLE_2ND_UART
(0xA6)
SerialWombatQueuedPulseOutput.h
SerialWombatChip::jumpToBoot
void jumpToBoot()
Jump to Bootloader and wait for a UART download of new firmware.
Definition: SerialWombat.h:930
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:1223
PIN_MODE_PULSE_ON_CHANGE
@ PIN_MODE_PULSE_ON_CHANGE
(25)
Definition: SerialWombat.h:266
PIN_MODE_SW18AB_CAPTOUCH
@ PIN_MODE_SW18AB_CAPTOUCH
(22)
Definition: SerialWombat.h:263
SerialWombatHSClock.h
PIN_MODE_HS_CLOCK
@ PIN_MODE_HS_CLOCK
Definition: SerialWombat.h:270
PIN_MODE_UART1_RX_TX
@ PIN_MODE_UART1_RX_TX
(23)
Definition: SerialWombat.h:264
SerialWombatCommands::COMMAND_BINARY_QUEUE_INFORMATION
@ COMMAND_BINARY_QUEUE_INFORMATION
(0x94)
SerialWombatWS2812.h
PIN_MODE_DEBOUNCE
@ PIN_MODE_DEBOUNCE
(10)
Definition: SerialWombat.h:253
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:282
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:349
SerialWombatChip::readPublicData
uint16_t readPublicData(SerialWombatDataSource dataSource)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:681
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:393
SerialWombatChip::digitalRead
int digitalRead(uint8_t pin)
Reads the state of a Pin.
Definition: SerialWombat.h:809
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:289
SerialWombatPinMode_t
SerialWombatPinMode_t
Definition: SerialWombat.h:243
SerialWombatAnalogInput.h
SerialWombatChip::analogRead
int analogRead(uint8_t pin)
Configures pin as analog input and does an immediate A/D conversion.
Definition: SerialWombat.h:830
SerialWombatCommands::COMMAND_BINARY_RW_PIN_MEMORY
@ COMMAND_BINARY_RW_PIN_MEMORY
(0xB5)
SerialWombatHBridge.h
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:849
SerialWombat18ABOscillatorTuner::SerialWombat18ABOscillatorTuner
SerialWombat18ABOscillatorTuner(SerialWombatChip &serialWombatChip)
Class constructor for SerialWombat18OscillatorTuner.
Definition: SerialWombat.h:1443
PIN_MODE_WATCHDOG
@ PIN_MODE_WATCHDOG
(7)
Definition: SerialWombat.h:251
SerialWombatChip::returnErrorCode
uint16_t returnErrorCode(uint8_t *rx)
Definition: SerialWombat.h:455
PIN_MODE_CONTROLLED
@ PIN_MODE_CONTROLLED
(1)
Definition: SerialWombat.h:245
PIN_MODE_SW_UART
@ PIN_MODE_SW_UART
(13)
Definition: SerialWombat.h:256
SerialWombatChip::queryVersion
bool queryVersion()
Send a version request to the Serial Wombat chip.
Definition: SerialWombat.h:871
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:1114
PIN_MODE_PS2KEYBOARD
@ PIN_MODE_PS2KEYBOARD
(32)
Definition: SerialWombat.h:273
SerialWombatLiquidCrystal.h
SerialWombatChip::readSupplyVoltage_mV
uint16_t readSupplyVoltage_mV(void)
Measure the Serial Wombat chip's Supply voltage.
Definition: SerialWombat.h:709
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:346
SerialWombatChip::_supplyVoltagemV
uint16_t _supplyVoltagemV
Definition: SerialWombat.h:310
SerialWombat18ABVGA.h
SerialWombatCommands::COMMAND_BINARY_QUEUE_CLONE
@ COMMAND_BINARY_QUEUE_CLONE
(0x95)
SerialWombat18CapTouch.h
PIN_MODE_RESISTANCEINPUT
@ PIN_MODE_RESISTANCEINPUT
(24)
Definition: SerialWombat.h:265
SerialWombatChip::readFramesExecuted
uint32_t readFramesExecuted()
Get the number of 1mS frames that have been executed since Serial Wombat chip reset.
Definition: SerialWombat.h:899
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:254
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:1070
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:780
PIN_MODE_PWM
@ PIN_MODE_PWM
(16)
Definition: SerialWombat.h:259
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)
PIN_MODE_HBRIDGE
@ PIN_MODE_HBRIDGE
(6)
Definition: SerialWombat.h:250
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:486
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:532
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:247
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:394
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:359
SerialWombatChip::SerialWombatChip
SerialWombatChip()
Definition: SerialWombat.cpp:31
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:765
PIN_MODE_PULSETIMER
@ PIN_MODE_PULSETIMER
(18)
Definition: SerialWombat.h:261
SerialWombatChip::uniqueIdentifierLength
uint8_t uniqueIdentifierLength
Definition: SerialWombat.h:329
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:1083
SerialWombatChip::readLastErrorCommand
int16_t readLastErrorCommand(uint8_t *cmd)
Returns the last Serial Wombat command that produced a protocol error.
Definition: SerialWombat.h:1313
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...
SerialWombat18ABDataLogger.h
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:799
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:258
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:916
SerialWombatCommands::CONFIGURE_PIN_MODE9
@ CONFIGURE_PIN_MODE9
(209)
SerialWombatChip::deviceIdentifier
uint16_t deviceIdentifier
Definition: SerialWombat.h:335
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
PIN_MODE_QUEUED_PULSE_OUTPUT
@ PIN_MODE_QUEUED_PULSE_OUTPUT
(34)
Definition: SerialWombat.h:275
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:1267
SerialWombatChip::readPublicData
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:664
SerialWombatCommands::COMMAND_BINARY_CONFIG_DATALOGGER
@ COMMAND_BINARY_CONFIG_DATALOGGER
(0x96)
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:405
PIN_MODE_HS_COUNTER
@ PIN_MODE_HS_COUNTER
< (29)
Definition: SerialWombat.h:271
SerialWombat18ABOscillatorTuner
A class which tunes the oscillator on a Serial Wombat 18AB chip.
Definition: SerialWombat.h:1432
SerialWombatChip::readFlashAddress
uint32_t readFlashAddress(uint32_t address)
Read Address from Flash based on 32 bit address.
Definition: SerialWombat.h:1005
SerialWombatChip::readTemperature_100thsDegC
int16_t readTemperature_100thsDegC(void)
Measure the Serial Wombat chip's internal temperature.
Definition: SerialWombat.h:742
SerialWombatFrequencyOutput.h
SerialWombatChip::uniqueIdentifier
uint8_t uniqueIdentifier[16]
Definition: SerialWombat.h:323
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:1094
SerialWombatChip::errorCount
uint16_t errorCount
Incremented every time a communication or command error is detected.
Definition: SerialWombat.h:343
SerialWombatChip::readRamAddress
uint8_t readRamAddress(uint16_t address)
Read Address from RAM based on 16 bit address.
Definition: SerialWombat.h:956
SerialWombatChip::readBirthday
uint32_t readBirthday()
Definition: SerialWombat.h:1374
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:984
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:115
SerialWombatCommands::CONFIGURE_PIN_MODE_HW_0
@ CONFIGURE_PIN_MODE_HW_0
(220)
PIN_MODE_WS2812
@ PIN_MODE_WS2812
(12)
Definition: SerialWombat.h:255
PIN_MODE_UNKNOWN
@ PIN_MODE_UNKNOWN
(0xFF)
Definition: SerialWombat.h:277
SerialWombatCommands::COMMAND_CALIBRATE_ANALOG
@ COMMAND_CALIBRATE_ANALOG
(0xA5)
PIN_MODE_FREQUENCY_OUTPUT
@ PIN_MODE_FREQUENCY_OUTPUT
(36)
Definition: SerialWombat.h:276
SerialWombatChip::configureDigitalPin
void configureDigitalPin(uint8_t pin, uint8_t highLow)
Definition: SerialWombat.h:351
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:341
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:1062
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:691
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:1127
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:626
SerialWombatCommands::COMMAND_BINARY_CONFIGURE
@ COMMAND_BINARY_CONFIGURE
(0x9F)
SerialWombatChip::readVersion_uint32
uint32_t readVersion_uint32(void)
Request version as a uint32.
Definition: SerialWombat.h:647
SerialWombatChip::fwVersion
uint8_t fwVersion[4]
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:316
SW_INPUT
@ SW_INPUT
Definition: SerialWombat.h:51
SerialWombatChip::~SerialWombatChip
~SerialWombatChip()
Definition: SerialWombat.cpp:37
SerialWombatChip::echo
int16_t echo(char *data)
Definition: SerialWombat.h:1363
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:1525
SerialWombat18ABOscillatorTuner::update
void update()
Call periodically to tune the SW18AB oscillator to reported millis.
Definition: SerialWombat.h:1448
PIN_MODE_I2C_CONTROLLER
@ PIN_MODE_I2C_CONTROLLER
(33)
Definition: SerialWombat.h:274
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:248
SerialWombatMatrixKeypad.h
SerialWombatCommands::CMD_RESYNC
@ CMD_RESYNC
('U')
SerialWombatChip::readDeviceIdentifier
void readDeviceIdentifier()
Definition: SerialWombat.h:436
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:257
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:1352
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:249
SerialWombatThroughputConsumer.h
SerialWombatChip::communicationErrorRetries
uint8_t communicationErrorRetries
How many times to retry a packet if communcation bus (such as I2C) error.
Definition: SerialWombat.h:1350
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:1024
SerialWombatCommands::CMD_RESET
@ CMD_RESET
('R')
SerialWombatDebouncedInput.h
PIN_MODE_FRAME_TIMER
@ PIN_MODE_FRAME_TIMER
(21)
Definition: SerialWombat.h:262
SerialWombatCommands::CONFIGURE_PIN_INPUTPROCESS
@ CONFIGURE_PIN_INPUTPROCESS
(211)
PIN_MODE_LIQUIDCRYSTAL
@ PIN_MODE_LIQUIDCRYSTAL
(28)
Definition: SerialWombat.h:269
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:252
SerialWombatChip::model
uint8_t model[4]
Contains the last model retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:313
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:1235
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:1341
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:1077
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:268
PIN_MODE_DIGITALIO
@ PIN_MODE_DIGITALIO
(0)
Definition: SerialWombat.h:244
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:1390
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:260
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:267
PIN_MODE_VGA
@ PIN_MODE_VGA
(31)
Definition: SerialWombat.h:272
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:1347
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