I2C general purpose interface code for file system.
More...
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "include/linux/i2c-dev.h"
#include "bbbandroidHAL.h"
|
int | i2cOpenAdaptor (const uint8_t adaptorNumber) |
|
int | i2cSetSlave (const int i2cFD, const uint8_t address) |
|
int | i2cSetAddress (const int i2cFD, const uint8_t add) |
|
int | i2cWriteByte (const int i2cFD, const uint8_t add, const uint8_t byte) |
|
int | i2cWriteBytes (const int i2cFD, const uint8_t add, const int length, const uint8_t *bytes) |
|
int | i2cReadByte (const int i2cFD, const uint8_t add) |
|
int | i2cReadBytes (const int i2cFD, const uint8_t add, const int length, uint8_t *buff) |
|
void | i2cClose (const int i2cFD) |
|
I2C general purpose interface code for file system.
- Author
- Ankur Yadav (ankur.nosp@m.ayad.nosp@m.av@gm.nosp@m.ail..nosp@m.com)
Maximum buffer for creating path using snprintf()
void i2cClose |
( |
const int |
i2cFD | ) |
|
This function is used to close I2C file descriptor.
- Parameters
-
i2cFD | a constant integer argument. |
int i2cOpenAdaptor |
( |
const uint8_t |
adaptorNumber | ) |
|
This function takes I2C adapter number as input and returns a file descriptor for accessing that I2C adapter.
- Parameters
-
adaptorNumber | a constant uint8_t argument. |
- Returns
- If successful then I2C file descriptor is returned and if it fails then -1 is returned.
int i2cReadByte |
( |
const int |
i2cFD, |
|
|
const uint8_t |
add |
|
) |
| |
It takes file descriptor and address of register from which data is to be read. It reads a byte from the address provided in input and returns the byte. It internally uses i2cSetAddress() to set pointer to proper address.
- Parameters
-
i2cFD | a constant integer argument. |
add | a constant uint8_t argument. |
- See Also
- i2cSetAddress()
- Returns
- byte on success and -1 if it fails.
int i2cReadBytes |
( |
const int |
i2cFD, |
|
|
const uint8_t |
add, |
|
|
const int |
length, |
|
|
uint8_t * |
buff |
|
) |
| |
It takes file descriptor, starting address of register from which data is to be read, length of data to be read and buffer to store the data as input. It is used to get 'length' number of bytes in 'buff' array from 'add' starting address.
- Parameters
-
i2cFD | a constant integer argument. |
add | a constant uint8_t argument. |
length | a constant integer argument. |
bytes | an uint8_t pointer argument. |
- Returns
- 0 on success and -1 if it fails.
int i2cSetAddress |
( |
const int |
i2cFD, |
|
|
const uint8_t |
add |
|
) |
| |
This is used by some other functions internally for random access of sensor registers. It takes file descriptor and random address as input to which file descriptor should point.
- Parameters
-
i2cFD | a constant integer argument. |
add | a constant uint8_t argument. |
- Returns
- 0 on success and -1 if it fails.
int i2cSetSlave |
( |
const int |
i2cFD, |
|
|
const uint8_t |
address |
|
) |
| |
This takes I2C adapter file descriptor and address at which device is attached as input and sets slave for file descriptor using ioctl call.
- Parameters
-
i2cFD | a constant integer argument. |
address | a constant uint8_t argument. |
- Returns
- If successful then 0 is returned and if it fails then -1 is returned.
int i2cWriteByte |
( |
const int |
i2cFD, |
|
|
const uint8_t |
add, |
|
|
const uint8_t |
byte |
|
) |
| |
This function takes file descriptor, address of register to write and byte to be written as input and writes byte provided in the argument at the address provided.
- Parameters
-
i2cFD | a constant integer argument. |
add | a constant uint8_t argument. |
byte | a constant uint8_t argument. |
- Returns
- 0 on success and -1 if it fails.
int i2cWriteBytes |
( |
const int |
i2cFD, |
|
|
const uint8_t |
add, |
|
|
const int |
length, |
|
|
const uint8_t * |
bytes |
|
) |
| |
It takes i2c file descriptor, start address of registers to be written, length of data and array containing bytes of data as input. This function is used to write bytes provided in argument from the address provided to address+length continuously.
- Parameters
-
i2cFD | a constant integer argument. |
add | a constant uint8_t argument. |
length | a constant integer argument. |
bytes | a constant uint8_t pointer argument. |
- Returns
- 0 on success and -1 if it fails.