Raspberry Pio Pico Drivers project
|
I2C Master controller class. More...
#include <i2cmaster.hpp>
Public Member Functions | |
I2cMaster (SdkWrapper &sdk, i2c_inst_t &i2c, uint clock_freq, uint scl_pin, uint sda_pin) | |
Initialize the given I2C port and setup the pins. | |
virtual | ~I2cMaster () |
deinit the I2C by SdkWrapper::i2c_deinit(); | |
virtual int | ReadBlocking (uint8_t addr, uint8_t *dst, size_t len, bool nostop) |
Attempt to read specified number of bytes from address, blocking. | |
virtual int | WriteBlocking (uint8_t addr, const uint8_t *src, size_t len, bool nostop) |
Attempt to write specified number of bytes to address, blocking. | |
virtual bool | IsDeviceExisting (uint8_t addr) |
Check wether device at specified I2C address exists or not. | |
I2C Master controller class.
This class provides a set of easy to use member function to control the I2C master controller. Everything operation in this class is polling based and blocking.
The constructor and destructor initializes and finalize the given I2C controller, respectively.
The ReadBlocking() and WriteBlocking() functions has nostop parameter. To use the restart condition, set this parameter to true.
In the case of the testing of the user program which uses this class, a programmer can use the pre-defined mock class rpp_driver::MockI2cMaster. inside i2cmaster.hpp.
rpp_driver::I2cMaster::I2cMaster | ( | SdkWrapper & | sdk, |
i2c_inst_t & | i2c, | ||
uint | clock_freq, | ||
uint | scl_pin, | ||
uint | sda_pin | ||
) |
Initialize the given I2C port and setup the pins.
sdk | Object of the SdkWrapper class. |
i2c | i2c_inst_t type &. *I2C0 or *I2C1 |
clock_freq | Usually 100,000 or 400,000[Hz]. |
scl_pin | GPIO pin # |
sda_pin | GPIO pin # |
Receive the uninitialized I2C hardware by parameter i2c, and initialize it by SdkWrapper::i2c_init(). And then, set given pins to I2C function, and pull them up.
|
virtual |
Check wether device at specified I2C address exists or not.
addr | 7-bit address of device to read from |
|
virtual |
Attempt to read specified number of bytes from address, blocking.
addr | 7-bit address of device to read from |
dst | Pointer to buffer to receive data |
len | Length of data in bytes to receive |
nostop | If true, master retains control of the bus at the end of the transfer (no Stop is issued), and the next transfer will begin with a Restart rather than a Start. |
|
virtual |
Attempt to write specified number of bytes to address, blocking.
addr | 7-bit address of device to write to |
src | Pointer to data to send |
len | Length of data in bytes to send |
nostop | If true, master retains control of the bus at the end of the transfer (no Stop is issued), and the next transfer will begin with a Restart rather than a Start. |