paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [5075] add horizontal infrared i2c


From: Gautier Hattenberger
Subject: [paparazzi-commits] [5075] add horizontal infrared i2c
Date: Tue, 20 Jul 2010 07:52:19 +0000

Revision: 5075
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=5075
Author:   gautier
Date:     2010-07-20 07:52:18 +0000 (Tue, 20 Jul 2010)
Log Message:
-----------
add horizontal infrared i2c

Modified Paths:
--------------
    paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.c
    paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.h

Modified: paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.c
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.c 2010-07-20 
07:19:06 UTC (rev 5074)
+++ paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.c 2010-07-20 
07:52:18 UTC (rev 5075)
@@ -23,21 +23,37 @@
 #include "infrared_i2c.h"
 #include "i2c.h"
 
-#define IR_VERT_I2C_ADDR (0x68 << 1)
-#define OC_BIT (1 << 4)
+#define IR_HOR_I2C_ADDR (0x6C << 1)
+#define IR_VER_I2C_ADDR (0x68 << 1)
+#define IR_HOR_OC_BIT (0 << 4)
+#define IR_VER_OC_BIT (1 << 4)
+#define IR_START_CONV (1 << 7)
 
-#define IR_I2C_IDLE            0
-#define IR_I2C_READ_TOP        1
-#define IR_I2C_CONFIGURE_TOP   2
+#define IR_HOR_I2C_SELECT_IR1 (0 << 5)
+#define IR_HOR_I2C_SELECT_IR2 (1 << 5)
 
+#define IR_I2C_IDLE             0
+#define IR_I2C_READ_IR1         1
+#define IR_I2C_IR2_SELECTED     2
+#define IR_I2C_READ_TOP         3
+#define IR_I2C_READ_IR2         4
+#define IR_I2C_IR1_SELECTED     5
+#define IR_I2C_CONFIGURE_HOR    6
+#define IR_I2C_CONFIGURE_VER    7
+
+// Global variables
+int16_t ir_i2c_ir1;
+int16_t ir_i2c_ir2;
 int16_t ir_i2c_top;
 
-// Local variables
 volatile bool_t ir_i2c_done;
 bool_t ir_i2c_data_available;
-static uint8_t ir_i2c_status;
 uint8_t ir_i2c_conf_word;
+bool_t ir_i2c_conf_done;
 
+// Local variables
+static uint8_t ir_i2c_status;
+
 #define NO_CONF_WORD 0xff
 #define ValidConfWord(_x) (_x < 0x4)
 
@@ -47,22 +63,23 @@
   ir_i2c_data_available = FALSE;
   ir_i2c_status = IR_I2C_IDLE;
   ir_i2c_conf_word = IR_I2C_DEFAULT_CONF;
+  ir_i2c_conf_done = FALSE;
 }
 
 void infrared_i2c_update( void ) {
   if (ir_i2c_done && ir_i2c_status == IR_I2C_IDLE) {
-    if (ValidConfWord(ir_i2c_conf_word)) {
-      i2c0_buf[0] = ir_i2c_conf_word | OC_BIT;
-      i2c0_transmit(IR_VERT_I2C_ADDR, 1, &ir_i2c_done);
+    if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_done) {
+      i2c0_buf[0] = 0;
+      i2c0_buf[0] = ir_i2c_conf_word | IR_HOR_OC_BIT | IR_START_CONV;
+      i2c0_transmit(IR_HOR_I2C_ADDR, 1, &ir_i2c_done);
       ir_i2c_done = FALSE;
-      ir_i2c_status = IR_I2C_CONFIGURE_TOP;
-      ir_i2c_conf_word = NO_CONF_WORD;
+      ir_i2c_status = IR_I2C_CONFIGURE_HOR;
     } else {
-      // Read next value TOP sensor
-      i2c0_receive(IR_VERT_I2C_ADDR, 2, &ir_i2c_done);
+      // Read next values
+      i2c0_receive(IR_HOR_I2C_ADDR, 3, &ir_i2c_done);
       ir_i2c_done = FALSE;
       ir_i2c_data_available = FALSE;
-      ir_i2c_status = IR_I2C_READ_TOP;
+      ir_i2c_status = IR_I2C_READ_IR1;
     }
   }
 }
@@ -71,12 +88,66 @@
   switch (ir_i2c_status) {
     case IR_I2C_IDLE :
       break;
+    case IR_I2C_READ_IR1 :
+      if (bit_is_set(i2c0_buf[2],7)) {
+        i2c0_receive(IR_HOR_I2C_ADDR, 3, &ir_i2c_done);
+        ir_i2c_done = FALSE;
+        break;
+      }
+      // Read IR1 value
+      ir_i2c_ir1 = (i2c0_buf[0]<<8) | i2c0_buf[1];
+      // Select IR2 channel
+      i2c0_buf[0] = 0;
+      i2c0_buf[0] = IR_HOR_I2C_SELECT_IR2 | IR_HOR_OC_BIT | ir_i2c_conf_word | 
IR_START_CONV;
+      i2c0_transmit(IR_HOR_I2C_ADDR, 1, &ir_i2c_done);
+      ir_i2c_done = FALSE;
+      ir_i2c_status = IR_I2C_IR2_SELECTED;
+      break;
+    case IR_I2C_IR2_SELECTED :
+      // IR2 selected, asking for TOP value
+      i2c0_receive(IR_VER_I2C_ADDR, 2, &ir_i2c_done);
+      ir_i2c_done = FALSE;
+      ir_i2c_status = IR_I2C_READ_TOP;
+      break;
     case IR_I2C_READ_TOP :
+      // Read TOP value
       ir_i2c_top = (i2c0_buf[0]<<8) | i2c0_buf[1];
+      // Asking for IR2 value
+      i2c0_receive(IR_HOR_I2C_ADDR, 3, &ir_i2c_done);
+      ir_i2c_done = FALSE;
+      ir_i2c_status = IR_I2C_READ_IR2;
+      break;
+    case IR_I2C_READ_IR2 :
+      // Read IR2 value
+      if (bit_is_set(i2c0_buf[2],7)) {
+        i2c0_receive(IR_HOR_I2C_ADDR, 3, &ir_i2c_done);
+        ir_i2c_done = FALSE;
+        break;
+      }
+      ir_i2c_ir2 = (i2c0_buf[0]<<8) | i2c0_buf[1];
       ir_i2c_data_available = TRUE;
+      // Select IR1 channel
+      i2c0_buf[0] = 0;
+      i2c0_buf[0] = IR_HOR_I2C_SELECT_IR1 | IR_HOR_OC_BIT | ir_i2c_conf_word | 
IR_START_CONV;
+      i2c0_transmit(IR_HOR_I2C_ADDR, 1, &ir_i2c_done);
+      ir_i2c_done = FALSE;
+      ir_i2c_status = IR_I2C_IR1_SELECTED;
+      break;
+    case IR_I2C_IR1_SELECTED :
+      // End reading cycle
       ir_i2c_status = IR_I2C_IDLE;
       break;
-    case IR_I2C_CONFIGURE_TOP :
+    case IR_I2C_CONFIGURE_HOR :
+      // HOR configured, now configuring TOP
+      i2c0_buf[0] = 0;
+      i2c0_buf[0] = ir_i2c_conf_word | IR_VER_OC_BIT;
+      i2c0_transmit(IR_VER_I2C_ADDR, 1, &ir_i2c_done);
+      ir_i2c_done = FALSE;
+      ir_i2c_status = IR_I2C_CONFIGURE_VER;
+      break;
+    case IR_I2C_CONFIGURE_VER :
+      // VER configured, end conf cycle
+      ir_i2c_conf_done = TRUE;
       ir_i2c_status = IR_I2C_IDLE;
       break;
   }

Modified: paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.h
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.h 2010-07-20 
07:19:06 UTC (rev 5074)
+++ paparazzi3/trunk/sw/airborne/modules/sensors/infrared_i2c.h 2010-07-20 
07:52:18 UTC (rev 5075)
@@ -30,7 +30,9 @@
 #include "std.h"
 #include "airframe.h"
 
-extern int16_t ir_i2c_top;  /* averaged vertical ir adc */
+extern int16_t ir_i2c_ir1;
+extern int16_t ir_i2c_ir2;
+extern int16_t ir_i2c_top;
 extern volatile bool_t ir_i2c_done;
 extern bool_t ir_i2c_data_available;
 extern uint8_t ir_i2c_conf_word;
@@ -41,6 +43,6 @@
 
 #define infrared_i2cEvent() { if (ir_i2c_done) infrared_i2c_event();   }
 
-#define infrared_i2cDownlink() DOWNLINK_SEND_DEBUG_IR_I2C(DefaultChannel, 
&ir_i2c_top)
+#define infrared_i2cDownlink() DOWNLINK_SEND_DEBUG_IR_I2C(DefaultChannel, 
&ir_i2c_ir1, &ir_i2c_ir2, &ir_i2c_top)
 
 #endif // INFRARED_I2C_H




reply via email to

[Prev in Thread] Current Thread [Next in Thread]