| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_SMBusGroup.h
Go to the documentation of this file.
1 /*!
2 LTC SMBus Support: Implementation for a shared SMBus layer
3
4 @verbatim
5
6 This API is shared with Linduino and RTOS code. End users should code to this
7 API to enable use of the PMBus code without modifications.
8
9 @endverbatim
10
11
12 Copyright 2018(c) Analog Devices, Inc.
13
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18 - Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 - Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in
22 the documentation and/or other materials provided with the
23 distribution.
24 - Neither the name of Analog Devices, Inc. nor the names of its
25 contributors may be used to endorse or promote products derived
26 from this software without specific prior written permission.
27 - The use of this software may or may not infringe the patent rights
28 of one or more patent holders. This license does not release you
29 from the requirement that you obtain separate licenses from these
30 patent holders to use this software.
31 - Use of the software either in source or binary form, must be run
32 on or directly connected to an Analog Devices Inc. component.
33
34 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
35 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
36 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
37 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
38 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
40 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45
46 /*! @file
47 @ingroup LT_SMBusGroup
48 Library Header File for LT_SMBusGroup
49 */
50
51 #ifndef LT_SMBusGroup_H_
52 #define LT_SMBusGroup_H_
53
54 #include <stdint.h>
55 #include <stdio.h>
56 #include <string.h>
57 #include "LT_I2CBus.h"
58 #include "LT_SMBusBase.h"
59
60 class LT_SMBusGroup : public LT_SMBusBase
61 {
62 private:
63 class Executable
64 {
65 protected:
66 LT_SMBus *executor;
67
68 Executable(LT_SMBus *e);
69
70 public:
71 virtual ~Executable() {}
72 virtual void execute() = 0;
73 };
74
75 class WriteByte : public Executable
76 {
77 uint8_t address;
78 uint8_t command;
79 uint8_t data;
80
81 public:
82 WriteByte(LT_SMBus *e, uint8_t a, uint8_t c, uint8_t d);
83 void execute();
84 };
85
86 class WriteBytes : public Executable
87 {
88 uint8_t *addresses;
89 uint8_t *commands;
90 uint8_t *data;
91 uint8_t no_addresses;
92
93 public:
94 WriteBytes(LT_SMBus *e, uint8_t *a, uint8_t *c, uint8_t *d, uint8_t n);
95 void execute();
96 };
97
98 class WriteWord : public Executable
99 {
100 uint8_t address;
101 uint8_t command;
102 uint16_t data;
103
104 public:
105 WriteWord(LT_SMBus *e, uint8_t a, uint8_t c, uint16_t d);
106 void execute();
107 };
108
109 class WriteBlock : public Executable
110 {
111 uint8_t address;
112 uint8_t command;
113 uint8_t *block;
114 uint16_t block_size;
115
116 public:
117 WriteBlock(LT_SMBus *e, uint8_t a, uint8_t c, uint8_t *b, uint16_t bl);
118 void execute();
119 };
120
121 class SendByte : public Executable
122 {
123 uint8_t address;
124 uint8_t command;
125
126 public:
127 SendByte(LT_SMBus *e, uint8_t a, uint8_t c);
128 void execute();
129 };
130
131 class Node
132 {
133 public:
134 Executable *executable;
135 Node *next;
136 };
137
138
139 private:
140 LT_SMBus *executor;
141 bool queueing;
142 Node *head;
143 Node *tail;
144
145 bool addToQueue(Executable *);
146
147 public:
148
149 LT_SMBusGroup(LT_SMBus *);
150 LT_SMBusGroup(LT_SMBus *, uint32_t speed);
151 virtual ~LT_SMBusGroup() {}
152
153 //! SMBus write byte command
154 //! @return void
155 void writeByte(uint8_t address, //!< Slave address
156 uint8_t command, //!< Command byte
157 uint8_t data //!< Data to send
158 );
159
160 //! SMBus write byte command for a list of addresses
161 //! @return void
162 void writeBytes(uint8_t *addresses, //!< Slave Addresses
163 uint8_t *commands, //!< Command bytes
164 uint8_t *data, //!< Data to send
165 uint8_t no_addresses
166 );
167
168 //! SMBus read byte command
169 //! @return byte
170 uint8_t readByte(uint8_t address, //!< Slave Address
171 uint8_t command //!< Command byte
172 );
173
174 //! SMBus write word command
175 //! @return void
176 void writeWord(uint8_t address, //!< Slave Address
177 uint8_t command, //!< Command byte
178 uint16_t data //!< Data to send
179 );
180
181 //! SMBus read word command
182 //! @return word
183 uint16_t readWord(uint8_t address, //!< Slave Address
184 uint8_t command //!< Command byte
185 );
186
187 //! SMBus write block command
188 //! @return void
189 void writeBlock(uint8_t address, //!< Slave Address
190 uint8_t command, //!< Command byte
191 uint8_t *block, //!< Data to send
192 uint16_t block_size
193 );
194
195 //! SMBus write then read block command
196 //! @return actual size
197 uint8_t writeReadBlock(uint8_t address, //!< Slave Address
198 uint8_t command, //!< Command byte
199 uint8_t *block_out, //!< Data to send
200 uint16_t block_out_size, //!< Size of data to send
201 uint8_t *block_in, //!< Memory to receive data
202 uint16_t block_in_size //!< Size of receive data memory
203 );
204
205 //! SMBus read block command
206 //! @return actual size
207 uint8_t readBlock(uint8_t address, //!< Slave Address
208 uint8_t command, //!< Command byte
209 uint8_t *block, //!< Memory to receive data
210 uint16_t block_size //!< Size of receive data memory
211 );
212
213 //! SMBus send byte command
214 //! @return void
215 void sendByte(uint8_t address, //!< Slave Address
216 uint8_t command //!< Command byte
217 );
218
219 //! Group Protocol Begin
220 //! @return void
221 void beginStoring();
222
223 //! Group Protocol Execute queued commands
224 //! @return void
225 void execute();
226 };
227
228 #endif /* LT_SMBusGroup_H_ */
LT_SMBusGroup::readByte
uint8_t readByte(uint8_t address, uint8_t command)
SMBus read byte command.
Definition: LT_SMBusGroup.cpp:91
LT_SMBusGroup::~LT_SMBusGroup
virtual ~LT_SMBusGroup()
Definition: LT_SMBusGroup.h:151
LT_SMBusGroup::writeReadBlock
uint8_t writeReadBlock(uint8_t address, uint8_t command, uint8_t *block_out, uint16_t block_out_size, uint8_t *block_in, uint16_t block_in_size)
SMBus write then read block command.
Definition: LT_SMBusGroup.cpp:124
LT_SMBusGroup::beginStoring
void beginStoring()
Group Protocol Begin.
Definition: LT_SMBusGroup.cpp:151
LT_SMBusGroup::execute
void execute()
Group Protocol Execute queued commands.
Definition: LT_SMBusGroup.cpp:175
LT_SMBusGroup::writeByte
void writeByte(uint8_t address, uint8_t command, uint8_t data)
SMBus write byte command.
Definition: LT_SMBusGroup.cpp:75
LT_SMBusGroup::LT_SMBusGroup
LT_SMBusGroup(LT_SMBus *)
Definition: LT_SMBusGroup.cpp:59
address
static uint8_t address
Definition: DC2091A.ino:83
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LT_SMBusGroup::writeBlock
void writeBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)
SMBus write block command.
Definition: LT_SMBusGroup.cpp:115
LT_SMBus
Definition: LT_SMBus.h:61
LT_I2CBus.h
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LT_SMBusGroup::writeWord
void writeWord(uint8_t address, uint8_t command, uint16_t data)
SMBus write word command.
Definition: LT_SMBusGroup.cpp:99
LT_SMBusGroup::writeBytes
void writeBytes(uint8_t *addresses, uint8_t *commands, uint8_t *data, uint8_t no_addresses)
SMBus write byte command for a list of addresses.
Definition: LT_SMBusGroup.cpp:83
LT_SMBusGroup
Definition: LT_SMBusGroup.h:60
LT_SMBusBase
Definition: LT_SMBusBase.h:60
LT_SMBusGroup::readWord
uint16_t readWord(uint8_t address, uint8_t command)
SMBus read word command.
Definition: LT_SMBusGroup.cpp:107
LT_SMBusGroup::sendByte
void sendByte(uint8_t address, uint8_t command)
SMBus send byte command.
Definition: LT_SMBusGroup.cpp:142
LT_SMBusGroup::readBlock
uint8_t readBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)
SMBus read block command.
Definition: LT_SMBusGroup.cpp:133
LT_SMBusBase.h
LTC SMBus Support: Implementation for a shared SMBus layer.