Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombat.h
Go to the documentation of this file.
1#ifndef SERIAL_WOMBAT_H__
2#define SERIAL_WOMBAT_H__
3
4/*
5Copyright 2020-2026 Broadwell Consulting Inc.
6
7"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
8the United States. See SerialWombat.com for usage guidance.
9
10Permission 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
17The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19
20THE 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#ifndef INPUT
35#define INPUT 0x0
36#endif
37
38
41
42
43#include "SerialWombatErrors.h"
44
46#define SW_LE16(_a) (uint8_t)((_a) & 0xFF), (uint8_t)((_a) >>8)
47
49#define SW_LE32(_a) (uint8_t)((_a) & 0xFF), (uint8_t)((_a) >>8) , (uint8_t)((_a) >>16), (uint8_t)((_a) >>24)
50
51#define ARRAY_UINT32(_array,_index) ((((uint32_t) _array[_index +3])<<24) + (((uint32_t) _array[_index +2])<<16) + (((uint32_t) _array[_index +1])<<8) + _array[_index])
52#define SW18AB_LATEST_FIRMWARE 223
53#define SW08B_LATEST_FIRMWARE 223
54#define SW4B_LATEST_FIRMWARE 203
55
56typedef enum
57{
58 SW_LOW = 0,
62
63
66
87// SW_DATA_SOURCE_PIN_20 = 20,
88// SW_DATA_SOURCE_PIN_21 = 21,
89// SW_DATA_SOURCE_PIN_22 = 22,
90// SW_DATA_SOURCE_PIN_23 = 23,
91// SW_DATA_SOURCE_PIN_24 = 24,
92// SW_DATA_SOURCE_PIN_25 = 25,
93// SW_DATA_SOURCE_PIN_26 = 26,
94// SW_DATA_SOURCE_PIN_27 = 27,
95// SW_DATA_SOURCE_PIN_28 = 28,
96// SW_DATA_SOURCE_PIN_29 = 29,
97// SW_DATA_SOURCE_PIN_30 = 30,
98// SW_DATA_SOURCE_PIN_31 = 31,
99// SW_DATA_SOURCE_PIN_32 = 32,
100// SW_DATA_SOURCE_PIN_33 = 33,
101// SW_DATA_SOURCE_PIN_34 = 34,
102// SW_DATA_SOURCE_PIN_35 = 35,
103// SW_DATA_SOURCE_PIN_36 = 36,
104// SW_DATA_SOURCE_PIN_37 = 37,
105// SW_DATA_SOURCE_PIN_38 = 38,
106// SW_DATA_SOURCE_PIN_39 = 39,
107// SW_DATA_SOURCE_PIN_40 = 40,
108// SW_DATA_SOURCE_PIN_41 = 41,
109// SW_DATA_SOURCE_PIN_42 = 42,
110// SW_DATA_SOURCE_PIN_43 = 43,
111// SW_DATA_SOURCE_PIN_44 = 44,
112// SW_DATA_SOURCE_PIN_45 = 45,
113// SW_DATA_SOURCE_PIN_46 = 46,
114// SW_DATA_SOURCE_PIN_47 = 47,
115// SW_DATA_SOURCE_PIN_48 = 48,
116// SW_DATA_SOURCE_PIN_49 = 49,
117// SW_DATA_SOURCE_PIN_50 = 50,
118// SW_DATA_SOURCE_PIN_51 = 51,
119// SW_DATA_SOURCE_PIN_52 = 52,
120// SW_DATA_SOURCE_PIN_53 = 53,
121// SW_DATA_SOURCE_PIN_54 = 54,
122// SW_DATA_SOURCE_PIN_55 = 55,
123// SW_DATA_SOURCE_PIN_56 = 56,
124// SW_DATA_SOURCE_PIN_57 = 57,
125// SW_DATA_SOURCE_PIN_58 = 58,
126// SW_DATA_SOURCE_PIN_59 = 59,
127// SW_DATA_SOURCE_PIN_60 = 60,
128// SW_DATA_SOURCE_PIN_61 = 61,
129// SW_DATA_SOURCE_PIN_62 = 62,
130// SW_DATA_SOURCE_PIN_63 = 63,
143
154 //NOT ANALOG SW_DATA_SOURCE_PIN_5_MV = 105,
155 //NOT ANALOG SW_DATA_SOURCE_PIN_6_MV = 106,
156 //NOT ANALOG SW_DATA_SOURCE_PIN_7_MV = 107,
157 //NOT ANALOG SW_DATA_SOURCE_PIN_8_MV = 108,
158 //NOT ANALOG SW_DATA_SOURCE_PIN_9_MV = 109,
159 //NOT ANALOG SW_DATA_SOURCE_PIN_10_MV = 110,
160 //NOT ANALOG SW_DATA_SOURCE_PIN_11_MV = 111,
161 //NOT ANALOG SW_DATA_SOURCE_PIN_12_MV = 112,
162 //NOT ANALOG SW_DATA_SOURCE_PIN_13_MV = 113,
163 //NOT ANALOG SW_DATA_SOURCE_PIN_14_MV = 114,
164 //NOT ANALOG SW_DATA_SOURCE_PIN_15_MV = 115,
171// SW_DATA_SOURCE_2HZ_SIN = 166,
174// SW_DATA_SOURCE_1HZ_SIN = 169,
177// SW_DATA_SOURCE_2SEC_SIN = 172,
180// SW_DATA_SOURCE_8SEC_SIN = 175,
183// SW_DATA_SOURCE_65SEC_SIN = 178,
185};
186
187#define ERROR_HOST_INCORRECT_NUMBER_BYTES_WRITTEN 0x10000
188#define ERROR_HOST_DATA_TOO_LONG 0x10001
189#define ERROR_HOST_NACK_ADDRESS 0x10002
190#define ERROR_HOST_NACK_DATA 0x10003
191#define ERROR_HOST_OTHER_I2C_ERROR 0x10004
192
193#define WOMBAT_MAXIMUM_PINS 20
194
196{
197 CMD_ECHO ='!',
200 CMD_RESET = 'R',
256
257};
258
259
300
301class SerialWombatChip;
302
303typedef void (*SerialWombatErrorHandler_t) (uint16_t errorNumber, SerialWombatChip* sw);
304
315{
316private:
317
318 char version[8] = { 0 };
319 HardwareSerial * Serial = NULL;
320 TwoWire* i2cInterface = NULL;
321 uint8_t _pinmode[WOMBAT_MAXIMUM_PINS]={}; // Includes Pullup
322 bool _pullDown[WOMBAT_MAXIMUM_PINS]={};
323 bool _openDrain[WOMBAT_MAXIMUM_PINS]={};
324 bool _highLow[WOMBAT_MAXIMUM_PINS] = {};
325 bool _asleep = false;
326 SerialWombatErrorHandler_t errorHandler = NULL;
327 bool _currentlyCommunicating = false;
328public:
335 uint16_t _supplyVoltagemV = 0;
336
338 uint8_t model[4] = { 0 };
339
341 uint8_t fwVersion[4] = { 0 };
342
348 uint8_t uniqueIdentifier[16];
349
355
361
368 uint16_t errorCount = 0;
369
371 bool inBoot = false;
372
374 int16_t lastErrorCode = 0;
375
384
385 void configureDigitalPin(uint8_t pin, uint8_t highLow)
386 {
387 uint8_t tx[8] = { 200,pin,0,0,0,0,0,0x55 };
388 uint8_t rx[8];
389 switch (_pinmode[pin])
390 {
391 case INPUT: // Arduino input
392 {
393 tx[3] = 2; //Input
394 }
395 break;
396 case OUTPUT:
397 {
398 if (highLow == LOW)
399 {
400 tx[3] = 0;
401 }
402 else if (highLow == HIGH)
403 {
404 tx[3] = 1;
405 }
406 else
407 {
408 return;
409 }
410 }
411 break;
412 case INPUT_PULLUP:
413 {
414 tx[3] = 2; //Input
415 tx[4] = 1; //Pullup on
416 }
417 break;
418 default:
419 {
420 return;
421 }
422 }
423 tx[6] = _openDrain[pin];
424 tx[5] = _pullDown[pin];
425 sendPacket(tx, rx, true);
426 }
427
431 uint32_t sendReadyTime = 0;
432
436 int16_t initialize()
437 {
438 lastErrorCode = 0;
439 readVersion();
443 return(lastErrorCode);
444 }
445
453 {
455 if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
456 { //16F15214
457 for (uint32_t address = 0x8100; address <= 0x8108; ++address)
458 {
459 uint32_t data = readFlashAddress(address);
462 /* Always zero... leave out
463 uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)(data>>8);
464 ++uniqueIdentifierLength;
465 */
466 }
467 }
468 else if (isSW18())
469 {
470 for (uint32_t address = 0x801600; address <= 0x801608; address += 2)
471 {
472 uint32_t data = readFlashAddress(address);
479 }
480 }
481 else if (isSW08())
482 {
483 //TODO
484 }
485
486 }
487
494
496 {
497 if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
498 { //16F15214
499
500 uint32_t data = readFlashAddress(0x8006);
501 deviceIdentifier = (uint16_t)data;
502 data = readFlashAddress(0x8005);
503 deviceRevision = (uint16_t)data;
504 }
505 else if (isSW18())
506 {
507 uint32_t data = readFlashAddress(0xFF0000);
508 deviceIdentifier = (uint16_t)data;
509 data = readFlashAddress(0xFF0002);
510 deviceRevision = (uint16_t)data & 0xF;
511 }
512 }
513
519 uint16_t returnErrorCode(uint8_t* rx)
520 {
521 uint16_t result = rx[1] - '0';
522 result *= 10;
523 result += rx[2] - '0';
524 result *= 10;
525 result += rx[3] - '0';
526 result *= 10;
527 result += rx[4] - '0';
528 result *= 10;
529 result += rx[5] - '0';
530 return(result);
531 }
532
533
534
535public:
550 int16_t begin(HardwareSerial& serial, bool reset = true)
551 {
552 Serial = &serial;
553 Serial->begin(115200);
554 Serial->setTimeout(2);
555 Serial->write((uint8_t*)"UUUUUUUU", 8);
556 delay(5);
557 while (Serial->read() >= 0);
558 if (reset)
559 {
561 sendReadyTime = millis() + 1000;
562 return(1);
563 }
564 else
565 {
566 return initialize();
567 }
568
569
570 }
571
581 int16_t begin(uint8_t i2cAddress);
582
596 int16_t begin(TwoWire& wire, uint8_t i2cAddress, bool reset = true)
597 {
598 i2cInterface = &wire;
599 address = i2cAddress;
600
601 Wire.beginTransmission(i2cAddress);
602 int error = Wire.endTransmission();
603
604
605 if (error != 0)
606 {
607 return(-1);
608 }
609
610 if (reset)
611 {
613 sendReadyTime = millis() + 250;
614 return(1);
615 }
616 else
617 {
618 sendReadyTime = 0;
619 return initialize();
620
621 }
622 }
623
625
636 int sendPacket( uint8_t tx[], uint8_t rx[]);
637
647 int sendPacket(uint8_t tx[]);
648
662 int sendPacket(uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch = 8, uint8_t endBytesToMatch = 0);
673 int sendPacket(uint8_t tx[], bool retryIfEchoDoesntMatch);
674
683
684 int sendPacketNoResponse(uint8_t tx[]);
685
694 char* readVersion(void)
695 {
696 uint8_t tx[] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
697 uint8_t rx[8];
698 sendPacket(tx, rx);
699 memcpy(version, &rx[1], 7);
700 version[7] = '\0';
701 memcpy(model, &rx[1], 3);
702 model[3] = '\0';
703 fwVersion[0] = rx[5];
704 fwVersion[1] = rx[6];
705 fwVersion[2] = rx[7];
706 return (version);
707 }
708
715 uint32_t readVersion_uint32(void)
716 {
717 readVersion();
718 return (
719 ((uint32_t)fwVersion[0] - '0') * 100 +
720 ((uint32_t)fwVersion[1] - '0') * 10 +
721 (uint32_t)fwVersion[2] - '0');
722 }
723
729 {
730 uint32_t v = readVersion_uint32();
731 if (isSW18())
732 {
733 return (v == SW18AB_LATEST_FIRMWARE);
734 }
735 else if (isSW08())
736 {
737 return (v == SW08B_LATEST_FIRMWARE);
738 }
739 else
740 {
741 return (v == SW4B_LATEST_FIRMWARE);
742
743 }
744 }
745
755 uint16_t readPublicData(uint8_t pin)
756 {
757 uint8_t tx[] = { 0x81,pin,255,255,0x55,0x55,0x55,0x55 };
758 uint8_t rx[8];
759 sendPacket(tx, rx);
760 return(rx[2] + (uint16_t)rx[3] * 256);
761 }
762
773 {
774 return (readPublicData((uint8_t)dataSource));
775 }
776
782 uint16_t writePublicData(uint8_t pin, uint16_t value)
783 {
784 uint8_t tx[] = { 0x82,pin,(uint8_t)(value & 0xFF),(uint8_t)(value >> 8) ,255,0x55,0x55,0x55 };
785 uint8_t rx[8];
786 sendPacket(tx, rx);
787 return (rx[2] + rx[3] * 256);
788 }
789
790 uint32_t comparePublicDataToThreshold(uint16_t threshold = 0)
791 {
792 uint8_t tx[] = { (uint8_t) SerialWombatCommands::COMMAND_BINARY_PIN_POLL_THRESHOLD,SW_LE16(threshold) ,0x55, 0x55,0x55,0x55,0x55 };
793 uint8_t rx[8];
794 sendPacket(tx, rx);
795 return (ARRAY_UINT32(rx,1));
796 }
797
807
808 uint16_t readSupplyVoltage_mV(void)
809 {
810 if (isSW18() || isSW08())
811 {
813 }
814 else
815 {
816 int32_t counts = readPublicData(66); // Get FVR counts (1.024 v)
817 if (counts > 0)
818 {
819 uint32_t mv = 1024 * 65536 / counts;
820 _supplyVoltagemV = (uint16_t)mv;
821 }
822 else
823 {
825 }
826 }
827 return(_supplyVoltagemV);
828 }
829
830
842 {
843 if (isSW18())
844 {
845 int32_t result = readPublicData(70);
846 if (result >= 32768)
847 {
848 result = result - 65536;
849 }
850 return ((int16_t)result);
851 }
852 else
853 {
854 return 2500;
855 }
856 }
857
865 {
866 uint8_t tx[9] = "ReSeT!#*";
868 }
869
878 void pinMode(uint8_t pin, uint8_t mode, bool pullDown = false, bool openDrain = false)
879 {
880 if (pin >= WOMBAT_MAXIMUM_PINS)
881 {
882 return;
883 }
884 _pullDown[pin] = pullDown;
885 _openDrain[pin] = openDrain;
886 _pinmode[pin] = mode;
887 configureDigitalPin(pin, mode);
888 }
889
897 void digitalWrite(uint8_t pin, uint8_t val)
898 {
899 configureDigitalPin(pin, val);
900 }
901
907 int digitalRead(uint8_t pin)
908 {
909 if (readPublicData(pin) > 0)
910 {
911 return (HIGH);
912 }
913 else
914 {
915 return (LOW);
916 }
917 }
918
928 int analogRead(uint8_t pin)
929 {
930 uint8_t tx[] = { 200,pin,PIN_MODE_ANALOGINPUT,0,0,0,0,0 };
931 uint8_t rx[8];
932 sendPacket(tx, rx);
933 return (readPublicData(pin) >> 6); // Scale from 16 bit value to 10 bit value.
934 }
935
947 void analogWrite(uint8_t pin, int val)
948 {
949 uint8_t dutyCycleLow = 0;
950 if (val == 255)
951 {
952 dutyCycleLow = 255;
953 }
954 uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_PWM,pin,dutyCycleLow,(uint8_t) val,false,0x55 };
955 uint8_t rx[8];
956 sendPacket(tx, rx);
957 }
958
970 {
971 uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
972 uint8_t rx[8];
973 sendPacket(tx, rx);
974 if (rx[0] == 'V' && (rx[1] == 'S' || rx[1] == 'B'))
975 {
976 model[0] = rx[1];
977 model[1] = rx[2];
978 model[2] = rx[3];
979 model[3] = 0;
980 fwVersion[0] = rx[5];
981 fwVersion[1] = rx[6];
982 fwVersion[2] = rx[7];
983 fwVersion[3] = 0;
984
985 inBoot = (rx[1] == 'B');
986 return (true);
987 }
988 return (false);
989 }
990
998 {
999 uint8_t tx[8] = { 0x81,67,68,0x55,0x55,0x55,0x55,0x55 };
1000 uint8_t rx[8];
1001 sendPacket(tx, rx);
1002 uint32_t returnval = rx[2] + (((uint32_t)rx[3]) << 8) + (((uint32_t)rx[4]) << 16) + (((uint32_t)rx[5]) << 24);
1003 return (returnval);
1004 }
1005
1013
1015 {
1016 return readPublicData(69);
1017 }
1018
1029 {
1030 uint8_t tx[] = "BoOtLoAd";
1031 sendPacket(tx);
1032 }
1033
1054 uint8_t readRamAddress(uint16_t address)
1055 {
1056 uint8_t tx[8] = { 0xA0,SW_LE16(address),0x55,0x55,0x55,0x55,0x55 };
1057 uint8_t rx[8];
1058 sendPacket(tx, rx);
1059 return(rx[3]);
1060 }
1061
1081
1082 int16_t writeRamAddress(uint16_t address, uint8_t value)
1083 {
1084 uint8_t tx[8] = { 0xA3,SW_LE16(address),0,0,value,0x55,0x55};
1085 return sendPacket(tx);
1086 }
1087
1102
1103 uint32_t readFlashAddress(uint32_t address)
1104 {
1105 uint8_t tx[8] = { 0xA1,SW_LE32(address),0x55,0x55,0x55 };
1106 uint8_t rx[8];
1107 sendPacket(tx, rx);
1108 return(((uint32_t)rx[4]) + (((uint32_t)rx[5]) <<8) + (((uint32_t)rx[6]) <<16) + (((uint32_t)rx[7]) <<24));
1109 }
1110
1122 int16_t readUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1123 {
1124 uint16_t bytesRead = 0;
1125 while (bytesRead < count)
1126 {
1127 byte tx[] = {(byte)SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER, (byte)(index & 0xFF), (byte)(index >> 8), 0x55, 0x55, 0x55, 0x55, 0x55};
1128 byte rx[8];
1129 int16_t result = sendPacket(tx, rx);
1130 if (result >= 0)
1131 {
1132 for (int i = 1; i < 8; ++i)
1133 {
1134 buffer[bytesRead] = rx[i];
1135 ++bytesRead;
1136 ++index;
1137 if (bytesRead >= count)
1138 {
1139 break;
1140 }
1141 }
1142 }
1143 else
1144 {
1145 return (bytesRead);
1146 }
1147 }
1148 return (bytesRead);
1149 }
1150
1162 void sleep4B()
1163 {
1164 uint8_t tx[8] = { 'S','l','E','e','P','!','#','*'};
1165 sendPacket(tx);
1166 _asleep = true;
1167 }
1168
1187 void sleep8B(uint16_t delay)
1188 {
1189 uint8_t tx[8] = { 'S','l','E','e','P','!',SW_LE16(delay)};
1190
1191 sendPacket(tx);
1192 _asleep = true;
1193 }
1194
1196 void wake()
1197 {
1198 uint8_t tx[8] = { '!','!','!','!','!','!','!','!' };
1199 sendPacket(tx);
1200 }
1201
1203 bool isSW04()
1204 {
1205 return ( model[1] == '0' && model[2] == '4');
1206 }
1207
1208
1210 bool isSW18()
1211 {
1212 return ( model[1] == '1' && model[2] == '8');
1213 }
1214
1215 bool isSW08()
1216 {
1217 return ( model[1] == '0' && model[2] == '8');
1218 }
1219
1229
1235 {
1236 if (isSW04())
1237 {
1238 switch (pinMode)
1239 {
1240 case PIN_MODE_DIGITALIO:
1243 case PIN_MODE_SERVO:
1244 case PIN_MODE_PWM:
1245 case PIN_MODE_DEBOUNCE:
1247 case PIN_MODE_WATCHDOG:
1250 return true;
1251
1252 default:
1253 return false;
1254 }
1255 }
1256
1257 uint8_t tx[8] = {(uint8_t)SerialWombatCommands::CONFIGURE_CHANNEL_MODE_CHECK_MODE_SUPPORTED, 1, (uint8_t)pinMode, 0x55, 0x55, 0x55, 0x55, 0x55};
1258 int16_t returnVal = sendPacket(tx);
1259 returnVal *= -1;
1260 return (returnVal != SW_ERROR_UNKNOWN_PIN_MODE);
1261 }
1262
1263
1264
1265
1267 int16_t eraseFlashPage(uint32_t address)
1268 {
1269 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1270 0, //Erase Page
1272 0x55,0x55 };
1273 return sendPacket(tx);
1274 }
1275
1276
1278 int16_t writeFlashRow(uint32_t address)
1279 {
1280 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1281 1, // Write entire row
1282 SW_LE32(address),0x55,0x55 };
1283 return sendPacket(tx);
1284 }
1285
1286
1287
1288
1298 int16_t setThroughputPin(uint8_t pin)
1299 {
1300 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1301 return sendPacket(tx);
1302 }
1303
1317 int16_t setThroughputPin(uint32_t address)
1318 {
1319 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_SET_ADDRESS,SW_LE32(address),0x55,0x55,0x55 };
1320 return sendPacket(tx);
1321 }
1322
1330 int writeUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1331 {
1332 uint16_t bytesSent = 0;
1333 if (count == 0)
1334 {
1335 return 0;
1336 }
1337
1338 { // Send first packet of up to 4 bytes
1339 uint8_t bytesToSend = 4;
1340 if (count < 4)
1341 {
1342 bytesToSend = (uint8_t)count;
1343 count = 0;
1344 }
1345 else
1346 {
1347 count -= 4;
1348 }
1349
1350 uint8_t tx[8] = { 0x84,SW_LE16(index), bytesToSend,0x55,0x55,0x55,0x55 };
1351 uint8_t rx[8];
1352
1353 uint8_t i;
1354 for (i = 0; i < bytesToSend; ++i)
1355 {
1356 tx[4 + i] = buffer[i];
1357 }
1358 int result = sendPacket(tx, rx);
1359 if (rx[0] == 'E')
1360 {
1361 return (result);
1362 }
1363 bytesSent = bytesToSend;
1364 }
1365 while (count >= 7) // Continue sending
1366 {
1367
1368 count -= 7;
1369 uint8_t tx[8] = { 0x85,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1370 uint8_t rx[8];
1371 uint8_t i;
1372 for (i = 0; i < 7; ++i)
1373 {
1374 tx[1 + i] = buffer[bytesSent + i];
1375 }
1376 int result = sendPacket(tx, rx);
1377 if (rx[0] == 'E')
1378 {
1379 return (result);
1380 }
1381 bytesSent += 7;
1382 }
1383 while (count > 0)
1384 {
1385
1386 { // Send first packet of up to 4 bytes
1387 uint8_t bytesToSend = 4;
1388 if (count < 4)
1389 {
1390 bytesToSend = (uint8_t)count;
1391 count = 0;
1392 }
1393 else
1394 {
1395 count -= 4;
1396 }
1397
1398 uint8_t tx[8] = { 0x84,SW_LE16(index + bytesSent), bytesToSend,0x55,0x55,0x55,0x55 };
1399 uint8_t rx[8];
1400
1401 uint8_t i;
1402 for (i = 0; i < bytesToSend; ++i)
1403 {
1404 tx[4 + i] = buffer[i + bytesSent];
1405 }
1406 int result = sendPacket(tx, rx);
1407 if (rx[0] == 'E')
1408 {
1409 return (result);
1410 }
1411 bytesSent += bytesToSend;
1412 }
1413 }
1414 return(bytesSent);
1415
1416
1417 }
1418
1425 int writeUserBuffer(uint16_t index, char* s)
1426 {
1427 return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1428 }
1429
1436 int writeUserBuffer(uint16_t index, const char s[])
1437 {
1438 return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1439 }
1440
1441
1442
1454 int16_t writeFrameTimerPin(uint8_t pin)
1455{
1456 uint8_t tx[] = { 0xC8 ,pin,(uint8_t)PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1457 return sendPacket(tx);
1458}
1459
1460
1468 static uint8_t find(bool keepTrying = false)
1469 {
1470 do
1471 {
1472 for (int i2cAddress = 0x60; i2cAddress <= 0x6F; ++i2cAddress)
1473 {
1474 Wire.beginTransmission(i2cAddress);
1475 int error = Wire.endTransmission();
1476
1477
1478 if (error == 0)
1479 {
1480 uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1481 uint8_t rx[8];
1482 Wire.beginTransmission(i2cAddress);
1483 Wire.write(tx, 8);
1484 Wire.endTransmission();
1485 Wire.requestFrom((uint8_t)i2cAddress, (uint8_t)8);
1486
1487 int count = 0;
1488 while (Wire.available() && count < 8)
1489 {
1490 rx[count] = Wire.read();
1491 ++count;
1492 }
1493 if (count == 8)
1494 {
1495 if (rx[0] == 'V' && (rx[1] == 'S' || rx[1]=='B'))
1496 {
1497 return(i2cAddress); // Found one.
1498 }
1499 }
1500 }
1501 }
1502 delay(0);
1503 }while (keepTrying);
1504 return(0); // Didn't find one.
1505 }
1506
1507
1514 int16_t readLastErrorCommand(uint8_t* cmd)
1515{
1516
1517 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET, 0,0x55,0x55,0x55,0x55,0x55,0x55 };
1518 uint8_t rx[8];
1519 if (sendPacket(tx, rx) >= 0)
1520 {
1521 for (int i = 1; i < 8; ++i)
1522 {
1523 cmd[i - 1] = rx[i];
1524 }
1525 }
1526 else
1527 {
1528 return (lastErrorCode);
1529 }
1530 tx[1] = 7;
1531 if (sendPacket(tx, rx) >= 0)
1532 {
1533 cmd[7] = rx[1];
1534 }
1535 return(lastErrorCode);
1536}
1537
1543 {
1544 errorHandler = handler;
1545 }
1546
1548 uint8_t address = 0;
1549
1552
1559 int16_t echo(uint8_t data[], uint8_t count = 7)
1560 {
1561 uint8_t tx[] = "!UUUUUUU";
1562 for (int i = 0; i < 7 && i < count; ++i)
1563 {
1564 tx[i + 1] = (uint8_t)data[i];
1565 }
1566 return sendPacket(tx);
1567 }
1568
1574
1575 int16_t echo(char* data)
1576 {
1577 int length = strlen(data);
1578 uint8_t tx[] = "!UUUUUUU";
1579 for (int i = 0; i < 7 && i < length; ++i)
1580 {
1581 tx[i + 1] = (uint8_t)data[i];
1582 }
1583 return sendPacket(tx);
1584 }
1585
1590 uint32_t readBirthday()
1591 {
1592 if (isSW18())
1593 {
1594 uint32_t birthday = (readFlashAddress(0x2A00C) >> 8) & 0xFF;
1595 birthday *= 100;
1596 birthday += (readFlashAddress(0x2A00C)) & 0xFF;
1597 birthday *= 100;
1598 birthday += readFlashAddress(0x2A00E) & 0xFF;
1599 birthday *= 100;
1600 birthday += readFlashAddress(0x2A010) & 0xFF;
1601 return (birthday);
1602 }
1603 return 0;
1604 }
1605
1610 int16_t readBrand(char* data)
1611 {
1612 uint8_t length = 0;
1613 if (isSW18())
1614 {
1615 for (int i = 0; i < 32; ++i)
1616 {
1617 uint32_t val = readFlashAddress(0x2A020 + i * 2) ;
1618 if ((val & 0xFF) != 0xFF)
1619 {
1620 data[i ] = (char)(val & 0xFF);
1621 ++length;
1622 }
1623 else
1624 {
1625 data[length] = 0;
1626 return (length);
1627 }
1628 }
1629 data[length] = 0;
1630 return (length);
1631 }
1632
1633 data[0] = 0;
1634 return 0 ;
1635 }
1636
1637};
1638
1653{
1654private:
1655 SerialWombatChip& _sw;
1656 uint32_t lastMillis = 0;
1657 uint32_t lastFrames = 0;
1658public:
1663 SerialWombat18ABOscillatorTuner(SerialWombatChip& serialWombatChip) : _sw(serialWombatChip) { }
1664
1668 void update() {
1669 uint32_t m = millis();
1670 if (lastMillis == 0)
1671 {
1672 lastMillis = m;
1673 uint32_t frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1674 uint16_t frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1675 if (frames != _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW))
1676 {
1677 frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1678 frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1679 }
1680 frames <<= 16;
1681 frames += frameslsb;
1682 lastFrames = frames;
1683
1684 }
1685 else if ((m - lastMillis) < 10000)
1686 {
1687 //Do nothing
1688 }
1689 else if (m < lastMillis)
1690 {
1691 //Has it been 47 days already?
1692 lastMillis = 0;
1693 }
1694 else
1695 {
1696 uint32_t diff = m - lastMillis;
1697
1698 uint32_t frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1699 uint16_t frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1700
1701 if (frames != _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW))
1702 {
1703 frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1704 frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1705 }
1706 frames <<= 16;
1707 frames += frameslsb;
1708 uint32_t framesDif = frames - lastFrames;
1709
1710 if (diff > framesDif )
1711 {
1712 // Running slow
1713 uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1714 SW_LE16(1),//Counts to increment
1715 SW_LE16(0), // Counts to decrement
1716 0x55,0x55,0x55};
1717 _sw.sendPacket(tx);
1718 }
1719 else if (diff < framesDif)
1720 {
1721 // Running mfast
1722 uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1723 SW_LE16(0),//Counts to increment
1724 SW_LE16(1), // Counts to decrement
1725 0x55,0x55,0x55 };
1726 _sw.sendPacket(tx);
1727
1728 }
1729
1730 lastMillis = m;
1731 lastFrames = frames;
1732
1733 }
1734
1735 }
1736
1737};
1738
1739/*
1740End of cross platform code synchronization. Random string to help the compare tool sync lines:
1741asdkj38vjn1nasdnvuwlamafdjiivnowalskive
1742*/
1743
1746
1747
1748
1749
1750
1759
1768
1769#include "SerialWombatPin.h"
1770#include "SerialWombatQueue.h"
1775#include "SerialWombatBlink.h"
1776#include "SerialWombat18CapTouch.h"
1777#include "SerialWombat18ABVGA.h"
1783#include "SerialWombatHBridge.h"
1784#include "SerialWombatHSClock.h"
1785#include "SerialWombatHSCounter.h"
1786#include "SerialWombatIRRx.h"
1787#include "SerialWombatIRTx.h"
1794#include "SerialWombatPulseTimer.h"
1795#include "SerialWombatPWM.h"
1796#include "SerialWombatQuadEnc.h"
1799#include "SerialWombatServo.h"
1800#include "SerialWombatSPI.h"
1801#include "SerialWombatTM1637.h"
1802#include "SerialWombatUART.h"
1804#include "SerialWombatWatchdog.h"
1805#include "SerialWombatWS2812.h"
1807#include "PCB0030_Bridge.h"
1808#include "PCB0031_Grip.h"
1809#include "PCB0041_Remcon.h"
1810#include "PCB0042_LSD.h"
1811#include "PCB0046_HSD.h"
1812#include "PCB0048_Mux.h"
1813
1814#endif
#define INPUT
#define SW18AB_LATEST_FIRMWARE
#define WOMBAT_MAXIMUM_PINS
void SerialWombatSerialErrorHandlerBrief(uint16_t error, SerialWombatChip *sw)
a sample error handler that can be registered with registerErrorHandler to report protocol errors on ...
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
SerialWombatCommands
@ COMMAND_CAPTURE_STARTUP_SEQUENCE
(0xB6)
@ COMMAND_BINARY_WRITE_FLASH
(0xA4)
@ COMMAND_BINARY_READ_USER_BUFFER
(0x83)
@ COMMAND_BINARY_QUEUE_INFORMATION
(0x94)
@ COMMAND_BINARY_QUEUE_INITIALIZE
(0x90)
@ COMMAND_BINARY_SET_PIN_BUFFFER
(0x82)
@ COMMAND_ENABLE_2ND_UART
(0xA6)
@ COMMAND_UART1_RX_7BYTES
(0xB3)
@ COMMAND_ADJUST_FREQUENCY
(0xB7)
@ COMMAND_BINARY_WRITE_USER_BUFFER
(0x84)
@ CONFIGURE_PIN_MODE_DISABLE
(219)
@ COMMAND_BINARY_QUEUE_CLONE
(0x95)
@ COMMAND_BINARY_QUEUE_ADD_BYTES
(0x91)
@ COMMAND_BINARY_READ_EEPROM
(0xA2)
@ COMMAND_BINARY_QUEUE_ADD_7BYTES
(0x92)
@ COMMAND_UART0_TX_7BYTES
(0xB0)
@ COMMAND_BINARY_QUEUE_READ_BYTES
(0x93)
@ COMMAND_BINARY_SET_ADDRESS
(0xB9)
@ CONFIGURE_PIN_INPUTPROCESS
(211)
@ CONFIGURE_CHANNEL_MODE_CHECK_MODE_SUPPORTED
(218)
@ COMMAND_BINARY_WRITE_USER_BUFFER_CONTINUE
(0x85)
@ COMMAND_BINARY_CONFIG_DATALOGGER
(0x96)
@ COMMAND_UART1_TX_7BYTES
(0xB2)
@ COMMAND_UART0_RX_7BYTES
(0xB1)
@ COMMAND_BINARY_RW_PIN_MEMORY
(0xB5)
@ COMMAND_READ_LAST_ERROR_PACKET
(0xA7)
@ COMMAND_BINARY_WRITE_RAM
(0xA3)
@ COMMAND_BINARY_READ_RAM
(0xA0)
@ COMMAND_BINARY_TEST_SEQUENCE
(0xB4)
@ CONFIGURE_CHANNEL_MODE_HW_2
(222)
@ COMMAND_BINARY_READ_PIN_BUFFFER
(0x81)
@ CONFIGURE_CHANNEL_MODE_HW_1
(221)
@ COMMAND_BINARY_READ_FLASH
(0xA1)
@ CONFIGURE_CHANNEL_MODE_HW_3
(223)
@ COMMAND_CALIBRATE_ANALOG
(0xA5)
@ COMMAND_BINARY_PIN_POLL_THRESHOLD
(0x8F)
@ COMMAND_BINARY_CONFIGURE
(0x9F)
#define SW08B_LATEST_FIRMWARE
#define SW_LE32(_a)
Convert a uint32_t to four bytes in little endian format for array initialization.
#define SW4B_LATEST_FIRMWARE
SerialWombatPinMode_t
@ PIN_MODE_PULSE_ON_CHANGE
(25)
@ PIN_MODE_FRAME_TIMER
(21)
@ PIN_MODE_UNKNOWN
(0xFF)
@ PIN_MODE_TM1637
(11)
@ PIN_MODE_PULSETIMER
(18)
@ PIN_MODE_PS2KEYBOARD
(32)
@ PIN_MODE_FREQUENCY_OUTPUT
(36)
@ PIN_MODE_HS_SERVO
(26)
@ PIN_MODE_CONTROLLED
(1)
@ PIN_MODE_QUEUED_PULSE_OUTPUT
(34)
@ PIN_MODE_HBRIDGE
(6)
@ PIN_MODE_SW18AB_CAPTOUCH
(22)
@ PIN_MODE_LIQUIDCRYSTAL
(28)
@ PIN_MODE_IRRX
(37)
@ PIN_MODE_QUADRATUREENCODER
(5)
@ PIN_MODE_UART_RX_TX
(17)
@ PIN_MODE_WATCHDOG
(7)
@ PIN_MODE_HS_COUNTER
< (29)
@ PIN_MODE_PROTECTED_OUTPUT
(8)
@ PIN_MODE_ANALOGINPUT
(2)
@ PIN_MODE_UART1_RX_TX
(23)
@ PIN_MODE_I2C_CONTROLLER
(33)
@ PIN_MODE_PWM
(16)
@ PIN_MODE_RESISTANCEINPUT
(24)
@ PIN_MODE_DEBOUNCE
(10)
@ PIN_MODE_BLINK
(40)
@ PIN_MODE_INPUT_PROCESSOR
(14)
@ PIN_MODE_ULTRASONIC_DISTANCE
(27)
@ PIN_MODE_HS_CLOCK
@ PIN_MODE_SERVO
(3)
@ PIN_MODE_DIGITALIO
(0)
@ PIN_MODE_THROUGHPUT_CONSUMER
(4)
@ PIN_MODE_MATRIX_KEYPAD
(15)
@ PIN_MODE_SW_UART
(13)
@ PIN_MODE_SPI
(41)
@ PIN_MODE_IRTX
(38)
@ PIN_MODE_VGA
(31)
@ PIN_MODE_WS2812
(12)
void SerialWombatSerialErrorHandlerVerbose(uint16_t error, SerialWombatChip *sw)
a sample error handler that can be registered with registerErrorHandler to report protocol errors on ...
SerialWombatDataSource
A list of Serial Wombat public data sources.
@ SW_DATA_SOURCE_PIN_10
(10) 16 bit public data provided by Pin 10
@ SW_DATA_SOURCE_VBG_COUNTS_VS_VREF
(76) A/D conversion of VBG against VRef . Used for mfg calibration
@ SW_DATA_SOURCE_PIN_5
(5) 16 bit public data provided by Pin 5
@ SW_DATA_SOURCE_PIN_14
(14) 16 bit public data provided by Pin 14
@ SW_DATA_SOURCE_PIN_13
(13) 16 bit public data provided by Pin 13
@ SW_DATA_SOURCE_1024mvCounts
(66) The number of ADC counts that result from a 1.024V reading
@ SW_DATA_SOURCE_TEMPERATURE
(70)The internal core temperature expressed in 100ths deg C
@ SW_DATA_SOURCE_PIN_1
(1) 16 bit public data provided by Pin 1
@ SW_DATA_SOURCE_FRAMES_RUN_LSW
(67) The number of frames run since reset, least significant 16 bits
@ SW_DATA_SOURCE_VCC_mVOLTS
(75) The system source voltage in mV
@ SW_DATA_SOURCE_PIN_11
(11) 16 bit public data provided by Pin 11
@ SW_DATA_SOURCE_8SEC_SAW
(174)Sawtooth wave that goes from 0 to 65535 to 0 every 8192 frames
@ SW_DATA_SOURCE_PIN_4_MV
(104) Pin 4 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_6
(6) 16 bit public data provided by Pin 6
@ SW_DATA_SOURCE_PIN_15
(15) 16 bit public data provided by Pin 15
@ SW_DATA_SOURCE_LFSR
A Linear FeedBack Shift register (32,7,5,3,2,1) based pseudo-random number generator.
@ SW_DATA_SOURCE_OVERRUN_FRAMES
(69) The number of frames that ran more than 1mS
@ SW_DATA_SOURCE_PIN_9
(9) 16 bit public data provided by Pin 9
@ SW_DATA_SOURCE_PIN_12
(12) 16 bit public data provided by Pin 12
@ SW_DATA_SOURCE_PIN_3_MV
(103) Pin 3 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_8
(8) 16 bit public data provided by Pin 8
@ SW_DATA_SOURCE_PIN_18
(18) 16 bit public data provided by Pin 18
@ SW_DATA_SOURCE_8SEC_SQUARE
(173)Square wave that alternates between 0 and 65535 every 4096 frames
@ SW_DATA_SOURCE_0x55
(85) 0x55 is a reserved value for resyncing. Returns 0x55 0x55
@ SW_DATA_SOURCE_RESET_REGISTER
Hardware dependent reset reason register contents.
@ SW_DATA_SOURCE_2SEC_SQUARE
(170)Square wave that alternates between 0 and 65535 every 1024 frames
@ SW_DATA_COM_ADDRESS_LOW
The Communications Address of the Device (Lower 16 bits)
@ SW_DATA_SOURCE_PIN_18_MV
(118) Pin 18 public output expressed in mV (for analog modes only)
@ SW_DATA_COM_ADDRESS_HIGH
The Communications Address of the Device (HIGHER 16 bits) Anticipated for CAN ID.
@ SW_DATA_SOURCE_ERRORS
(72)The number of incoming packets that have caused errors since reset (rolls over at 65535)
@ SW_DATA_SOURCE_PIN_0_MV
(100) Pin 0 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_4
(4) 16 bit public data provided by Pin 4
@ SW_DATA_SOURCE_SYSTEM_UTILIZATION
(74) A number between 0 and 65535 that scales to the average length of pin processing frames between ...
@ SW_DATA_SOURCE_PACKETS_RECEIVED
(71) The nubmer of incoming command packets that have been processed since reset (rolls over at 65535...
@ SW_DATA_SOURCE_1HZ_SQUARE
(167) Square wave that alternates between 0 and 65535 every 512 frames
@ SW_DATA_SOURCE_2SEC_SAW
(171)Sawtooth wave that goes from 0 to 65535 to 0 every 2048 frames
@ SW_DATA_SOURCE_PIN_17_MV
(117) Pin 17 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_1_MV
(101) Pin 1 public output expressed in mV (for analog modes only)
@ 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...
@ SW_DATA_SOURCE_PIN_16_MV
(116) Pin 16 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_0
(0) 16 bit public data provided by Pin 0
@ SW_DATA_SOURCE_PIN_2
(2) 16 bit public data provided by Pin 2
@ SW_DATA_SOURCE_PIN_2_MV
(102) Pin 2 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_16
(16) 16 bit public data provided by Pin 16
@ SW_DATA_SOURCE_1HZ_SAW
(168) Sawtooth wave that goes from 0 to 65535 to 0 every 1024 frames
@ SW_DATA_SOURCE_PIN_19_MV
(119) Pin 19 public output expressed in mV (for analog modes only)
@ SW_DATA_SOURCE_PIN_7
(7) 16 bit public data provided by Pin 7
@ SW_DATA_SOURCE_FRAMES_RUN_MSW
(68) The number of frames run since reset, most significant 16 bits
@ SW_DATA_SOURCE_INCREMENTING_NUMBER
(65) An number that increments each time it is accessed.
@ SW_DATA_SOURCE_PIN_19
(19) 16 bit public data provided by Pin 19
@ SW_DATA_SOURCE_2HZ_SAW
(165) Sawtooth wave that goes from 0 to 65535 to 0 every 512 frames
@ SW_DATA_SOURCE_PIN_17
(17) 16 bit public data provided by Pin 17
@ SW_DATA_SOURCE_PIN_3
(3) 16 bit public data provided by Pin 3
@ SW_DATA_SOURCE_65SEC_SAW
(177 )Sawtooth wave that goes from 0 to 65535 to 0 every 65536 frames
@ SW_DATA_SOURCE_NONE
(255 ) Used to mean "No Source Selected"
@ SW_DATA_SOURCE_2HZ_SQUARE
(164) Square wave that alternates between 0 and 65535 every 256 frames
@ SW_DATA_SOURCE_65SEC_SQUARE
(176) Square wave that alternates between 0 and 65535 every 32768 frames
#define ARRAY_UINT32(_array, _index)
void(* SerialWombatErrorHandler_t)(uint16_t errorNumber, SerialWombatChip *sw)
SerialWombatPinState_t
@ SW_INPUT
@ SW_HIGH
@ SW_LOW
@ SW_ERROR_UNKNOWN_PIN_MODE
(#3) A Pin mode was indicated that is not avaialble on this model or version of Serial Wombat chip
SerialWombat18ABOscillatorTuner(SerialWombatChip &serialWombatChip)
Class constructor for SerialWombat18OscillatorTuner.
void update()
Call periodically to tune the SW18AB oscillator to reported millis.
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
int16_t setThroughputPin(uint32_t address)
Set this chip Address (SW8B only)
uint8_t uniqueIdentifier[16]
bool isLatestFirmware(void)
Check if the firmware is the latest version (or more precisely, if the firmware matches this verison ...
uint8_t address
The I2C address of the SerialWombatChip instance.
uint16_t deviceRevision
void wake()
Called to send a dummy packet to the Serial Wombat 8B chip to wake it from sleep and ready it for oth...
uint32_t sendReadyTime
Used as a countdown after a reset command is issued.
uint8_t uniqueIdentifierLength
bool isSW04()
Returns true if the instance received a model number corresponding to the Serial Wombat 18 series of ...
uint32_t comparePublicDataToThreshold(uint16_t threshold=0)
int16_t echo(uint8_t data[], uint8_t count=7)
Echo a byte array back to the host. Used for testing and debugging.
void digitalWrite(uint8_t pin, uint8_t val)
Set an output pin High or Low.
uint32_t readFlashAddress(uint32_t address)
Read Address from Flash based on 32 bit address.
bool inBoot
Set to true if boot mode is indicated by a version query.
bool isPinModeSupported(int pinMode)
Check if a specific pin mode is supported by the firmware in the Serial Wombat chip....
bool isPinModeSupported(SerialWombatPinMode_t pinMode)
Check if a specific pin mode is supported by the firmware in the Serial Wombat chip....
bool isSW08()
Returns true if the instance received a model number corresponding to the Serial Wombat 08 series of ...
void readUniqueIdentifier()
Read the unique identifier from the Serial Wombat chip and store it in uniqueIdentifier.
char * readVersion(void)
Request version string (combined model and firmware) and return pointer to it.
void configureDigitalPin(uint8_t pin, uint8_t highLow)
Configure a pin to a digital state with the same parameters as Arduino's digitalWrite() function.
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
uint8_t fwVersion[4]
Contains the last firmware Version retreived by queryVersion() as a zero-terminated string.
uint32_t readBirthday()
Read the birthday of the Serial Wombat 18AB chip.
uint8_t communicationErrorRetries
How many times to retry a packet if communcation bus (such as I2C) error.
int16_t echo(char *data)
Echo a byte array back to the host. Used for testing and debugging.
uint16_t readOverflowFrames()
Get the number of times an overflow Frame has occured.
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 ...
void readDeviceIdentifier()
Read the device identifier from the Serial Wombat chip and store it in deviceIdentifier.
int writeUserBuffer(uint16_t index, uint8_t *buffer, uint16_t count)
Write bytes to the User Memory Buffer in the Serial Wombat chip.
int16_t readTemperature_100thsDegC(void)
Measure the Serial Wombat chip's internal temperature.
int sendPacketNoResponse(uint8_t tx[])
Send an 8 byte packet to the Serial Wombat chip, don't wait for a response.
uint8_t readRamAddress(uint16_t address)
Read Address from RAM based on 16 bit address.
int16_t readUserBuffer(uint16_t index, uint8_t *buffer, uint16_t count)
Read data from the Serial Wombat 18AB's internal RAM buffer.
bool isSW18()
Returns true if the instance received a model number corresponding to the Serial Wombat 18 series of ...
int16_t lastErrorCode
The last error code returned as part of a protocol error message expressed as a positive integer.
int16_t readBrand(char *data)
Read the brand of the Serial Wombat 18AB chip.
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.
int16_t setThroughputPin(uint8_t pin)
Set a pin to be a throughput monitoring pin.
int16_t begin(HardwareSerial &serial, bool reset=true)
initialize a Serial Wombat chip to use a Serial Interface.
int sendPacket(uint8_t tx[], uint8_t rx[])
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
void sleep4B()
Shuts down most functions of the Serial Wombat 4B chip reducing power consumption.
uint32_t readVersion_uint32(void)
Request version as a uint32.
uint16_t writePublicData(uint8_t pin, uint16_t value)
Write a 16 bit value to a Serial Wombat pin Mode.
uint16_t readSupplyVoltage_mV(void)
Measure the Serial Wombat chip's Supply voltage.
int16_t writeFlashRow(uint32_t address)
Writes a row in flash. Intended for use with the Bootloader, not by end users outside of bootloading ...
int writeUserBuffer(uint16_t index, char *s)
Write bytes to the User Memory Buffer in the Serial Wombat chip.
int16_t eraseFlashPage(uint32_t address)
Erases a page in flash. Intended for use with the Bootloader, not by end users outside of bootloading...
uint16_t returnErrorCode(uint8_t *rx)
Convert an ASCII Error code from a received packet into an integer error code.
uint16_t deviceIdentifier
int16_t writeRamAddress(uint16_t address, uint8_t value)
Write byte to Address in RAM based on 16 bit address.
int16_t initialize()
An internal function used to set up the Serial Wombat chip and this class. Call begin() instead of th...
int16_t writeFrameTimerPin(uint8_t pin)
Set a pin to be a frame timer for system utilization (SW18AB Only)
uint16_t _supplyVoltagemV
void registerErrorHandler(SerialWombatErrorHandler_t handler)
Registers an error handler that is called by the SerialWombatChip sendPacket() command when a protoco...
int16_t begin(TwoWire &wire, uint8_t i2cAddress, bool reset=true)
initialize a Serial Wombat chip to use a specified I2C Interface and address.
void analogWrite(uint8_t pin, int val)
Set a pin to PWM output.
void sleep8B(uint16_t delay)
Shuts down the Serial Wombat 8B chip reducing power consumption as low as 10uA.
uint16_t errorCount
Incremented every time a communication or command error is detected.
int writeUserBuffer(uint16_t index, const char s[])
Write bytes to the User Memory Buffer in the Serial Wombat chip.
int analogRead(uint8_t pin)
Configures pin as analog input and does an immediate A/D conversion.
uint16_t readPublicData(SerialWombatDataSource dataSource)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
bool queryVersion()
Send a version request to the Serial Wombat chip.
void jumpToBoot()
Jump to Bootloader and wait for a UART download of new firmware.
int digitalRead(uint8_t pin)
Reads the state of a Pin.
void hardwareReset()
Send a reset command to the Serial Wombat chip.
uint8_t model[4]
Contains the last model retreived by queryVersion() as a zero-terminated string.
uint32_t readFramesExecuted()
Get the number of 1mS frames that have been executed since Serial Wombat chip reset.
int16_t readLastErrorCommand(uint8_t *cmd)
Returns the last Serial Wombat command that produced a protocol error.
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.