Browse Source

Bugfix: bitfury: Check for necessity of linux/i2c.h so build succeeds with i2c-tools's userspace linux/i2c-dev.h

Luke Dashjr 12 years ago
parent
commit
66e5d6b633
3 changed files with 24 additions and 4 deletions
  1. 18 0
      configure.ac
  2. 0 2
      spidevc.c
  3. 6 2
      tm_i2c.c

+ 18 - 0
configure.ac

@@ -77,6 +77,24 @@ AC_CHECK_HEADERS([linux/spi/spidev.h])
 
 
 AC_CHECK_HEADERS([sys/file.h])
 AC_CHECK_HEADERS([sys/file.h])
 
 
+AC_CHECK_MEMBER([struct i2c_msg.buf],[
+	true
+],[
+	dnl Note the member is different here to avoid caching screwing things up
+	AC_CHECK_MEMBER([struct i2c_msg.len],[
+		AC_DEFINE([NEED_LINUX_I2C_H],[1],[Defined if linux/i2c.h is needed to supplement linux/i2c-dev.h])
+	],[
+		true
+	],[
+		AC_INCLUDES_DEFAULT
+		#include <linux/i2c.h>
+		#include <linux/i2c-dev.h>
+	])
+],[
+	AC_INCLUDES_DEFAULT
+	#include <linux/i2c-dev.h>
+])
+
 # Setuid
 # Setuid
 AC_CHECK_HEADERS([pwd.h])
 AC_CHECK_HEADERS([pwd.h])
 
 

+ 0 - 2
spidevc.c

@@ -47,8 +47,6 @@
 #include <linux/spi/spidev.h>
 #include <linux/spi/spidev.h>
 #include <time.h>
 #include <time.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <linux/i2c.h>
-#include <linux/i2c-dev.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
 #endif
 #endif
 
 

+ 6 - 2
tm_i2c.c

@@ -20,11 +20,15 @@
  * THE SOFTWARE.
  * THE SOFTWARE.
  */
  */
 
 
+#include "config.h"
+
 #include <fcntl.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
+#ifdef NEED_LINUX_I2C_H
 #include <linux/i2c.h>
 #include <linux/i2c.h>
+#endif
 #include <linux/i2c-dev.h>
 #include <linux/i2c-dev.h>
 
 
 #include "logging.h"
 #include "logging.h"
@@ -71,7 +75,7 @@ unsigned int tm_i2c_req(int fd, unsigned char addr, unsigned char cmd, unsigned
 	msg.addr = addr;
 	msg.addr = addr;
 	msg.flags = 0;
 	msg.flags = 0;
 	msg.len = 3;
 	msg.len = 3;
-	msg.buf = buf;
+	msg.buf = (void*)tm;
 	msg_rdwr.msgs = &msg;
 	msg_rdwr.msgs = &msg;
 	msg_rdwr.nmsgs = 1;
 	msg_rdwr.nmsgs = 1;
 	if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0) {
 	if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0) {
@@ -83,7 +87,7 @@ unsigned int tm_i2c_req(int fd, unsigned char addr, unsigned char cmd, unsigned
 	msg.addr = addr;
 	msg.addr = addr;
 	msg.flags = I2C_M_RD;
 	msg.flags = I2C_M_RD;
 	msg.len = 3;
 	msg.len = 3;
-	msg.buf = buf;
+	msg.buf = (void*)tm;
 	msg_rdwr.msgs = &msg;
 	msg_rdwr.msgs = &msg;
 	msg_rdwr.nmsgs = 1;
 	msg_rdwr.nmsgs = 1;
 	if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0) {
 	if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0) {