Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatThroughputConsumer.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2021-2023 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#include <stdint.h>
28#include "SerialWombat.h"
29
44 class SerialWombatThroughputConsumer: public SerialWombatPin
45{
46 public:
51 SerialWombatThroughputConsumer(SerialWombatChip& serialWombat):SerialWombatPin(serialWombat){}
52
53 /*
54 @brief Initialize an instance of the Throughput Conumer class. All delays are set to 0.
55 @return Returns a negative error code if initialization failed.
56 */
57 int16_t begin(uint8_t pin)
58 {
59 _pin = pin;
60 uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,
61 (uint8_t)PIN_MODE_THROUGHPUT_CONSUMER,
62 0x55,0x55,0x55,0x55,0x55 };
63 return _sw.sendPacket(tx);
64 }
65
66
72 */
73 int16_t writeAll(uint16_t delay)
74 {
75 for (int i = 0; i < 16; ++i)
76 {
77 uint8_t tx[] = {(uint8_t) SerialWombatCommands::CONFIGURE_PIN_MODE1,
78 _pin,
79 (uint8_t) PIN_MODE_THROUGHPUT_CONSUMER ,
80 (uint8_t)i,
81 SW_LE16(delay), 0x55,0x55 };
82 int16_t result = _sw.sendPacket(tx);
83 if (result < 0)
84 {
85 return (result);
86 }
87 }
88 return 0;
89 }
90
99 int16_t write(uint8_t frame, uint16_t delay)
100 {
101 uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE1,
102 _pin,
103 (uint8_t)PIN_MODE_THROUGHPUT_CONSUMER ,
104 frame,
105 SW_LE16(delay), 0x55,0x55 };
106 return( _sw.sendPacket(tx));
107 }
108
109
117 int16_t delayInCommProcessing(uint16_t delay)
118 {
119 uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE2,
120 _pin,
121 (uint8_t)PIN_MODE_THROUGHPUT_CONSUMER ,
122 SW_LE16(delay), 0x55,0x55, 0x55 };
123 return(_sw.sendPacket(tx));
124 }
125
126};
127
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:41
SerialWombatCommands::CONFIGURE_PIN_MODE0
@ CONFIGURE_PIN_MODE0
(200)
Definition SerialWombat.h:228
SerialWombatCommands::CONFIGURE_PIN_MODE2
@ CONFIGURE_PIN_MODE2
(202)
Definition SerialWombat.h:230
SerialWombatCommands::CONFIGURE_PIN_MODE1
@ CONFIGURE_PIN_MODE1
(201)
Definition SerialWombat.h:229
PIN_MODE_THROUGHPUT_CONSUMER
@ PIN_MODE_THROUGHPUT_CONSUMER
(4)
Definition SerialWombat.h:255
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:297
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:194
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
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
SerialWombatThroughputConsumer::begin
int16_t begin(uint8_t pin)
Definition SerialWombatThroughputConsumer.h:57
SerialWombatThroughputConsumer::SerialWombatThroughputConsumer
SerialWombatThroughputConsumer(SerialWombatChip &serialWombat)
Constructor for SerialWombatThroughputConsumer class.
Definition SerialWombatThroughputConsumer.h:51
SerialWombatThroughputConsumer::delayInCommProcessing
int16_t delayInCommProcessing(uint16_t delay)
Delay a specified number of uS within the packet processing routine.
Definition SerialWombatThroughputConsumer.h:117
SerialWombatThroughputConsumer::writeAll
int16_t writeAll(uint16_t delay)
Set all delay times to a specified number of uS / /.
Definition SerialWombatThroughputConsumer.h:73
SerialWombatThroughputConsumer::write
int16_t write(uint8_t frame, uint16_t delay)
Set a frame delay time to a specified number of uS.
Definition SerialWombatThroughputConsumer.h:99