From 521dad36cb4533e423fe14602165a534080b7344 Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Thu, 15 Oct 2020 23:28:26 +0200 Subject: i2sensors: SMBUS lib loading --- Makefile | 10 +++++++--- src/main.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 255d599..82169a0 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ ACC = arm-linux-gnueabihf-gcc DATE = $(shell date "+%Y-%m-%d %H:%M:%S" ) VFLAGS = -D"_BUILD_TIME_=\"$(DATE)\"" CFLAGS = -Wall +#-D"WITH_I2C_SMBUS" -all: dir x86 +all: dir smbus ##copy dir: @@ -13,12 +14,15 @@ dir: armhf: $(ACC) $(CFLAGS) $(VFLAGS) src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors-armhf -li2c -x86: - $(CC) $(CFLAGS) $(VFLAGS) src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors -li2c +tiny: + $(CC) $(CFLAGS) $(VFLAGS) src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors geode: $(CC) $(CFLAGS) $(VFLAGS) -m32 -march=geode src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors -li2c +smbus: + $(CC) $(CFLAGS) $(VFLAGS) -D"WITH_I2C_SMBUS" src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors -li2c + copy: scp -r build/i2sensors-armhf root@cb2:/tmp/i2sensors # rsync -aHv -q -e "ssh" build/i2sensors-arm root@cb2:/tmp/i2sensors diff --git a/src/main.c b/src/main.c index 26e79ba..d9644be 100644 --- a/src/main.c +++ b/src/main.c @@ -12,7 +12,9 @@ #include #include -#include +#ifdef WITH_I2C_SMBUS + #include +#endif #include #include "deftypes.h" @@ -83,10 +85,11 @@ void print_help(void) { __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, __uint16_t rdlen){ //# [buf] = 32 byte +#ifdef WITH_I2C_SMBUS __int32_t data=0; - if( funcs & I2C_FUNC_I2C ){ - + if( funcs & I2C_FUNC_I2C ){ +#endif if(write(devicef, buf, 1) != 1){ //# write one byte to device fprintf (stderr, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); } @@ -95,6 +98,7 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _ fprintf (stderr, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); } +#ifdef WITH_I2C_SMBUS } else if ( funcs && I2C_FUNC_SMBUS_WORD_DATA ){ if(i2c_smbus_write_byte(devicef, buf[0] ) == -1){ //# write one byte to device fprintf (stderr, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); @@ -107,6 +111,7 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _ buf[1] = (data >> 8) & 0x0FF; } } +#endif return buf; } -- cgit v1.2.3