Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatPin.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2023-2025 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7
8 Permission 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
15 The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17
18 THE 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
38 class SerialWombatPin
39{
40 public:
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
103 int digitalRead()
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 {
153 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE,
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
207 void setPinNumberForTesting(uint8_t pin)
208 {
209 _pin = pin;
210 }
211
212 protected:
213 uint8_t _pin = 255;
214 SerialWombatChip& _sw;
215 uint8_t _pinMode = 0;
216
217};
218
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition SerialWombat.h:46
SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE
@ CONFIGURE_PIN_MODE_DISABLE
(219)
Definition SerialWombat.h:249
SerialWombatCommands::COMMAND_SET_PIN_HW
@ COMMAND_SET_PIN_HW
(0xB8)
Definition SerialWombat.h:235
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:315
SerialWombatPin::enablePullup
int16_t enablePullup(bool enabled)
Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
Definition SerialWombatPin.h:166
SerialWombatPin::initPacketNoResponse
int16_t initPacketNoResponse(uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
Definition SerialWombatPin.h:136
SerialWombatPin::writePublicData
uint16_t writePublicData(uint16_t value)
Write a 16 bit value to this pin.
Definition SerialWombatPin.h:113
SerialWombatPin::enableOpenDrain
int16_t enableOpenDrain(bool enabled)
Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
Definition SerialWombatPin.h:186
SerialWombatPin::enablePulldown
int16_t enablePulldown(bool enabled)
Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
Definition SerialWombatPin.h:176
SerialWombatPin::swPinModeNumber
uint8_t swPinModeNumber()
Returns the Mode number. Used primarily by derived classes to populate packet data.
Definition SerialWombatPin.h:126
SerialWombatPin::forceDMA
int16_t forceDMA(bool enabled)
Forces use of DMA instead of hardware timing resources on SW18AB.
Definition SerialWombatPin.h:197
SerialWombatPin::readPublicData
uint16_t readPublicData()
Read the 16 Bit public data associated with this pin.
Definition SerialWombatPin.h:65
SerialWombatPin::digitalWrite
void digitalWrite(uint8_t val)
Set output pin High or Low.
Definition SerialWombatPin.h:91
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:214
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
SerialWombatPin::pinMode
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.
Definition SerialWombatPin.h:79
SerialWombatPin::digitalRead
int digitalRead()
Reads the state of the Pin.
Definition SerialWombatPin.h:103
SerialWombatPin::disable
int16_t disable()
Disables the pin mode (if applicable)
Definition SerialWombatPin.h:149
SerialWombatPin::setPinNumberForTesting
void setPinNumberForTesting(uint8_t pin)
A function designed for testing only. May have unpredictable results if used in real time....
Definition SerialWombatPin.h:207
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip, uint8_t pin)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:54
SerialWombatPin::initPacketNoResponse
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)
Definition SerialWombatPin.h:130
SerialWombatPin::initPacketNoResponse
int16_t initPacketNoResponse(uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
Definition SerialWombatPin.h:141
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:213
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition SerialWombatPin.h:120
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition SerialWombatPin.h:215