MCPcopy Create free account
hub / github.com/SlimeVR/SlimeVR-Tracker-ESP / readBitsW

Method readBitsW

lib/i2cdev/I2Cdev.cpp:162–177  ·  view source on GitHub ↗

Read multiple bits from a 16-bit device register. * @param devAddr I2C slave device address * @param regAddr Register regAddr to read from * @param bitStart First bit position to read (0-15) * @param length Number of bits to read (not more than 16) * @param data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05) * @param timeout Optional read timeo

Source from the content-addressed store, hash-verified

160 * @return Status of read operation (1 = success, 0 = failure, -1 = timeout)
161 */
162int8_t I2Cdev::readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout, void *wireObj) {
163 // 1101011001101001 read byte
164 // fedcba9876543210 bit numbers
165 // xxx args: bitStart=12, length=3
166 // 010 masked
167 // -> 010 shifted
168 uint8_t count;
169 uint16_t w;
170 if ((count = readWord(devAddr, regAddr, &w, timeout, wireObj)) != 0) {
171 uint16_t mask = ((1 << length) - 1) << (bitStart - length + 1);
172 w &= mask;
173 w >>= (bitStart - length + 1);
174 *data = w;
175 }
176 return count;
177}
178
179/** Read single byte from an 8-bit device register.
180 * @param devAddr I2C slave device address

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected