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 {
276 
277 class SerialWombatChip;
278 
279 typedef void (*SerialWombatErrorHandler_t) (uint16_t errorNumber, SerialWombatChip* sw);
280 
287 {
288 private:
289 
290  char version[8] = { 0 };
291  HardwareSerial * Serial = NULL;
292  TwoWire* i2cInterface = NULL;
293  uint8_t _pinmode[WOMBAT_MAXIMUM_PINS]={}; // Includes Pullup
294  bool _pullDown[WOMBAT_MAXIMUM_PINS]={};
295  bool _openDrain[WOMBAT_MAXIMUM_PINS]={};
296  bool _highLow[WOMBAT_MAXIMUM_PINS] = {};
297  bool _asleep = false;
298  SerialWombatErrorHandler_t errorHandler = NULL;
299  bool _currentlyCommunicating = false;
300 public:
307  uint16_t _supplyVoltagemV = 0;
308 
310  uint8_t model[4] = { 0 };
311 
313  uint8_t fwVersion[4] = { 0 };
314 
320  uint8_t uniqueIdentifier[16];
321 
327 
333 
338  uint16_t deviceRevision;
340  uint16_t errorCount = 0;
341 
343  bool inBoot = false;
344 
346  int16_t lastErrorCode = 0;
347 
348  void configureDigitalPin(uint8_t pin, uint8_t highLow)
349  {
350  uint8_t tx[8] = { 200,pin,0,0,0,0,0,0x55 };
351  uint8_t rx[8];
352  switch (_pinmode[pin])
353  {
354  case INPUT: // Arduino input
355  {
356  tx[3] = 2; //Input
357  }
358  break;
359  case OUTPUT:
360  {
361  if (highLow == LOW)
362  {
363  tx[3] = 0;
364  }
365  else if (highLow == HIGH)
366  {
367  tx[3] = 1;
368  }
369  else
370  {
371  return;
372  }
373  }
374  break;
375  case INPUT_PULLUP:
376  {
377  tx[3] = 2; //Input
378  tx[4] = 1; //Pullup on
379  }
380  break;
381  default:
382  {
383  return;
384  }
385  }
386  tx[6] = _openDrain[pin];
387  tx[5] = _pullDown[pin];
388  sendPacket(tx, rx, true);
389  }
390  uint32_t sendReadyTime = 0;
391  int16_t initialize()
392  {
393  int16_t retvalue = -1;
394  lastErrorCode = 0;
395  readVersion();
399  return(lastErrorCode);
400  }
401 
403  {
405  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
406  { //16F15214
407  for (uint32_t address = 0x8100; address <= 0x8108; ++address)
408  {
409  uint32_t data = readFlashAddress(address);
410  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)data;
412  /* Always zero... leave out
413  uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)(data>>8);
414  ++uniqueIdentifierLength;
415  */
416  }
417  }
418  else if (isSW18())
419  {
420  for (uint32_t address = 0x801600; address <= 0x801608; address += 2)
421  {
422  uint32_t data = readFlashAddress(address);
429  }
430  }
431  }
432 
434  {
435  if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
436  { //16F15214
437 
438  uint32_t data = readFlashAddress(0x8006);
439  deviceIdentifier = (uint16_t)data;
440  data = readFlashAddress(0x8005);
441  deviceRevision = (uint16_t)data;
442  }
443  else if (isSW18())
444  {
445  uint32_t data = readFlashAddress(0xFF0000);
446  deviceIdentifier = (uint16_t)data;
447  data = readFlashAddress(0xFF0002);
448  deviceRevision = (uint16_t)data & 0xF;
449  }
450  }
451 
452  uint16_t returnErrorCode(uint8_t* rx)
453  {
454  uint16_t result = rx[1] - '0';
455  result *= 10;
456  result += rx[2] - '0';
457  result *= 10;
458  result += rx[3] - '0';
459  result *= 10;
460  result += rx[4] - '0';
461  result *= 10;
462  result += rx[5] - '0';
463  return(result);
464  }
465 
466 
467 
468 public:
483  int16_t begin(HardwareSerial& serial, bool reset = true)
484  {
485  Serial = &serial;
486  Serial->begin(115200);
487  Serial->setTimeout(2);
488  Serial->write((uint8_t*)"UUUUUUUU", 8);
489  delay(5);
490  while (Serial->read() >= 0);
491  if (reset)
492  {
493  hardwareReset();
494  sendReadyTime = millis() + 1000;
495  return(1);
496  }
497  else
498  {
499  return initialize();
500  }
501 
502 
503  }
504 
514  int16_t begin(uint8_t i2cAddress);
515 
529  int16_t begin(TwoWire& wire, uint8_t i2cAddress, bool reset = true)
530  {
531  i2cInterface = &wire;
532  address = i2cAddress;
533 
534  Wire.beginTransmission(i2cAddress);
535  int error = Wire.endTransmission();
536 
537 
538  if (error != 0)
539  {
540  return(-1);
541  }
542 
543  if (reset)
544  {
545  hardwareReset();
546  sendReadyTime = millis() + 1000;
547  return(1);
548  }
549  else
550  {
551  sendReadyTime = 0;
552  return initialize();
553 
554  }
555  }
556 
558 
569  int sendPacket( uint8_t tx[], uint8_t rx[]);
570 
580  int sendPacket(uint8_t tx[]);
581 
592  int sendPacket(uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch = 8, uint8_t endBytesToMatch = 0);
602  int sendPacket(uint8_t tx[], bool retryIfEchoDoesntMatch);
603 
613  int sendPacketNoResponse(uint8_t tx[]);
614 
623  char* readVersion(void)
624  {
625  uint8_t tx[] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
626  uint8_t rx[8];
627  sendPacket(tx, rx);
628  memcpy(version, &rx[1], 7);
629  version[7] = '\0';
630  memcpy(model, &rx[1], 3);
631  model[3] = '\0';
632  fwVersion[0] = rx[5];
633  fwVersion[1] = rx[6];
634  fwVersion[2] = rx[7];
635  return (version);
636  }
637 
644  uint32_t readVersion_uint32(void)
645  {
646  readVersion();
647  return ((((uint32_t)fwVersion[0]) << 16) |
648  (((uint32_t)fwVersion[1]) << 8) |
649  fwVersion[2]);
650  }
651 
661  uint16_t readPublicData(uint8_t pin)
662  {
663  uint8_t tx[] = { 0x81,pin,255,255,0x55,0x55,0x55,0x55 };
664  uint8_t rx[8];
665  sendPacket(tx, rx);
666  return(rx[2] + (uint16_t)rx[3] * 256);
667  }
668 
679  {
680  return (readPublicData((uint8_t)dataSource));
681  }
682 
688  uint16_t writePublicData(uint8_t pin, uint16_t value)
689  {
690  uint8_t tx[] = { 0x82,pin,(uint8_t)(value & 0xFF),(uint8_t)(value >> 8) ,255,0x55,0x55,0x55 };
691  uint8_t rx[8];
692  sendPacket(tx, rx);
693  return (rx[2] + rx[3] * 256);
694  }
695 
706  uint16_t readSupplyVoltage_mV(void)
707  {
708  if (isSW18())
709  {
711  }
712  else
713  {
714  int32_t counts = readPublicData(66); // Get FVR counts (1.024 v)
715  if (counts > 0)
716  {
717  uint32_t mv = 1024 * 65536 / counts;
718  _supplyVoltagemV = (uint16_t)mv;
719  }
720  else
721  {
722  _supplyVoltagemV = 0;
723  }
724  }
725  return(_supplyVoltagemV);
726  }
727 
728 
740  {
741  if (isSW18())
742  {
743  int32_t result = readPublicData(70);
744  if (result >= 32768)
745  {
746  result = result - 65536;
747  }
748  return ((int16_t)result);
749  }
750  else
751  {
752  return 2500;
753  }
754  }
755 
763  {
764  uint8_t tx[9] = "ReSeT!#*";
765  uint8_t rx[8];
766  sendPacket(tx, rx);
767  }
768 
777  void pinMode(uint8_t pin, uint8_t mode, bool pullDown = false, bool openDrain = false)
778  {
779  if (pin >= WOMBAT_MAXIMUM_PINS)
780  {
781  return;
782  }
783  _pullDown[pin] = openDrain;
784  _openDrain[pin] = openDrain;
785  _pinmode[pin] = mode;
786  configureDigitalPin(pin, mode);
787  }
788 
796  void digitalWrite(uint8_t pin, uint8_t val)
797  {
798  configureDigitalPin(pin, val);
799  }
800 
806  int digitalRead(uint8_t pin)
807  {
808  if (readPublicData(pin) > 0)
809  {
810  return (HIGH);
811  }
812  else
813  {
814  return (LOW);
815  }
816  }
817 
827  int analogRead(uint8_t pin)
828  {
829  uint8_t tx[] = { 200,pin,PIN_MODE_ANALOGINPUT,0,0,0,0,0 };
830  uint8_t rx[8];
831  sendPacket(tx, rx);
832  return (readPublicData(pin) >> 6); // Scale from 16 bit value to 10 bit value.
833  }
834 
846  void analogWrite(uint8_t pin, int val)
847  {
848  uint8_t dutyCycleLow = 0;
849  if (val == 255)
850  {
851  dutyCycleLow = 255;
852  }
853  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_PWM,pin,dutyCycleLow,(uint8_t) val,false,0x55 };
854  uint8_t rx[8];
855  sendPacket(tx, rx);
856  }
857 
869  {
870  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
871  uint8_t rx[8];
872  sendPacket(tx, rx);
873  if (rx[0] == 'V' && (rx[1] == 'S' || rx[1] == 'B'))
874  {
875  model[0] = rx[1];
876  model[1] = rx[2];
877  model[2] = rx[3];
878  model[3] = 0;
879  fwVersion[0] = rx[5];
880  fwVersion[1] = rx[6];
881  fwVersion[2] = rx[7];
882  fwVersion[3] = 0;
883 
884  inBoot = (rx[1] == 'B');
885  return (true);
886  }
887  return (false);
888  }
889 
897  {
898  uint8_t tx[8] = { 0x81,67,68,0x55,0x55,0x55,0x55,0x55 };
899  uint8_t rx[8];
900  sendPacket(tx, rx);
901  uint32_t returnval = rx[2] + (((uint32_t)rx[3]) << 8) + (((uint32_t)rx[4]) << 16) + (((uint32_t)rx[5]) << 24);
902  return (returnval);
903  }
904 
914  {
915  return readPublicData(69);
916  }
917 
927  void jumpToBoot()
928  {
929  uint8_t tx[] = "BoOtLoAd";
930  sendPacket(tx);
931  }
932 
953  uint8_t readRamAddress(uint16_t address)
954  {
955  uint8_t tx[8] = { 0xA0,SW_LE16(address),0x55,0x55,0x55,0x55,0x55 };
956  uint8_t rx[8];
957  sendPacket(tx, rx);
958  return(rx[3]);
959  }
960 
981  int16_t writeRamAddress(uint16_t address, uint8_t value)
982  {
983  uint8_t tx[8] = { 0xA3,SW_LE16(address),0,0,value,0x55,0x55};
984  return sendPacket(tx);
985  }
986 
1002  uint32_t readFlashAddress(uint32_t address)
1003  {
1004  uint8_t tx[8] = { 0xA1,SW_LE32(address),0x55,0x55,0x55 };
1005  uint8_t rx[8];
1006  sendPacket(tx, rx);
1007  return(((uint32_t)rx[4]) + (((uint32_t)rx[5]) <<8) + (((uint32_t)rx[6]) <<16) + (((uint32_t)rx[7]) <<24));
1008  }
1009 
1021  int16_t readUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1022  {
1023  uint16_t bytesRead = 0;
1024  while (bytesRead < count)
1025  {
1026  byte tx[] = {(byte)SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER, (byte)(index & 0xFF), (byte)(index >> 8), 0x55, 0x55, 0x55, 0x55, 0x55};
1027  byte rx[8];
1028  int16_t result = sendPacket(tx, rx);
1029  if (result >= 0)
1030  {
1031  for (int i = 1; i < 8; ++i)
1032  {
1033  buffer[bytesRead] = rx[i];
1034  ++bytesRead;
1035  ++index;
1036  if (bytesRead >= count)
1037  {
1038  break;
1039  }
1040  }
1041  }
1042  else
1043  {
1044  return (bytesRead);
1045  }
1046  }
1047  return (bytesRead);
1048  }
1059  void sleep()
1060  {
1061  uint8_t tx[8] = { 'S','l','E','e','P','!','#','*'};
1062  sendPacket(tx);
1063  _asleep = true;
1064  }
1065 
1067  void wake()
1068  {
1069  uint8_t tx[8] = { '!','!','!','!','!','!','!','!' };
1070  sendPacket(tx);
1071  }
1072 
1074  bool isSW18()
1075  {
1076  return ( model[1] == '1' && model[2] == '8');
1077  }
1078 
1080  int16_t eraseFlashPage(uint32_t address)
1081  {
1082  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1083  0, //Erase Page
1084  SW_LE32(address),
1085  0x55,0x55 };
1086  return sendPacket(tx);
1087  }
1088 
1089 
1091  int16_t writeFlashRow(uint32_t address)
1092  {
1093  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1094  1, // Write entire row
1095  SW_LE32(address),0x55,0x55 };
1096  return sendPacket(tx);
1097  }
1098 
1099 
1100 
1101 
1111  int16_t setThroughputPin(uint8_t pin)
1112  {
1113  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1114  return sendPacket(tx);
1115  }
1116 
1124  int writeUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1125  {
1126  uint16_t bytesSent = 0;
1127  if (count == 0)
1128  {
1129  return 0;
1130  }
1131 
1132  { // Send first packet of up to 4 bytes
1133  uint8_t bytesToSend = 4;
1134  if (count < 4)
1135  {
1136  bytesToSend = (uint8_t)count;
1137  count = 0;
1138  }
1139  else
1140  {
1141  count -= 4;
1142  }
1143 
1144  uint8_t tx[8] = { 0x84,SW_LE16(index), bytesToSend,0x55,0x55,0x55,0x55 };
1145  uint8_t rx[8];
1146 
1147  uint8_t i;
1148  for (i = 0; i < bytesToSend; ++i)
1149  {
1150  tx[4 + i] = buffer[i];
1151  }
1152  int result = sendPacket(tx, rx);
1153  if (rx[0] == 'E')
1154  {
1155  return (result);
1156  }
1157  bytesSent = bytesToSend;
1158  }
1159  while (count >= 7) // Continue sending
1160  {
1161 
1162  count -= 7;
1163  uint8_t tx[8] = { 0x85,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1164  uint8_t rx[8];
1165  uint8_t i;
1166  for (i = 0; i < 7; ++i)
1167  {
1168  tx[1 + i] = buffer[bytesSent + i];
1169  }
1170  int result = sendPacket(tx, rx);
1171  if (rx[0] == 'E')
1172  {
1173  return (result);
1174  }
1175  bytesSent += 7;
1176  }
1177  while (count > 0)
1178  {
1179 
1180  { // Send first packet of up to 4 bytes
1181  uint8_t bytesToSend = 4;
1182  if (count < 4)
1183  {
1184  bytesToSend = (uint8_t)count;
1185  count = 0;
1186  }
1187  else
1188  {
1189  count -= 4;
1190  }
1191 
1192  uint8_t tx[8] = { 0x84,SW_LE16(index + bytesSent), bytesToSend,0x55,0x55,0x55,0x55 };
1193  uint8_t rx[8];
1194 
1195  uint8_t i;
1196  for (i = 0; i < bytesToSend; ++i)
1197  {
1198  tx[4 + i] = buffer[i + bytesSent];
1199  }
1200  int result = sendPacket(tx, rx);
1201  if (rx[0] == 'E')
1202  {
1203  return (result);
1204  }
1205  bytesSent += bytesToSend;
1206  }
1207  }
1208  return(bytesSent);
1209 
1210 
1211  }
1212 
1220  int writeUserBuffer(uint16_t index, char* s)
1221  {
1222  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1223  }
1224 
1232  int writeUserBuffer(uint16_t index, const char s[])
1233  {
1234  return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1235  }
1236 
1237 
1238 
1250  int16_t writeFrameTimerPin(uint8_t pin)
1251 {
1252  uint8_t tx[] = { 0xC8 ,pin,(uint8_t)PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1253  return sendPacket(tx);
1254 }
1255 
1256 
1264  static uint8_t find(bool keepTrying = false)
1265  {
1266  do
1267  {
1268  for (int i2cAddress = 0x68; i2cAddress <= 0x6F; ++i2cAddress)
1269  {
1270  Wire.beginTransmission(i2cAddress);
1271  int error = Wire.endTransmission();
1272 
1273 
1274  if (error == 0)
1275  {
1276  uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1277  uint8_t rx[8];
1278  Wire.beginTransmission(i2cAddress);
1279  Wire.write(tx, 8);
1280  Wire.endTransmission();
1281  Wire.requestFrom((uint8_t)i2cAddress, (uint8_t)8);
1282 
1283  int count = 0;
1284  while (Wire.available() && count < 8)
1285  {
1286  rx[count] = Wire.read();
1287  ++count;
1288  }
1289  if (count == 8)
1290  {
1291  if (rx[0] == 'V' && rx[1] == 'S')
1292  {
1293  return(i2cAddress); // Found one.
1294  }
1295  }
1296  }
1297  }
1298  delay(0);
1299  }while (keepTrying);
1300  return(0); // Didn't find one.
1301  }
1302 
1303 
1310  int16_t readLastErrorCommand(uint8_t* cmd)
1311 {
1312  //TODO this doen't look like it returns the error
1313  uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET, 0,0x55,0x55,0x55,0x55,0x55,0x55 };
1314  uint8_t rx[8];
1315  if (sendPacket(tx, rx) >= 0)
1316  {
1317  for (int i = 1; i < 8; ++i)
1318  {
1319  cmd[i - 1] = rx[i];
1320  }
1321  }
1322  else
1323  {
1324  return (lastErrorCode);
1325  }
1326  tx[1] = 7;
1327  if (sendPacket(tx, rx) >= 0)
1328  {
1329  cmd[7] = rx[1];
1330  }
1331  return(lastErrorCode);
1332 }
1333 
1339  {
1340  errorHandler = handler;
1341  }
1342 
1344  uint8_t address = 0;
1345 
1348 
1349  int16_t echo(uint8_t data[], uint8_t count = 7)
1350  {
1351  uint8_t tx[] = "!UUUUUUU";
1352  for (int i = 0; i < 7 && i < count; ++i)
1353  {
1354  tx[i + 1] = (uint8_t)data[i];
1355  }
1356  return sendPacket(tx);
1357  }
1358 
1359 
1360  int16_t echo(char* data)
1361  {
1362  int length = strlen(data);
1363  uint8_t tx[] = "!UUUUUUU";
1364  for (int i = 0; i < 7 && i < length; ++i)
1365  {
1366  tx[i + 1] = (uint8_t)data[i];
1367  }
1368  return sendPacket(tx);
1369  }
1370 
1371  uint32_t readBirthday()
1372  {
1373  if (isSW18())
1374  {
1375  uint32_t birthday = (readFlashAddress(0x2A00C) >> 8) & 0xFF;
1376  birthday *= 100;
1377  birthday += (readFlashAddress(0x2A00C)) & 0xFF;
1378  birthday *= 100;
1379  birthday += readFlashAddress(0x2A00E) & 0xFF;
1380  birthday *= 100;
1381  birthday += readFlashAddress(0x2A010) & 0xFF;
1382  return (birthday);
1383  }
1384  return 0;
1385  }
1386 
1387  int16_t readBrand(char* data)
1388  {
1389  uint8_t length = 0;
1390  if (isSW18())
1391  {
1392  for (int i = 0; i < 32; ++i)
1393  {
1394  uint32_t val = readFlashAddress(0x2A020 + i * 2) ;
1395  if ((val & 0xFF) != 0xFF)
1396  {
1397  data[i ] = (char)(val & 0xFF);
1398  ++length;
1399  }
1400  else
1401  {
1402  data[length] = 0;
1403  return (length);
1404  }
1405  }
1406  data[length] = 0;
1407  return (length);
1408  }
1409 
1410  data[0] = 0;
1411  return 0 ;
1412  }
1413 
1414 };
1415 
1430 {
1431 private:
1432  SerialWombatChip& _sw;
1433  uint32_t lastMillis = 0;
1434  uint32_t lastFrames = 0;
1435 public:
1440  SerialWombat18ABOscillatorTuner(SerialWombatChip& serialWombatChip) : _sw(serialWombatChip) { }
1441 
1445  void update() {
1446  uint32_t m = millis();
1447  if (lastMillis == 0)
1448  {
1449  lastMillis = m;
1453  {
1456  }
1457  frames <<= 16;
1458  frames += frameslsb;
1459  lastFrames = frames;
1460 
1461  }
1462  else if ((m - lastMillis) < 10000)
1463  {
1464  //Do nothing
1465  }
1466  else if (m < lastMillis)
1467  {
1468  //Has it been 47 days already?
1469  lastMillis = 0;
1470  }
1471  else
1472  {
1473  uint32_t diff = m - lastMillis;
1474 
1477 
1479  {
1482  }
1483  frames <<= 16;
1484  frames += frameslsb;
1485  uint32_t framesDif = frames - lastFrames;
1486 
1487  if (diff > framesDif )
1488  {
1489  // Running slow
1490  uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1491  SW_LE16(1),//Counts to increment
1492  SW_LE16(0), // Counts to decrement
1493  0x55,0x55,0x55};
1494  _sw.sendPacket(tx);
1495  }
1496  else if (diff < framesDif)
1497  {
1498  // Running mfast
1499  uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1500  SW_LE16(0),//Counts to increment
1501  SW_LE16(1), // Counts to decrement
1502  0x55,0x55,0x55 };
1503  _sw.sendPacket(tx);
1504 
1505  }
1506 
1507  lastMillis = m;
1508  lastFrames = frames;
1509 
1510  }
1511 
1512  }
1513 
1514 };
1515 
1516 /*
1517 End of cross platform code synchronization. Random string to help the compare tool sync lines:
1518 asdkj38vjn1nasdnvuwlamafdjiivnowalskive
1519 */
1520 
1522 class SerialWombat : public SerialWombatChip {};
1523 
1524 
1525 
1526 
1527 
1535 void SerialWombatSerialErrorHandlerBrief(uint16_t error, SerialWombatChip* sw);
1537 
1538 #include "SerialWombatPin.h"
1539 #include "SerialWombatErrors.h"
1540 #include "SerialWombatQueue.h"
1544 #include "SerialWombat18CapTouch.h"
1545 #include "SerialWombat18ABVGA.h"
1546 #include "SerialWombatAnalogInput.h"
1548 #include "SerialWombatHBridge.h"
1549 #include "SerialWombatHSClock.h"
1550 #include "SerialWombatHSCounter.h"
1551 #include "SerialWombatLiquidCrystal.h"
1552 #include "SerialWombatMatrixKeypad.h"
1555 #include "SerialWombatPS2Keyboard.h"
1556 #include "SerialWombatPulseOnChange.h"
1557 #include "SerialWombatPulseTimer.h"
1558 #include "SerialWombatPWM.h"
1559 #include "SerialWombatQuadEnc.h"
1562 #include "SerialWombatServo.h"
1563 #include "SerialWombatTM1637.h"
1564 #include "SerialWombatUART.h"
1566 #include "SerialWombatWatchdog.h"
1567 #include "SerialWombatWS2812.h"
1569 
1570 #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:1250
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:286
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)
SerialWombatQueuedPulseOutput.h
SerialWombatChip::jumpToBoot
void jumpToBoot()
Jump to Bootloader and wait for a UART download of new firmware.
Definition: SerialWombat.h:927
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:1220
PIN_MODE_PULSE_ON_CHANGE
@ PIN_MODE_PULSE_ON_CHANGE
(25)
Definition: SerialWombat.h:264
PIN_MODE_SW18AB_CAPTOUCH
@ PIN_MODE_SW18AB_CAPTOUCH
(22)
Definition: SerialWombat.h:261
SerialWombatHSClock.h
PIN_MODE_HS_CLOCK
@ PIN_MODE_HS_CLOCK
Definition: SerialWombat.h:268
PIN_MODE_UART1_RX_TX
@ PIN_MODE_UART1_RX_TX
(23)
Definition: SerialWombat.h:262
SerialWombatCommands::COMMAND_BINARY_QUEUE_INFORMATION
@ COMMAND_BINARY_QUEUE_INFORMATION
(0x94)
SerialWombatWS2812.h
PIN_MODE_DEBOUNCE
@ PIN_MODE_DEBOUNCE
(10)
Definition: SerialWombat.h:251
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:279
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:346
SerialWombatChip::readPublicData
uint16_t readPublicData(SerialWombatDataSource dataSource)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:678
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:390
SerialWombatChip::digitalRead
int digitalRead(uint8_t pin)
Reads the state of a Pin.
Definition: SerialWombat.h:806
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: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:827
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:846
SerialWombat18ABOscillatorTuner::SerialWombat18ABOscillatorTuner
SerialWombat18ABOscillatorTuner(SerialWombatChip &serialWombatChip)
Class constructor for SerialWombat18OscillatorTuner.
Definition: SerialWombat.h:1440
PIN_MODE_WATCHDOG
@ PIN_MODE_WATCHDOG
(7)
Definition: SerialWombat.h:249
SerialWombatChip::returnErrorCode
uint16_t returnErrorCode(uint8_t *rx)
Definition: SerialWombat.h:452
PIN_MODE_CONTROLLED
@ PIN_MODE_CONTROLLED
(1)
Definition: SerialWombat.h:243
PIN_MODE_SW_UART
@ PIN_MODE_SW_UART
(13)
Definition: SerialWombat.h:254
SerialWombatChip::queryVersion
bool queryVersion()
Send a version request to the Serial Wombat chip.
Definition: SerialWombat.h:868
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:1111
PIN_MODE_PS2KEYBOARD
@ PIN_MODE_PS2KEYBOARD
(32)
Definition: SerialWombat.h:271
SerialWombatLiquidCrystal.h
SerialWombatChip::readSupplyVoltage_mV
uint16_t readSupplyVoltage_mV(void)
Measure the Serial Wombat chip's Supply voltage.
Definition: SerialWombat.h:706
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:343
SerialWombatChip::_supplyVoltagemV
uint16_t _supplyVoltagemV
Definition: SerialWombat.h:307
SerialWombat18ABVGA.h
SerialWombat18CapTouch.h
PIN_MODE_RESISTANCEINPUT
@ PIN_MODE_RESISTANCEINPUT
(24)
Definition: SerialWombat.h:263
SerialWombatChip::readFramesExecuted
uint32_t readFramesExecuted()
Get the number of 1mS frames that have been executed since Serial Wombat chip reset.
Definition: SerialWombat.h:896
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:252
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:1067
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:777
PIN_MODE_PWM
@ PIN_MODE_PWM
(16)
Definition: SerialWombat.h:257
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:248
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:483
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:529
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:391
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:762
PIN_MODE_PULSETIMER
@ PIN_MODE_PULSETIMER
(18)
Definition: SerialWombat.h:259
SerialWombatChip::uniqueIdentifierLength
uint8_t uniqueIdentifierLength
Definition: SerialWombat.h:326
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:1080
SerialWombatChip::readLastErrorCommand
int16_t readLastErrorCommand(uint8_t *cmd)
Returns the last Serial Wombat command that produced a protocol error.
Definition: SerialWombat.h:1310
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:796
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:256
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:913
SerialWombatCommands::CONFIGURE_PIN_MODE9
@ CONFIGURE_PIN_MODE9
(209)
SerialWombatChip::deviceIdentifier
uint16_t deviceIdentifier
Definition: SerialWombat.h:332
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:273
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:1264
SerialWombatChip::readPublicData
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:661
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:402
PIN_MODE_HS_COUNTER
@ PIN_MODE_HS_COUNTER
< (29)
Definition: SerialWombat.h:269
SerialWombat18ABOscillatorTuner
A class which tunes the oscillator on a Serial Wombat 18AB chip.
Definition: SerialWombat.h:1429
SerialWombatChip::readFlashAddress
uint32_t readFlashAddress(uint32_t address)
Read Address from Flash based on 32 bit address.
Definition: SerialWombat.h:1002
SerialWombatChip::readTemperature_100thsDegC
int16_t readTemperature_100thsDegC(void)
Measure the Serial Wombat chip's internal temperature.
Definition: SerialWombat.h:739
SerialWombatChip::uniqueIdentifier
uint8_t uniqueIdentifier[16]
Definition: SerialWombat.h:320
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:1091
SerialWombatChip::errorCount
uint16_t errorCount
Incremented every time a communication or command error is detected.
Definition: SerialWombat.h:340
SerialWombatChip::readRamAddress
uint8_t readRamAddress(uint16_t address)
Read Address from RAM based on 16 bit address.
Definition: SerialWombat.h:953
SerialWombatChip::readBirthday
uint32_t readBirthday()
Definition: SerialWombat.h:1371
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:981
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:253
PIN_MODE_UNKNOWN
@ PIN_MODE_UNKNOWN
(0xFF)
Definition: SerialWombat.h:274
SerialWombatCommands::COMMAND_CALIBRATE_ANALOG
@ COMMAND_CALIBRATE_ANALOG
(0xA5)
SerialWombatChip::configureDigitalPin
void configureDigitalPin(uint8_t pin, uint8_t highLow)
Definition: SerialWombat.h:348
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:338
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:1059
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:688
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:1124
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:623
SerialWombatCommands::COMMAND_BINARY_CONFIGURE
@ COMMAND_BINARY_CONFIGURE
(0x9F)
SerialWombatChip::readVersion_uint32
uint32_t readVersion_uint32(void)
Request version as a uint32.
Definition: SerialWombat.h:644
SerialWombatChip::fwVersion
uint8_t fwVersion[4]
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:313
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:1360
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:1522
SerialWombat18ABOscillatorTuner::update
void update()
Call periodically to tune the SW18AB oscillator to reported millis.
Definition: SerialWombat.h:1445
PIN_MODE_I2C_CONTROLLER
@ PIN_MODE_I2C_CONTROLLER
(33)
Definition: SerialWombat.h:272
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:433
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:255
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:1349
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:1347
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:1021
SerialWombatCommands::CMD_RESET
@ CMD_RESET
('R')
SerialWombatDebouncedInput.h
PIN_MODE_FRAME_TIMER
@ PIN_MODE_FRAME_TIMER
(21)
Definition: SerialWombat.h:260
SerialWombatCommands::CONFIGURE_PIN_INPUTPROCESS
@ CONFIGURE_PIN_INPUTPROCESS
(211)
PIN_MODE_LIQUIDCRYSTAL
@ PIN_MODE_LIQUIDCRYSTAL
(28)
Definition: SerialWombat.h:267
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:250
SerialWombatChip::model
uint8_t model[4]
Contains the last model retreived by queryVersion() as a zero-terminated string.
Definition: SerialWombat.h:310
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:1232
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:1338
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:1074
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:266
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:1387
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:258
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:265
PIN_MODE_VGA
@ PIN_MODE_VGA
(31)
Definition: SerialWombat.h:270
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:1344
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