i2c_bb/README.md

97 lines
2.6 KiB
Markdown
Raw Normal View History

2019-07-29 13:19:20 +00:00
# I2C BB
2019-08-01 11:05:17 +00:00
I2C bitbang gpio driver.
2019-07-29 13:19:20 +00:00
## Installation
```shell
make install
```
Installs `libi2c_bb.a` and `libi2c_bb.so` in the directory `$(PREFIX)/lib/`. It also installs the include header file `i2c.h` in the directory `$(PREFIX)/include/i2c_bb/`. The default value for `PREFIX` is: `PREFIX=usr`. To use another location for installation changing the value of the `PREFIX` variable is needed. E.g.:
```shell
PREFIX=/usr/local/ make install
```
## Uninstallation
```shell
make install
```
Removes the files installed with the `install` make target.
> **NOTE:** If `PREFIX` variable was changed during installation process the same value needs to be set for uninstallation. E.g.:
```shell
PREFIX=/usr/local/ make install
```
## Example
```C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <stdbool.h>
#include <i2c_bb/i2c.h>
#define I2C_SLAVE_ADDR 0x48
#define BUFFER_SIZE 3
const static struct i2c_bb i2c_dev = {
2019-08-01 11:05:17 +00:00
.pin_sda = 4,
.pin_scl = 24,
2019-07-29 13:19:20 +00:00
};
int main(void)
{
int res;
char buffer[BUFFER_SIZE]
openlog("i2c_bb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
res = i2c_open(&i2c_dev);
if(res != EXIT_SUCCESS) {
syslog(LOG_ERR, "Unable to open i2c device.\n");
return res;
}
buffer[0] = 0x01;
buffer[1] = 0xc1;
buffer[2] = 0x87;
// Write to register address 0x01 value 0xc187:
i2c_write(&i2c_dev, I2C_SLAVE_ADDR, buffer, BUFFER_SIZE);
buffer[0] = 0x00;
// Set register address 0x00:
i2c_write(&i2c_dev, addr, buffer, 1);
// Read from register 0x00 two bytes:
i2c_read(&i2c_dev, I2C_SLAVE_ADDR, buffer, 2);
i2c_close(&i2c_dev);
return EXIT_SUCCESS;
}
```
## Additional make targets
| Target | Meaning |
| --------------- | ----------------------------------------------------------- |
| all | Build the code, assemble the static and shared library. |
| install | Install the libraries and necessary include header files. |
| uninstall | Uninstall the libraries and necessary include header files. |
| clean | Clean up build artifacts. |
| distclean | Remove all folders created during any build step. |
| build_unit_test | Build the unit tests. |
| exec_unit_test | Execute the unit tests. |
| coverage | Determine code coverage of the unit tests. |
| check | Static code analysis (cppcheck). |
2019-09-05 19:32:21 +00:00