summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-11-17 18:27:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2013-11-17 18:27:44 +0100
commite050f96dee9da9dc73176ca1be3c26161f0ae1f9 (patch)
tree5f9851b3868acd5102cd70be8d68d4806c5deb64
parente1c76b9f608288adce84cd054618b492cd64935f (diff)
prepare to make sda/scl bits configurable
-rw-r--r--commandline/i2c-util.c19
-rw-r--r--commandline/i2c-util.h3
-rw-r--r--commandline/i2c.c6
3 files changed, 15 insertions, 13 deletions
diff --git a/commandline/i2c-util.c b/commandline/i2c-util.c
index a060a03..8033d12 100644
--- a/commandline/i2c-util.c
+++ b/commandline/i2c-util.c
@@ -36,6 +36,9 @@ obtained from http://libusb.sourceforge.net/.
#define PSCMD_OFF 3
/* These are the vendor specific SETUP commands implemented by our USB device */
+char bit_sda = 6;
+char bit_scl = 7;
+
usb_dev_handle *handle = NULL;
static int usbGetStringAscii(usb_dev_handle * dev, int index, int langid, char
@@ -193,22 +196,22 @@ static void verify_high(unsigned char bit, char *bitname)
void verify_sda_low()
{
- verify_low(BIT_SDA, "SDA");
+ verify_low(bit_sda, "SDA");
}
void verify_sda_high()
{
- verify_high(BIT_SDA, "SDA");
+ verify_high(bit_sda, "SDA");
}
void verify_scl_low()
{
- verify_low(BIT_SCL, "SCL");
+ verify_low(bit_scl, "SCL");
}
void verify_scl_high()
{
- verify_high(BIT_SCL, "SCL");
+ verify_high(bit_scl, "SCL");
}
/*
@@ -224,7 +227,7 @@ void set_sda(char value)
usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
- (value ? PSCMD_ON : PSCMD_OFF), 0, BIT_SDA,
+ (value ? PSCMD_ON : PSCMD_OFF), 0, bit_sda,
(char *)buffer, sizeof(buffer), 5000);
}
@@ -235,7 +238,7 @@ void set_scl(char value)
usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
- (value ? PSCMD_ON : PSCMD_OFF), 0, BIT_SCL,
+ (value ? PSCMD_ON : PSCMD_OFF), 0, bit_scl,
(char *)buffer, sizeof(buffer), 5000);
}
@@ -255,7 +258,7 @@ unsigned char i2c_tx_byte(unsigned char byte)
set_scl(1);
usleep(100);
if (i < 0) {
- if (get_status() & (1 << BIT_SDA))
+ if (get_status() & (1 << bit_sda))
ack = 0;
else
ack = 1;
@@ -278,7 +281,7 @@ unsigned char i2c_rx_byte(unsigned char send_ack)
set_sda(0);
set_scl(1);
usleep(100);
- if ((i >= 0) && ( get_status() & (1 << BIT_SDA)))
+ if ((i >= 0) && ( get_status() & (1 << bit_sda)))
ret |= (1 << i);
if (( i < 0) && send_ack)
set_sda(1);
diff --git a/commandline/i2c-util.h b/commandline/i2c-util.h
index 6bf13b3..f3c5738 100644
--- a/commandline/i2c-util.h
+++ b/commandline/i2c-util.h
@@ -1,6 +1,3 @@
-#define BIT_SDA 6
-#define BIT_SCL 7
-
void verify_sda_low();
void verify_sda_high();
void verify_scl_low();
diff --git a/commandline/i2c.c b/commandline/i2c.c
index 8d28347..ce0f70e 100644
--- a/commandline/i2c.c
+++ b/commandline/i2c.c
@@ -10,6 +10,8 @@ int main(int argc, char **argv)
signed char i;
short int number;
+ char bit_sda = 6;
+
i2c_init();
i2c_start();
puts("ready");
@@ -33,13 +35,13 @@ int main(int argc, char **argv)
usleep(10);
//verify_scl_high();
if (i < 0) {
- if (get_status() & (1 << BIT_SDA))
+ if (get_status() & (1 << bit_sda))
puts("> NAK");
else
puts("> ACK");
}
else if (number == 256) {
- if (get_status() & (1 << BIT_SDA))
+ if (get_status() & (1 << bit_sda))
puts("1");
else
puts("0");