From: Jon Feldman Date: Sat, 18 Jun 2016 23:46:41 +0000 (+0000) Subject: Patch for bdfe X-Git-Tag: v0.1.1~17 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=4066bead9c95c12b512adb89f73ecce56955780a;p=corbenik%2Fcorbenik.git Patch for bdfe Stubs out Linux i2c functions to allow build on cygwin to succeed. Apply with `patch -Np1 -i host/stub-i2c-bdfe.patch` --- diff --git a/host/stub-i2c-bdfe.patch b/host/stub-i2c-bdfe.patch new file mode 100644 index 0000000..19ee9d3 --- /dev/null +++ b/host/stub-i2c-bdfe.patch @@ -0,0 +1,100 @@ +diff -urN bdfe/li2c.c bdfe-stubi2c/li2c.c +--- bdfe/li2c.c 2016-06-18 23:35:56.639775500 +0000 ++++ bdfe-stubi2c/li2c.c 2016-06-18 23:35:15.467047200 +0000 +@@ -38,95 +38,34 @@ + options i2c_bcm2708 baudrate=400000 + */ + +-#include +-#include +-#include +-#include +-#include +- + #include "li2c.h" + +-/* by default RPi mode, so bus 1 is valid for RPi and Edison */ +-static li2c_mode_t i2c_mode = LI2C_RPI; +- +-/** i2c bus file descriptors */ +-static int i2c_bus[LI2C_MAX_BUS]; +- +-static int is_valid_bus(uint8_t bus) +-{ +- if (i2c_mode == LI2C_RPI) { +- if (bus > PI2C_MAX_BUS) +- return 0; +- return 1; +- } +- if (i2c_mode == LI2C_EDISON) { +- if (bus > EDI2C_MAX_BUS) +- return 0; +- return 1; +- } +- return 0; +-} +- + /* select I2C mode - Raspberry or Edison for bus index validation */ + int li2c_init(li2c_mode_t mode) + { +- for(int i = 0; i < LI2C_MAX_BUS; i++) +- i2c_bus[i] = -1; +- i2c_mode = mode; + return 0; + } + + /** open I2C bus if not opened yet and store file descriptor */ + int li2c_open(uint8_t bus) + { +- char bus_name[64]; +- +- if (!is_valid_bus(bus)) +- return -1; +- +- // already opened? +- if (i2c_bus[bus] >= 0) +- return 0; +- +- // open i2c bus and store file descriptor +- sprintf(bus_name, "/dev/i2c-%u", bus); +- +- if ((i2c_bus[bus] = open(bus_name, O_RDWR)) < 0) +- return -1; +- + return 0; + } + + /** close I2C bus file descriptor */ + int li2c_close(uint8_t bus) + { +- if (!is_valid_bus(bus)) +- return -1; +- +- if (i2c_bus[bus] >= 0) +- close(i2c_bus[bus]); +- i2c_bus[bus] = -1; +- + return 0; + } + + /** select I2C device for li2c_write() calls */ + int li2c_select(uint8_t bus, uint8_t slave) + { +- if (!is_valid_bus(bus) || (i2c_bus[bus] < 0)) +- return -1; +- +- return ioctl(i2c_bus[bus], I2C_SLAVE, slave); ++ return 0; + } + + /** write to I2C device selected by li2c_select() */ + int li2c_write(uint8_t bus, const uint8_t *data, uint32_t len) + { +- if (!is_valid_bus(bus) || (i2c_bus[bus] < 0)) +- return -1; +- +- if (write(i2c_bus[bus], data, len) != (ssize_t)len) +- return -1; +- + return 0; + }