doxy i2c
This commit is contained in:
parent
f1d3b87620
commit
63b9ebf208
|
|
@ -9,7 +9,6 @@ git:
|
||||||
quiet: true
|
quiet: true
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- ARDUINO_IDE_VERSION="1.8.7"
|
|
||||||
- PRETTYNAME="Adafruit BusIO Library"
|
- PRETTYNAME="Adafruit BusIO Library"
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,22 @@
|
||||||
|
|
||||||
//#define DEBUG_SERIAL Serial
|
//#define DEBUG_SERIAL Serial
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Create an I2C device at a given address
|
||||||
|
* @param addr The 7-bit I2C address for the device
|
||||||
|
* @param theWire The I2C bus to use, defaults to &Wire
|
||||||
|
*/
|
||||||
Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) {
|
Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) {
|
||||||
_addr = addr;
|
_addr = addr;
|
||||||
_wire = theWire;
|
_wire = theWire;
|
||||||
_begun = false;
|
_begun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Initializes and does basic address detection
|
||||||
|
* @return True if I2C initialized and a device with the addr found
|
||||||
|
*/
|
||||||
|
|
||||||
bool Adafruit_I2CDevice::begin(void) {
|
bool Adafruit_I2CDevice::begin(void) {
|
||||||
_wire->begin();
|
_wire->begin();
|
||||||
_begun = true;
|
_begun = true;
|
||||||
|
|
@ -16,6 +26,12 @@ bool Adafruit_I2CDevice::begin(void) {
|
||||||
return detected();
|
return detected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Scans I2C for the address - note will give a false-positive
|
||||||
|
* if there's no pullups on I2C
|
||||||
|
* @return True if I2C initialized and a device with the addr found
|
||||||
|
*/
|
||||||
bool Adafruit_I2CDevice::detected(void) {
|
bool Adafruit_I2CDevice::detected(void) {
|
||||||
// Init I2C if not done yet
|
// Init I2C if not done yet
|
||||||
if (!_begun && !begin()) {
|
if (!_begun && !begin()) {
|
||||||
|
|
@ -30,6 +46,15 @@ bool Adafruit_I2CDevice::detected(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Write a buffer or two to the I2C device. Cannot be more than 32 bytes.
|
||||||
|
* @param buffer Pointer to buffer of data to write
|
||||||
|
* @param len Number of bytes from buffer to write
|
||||||
|
* @param prefix Pointer to optional array of data to write before buffer. Cannot be more than 32 bytes.
|
||||||
|
* @param prefix_len Number of bytes from prefix buffer to write
|
||||||
|
* @param stop Whether to send an I2C STOP signal on write
|
||||||
|
* @return True if write was successful, otherwise false.
|
||||||
|
*/
|
||||||
bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t *prefix_buffer, size_t prefix_len) {
|
bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t *prefix_buffer, size_t prefix_len) {
|
||||||
if ((len+prefix_len) > 32) {
|
if ((len+prefix_len) > 32) {
|
||||||
// currently not guaranteed to work if more than 32 bytes!
|
// currently not guaranteed to work if more than 32 bytes!
|
||||||
|
|
@ -85,6 +110,14 @@ bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t *
|
||||||
return (_wire -> endTransmission(stop) == 0);
|
return (_wire -> endTransmission(stop) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Read from I2C into a buffer from the I2C device. Cannot be more than 32 bytes.
|
||||||
|
* @param buffer Pointer to buffer of data to read into
|
||||||
|
* @param len Number of bytes from buffer to read.
|
||||||
|
* @param stop Whether to send an I2C STOP signal on read
|
||||||
|
* @return True if read was successful, otherwise false.
|
||||||
|
*/
|
||||||
bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
|
bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
|
||||||
if (len > 32) {
|
if (len > 32) {
|
||||||
// currently not guaranteed to work if more than 32 bytes!
|
// currently not guaranteed to work if more than 32 bytes!
|
||||||
|
|
@ -125,6 +158,15 @@ bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Write some data, then read some data from I2C into another buffer. Cannot be more than 32 bytes. The buffers can point to same/overlapping locations.
|
||||||
|
* @param write_buffer Pointer to buffer of data to write from
|
||||||
|
* @param write_len Number of bytes from buffer to write.
|
||||||
|
* @param read_buffer Pointer to buffer of data to read into.
|
||||||
|
* @param read_len Number of bytes from buffer to read.
|
||||||
|
* @param stop Whether to send an I2C STOP signal between the write and read
|
||||||
|
* @return True if write & read was successful, otherwise false.
|
||||||
|
*/
|
||||||
bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop) {
|
bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop) {
|
||||||
if (! write(write_buffer, write_len, stop)) {
|
if (! write(write_buffer, write_len, stop)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -134,7 +176,10 @@ bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer, size_t write_len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the 7-bit address of this device
|
||||||
|
* @return The 7-bit address of this device
|
||||||
|
*/
|
||||||
uint8_t Adafruit_I2CDevice::address(void) {
|
uint8_t Adafruit_I2CDevice::address(void) {
|
||||||
return _addr;
|
return _addr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue