Compare commits
23 Commits
1.0
..
6b0f6f3093
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b0f6f3093 | |||
| 7f5d18d554 | |||
| 98c04194fe | |||
| 29d76c9d2f | |||
| bcc4cb8291 | |||
| 695bf90c03 | |||
| 2a528c0976 | |||
| 501991058c | |||
| b6ca09b58e | |||
| fe1d96853c | |||
| 9b8936af89 | |||
| af70fc34a9 | |||
| 72c14a53fe | |||
| 23ad1f3445 | |||
| 9590757913 | |||
| e5d3ef4624 | |||
| beddee2f57 | |||
| 45201ec19c | |||
| 6f483252a0 | |||
| c12d49bca0 | |||
| 39592bc80e | |||
| 1d317af410 | |||
| 82becab1cc |
Vendored
-17
@@ -54,23 +54,6 @@
|
|||||||
"isDefault": true
|
"isDefault": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "distclean",
|
|
||||||
"type":"shell",
|
|
||||||
"command": "make distclean -j8",
|
|
||||||
"problemMatcher": {
|
|
||||||
"base": "$gcc",
|
|
||||||
"owner": "gcc",
|
|
||||||
"fileLocation": [
|
|
||||||
"relative",
|
|
||||||
"${workspaceFolder}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "build_unit_test",
|
"label": "build_unit_test",
|
||||||
"type":"shell",
|
"type":"shell",
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ UNIT_TEST_TARGET = $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)/$(TARGET_FILE)
|
|||||||
|
|
||||||
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||||
|
|
||||||
.PHONY: all install uninstall clean distclean
|
.PHONY: all install uninstall clean
|
||||||
all: $(STATIC_LIB) $(DYNAMIC_LIB)
|
all: $(STATIC_LIB) $(DYNAMIC_LIB)
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
@@ -80,9 +80,6 @@ clean:
|
|||||||
rm -f $(OBJ_DIR)/*.gcda $(OBJ_DIR)/*.gcno
|
rm -f $(OBJ_DIR)/*.gcda $(OBJ_DIR)/*.gcno
|
||||||
rm -fr $(COVERAGE_DIR)
|
rm -fr $(COVERAGE_DIR)
|
||||||
|
|
||||||
distclean:
|
|
||||||
rm -fr $(BIN_DIR) $(OBJ_DIR) $(LIB_DIR) $(COVERAGE_DIR)
|
|
||||||
|
|
||||||
.PHONY: coverage
|
.PHONY: coverage
|
||||||
coverage: _cov_genhtml
|
coverage: _cov_genhtml
|
||||||
$(eval COVERAGE:=$(shell grep 'lines' .coverage.tmp | egrep -o '[0-9]+.[0-9]+%'))
|
$(eval COVERAGE:=$(shell grep 'lines' .coverage.tmp | egrep -o '[0-9]+.[0-9]+%'))
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
# I2C BB
|
|
||||||
|
|
||||||
I2C bitbang gpio driver using gpio_sys gpio driver
|
|
||||||
|
|
||||||
## 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
|
|
||||||
|
|
||||||
static const struct gpio_sys gpio_sda = {
|
|
||||||
.pin = 4,
|
|
||||||
.direction = 0, // out
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct gpio_sys gpio_scl = {
|
|
||||||
.pin = 24,
|
|
||||||
.direction = 0, // out
|
|
||||||
};
|
|
||||||
|
|
||||||
const static struct i2c_bb i2c_dev = {
|
|
||||||
.sda = &gpio_sda,
|
|
||||||
.scl = &gpio_scl,
|
|
||||||
};
|
|
||||||
|
|
||||||
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). |
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef __I2C_BB_H__
|
#ifndef __I2C_BB_H__
|
||||||
#define __I2C_BB_H__
|
#define __I2C_BB_H__
|
||||||
|
|
||||||
#include <libgpio_sys/gpio.h>
|
#include <libgpio_sys/gpio_sys.h>
|
||||||
|
|
||||||
struct i2c_bb {
|
struct i2c_bb {
|
||||||
struct gpio_sys *sda;
|
struct gpio_sys *sda;
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <i2c.h>
|
#include <i2c_bb.h>
|
||||||
|
|
||||||
|
|
||||||
static void write_bit(const struct i2c_bb *i2c, uint8_t bit);
|
static void write_bit(const struct i2c_bb *i2c, uint8_t bit);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <utest.h>
|
#include <utest.h>
|
||||||
#include <mock_gpio.h>
|
#include <mock_gpio.h>
|
||||||
|
|
||||||
#include <i2c.h>
|
#include <i2c_bb.h>
|
||||||
|
|
||||||
UTEST(i2c_close, success)
|
UTEST(i2c_close, success)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <utest.h>
|
#include <utest.h>
|
||||||
#include <mock_gpio.h>
|
#include <mock_gpio.h>
|
||||||
|
|
||||||
#include <i2c.h>
|
#include <i2c_bb.h>
|
||||||
|
|
||||||
UTEST(i2c_open, success)
|
UTEST(i2c_open, success)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user