Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombatPin.h
Go to the documentation of this file.
1#pragma once
2/*
3Copyright 2023-2025 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6the United States. See SerialWombat.com for usage guidance.
7
8Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25*/
26
39{
40public:
45 SerialWombatPin(SerialWombatChip& serialWombatChip): _sw(serialWombatChip)
46 {
47 }
48
54 SerialWombatPin(SerialWombatChip& serialWombatChip, uint8_t pin): _sw(serialWombatChip)
55 {
56 _pin = pin;
57 }
58
65 uint16_t readPublicData()
66 {
67 return _sw.readPublicData(_pin);
68 };
69
70
79 void pinMode(uint8_t mode, bool pullDown = false, bool openDrain = false)
80 {
81 _sw.pinMode(_pin, mode, pullDown, openDrain);
82 }
83
91 void digitalWrite(uint8_t val)
92 {
93 _sw.digitalWrite(_pin, val);
94 }
95
104 {
105 return (_sw.digitalRead(_pin));
106 }
107
108
113 uint16_t writePublicData(uint16_t value)
114 { return _sw.writePublicData(_pin, value); }
115
120 uint8_t pin() {return _pin;}
121
126 uint8_t swPinModeNumber() { return _pinMode; }
127
128
129
130 int16_t initPacketNoResponse(uint8_t packetNumber,uint8_t param0 = 0x55, uint8_t param1 = 0x55, uint8_t param2 = 0x55, uint8_t param3 = 0x55, uint8_t param4 = 0x55)
131 {
132 uint8_t tx[] = { (uint8_t)(200 +packetNumber), _pin, _pinMode,param0,param1,param2,param3,param4} ;
133 return (_sw.sendPacket(tx));
134 }
135
136 int16_t initPacketNoResponse(uint8_t packetNumber,uint16_t param0 = 0x55, uint8_t param1 = 0x55, uint8_t param2 = 0x55, uint8_t param3 = 0x55 )
137 {
138 uint8_t tx[] = { (uint8_t)(200 +packetNumber), _pin, _pinMode,SW_LE16(param0),param1,param2,param3} ;
139 return (_sw.sendPacket(tx));
140 }
141 int16_t initPacketNoResponse(uint8_t packetNumber,uint16_t param0,uint16_t param1, uint8_t param2 = 0x55)
142 {
143 uint8_t tx[] = { (uint8_t)(200 +packetNumber), _pin, _pinMode, SW_LE16(param0),SW_LE16(param1),param2 };
144 return (_sw.sendPacket(tx));
145 }
146
149 int16_t disable ()
150 {
151 uint8_t tx[] =
152 {
154 _pin,
155 _pinMode,
156 0x55,0x55,0x55,0x55,0x55
157 };
158 return _sw.sendPacket(tx);
159 }
160
166 int16_t enablePullup(bool enabled)
167 {
168 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,(uint8_t)(enabled?1:0),0x55,0x55,0x55,0x55,0x55};
169 return (_sw.sendPacket(tx));
170 }
171
176 int16_t enablePulldown(bool enabled)
177 {
178 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,0x55,(uint8_t)(enabled?1:0),0x55,0x55,0x55,0x55};
179 return (_sw.sendPacket(tx));
180 }
181
186 int16_t enableOpenDrain(bool enabled)
187 {
188 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,0x55,0x55,(uint8_t)(enabled?1:0),0x55,0x55,0x55};
189 return (_sw.sendPacket(tx));
190 }
191
197 int16_t forceDMA(bool enabled)
198 {
199 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,0x55,0x55,(uint8_t)(enabled?1:0),0x55,0x55,0x55};
200 return (_sw.sendPacket(tx));
201 }
202
208 {
209 _pin = pin;
210 }
211
212protected:
213 uint8_t _pin = 255;
215 uint8_t _pinMode = 0;
216
217};
218
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
@ CONFIGURE_PIN_MODE_DISABLE
(219)
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
int16_t enablePullup(bool enabled)
Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
int16_t initPacketNoResponse(uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
uint16_t writePublicData(uint16_t value)
Write a 16 bit value to this pin.
int16_t enableOpenDrain(bool enabled)
Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
int16_t enablePulldown(bool enabled)
Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
uint8_t swPinModeNumber()
Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t forceDMA(bool enabled)
Forces use of DMA instead of hardware timing resources on SW18AB.
uint16_t readPublicData()
Read the 16 Bit public data associated with this pin.
void digitalWrite(uint8_t val)
Set output pin High or Low.
SerialWombatChip & _sw
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
void pinMode(uint8_t mode, bool pullDown=false, bool openDrain=false)
Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
int digitalRead()
Reads the state of the Pin.
int16_t disable()
Disables the pin mode (if applicable)
void setPinNumberForTesting(uint8_t pin)
A function designed for testing only. May have unpredictable results if used in real time....
SerialWombatPin(SerialWombatChip &serialWombatChip, uint8_t pin)
Instantiates a Serial Wombat Pin.
int16_t initPacketNoResponse(uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t initPacketNoResponse(uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.