summaryrefslogtreecommitdiff
path: root/n/es-2006/src/sensor_rvb.c
diff options
context:
space:
mode:
authordufourj2006-05-11 21:39:02 +0000
committerdufourj2006-05-11 21:39:02 +0000
commite9e974cb64950afe3bf54c82d5a047a18655b831 (patch)
tree262f27a7aa25b73b4fc7f32655e03aa3cc330a12 /n/es-2006/src/sensor_rvb.c
parent4d3ee19aec9942f5ef1ddcc2b0dd843cd50bf49a (diff)
ES :
RVB : - renomage de es_config en timer_1 ; - possibilité de configurer des paramètres du module RVB de façon dynamique. Autre : - ajout de la gestion du bouton de sélection de couleurs, jack et contact frontal (Patrick).
Diffstat (limited to 'n/es-2006/src/sensor_rvb.c')
-rw-r--r--n/es-2006/src/sensor_rvb.c87
1 files changed, 41 insertions, 46 deletions
diff --git a/n/es-2006/src/sensor_rvb.c b/n/es-2006/src/sensor_rvb.c
index b6576e1..e98d62f 100644
--- a/n/es-2006/src/sensor_rvb.c
+++ b/n/es-2006/src/sensor_rvb.c
@@ -23,7 +23,7 @@
*
* }}} */
#include "sensor_rvb.h"
-#include "es_config.h"
+#include "timer_1.h"
#include "io.h"
#include "modules/utils/utils.h" /* regv */
@@ -34,11 +34,12 @@
/** Colors selection pins. */
#define S1RVB 7
#define S0RVB 6
-/** Max input capture before considering we can start the real capture. */
-#define RVB_MAX_FALSE_IC 8
+/** Max input capture before considering we can start the real capture.
+ * (default value) */
+#define RVB_MAX_FALSE_IC 9
/** Max overflow of the timer 1 before thinking the sensor is HS. */
/* TODO Find a way to compute this value */
-#define RVB_MAX_OVERFLOW 250
+#define RVB_MAX_OVERFLOW 253
/** Wait time between IO change in ns. */
#define RVB_SENSOR_DELAY_IO 125
/** All the possible states. */
@@ -52,6 +53,13 @@
#define RVB_STATE_NEXT_COLOR 4 /* Selecting another color */
#define RVB_STATE_WATCH 5 /* For debuging */
+/*** Config ***/
+/** Max input capture before considering we can start the real capture. */
+uint8_t sensor_rvb_conf_max_false_ic_;
+/** Max overflow of the timer 1 before thinking the sensor is HS. */
+uint8_t sensor_rvb_conf_max_ov_;
+/** Wait time between IO change in ns. */
+uint8_t sensor_rvb_conf_delay_;
/** RVB sensor state flag. */
volatile uint8_t sensor_rvb_state_;
/** Internal computed result for one color. */
@@ -64,8 +72,6 @@ volatile uint8_t sensor_rvb_color_;
volatile uint8_t sensor_rvb_overflow_count_;
/** Results table for 9 RVB sensors (RVCB) */
volatile uint16_t sensor_rvb_values[RVB_MAX_SENSOR][4];
-/** Geting stats only for one sensors and disabling computing the others. */
-uint8_t sensor_rvb_enable;
/** Count the number of IC before starting a good capture. */
uint8_t sensor_rvb_ic_count_;
@@ -89,7 +95,7 @@ sensor_rvb_color_select (uint8_t sensor_rvb_color)
/* Select the color */
PORTF = (PORTF & ~0xC0) | (sensor_rvb_color << 6);
/* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ utils_delay_ns (sensor_rvb_conf_delay_);
/* Color exists */
return 1;
default:
@@ -124,11 +130,11 @@ sensor_rvb_sensor_select (uint8_t sensor_rvb_num)
PORTC = 0xff;
PORTD |= _BV(6);
/* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ utils_delay_ns (sensor_rvb_conf_delay_);
return 0;
}
/* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ utils_delay_ns (sensor_rvb_conf_delay_);
return 1;
}
@@ -136,8 +142,10 @@ sensor_rvb_sensor_select (uint8_t sensor_rvb_num)
void
sensor_rvb_init (void)
{
- /* We enable the system */
- sensor_rvb_enable = 1;
+ /* Init config */
+ sensor_rvb_conf_max_false_ic_ = RVB_MAX_FALSE_IC;
+ sensor_rvb_conf_max_ov_ = RVB_MAX_OVERFLOW;
+ sensor_rvb_conf_delay_ = RVB_SENSOR_DELAY_IO;
/* No sensor selected */
sensor_rvb_sensor_select (0);
/* Put ENA* pins in output */
@@ -149,46 +157,33 @@ sensor_rvb_init (void)
sensor_rvb_state_ = RVB_STATE_SLEEP;
}
+/** Configure some internal variables. */
+void
+sensor_rvb_config (uint8_t false_ic, uint8_t max_ov, uint8_t latency)
+{
+ sensor_rvb_conf_max_false_ic_ = false_ic;
+ sensor_rvb_conf_max_ov_ = max_ov;
+ sensor_rvb_conf_delay_ = latency;
+}
+
/** Start updating RVBC values for sensors. */
void
sensor_rvb_start_capture (void)
{
/* Are we already getting a sensor ? */
- if ((sensor_rvb_state_ == RVB_STATE_SLEEP) && sensor_rvb_enable)
+ if (sensor_rvb_state_ == RVB_STATE_SLEEP)
{
sensor_rvb_state_ = RVB_STATE_NEXT_SENSOR;
/* Start with sensor one */
sensor_rvb_number_ = 0;
/* Select it and launch capture */
sensor_rvb_update ();
+ /* Enable interrupt for IC1 and counter overflow */
+ TIMSK |= _BV (TICIE1);
+ TIMSK |= _BV (TOIE1);
}
}
-/** Watch only one sensor. Usefull for debugging. *//*{{{*/
-void
-sensor_rvb_watch (uint8_t sensor_num, uint8_t sensor_col)
-{
- // XXX Better approach.
- return;
- /* Disable all interrupt that could be enabled */
- TIMSK &= ~_BV (TICIE1);
- TIMSK &= ~_BV (TOIE1);
- /* Put ourself in off mode */
- sensor_rvb_enable = 0;
- sensor_rvb_state_ = RVB_STATE_WATCH;
- /* Select the color */
- sensor_rvb_color_select (sensor_rvb_color_ = sensor_col);
- /* Disable sensors */
- sensor_rvb_sensor_select (0);
- /* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
- /* Select sensor here */
- sensor_rvb_sensor_select (sensor_num + 1);
- /* Wait for output of sensor to be ready */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
-}
-/*}}}*/
-
/** Update everything for you. */
void
sensor_rvb_update (void)
@@ -205,8 +200,7 @@ sensor_rvb_update (void)
{
sensor_rvb_state_ = RVB_STATE_WAIT_IC;
/* Ensure we have no pending interrupt for IC1. */
- // XXX | ?
- TIFR |= _BV (ICF1);
+ TIFR = _BV (ICF1);
/* Enable interrupt for IC1 */
TIMSK |= _BV (TICIE1);
}
@@ -221,6 +215,9 @@ sensor_rvb_update (void)
/* Disable IC1 and TC1 overflow interrupts */
TIMSK &= ~_BV (TICIE1);
TIMSK &= ~_BV (TOIE1);
+ /* Ensure we have no pending interrupt for IC1. */
+ TIFR = _BV (ICF1);
+ /* Finish ! Go to sleep */
sensor_rvb_state_ = RVB_STATE_SLEEP;
return;
}
@@ -228,12 +225,10 @@ sensor_rvb_update (void)
sensor_rvb_color_select (sensor_rvb_color_ = 0);
sensor_rvb_state_ = RVB_STATE_WAIT_IC;
sensor_rvb_overflow_count_ = 0;
- /* Ensure we have no pending interrupt for IC1. */
- // XXX | ?
- TIFR |= _BV (ICF1);
- /* Enable interrupt for IC1 and counter overflow */
+// /* Ensure we have no pending interrupt for IC1. */
+// TIFR = _BV (ICF1);
+ /* Enable interrupt for IC1 */
TIMSK |= _BV (TICIE1);
- TIMSK |= _BV (TOIE1);
}
}
@@ -249,7 +244,7 @@ SIGNAL (SIG_OVERFLOW1)
case RVB_STATE_WAIT_IC2:
// XXX >= Sucks !
// TODO : check this >= and the IC2 used
- if (++sensor_rvb_overflow_count_ >= RVB_MAX_OVERFLOW)
+ if (++sensor_rvb_overflow_count_ >= sensor_rvb_conf_max_ov_)
{
/* Disable IC interrupt */
TIMSK &= ~_BV (TICIE1);
@@ -267,7 +262,7 @@ SIGNAL (SIG_INPUT_CAPTURE1)
switch (sensor_rvb_state_)
{
case RVB_STATE_WAIT_IC:
- sensor_rvb_ic_count_ = RVB_MAX_FALSE_IC;
+ sensor_rvb_ic_count_ = sensor_rvb_conf_max_false_ic_;
sensor_rvb_state_ = RVB_STATE_WAIT_IC2;
/* nobreak */
case RVB_STATE_WAIT_IC2: