| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_I2CBus.h
Go to the documentation of this file.
1 /*!
2 LT_I2CBus: Routines to communicate to I2C by Wire Library.
3
4
5 Copyright 2018(c) Analog Devices, Inc.
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 - Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 - Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17 - Neither the name of Analog Devices, Inc. nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20 - The use of this software may or may not infringe the patent rights
21 of one or more patent holders. This license does not release you
22 from the requirement that you obtain separate licenses from these
23 patent holders to use this software.
24 - Use of the software either in source or binary form, must be run
25 on or directly connected to an Analog Devices Inc. component.
26
27 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
28 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
29 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
31 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
33 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*! @file
40 @ingroup LT_I2CBus
41 Library Header File for LT_I2CBus
42 */
43
44 #ifndef LT_I2CBus_H
45 #define LT_I2CBus_H
46
47 #include <stdint.h>
48 #include <LT_Wire.h>
49
50 class LT_I2CBus
51 {
52 private:
53 bool inGroupProtocol_;
54 uint32_t speed_;
55
56 public:
57 LT_I2CBus();
58 LT_I2CBus(uint32_t speed);
59
60 //! Change the speed of the bus.
61 void changeSpeed(uint32_t speed //!< the speed
62 );
63
64 //! Get the speed of the bus.
65 uint32_t getSpeed();
66
67 //! Read a byte, store in "value".
68 //! @return 0 on success, 1 on failure
69 int8_t readByte(uint8_t address, //!< 7-bit I2C address
70 uint8_t *value //!< Byte to be read
71 );
72
73 //! Write "value" byte to device at "address"
74 //! @return 0 on success, 1 on failure
75 int8_t writeByte(uint8_t address, //!< 7-bit I2C address
76 uint8_t value //!< Byte to be written
77 );
78
79 //! Read a byte of data at register specified by "command", store in "value"
80 //! @return 0 on success, 1 on failure
81 int8_t readByteData(uint8_t address, //!< 7-bit I2C address
82 uint8_t command, //!< Command byte
83 uint8_t *value //!< Byte to be read
84 );
85
86 //! Write a byte of data to register specified by "command"
87 //! @return 0 on success, 1 on failure
88 int8_t writeByteData(uint8_t address, //!< 7-bit I2C address
89 uint8_t command, //!< Command byte
90 uint8_t value //!< Byte to be written
91 );
92
93 //! Read a 16-bit word of data from register specified by "command"
94 //! @return 0 on success, 1 on failure
95 int8_t readWordData(uint8_t address, //!< 7-bit I2C address
96 uint8_t command, //!< Command byte
97 uint16_t *value //!< Word to be read
98 );
99
100 //! Write a 16-bit word of data to register specified by "command"
101 //! @return 0 on success, 1 on failure
102 int8_t writeWordData(uint8_t address, //!< 7-bit I2C address
103 uint8_t command, //!< Command byte
104 uint16_t value //!< Word to be written
105 );
106
107 //! Read a block of data, starting at register specified by "command" and ending at (command + length - 1)
108 //! @return 0 on success, 1 on failure
109 int8_t readBlockData(uint8_t address, //!< 7-bit I2C address
110 uint8_t command, //!< Command byte
111 uint16_t length, //!< Length of array
112 uint8_t *values //!< Byte array to be read
113 );
114
115 //! Read a block of data, starting at register specified by "command" and ending at (command + length - 1)
116 //! @return 0 on success, 1 on failure
117 int8_t readBlockDataPec(uint8_t address, //!< 7-bit I2C address
118 uint8_t command, //!< Command byte
119 uint16_t length, //!< Length of array
120 uint8_t *values //!< Byte array to be read
121 );
122
123 //! Read a block of data, no command byte, reads length number of bytes and stores it in values.
124 //! @return 0 on success, 1 on failure
125 int8_t readBlockData(uint8_t address, //!< 7-bit I2C address
126 uint16_t length, //!< Length of array
127 uint8_t *values //!< Byte array to be read
128 );
129
130 //! Read a block of data, no command byte, reads length number of bytes and stores it in values.
131 //! @return 0 on success, 1 on failure
132 int8_t readBlockDataPec(uint8_t address, //!< 7-bit I2C address
133 uint16_t length, //!< Length of array
134 uint8_t *values //!< Byte array to be read
135 );
136
137
138
139 //! Write a block of data, starting at register specified by "command" and ending at (command + length - 1)
140 //! @return 0 on success, 1 on failure
141 int8_t writeBlockData(uint8_t address, //!< 7-bit I2C address
142 uint8_t command, //!< Command byte
143 uint16_t length, //!< Length of array
144 uint8_t *values //!< Byte array to be written
145 );
146
147 //! Write a two command bytes, then receive a block of data
148 //! @return 0 on success, 1 on failure
149 int8_t twoByteCommandReadBlock(uint8_t address, //!< 7-bit I2C address
150 uint16_t command, //!< Command word
151 uint16_t length, //!< Length of array
152 uint8_t *values //!< Byte array to be read
153 );
154
155 //! Initializes Linduino I2C port.
156 //! Before communicating to the I2C port through the QuikEval connector, you must also run
157 //! quikeval_I2C_connect to connect the I2C port to the QuikEval connector through the
158 //! QuikEval MUX (and disconnect SPI).
159 void quikevalI2CInit(void);
160
161 //! Switch MUX to connect I2C pins to QuikEval connector.
162 //! This will disconnect SPI pins.
163 void quikevalI2CConnect(void);
164
165 //! starts group protocol so I2CBus knows to repeat START instead of STOP.
166 void startGroupProtocol(void);
167
168 //! ends group protocol so I2CBus knows to send STOPs again.
169 void endGroupProtocol(void);
170 };
171
172 #endif // LT_I2CBus_H
LT_I2CBus::endGroupProtocol
void endGroupProtocol(void)
ends group protocol so I2CBus knows to send STOPs again.
Definition: LT_I2CBus.cpp:244
LT_I2CBus::quikevalI2CInit
void quikevalI2CInit(void)
Initializes Linduino I2C port.
Definition: LT_I2CBus.cpp:225
LT_I2CBus::writeWordData
int8_t writeWordData(uint8_t address, uint8_t command, uint16_t value)
Write a 16-bit word of data to register specified by "command".
Definition: LT_I2CBus.cpp:148
LT_I2CBus::readByteData
int8_t readByteData(uint8_t address, uint8_t command, uint8_t *value)
Read a byte of data at register specified by "command", store in "value".
Definition: LT_I2CBus.cpp:106
LT_I2CBus::readBlockData
int8_t readBlockData(uint8_t address, uint8_t command, uint16_t length, uint8_t *values)
Read a block of data, starting at register specified by "command" and ending at (command + length - 1...
Definition: LT_I2CBus.cpp:161
LT_I2CBus::writeBlockData
int8_t writeBlockData(uint8_t address, uint8_t command, uint16_t length, uint8_t *values)
Write a block of data, starting at register specified by "command" and ending at (command + length - ...
Definition: LT_I2CBus.cpp:187
LT_I2CBus::startGroupProtocol
void startGroupProtocol(void)
starts group protocol so I2CBus knows to repeat START instead of STOP.
Definition: LT_I2CBus.cpp:240
address
static uint8_t address
Definition: DC2091A.ino:83
LT_Wire.h
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
LT_I2CBus::twoByteCommandReadBlock
int8_t twoByteCommandReadBlock(uint8_t address, uint16_t command, uint16_t length, uint8_t *values)
Write a two command bytes, then receive a block of data.
Definition: LT_I2CBus.cpp:206
LT_I2CBus::readWordData
int8_t readWordData(uint8_t address, uint8_t command, uint16_t *value)
Read a 16-bit word of data from register specified by "command".
Definition: LT_I2CBus.cpp:131
LT_I2CBus::changeSpeed
void changeSpeed(uint32_t speed)
Change the speed of the bus.
Definition: LT_I2CBus.cpp:73
LT_I2CBus
Definition: LT_I2CBus.h:50
LT_I2CBus::quikevalI2CConnect
void quikevalI2CConnect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2CBus.cpp:232
LT_I2CBus::readBlockDataPec
int8_t readBlockDataPec(uint8_t address, uint8_t command, uint16_t length, uint8_t *values)
Read a block of data, starting at register specified by "command" and ending at (command + length - 1...
LT_I2CBus::LT_I2CBus
LT_I2CBus()
Definition: LT_I2CBus.cpp:59
LT_I2CBus::writeByte
int8_t writeByte(uint8_t address, uint8_t value)
Write "value" byte to device at "address".
Definition: LT_I2CBus.cpp:95
LT_I2CBus::getSpeed
uint32_t getSpeed()
Get the speed of the bus.
Definition: LT_I2CBus.cpp:78
LT_I2CBus::writeByteData
int8_t writeByteData(uint8_t address, uint8_t command, uint8_t value)
Write a byte of data to register specified by "command".
Definition: LT_I2CBus.cpp:119
LT_I2CBus::readByte
int8_t readByte(uint8_t address, uint8_t *value)
Read a byte, store in "value".
Definition: LT_I2CBus.cpp:84
values
static uint8_t values[4]
Definition: DC2218A.ino:117