Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatPin.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2023-2024 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
92 void digitalWrite(uint8_t val)
93 {
94 _sw.digitalWrite(_pin, val);
95 }
96
104 int digitalRead()
105 {
106 return (_sw.digitalRead(_pin));
107 }
108
109
114 uint16_t writePublicData(uint16_t value)
115 { return _sw.writePublicData(_pin, value); }
116
121 uint8_t pin() {return _pin;}
122
127 uint8_t swPinModeNumber() { return _pinMode; }
128
129
130
131 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)
132 {
133 uint8_t tx[] = { (uint8_t)(200 +packetNumber), _pin, _pinMode,param0,param1,param2,param3,param4} ;
134 return (_sw.sendPacket(tx));
135 }
136
137 int16_t initPacketNoResponse(uint8_t packetNumber,uint16_t param0 = 0x55, uint8_t param1 = 0x55, uint8_t param2 = 0x55, uint8_t param3 = 0x55 )
138 {
139 uint8_t tx[] = { (uint8_t)(200 +packetNumber), _pin, _pinMode,SW_LE16(param0),param1,param2,param3} ;
140 return (_sw.sendPacket(tx));
141 }
142 int16_t initPacketNoResponse(uint8_t packetNumber,uint16_t param0,uint16_t param1, uint8_t param2 = 0x55)
143 {
144 uint8_t tx[] = { (uint8_t)(200 +packetNumber), _pin, _pinMode, SW_LE16(param0),SW_LE16(param1),param2 };
145 return (_sw.sendPacket(tx));
146 }
147
150 int16_t disable ()
151 {
152 uint8_t tx[] =
153 {
154 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE,
155 _pin,
156 _pinMode,
157 0x55,0x55,0x55,0x55,0x55
158 };
159 return _sw.sendPacket(tx);
160 }
161
167 int16_t enablePullup(bool enabled)
168 {
169 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,(uint8_t)(enabled?1:0),0x55,0x55,0x55,0x55,0x55};
170 return (_sw.sendPacket(tx));
171 }
172
177 int16_t enablePullDown(bool enabled)
178 {
179 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,0x55,(uint8_t)(enabled?1:0),0x55,0x55,0x55,0x55};
180 return (_sw.sendPacket(tx));
181 }
182
187 int16_t enableOpenDrain(bool enabled)
188 {
189 uint8_t tx[] = {(uint8_t)SerialWombatCommands::COMMAND_SET_PIN_HW,_pin,0x55,0x55,(uint8_t)(enabled?1:0),0x55,0x55,0x55};
190 return (_sw.sendPacket(tx));
191 }
192 protected:
193 uint8_t _pin = 255;
194 SerialWombatChip& _sw;
195 uint8_t _pinMode = 0;
196
197};
198
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition SerialWombat.h:41
SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE
@ CONFIGURE_PIN_MODE_DISABLE
(219)
Definition SerialWombat.h:240
SerialWombatCommands::COMMAND_SET_PIN_HW
@ COMMAND_SET_PIN_HW
(0xB8)
Definition SerialWombat.h:226
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:297
SerialWombatPin::enablePullup
int16_t enablePullup(bool enabled)
Enables the weak pull up on a pin. Implemented on SW18AB only.
Definition SerialWombatPin.h:167
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:137
SerialWombatPin::writePublicData
uint16_t writePublicData(uint16_t value)
Write a 16 bit value to this pin.
Definition SerialWombatPin.h:114
SerialWombatPin::enableOpenDrain
int16_t enableOpenDrain(bool enabled)
Enables open drain mode on a pin. Implemented on SW18AB only.
Definition SerialWombatPin.h:187
SerialWombatPin::swPinModeNumber
uint8_t swPinModeNumber()
Returns the Mode number. Used primarily by derived classes to populate packet data.
Definition SerialWombatPin.h:127
SerialWombatPin::enablePullDown
int16_t enablePullDown(bool enabled)
Enables the weak pull down on a pin. Implemented on SW18AB only.
Definition SerialWombatPin.h:177
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:92
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:194
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:104
SerialWombatPin::disable
int16_t disable()
Disables the pin mode (if applicable)
Definition SerialWombatPin.h:150
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:131
SerialWombatPin::initPacketNoResponse
int16_t initPacketNoResponse(uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
Definition SerialWombatPin.h:142
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:193
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition SerialWombatPin.h:121
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition SerialWombatPin.h:195