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-2025 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
35
36
39
41#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#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])
47#define SW18AB_LATEST_FIRMWARE 220
48#define SW08B_LATEST_FIRMWARE 220
49#define SW4B_LATEST_FIRMWARE 203
50
51typedef enum
52{
53 SW_LOW = 0,
57
58
61
82// SW_DATA_SOURCE_PIN_20 = 20,
83// SW_DATA_SOURCE_PIN_21 = 21,
84// SW_DATA_SOURCE_PIN_22 = 22,
85// SW_DATA_SOURCE_PIN_23 = 23,
86// SW_DATA_SOURCE_PIN_24 = 24,
87// SW_DATA_SOURCE_PIN_25 = 25,
88// SW_DATA_SOURCE_PIN_26 = 26,
89// SW_DATA_SOURCE_PIN_27 = 27,
90// SW_DATA_SOURCE_PIN_28 = 28,
91// SW_DATA_SOURCE_PIN_29 = 29,
92// SW_DATA_SOURCE_PIN_30 = 30,
93// SW_DATA_SOURCE_PIN_31 = 31,
94// SW_DATA_SOURCE_PIN_32 = 32,
95// SW_DATA_SOURCE_PIN_33 = 33,
96// SW_DATA_SOURCE_PIN_34 = 34,
97// SW_DATA_SOURCE_PIN_35 = 35,
98// SW_DATA_SOURCE_PIN_36 = 36,
99// SW_DATA_SOURCE_PIN_37 = 37,
100// SW_DATA_SOURCE_PIN_38 = 38,
101// SW_DATA_SOURCE_PIN_39 = 39,
102// SW_DATA_SOURCE_PIN_40 = 40,
103// SW_DATA_SOURCE_PIN_41 = 41,
104// SW_DATA_SOURCE_PIN_42 = 42,
105// SW_DATA_SOURCE_PIN_43 = 43,
106// SW_DATA_SOURCE_PIN_44 = 44,
107// SW_DATA_SOURCE_PIN_45 = 45,
108// SW_DATA_SOURCE_PIN_46 = 46,
109// SW_DATA_SOURCE_PIN_47 = 47,
110// SW_DATA_SOURCE_PIN_48 = 48,
111// SW_DATA_SOURCE_PIN_49 = 49,
112// SW_DATA_SOURCE_PIN_50 = 50,
113// SW_DATA_SOURCE_PIN_51 = 51,
114// SW_DATA_SOURCE_PIN_52 = 52,
115// SW_DATA_SOURCE_PIN_53 = 53,
116// SW_DATA_SOURCE_PIN_54 = 54,
117// SW_DATA_SOURCE_PIN_55 = 55,
118// SW_DATA_SOURCE_PIN_56 = 56,
119// SW_DATA_SOURCE_PIN_57 = 57,
120// SW_DATA_SOURCE_PIN_58 = 58,
121// SW_DATA_SOURCE_PIN_59 = 59,
122// SW_DATA_SOURCE_PIN_60 = 60,
123// SW_DATA_SOURCE_PIN_61 = 61,
124// SW_DATA_SOURCE_PIN_62 = 62,
125// SW_DATA_SOURCE_PIN_63 = 63,
145 //NOT ANALOG SW_DATA_SOURCE_PIN_5_MV = 105,
146 //NOT ANALOG SW_DATA_SOURCE_PIN_6_MV = 106,
147 //NOT ANALOG SW_DATA_SOURCE_PIN_7_MV = 107,
148 //NOT ANALOG SW_DATA_SOURCE_PIN_8_MV = 108,
149 //NOT ANALOG SW_DATA_SOURCE_PIN_9_MV = 109,
150 //NOT ANALOG SW_DATA_SOURCE_PIN_10_MV = 110,
151 //NOT ANALOG SW_DATA_SOURCE_PIN_11_MV = 111,
152 //NOT ANALOG SW_DATA_SOURCE_PIN_12_MV = 112,
153 //NOT ANALOG SW_DATA_SOURCE_PIN_13_MV = 113,
154 //NOT ANALOG SW_DATA_SOURCE_PIN_14_MV = 114,
155 //NOT ANALOG SW_DATA_SOURCE_PIN_15_MV = 115,
162// SW_DATA_SOURCE_2HZ_SIN = 166,
165// SW_DATA_SOURCE_1HZ_SIN = 169,
168// SW_DATA_SOURCE_2SEC_SIN = 172,
171// SW_DATA_SOURCE_8SEC_SIN = 175,
174// SW_DATA_SOURCE_65SEC_SIN = 178,
176};
177
178#define ERROR_HOST_INCORRECT_NUMBER_BYTES_WRITTEN 0x10000
179#define ERROR_HOST_DATA_TOO_LONG 0x10001
180#define ERROR_HOST_NACK_ADDRESS 0x10002
181#define ERROR_HOST_NACK_DATA 0x10003
182#define ERROR_HOST_OTHER_I2C_ERROR 0x10004
183
184#define WOMBAT_MAXIMUM_PINS 20
185
187{
188 CMD_ECHO ='!',
191 CMD_RESET = 'R',
246
247};
248
249
286
287class SerialWombatChip;
288
289typedef void (*SerialWombatErrorHandler_t) (uint16_t errorNumber, SerialWombatChip* sw);
290
297{
298private:
299
300 char version[8] = { 0 };
301 HardwareSerial * Serial = NULL;
302 TwoWire* i2cInterface = NULL;
303 uint8_t _pinmode[WOMBAT_MAXIMUM_PINS]={}; // Includes Pullup
304 bool _pullDown[WOMBAT_MAXIMUM_PINS]={};
305 bool _openDrain[WOMBAT_MAXIMUM_PINS]={};
306 bool _highLow[WOMBAT_MAXIMUM_PINS] = {};
307 bool _asleep = false;
308 SerialWombatErrorHandler_t errorHandler = NULL;
309 bool _currentlyCommunicating = false;
310public:
317 uint16_t _supplyVoltagemV = 0;
318
320 uint8_t model[4] = { 0 };
321
323 uint8_t fwVersion[4] = { 0 };
324
330 uint8_t uniqueIdentifier[16];
331
337
343
350 uint16_t errorCount = 0;
351
353 bool inBoot = false;
354
356 int16_t lastErrorCode = 0;
357
358 void configureDigitalPin(uint8_t pin, uint8_t highLow)
359 {
360 uint8_t tx[8] = { 200,pin,0,0,0,0,0,0x55 };
361 uint8_t rx[8];
362 switch (_pinmode[pin])
363 {
364 case INPUT: // Arduino input
365 {
366 tx[3] = 2; //Input
367 }
368 break;
369 case OUTPUT:
370 {
371 if (highLow == LOW)
372 {
373 tx[3] = 0;
374 }
375 else if (highLow == HIGH)
376 {
377 tx[3] = 1;
378 }
379 else
380 {
381 return;
382 }
383 }
384 break;
385 case INPUT_PULLUP:
386 {
387 tx[3] = 2; //Input
388 tx[4] = 1; //Pullup on
389 }
390 break;
391 default:
392 {
393 return;
394 }
395 }
396 tx[6] = _openDrain[pin];
397 tx[5] = _pullDown[pin];
398 sendPacket(tx, rx, true);
399 }
400 uint32_t sendReadyTime = 0;
401 int16_t initialize()
402 {
403 lastErrorCode = 0;
404 readVersion();
408 return(lastErrorCode);
409 }
410
412 {
414 if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
415 { //16F15214
416 for (uint32_t address = 0x8100; address <= 0x8108; ++address)
417 {
418 uint32_t data = readFlashAddress(address);
421 /* Always zero... leave out
422 uniqueIdentifier[uniqueIdentifierLength] = (uint8_t)(data>>8);
423 ++uniqueIdentifierLength;
424 */
425 }
426 }
427 else if (isSW18())
428 {
429 for (uint32_t address = 0x801600; address <= 0x801608; address += 2)
430 {
431 uint32_t data = readFlashAddress(address);
438 }
439 }
440 }
441
443 {
444 if (version[0] == 'S' && version[1] == '0' && version[2] == '4')
445 { //16F15214
446
447 uint32_t data = readFlashAddress(0x8006);
448 deviceIdentifier = (uint16_t)data;
449 data = readFlashAddress(0x8005);
450 deviceRevision = (uint16_t)data;
451 }
452 else if (isSW18())
453 {
454 uint32_t data = readFlashAddress(0xFF0000);
455 deviceIdentifier = (uint16_t)data;
456 data = readFlashAddress(0xFF0002);
457 deviceRevision = (uint16_t)data & 0xF;
458 }
459 }
460
461 uint16_t returnErrorCode(uint8_t* rx)
462 {
463 uint16_t result = rx[1] - '0';
464 result *= 10;
465 result += rx[2] - '0';
466 result *= 10;
467 result += rx[3] - '0';
468 result *= 10;
469 result += rx[4] - '0';
470 result *= 10;
471 result += rx[5] - '0';
472 return(result);
473 }
474
475
476
477public:
492 int16_t begin(HardwareSerial& serial, bool reset = true)
493 {
494 Serial = &serial;
495 Serial->begin(115200);
496 Serial->setTimeout(2);
497 Serial->write((uint8_t*)"UUUUUUUU", 8);
498 delay(5);
499 while (Serial->read() >= 0);
500 if (reset)
501 {
503 sendReadyTime = millis() + 1000;
504 return(1);
505 }
506 else
507 {
508 return initialize();
509 }
510
511
512 }
513
523 int16_t begin(uint8_t i2cAddress);
524
538 int16_t begin(TwoWire& wire, uint8_t i2cAddress, bool reset = true)
539 {
540 i2cInterface = &wire;
541 address = i2cAddress;
542
543 Wire.beginTransmission(i2cAddress);
544 int error = Wire.endTransmission();
545
546
547 if (error != 0)
548 {
549 return(-1);
550 }
551
552 if (reset)
553 {
555 sendReadyTime = millis() + 250;
556 return(1);
557 }
558 else
559 {
560 sendReadyTime = 0;
561 return initialize();
562
563 }
564 }
565
567
578 int sendPacket( uint8_t tx[], uint8_t rx[]);
579
589 int sendPacket(uint8_t tx[]);
590
601 int sendPacket(uint8_t tx[], uint8_t rx[], bool retryIfEchoDoesntMatch, uint8_t beginningBytesToMatch = 8, uint8_t endBytesToMatch = 0);
611 int sendPacket(uint8_t tx[], bool retryIfEchoDoesntMatch);
612
621
622 int sendPacketNoResponse(uint8_t tx[]);
623
632 char* readVersion(void)
633 {
634 uint8_t tx[] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
635 uint8_t rx[8];
636 sendPacket(tx, rx);
637 memcpy(version, &rx[1], 7);
638 version[7] = '\0';
639 memcpy(model, &rx[1], 3);
640 model[3] = '\0';
641 fwVersion[0] = rx[5];
642 fwVersion[1] = rx[6];
643 fwVersion[2] = rx[7];
644 return (version);
645 }
646
653 uint32_t readVersion_uint32(void)
654 {
655 readVersion();
656 return (
657 ((uint32_t)fwVersion[0] - '0') * 100 +
658 ((uint32_t)fwVersion[1] - '0') * 10 +
659 (uint32_t)fwVersion[2] - '0');
660 }
661
663 {
664 uint32_t v = readVersion_uint32();
665 if (isSW18())
666 {
667 return (v == SW18AB_LATEST_FIRMWARE);
668 }
669 else if (isSW08())
670 {
671 return (v == SW08B_LATEST_FIRMWARE);
672 }
673 else
674 {
675 return (v == SW4B_LATEST_FIRMWARE);
676
677 }
678 }
679
689 uint16_t readPublicData(uint8_t pin)
690 {
691 uint8_t tx[] = { 0x81,pin,255,255,0x55,0x55,0x55,0x55 };
692 uint8_t rx[8];
693 sendPacket(tx, rx);
694 return(rx[2] + (uint16_t)rx[3] * 256);
695 }
696
707 {
708 return (readPublicData((uint8_t)dataSource));
709 }
710
716 uint16_t writePublicData(uint8_t pin, uint16_t value)
717 {
718 uint8_t tx[] = { 0x82,pin,(uint8_t)(value & 0xFF),(uint8_t)(value >> 8) ,255,0x55,0x55,0x55 };
719 uint8_t rx[8];
720 sendPacket(tx, rx);
721 return (rx[2] + rx[3] * 256);
722 }
723
724 uint32_t comparePublicDataToThreshold(uint16_t threshold = 0)
725 {
726 uint8_t tx[] = { (uint8_t) SerialWombatCommands::COMMAND_BINARY_PIN_POLL_THRESHOLD,SW_LE16(threshold) ,0x55, 0x55,0x55,0x55,0x55 };
727 uint8_t rx[8];
728 sendPacket(tx, rx);
729 return (ARRAY_UINT32(rx,1));
730 }
731
741
742 uint16_t readSupplyVoltage_mV(void)
743 {
744 if (isSW18() || isSW08())
745 {
747 }
748 else
749 {
750 int32_t counts = readPublicData(66); // Get FVR counts (1.024 v)
751 if (counts > 0)
752 {
753 uint32_t mv = 1024 * 65536 / counts;
754 _supplyVoltagemV = (uint16_t)mv;
755 }
756 else
757 {
759 }
760 }
761 return(_supplyVoltagemV);
762 }
763
764
776 {
777 if (isSW18())
778 {
779 int32_t result = readPublicData(70);
780 if (result >= 32768)
781 {
782 result = result - 65536;
783 }
784 return ((int16_t)result);
785 }
786 else
787 {
788 return 2500;
789 }
790 }
791
799 {
800 uint8_t tx[9] = "ReSeT!#*";
802 }
803
812 void pinMode(uint8_t pin, uint8_t mode, bool pullDown = false, bool openDrain = false)
813 {
814 if (pin >= WOMBAT_MAXIMUM_PINS)
815 {
816 return;
817 }
818 _pullDown[pin] = pullDown;
819 _openDrain[pin] = openDrain;
820 _pinmode[pin] = mode;
821 configureDigitalPin(pin, mode);
822 }
823
831 void digitalWrite(uint8_t pin, uint8_t val)
832 {
833 configureDigitalPin(pin, val);
834 }
835
841 int digitalRead(uint8_t pin)
842 {
843 if (readPublicData(pin) > 0)
844 {
845 return (HIGH);
846 }
847 else
848 {
849 return (LOW);
850 }
851 }
852
862 int analogRead(uint8_t pin)
863 {
864 uint8_t tx[] = { 200,pin,PIN_MODE_ANALOGINPUT,0,0,0,0,0 };
865 uint8_t rx[8];
866 sendPacket(tx, rx);
867 return (readPublicData(pin) >> 6); // Scale from 16 bit value to 10 bit value.
868 }
869
881 void analogWrite(uint8_t pin, int val)
882 {
883 uint8_t dutyCycleLow = 0;
884 if (val == 255)
885 {
886 dutyCycleLow = 255;
887 }
888 uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_PWM,pin,dutyCycleLow,(uint8_t) val,false,0x55 };
889 uint8_t rx[8];
890 sendPacket(tx, rx);
891 }
892
904 {
905 uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
906 uint8_t rx[8];
907 sendPacket(tx, rx);
908 if (rx[0] == 'V' && (rx[1] == 'S' || rx[1] == 'B'))
909 {
910 model[0] = rx[1];
911 model[1] = rx[2];
912 model[2] = rx[3];
913 model[3] = 0;
914 fwVersion[0] = rx[5];
915 fwVersion[1] = rx[6];
916 fwVersion[2] = rx[7];
917 fwVersion[3] = 0;
918
919 inBoot = (rx[1] == 'B');
920 return (true);
921 }
922 return (false);
923 }
924
932 {
933 uint8_t tx[8] = { 0x81,67,68,0x55,0x55,0x55,0x55,0x55 };
934 uint8_t rx[8];
935 sendPacket(tx, rx);
936 uint32_t returnval = rx[2] + (((uint32_t)rx[3]) << 8) + (((uint32_t)rx[4]) << 16) + (((uint32_t)rx[5]) << 24);
937 return (returnval);
938 }
939
947
949 {
950 return readPublicData(69);
951 }
952
963 {
964 uint8_t tx[] = "BoOtLoAd";
965 sendPacket(tx);
966 }
967
988 uint8_t readRamAddress(uint16_t address)
989 {
990 uint8_t tx[8] = { 0xA0,SW_LE16(address),0x55,0x55,0x55,0x55,0x55 };
991 uint8_t rx[8];
992 sendPacket(tx, rx);
993 return(rx[3]);
994 }
995
1015
1016 int16_t writeRamAddress(uint16_t address, uint8_t value)
1017 {
1018 uint8_t tx[8] = { 0xA3,SW_LE16(address),0,0,value,0x55,0x55};
1019 return sendPacket(tx);
1020 }
1021
1036
1037 uint32_t readFlashAddress(uint32_t address)
1038 {
1039 uint8_t tx[8] = { 0xA1,SW_LE32(address),0x55,0x55,0x55 };
1040 uint8_t rx[8];
1041 sendPacket(tx, rx);
1042 return(((uint32_t)rx[4]) + (((uint32_t)rx[5]) <<8) + (((uint32_t)rx[6]) <<16) + (((uint32_t)rx[7]) <<24));
1043 }
1044
1056 int16_t readUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1057 {
1058 uint16_t bytesRead = 0;
1059 while (bytesRead < count)
1060 {
1061 byte tx[] = {(byte)SerialWombatCommands::COMMAND_BINARY_READ_USER_BUFFER, (byte)(index & 0xFF), (byte)(index >> 8), 0x55, 0x55, 0x55, 0x55, 0x55};
1062 byte rx[8];
1063 int16_t result = sendPacket(tx, rx);
1064 if (result >= 0)
1065 {
1066 for (int i = 1; i < 8; ++i)
1067 {
1068 buffer[bytesRead] = rx[i];
1069 ++bytesRead;
1070 ++index;
1071 if (bytesRead >= count)
1072 {
1073 break;
1074 }
1075 }
1076 }
1077 else
1078 {
1079 return (bytesRead);
1080 }
1081 }
1082 return (bytesRead);
1083 }
1084
1094 void sleep()
1095 {
1096 uint8_t tx[8] = { 'S','l','E','e','P','!','#','*'};
1097 sendPacket(tx);
1098 _asleep = true;
1099 }
1100
1102 void wake()
1103 {
1104 uint8_t tx[8] = { '!','!','!','!','!','!','!','!' };
1105 sendPacket(tx);
1106 }
1107
1109 bool isSW18()
1110 {
1111 return ( model[1] == '1' && model[2] == '8');
1112 }
1113
1114 bool isSW08()
1115 {
1116 return ( model[1] == '0' && model[2] == '8');
1117 }
1118
1120 int16_t eraseFlashPage(uint32_t address)
1121 {
1122 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1123 0, //Erase Page
1125 0x55,0x55 };
1126 return sendPacket(tx);
1127 }
1128
1129
1131 int16_t writeFlashRow(uint32_t address)
1132 {
1133 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_WRITE_FLASH,
1134 1, // Write entire row
1135 SW_LE32(address),0x55,0x55 };
1136 return sendPacket(tx);
1137 }
1138
1139
1140
1141
1151 int16_t setThroughputPin(uint8_t pin)
1152 {
1153 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1154 return sendPacket(tx);
1155 }
1156
1170 int16_t setThroughputPin(uint32_t address)
1171 {
1172 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_BINARY_SET_ADDRESS,SW_LE32(address),0x55,0x55,0x55 };
1173 return sendPacket(tx);
1174 }
1175
1183 int writeUserBuffer(uint16_t index, uint8_t* buffer, uint16_t count)
1184 {
1185 uint16_t bytesSent = 0;
1186 if (count == 0)
1187 {
1188 return 0;
1189 }
1190
1191 { // Send first packet of up to 4 bytes
1192 uint8_t bytesToSend = 4;
1193 if (count < 4)
1194 {
1195 bytesToSend = (uint8_t)count;
1196 count = 0;
1197 }
1198 else
1199 {
1200 count -= 4;
1201 }
1202
1203 uint8_t tx[8] = { 0x84,SW_LE16(index), bytesToSend,0x55,0x55,0x55,0x55 };
1204 uint8_t rx[8];
1205
1206 uint8_t i;
1207 for (i = 0; i < bytesToSend; ++i)
1208 {
1209 tx[4 + i] = buffer[i];
1210 }
1211 int result = sendPacket(tx, rx);
1212 if (rx[0] == 'E')
1213 {
1214 return (result);
1215 }
1216 bytesSent = bytesToSend;
1217 }
1218 while (count >= 7) // Continue sending
1219 {
1220
1221 count -= 7;
1222 uint8_t tx[8] = { 0x85,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1223 uint8_t rx[8];
1224 uint8_t i;
1225 for (i = 0; i < 7; ++i)
1226 {
1227 tx[1 + i] = buffer[bytesSent + i];
1228 }
1229 int result = sendPacket(tx, rx);
1230 if (rx[0] == 'E')
1231 {
1232 return (result);
1233 }
1234 bytesSent += 7;
1235 }
1236 while (count > 0)
1237 {
1238
1239 { // Send first packet of up to 4 bytes
1240 uint8_t bytesToSend = 4;
1241 if (count < 4)
1242 {
1243 bytesToSend = (uint8_t)count;
1244 count = 0;
1245 }
1246 else
1247 {
1248 count -= 4;
1249 }
1250
1251 uint8_t tx[8] = { 0x84,SW_LE16(index + bytesSent), bytesToSend,0x55,0x55,0x55,0x55 };
1252 uint8_t rx[8];
1253
1254 uint8_t i;
1255 for (i = 0; i < bytesToSend; ++i)
1256 {
1257 tx[4 + i] = buffer[i + bytesSent];
1258 }
1259 int result = sendPacket(tx, rx);
1260 if (rx[0] == 'E')
1261 {
1262 return (result);
1263 }
1264 bytesSent += bytesToSend;
1265 }
1266 }
1267 return(bytesSent);
1268
1269
1270 }
1271
1279 int writeUserBuffer(uint16_t index, char* s)
1280 {
1281 return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1282 }
1283
1291 int writeUserBuffer(uint16_t index, const char s[])
1292 {
1293 return writeUserBuffer(index, (uint8_t*)s, (uint16_t)strlen(s));
1294 }
1295
1296
1297
1309 int16_t writeFrameTimerPin(uint8_t pin)
1310{
1311 uint8_t tx[] = { 0xC8 ,pin,(uint8_t)PIN_MODE_FRAME_TIMER,0x55,0x55,0x55,0x55,0x55 };
1312 return sendPacket(tx);
1313}
1314
1315
1323 static uint8_t find(bool keepTrying = false)
1324 {
1325 do
1326 {
1327 for (int i2cAddress = 0x60; i2cAddress <= 0x6F; ++i2cAddress)
1328 {
1329 Wire.beginTransmission(i2cAddress);
1330 int error = Wire.endTransmission();
1331
1332
1333 if (error == 0)
1334 {
1335 uint8_t tx[8] = { 'V',0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
1336 uint8_t rx[8];
1337 Wire.beginTransmission(i2cAddress);
1338 Wire.write(tx, 8);
1339 Wire.endTransmission();
1340 Wire.requestFrom((uint8_t)i2cAddress, (uint8_t)8);
1341
1342 int count = 0;
1343 while (Wire.available() && count < 8)
1344 {
1345 rx[count] = Wire.read();
1346 ++count;
1347 }
1348 if (count == 8)
1349 {
1350 if (rx[0] == 'V' && (rx[1] == 'S' || rx[1]=='B'))
1351 {
1352 return(i2cAddress); // Found one.
1353 }
1354 }
1355 }
1356 }
1357 delay(0);
1358 }while (keepTrying);
1359 return(0); // Didn't find one.
1360 }
1361
1362
1369 int16_t readLastErrorCommand(uint8_t* cmd)
1370{
1371 //TODO this doen't look like it returns the error
1372 uint8_t tx[8] = { (uint8_t)SerialWombatCommands::COMMAND_READ_LAST_ERROR_PACKET, 0,0x55,0x55,0x55,0x55,0x55,0x55 };
1373 uint8_t rx[8];
1374 if (sendPacket(tx, rx) >= 0)
1375 {
1376 for (int i = 1; i < 8; ++i)
1377 {
1378 cmd[i - 1] = rx[i];
1379 }
1380 }
1381 else
1382 {
1383 return (lastErrorCode);
1384 }
1385 tx[1] = 7;
1386 if (sendPacket(tx, rx) >= 0)
1387 {
1388 cmd[7] = rx[1];
1389 }
1390 return(lastErrorCode);
1391}
1392
1398 {
1399 errorHandler = handler;
1400 }
1401
1403 uint8_t address = 0;
1404
1407
1408 int16_t echo(uint8_t data[], uint8_t count = 7)
1409 {
1410 uint8_t tx[] = "!UUUUUUU";
1411 for (int i = 0; i < 7 && i < count; ++i)
1412 {
1413 tx[i + 1] = (uint8_t)data[i];
1414 }
1415 return sendPacket(tx);
1416 }
1417
1418
1419 int16_t echo(char* data)
1420 {
1421 int length = strlen(data);
1422 uint8_t tx[] = "!UUUUUUU";
1423 for (int i = 0; i < 7 && i < length; ++i)
1424 {
1425 tx[i + 1] = (uint8_t)data[i];
1426 }
1427 return sendPacket(tx);
1428 }
1429
1430 uint32_t readBirthday()
1431 {
1432 if (isSW18())
1433 {
1434 uint32_t birthday = (readFlashAddress(0x2A00C) >> 8) & 0xFF;
1435 birthday *= 100;
1436 birthday += (readFlashAddress(0x2A00C)) & 0xFF;
1437 birthday *= 100;
1438 birthday += readFlashAddress(0x2A00E) & 0xFF;
1439 birthday *= 100;
1440 birthday += readFlashAddress(0x2A010) & 0xFF;
1441 return (birthday);
1442 }
1443 return 0;
1444 }
1445
1446 int16_t readBrand(char* data)
1447 {
1448 uint8_t length = 0;
1449 if (isSW18())
1450 {
1451 for (int i = 0; i < 32; ++i)
1452 {
1453 uint32_t val = readFlashAddress(0x2A020 + i * 2) ;
1454 if ((val & 0xFF) != 0xFF)
1455 {
1456 data[i ] = (char)(val & 0xFF);
1457 ++length;
1458 }
1459 else
1460 {
1461 data[length] = 0;
1462 return (length);
1463 }
1464 }
1465 data[length] = 0;
1466 return (length);
1467 }
1468
1469 data[0] = 0;
1470 return 0 ;
1471 }
1472
1473};
1474
1489{
1490private:
1491 SerialWombatChip& _sw;
1492 uint32_t lastMillis = 0;
1493 uint32_t lastFrames = 0;
1494public:
1499 SerialWombat18ABOscillatorTuner(SerialWombatChip& serialWombatChip) : _sw(serialWombatChip) { }
1500
1504 void update() {
1505 uint32_t m = millis();
1506 if (lastMillis == 0)
1507 {
1508 lastMillis = m;
1509 uint32_t frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1510 uint16_t frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1511 if (frames != _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW))
1512 {
1513 frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1514 frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1515 }
1516 frames <<= 16;
1517 frames += frameslsb;
1518 lastFrames = frames;
1519
1520 }
1521 else if ((m - lastMillis) < 10000)
1522 {
1523 //Do nothing
1524 }
1525 else if (m < lastMillis)
1526 {
1527 //Has it been 47 days already?
1528 lastMillis = 0;
1529 }
1530 else
1531 {
1532 uint32_t diff = m - lastMillis;
1533
1534 uint32_t frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1535 uint16_t frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1536
1537 if (frames != _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW))
1538 {
1539 frameslsb = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_LSW);
1540 frames = _sw.readPublicData(SerialWombatDataSource::SW_DATA_SOURCE_FRAMES_RUN_MSW);
1541 }
1542 frames <<= 16;
1543 frames += frameslsb;
1544 uint32_t framesDif = frames - lastFrames;
1545
1546 if (diff > framesDif )
1547 {
1548 // Running slow
1549 uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1550 SW_LE16(1),//Counts to increment
1551 SW_LE16(0), // Counts to decrement
1552 0x55,0x55,0x55};
1553 _sw.sendPacket(tx);
1554 }
1555 else if (diff < framesDif)
1556 {
1557 // Running mfast
1558 uint8_t tx[] = { (uint8_t)SerialWombatCommands::COMMAND_ADJUST_FREQUENCY,
1559 SW_LE16(0),//Counts to increment
1560 SW_LE16(1), // Counts to decrement
1561 0x55,0x55,0x55 };
1562 _sw.sendPacket(tx);
1563
1564 }
1565
1566 lastMillis = m;
1567 lastFrames = frames;
1568
1569 }
1570
1571 }
1572
1573};
1574
1575/*
1576End of cross platform code synchronization. Random string to help the compare tool sync lines:
1577asdkj38vjn1nasdnvuwlamafdjiivnowalskive
1578*/
1579
1582
1583
1584
1585
1586
1596
1597#include "SerialWombatPin.h"
1598#include "SerialWombatErrors.h"
1599#include "SerialWombatQueue.h"
1604#include "SerialWombat18CapTouch.h"
1605#include "SerialWombat18ABVGA.h"
1609#include "SerialWombatHBridge.h"
1610#include "SerialWombatHSClock.h"
1611#include "SerialWombatHSCounter.h"
1618#include "SerialWombatPulseTimer.h"
1619#include "SerialWombatPWM.h"
1620#include "SerialWombatQuadEnc.h"
1623#include "SerialWombatServo.h"
1624#include "SerialWombatTM1637.h"
1625#include "SerialWombatUART.h"
1627#include "SerialWombatWatchdog.h"
1628#include "SerialWombatWS2812.h"
1630
1631#endif
#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)
@ 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_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_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_VGA
(31)
@ PIN_MODE_WS2812
(12)
void SerialWombatSerialErrorHandlerVerbose(uint16_t error, SerialWombatChip *sw)
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
(78) A Linear Feedback Shift Register that produces a Pseudo random sequence of 16 bit values
@ 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_2SEC_SQUARE
(170)Square wave that alternates between 0 and 65535 every 1024 frames
@ SW_DATA_SOURCE_PIN_18_MV
(118) Pin 18 public output expressed in mV (for analog modes only)
@ 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
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)
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 chip to wake it from sleep and ready it for other ...
uint32_t sendReadyTime
uint8_t uniqueIdentifierLength
uint32_t comparePublicDataToThreshold(uint16_t threshold=0)
int16_t echo(uint8_t data[], uint8_t count=7)
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 isSW08()
Returns true if the instance received a model number corresponding to the Serial Wombat 08 series of ...
void readUniqueIdentifier()
char * readVersion(void)
Request version string (combined model and firmware) and return pointer to it.
void configureDigitalPin(uint8_t pin, uint8_t highLow)
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()
uint8_t communicationErrorRetries
How many times to retry a packet if communcation bus (such as I2C) error.
int16_t echo(char *data)
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()
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)
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.
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)
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()
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.
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.
void sleep()
Shuts down most functions of the Serial Wombat chip reducing power consumption.
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.