![]() |
Bioscara
DALSA's DIY SCARA Robot Arm.
|
Low level utility for I2C communication on Raspberry Pi using lgpio library. More...
#include <cstring>#include <errno.h>#include <fcntl.h>#include <iostream>#include <termios.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | ACK 'O' |
| #define | NACK 'N' |
| #define | RFLAGS_SIZE 1 |
| Size of the return flags in bytes. | |
| #define | MAX_BUFFER 4 |
| Maximum size of I2C Payload in bytes. | |
Functions | |
| int | openI2CDevHandle (const int dev_addr) |
| Initiates an I2C device on the bus. | |
| int | readFromI2CDev (const int dev_handle, const int reg, char *buffer, const int data_length) |
| reads block of bytes from device to buffer | |
| int | writeToI2CDev (const int dev_handle, const int reg, char *tx_buffer, const int data_length, char *RFLAGS_buffer) |
| writes block of bytes from buffer to device | |
| int | closeI2CDevHandle (int &dev_handle) |
| close an I2C device on the bus | |
Low level utility for I2C communication on Raspberry Pi using lgpio library.
lgpio needs to be installed and linked! Installation:
bash
| #define ACK 'O' |
| #define MAX_BUFFER 4 |
Maximum size of I2C Payload in bytes.
4 bytes used to transmit floats and int32_t
| #define NACK 'N' |
| #define RFLAGS_SIZE 1 |
Size of the return flags in bytes.
Only one byte used and hence set to 1.
| int closeI2CDevHandle | ( | int & | dev_handle | ) |
close an I2C device on the bus
| dev_handle | device handle obtained from openI2CDevHandle |
| int openI2CDevHandle | ( | const int | dev_addr | ) |
Initiates an I2C device on the bus.
| dev_addr | 7-bit device adress [0 - 0x7F] |
| int readFromI2CDev | ( | const int | dev_handle, |
| const int | reg, | ||
| char * | buffer, | ||
| const int | data_length | ||
| ) |
reads block of bytes from device to buffer
| dev_handle | device handle obtained from openI2CDevHandle |
| reg | the command/data register |
| buffer | pointer to data buffer to hold received values |
| data_length | number of bytes to read |
| int writeToI2CDev | ( | const int | dev_handle, |
| const int | reg, | ||
| char * | tx_buffer, | ||
| const int | data_length, | ||
| char * | RFLAGS_buffer | ||
| ) |
writes block of bytes from buffer to device
| dev_handle | device handle obtained from openI2CDevHandle |
| reg | the command/data register |
| tx_buffer | pointer to data buffer holding the data to send |
| data_length | number of bytes to send |
| RFLAGS_buffer | buffer to hold returned flags |