Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatHBridge.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2024-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
27
28#include <stdint.h>
29#include "SerialWombat.h"
32
33 typedef enum
34{
35 HBRIDGE_OFF_BOTH_LOW = 0,
36 HBRIDGE_OFF_BOTH_HIGH = 1,
37 HBRIDGE_RELAY_AND_PWM = 2,
38}SerialWombatHBridgeDriverMode;
39
47
48 class SerialWombatHBridge : public SerialWombatPin
49{
50 public:
55 SerialWombatHBridge(SerialWombatChip& serialWombat) :SerialWombatPin(serialWombat) {}
56
64 int16_t begin(uint8_t pin, uint8_t secondPin, uint16_t PWMPeriod_uS = 1000,SerialWombatHBridgeDriverMode driverMode = HBRIDGE_OFF_BOTH_LOW)
65 {
66 _pin = pin;
67 _pinMode = (uint8_t)PIN_MODE_HBRIDGE;
68 int16_t result = initPacketNoResponse(0,secondPin,(uint8_t) driverMode);
69 if (result < 0) return result;
70 uint8_t tx2[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE_HW_0,_pin,PIN_MODE_HBRIDGE,SW_LE16(PWMPeriod_uS),0x55,0x55,0x55 };
71 _sw.sendPacket(tx2);
72 return initPacketNoResponse(20,PWMPeriod_uS);
73 }
74
75
76 private:
77};
78
79
81 class SerialWombatHBridge_18AB: public SerialWombatHBridge, public SerialWombatAbstractScaledOutput
82{
83 public:
84 SerialWombatHBridge_18AB(SerialWombatChip& serialWombat) :SerialWombatHBridge(serialWombat), SerialWombatAbstractScaledOutput(serialWombat)
85 {}
86
87
92 uint8_t pin()
93{
94 return SerialWombatPin::_pin;
95}
96
100 uint8_t swPinModeNumber()
101 {
102 return SerialWombatPin::_pinMode;
103 }
104};
105
SerialWombat.h
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_HW_0
@ CONFIGURE_PIN_MODE_HW_0
(220)
Definition SerialWombat.h:252
PIN_MODE_HBRIDGE
@ PIN_MODE_HBRIDGE
(6)
Definition SerialWombat.h:267
SerialWombatHBridgeDriverMode
SerialWombatHBridgeDriverMode
Definition SerialWombatHBridge.h:34
HBRIDGE_OFF_BOTH_LOW
@ HBRIDGE_OFF_BOTH_LOW
Definition SerialWombatHBridge.h:35
HBRIDGE_RELAY_AND_PWM
@ HBRIDGE_RELAY_AND_PWM
Definition SerialWombatHBridge.h:37
HBRIDGE_OFF_BOTH_HIGH
@ HBRIDGE_OFF_BOTH_HIGH
Definition SerialWombatHBridge.h:36
SerialWombatAbstractScaledOutput::SerialWombatAbstractScaledOutput
SerialWombatAbstractScaledOutput(SerialWombatChip &sw)
Constructor for the SerialWombatAbstractScaledOutput Class.
Definition SerialWombatAbstractScaledOutput.h:70
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:315
SerialWombatHBridge_18AB::pin
uint8_t pin()
fulfills a virtual function requirement of SerialWombatAbstractScaledOutput
Definition SerialWombatHBridge.h:92
SerialWombatHBridge_18AB::SerialWombatHBridge_18AB
SerialWombatHBridge_18AB(SerialWombatChip &serialWombat)
Definition SerialWombatHBridge.h:84
SerialWombatHBridge_18AB::swPinModeNumber
uint8_t swPinModeNumber()
fulfills a virtual function requirement of SerialWombatAbstractScaledOutput
Definition SerialWombatHBridge.h:100
SerialWombatHBridge::SerialWombatHBridge
SerialWombatHBridge(SerialWombatChip &serialWombat)
Constructor for SerialWombatHBridge class.
Definition SerialWombatHBridge.h:55
SerialWombatHBridge::begin
int16_t begin(uint8_t pin, uint8_t secondPin, uint16_t PWMPeriod_uS=1000, SerialWombatHBridgeDriverMode driverMode=HBRIDGE_OFF_BOTH_LOW)
Initialize a pin that has been declared as HBridge.
Definition SerialWombatHBridge.h:64
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:214
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
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::_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