* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
#define ADC_CONF(x) ( ADC_REF_AVCC | ADC_MODE_INT | MUX_ADC##x )
/* define which ADC to poll, see in sensor.h */
#define ADC_CONF(x) ( ADC_REF_AVCC | ADC_MODE_INT | MUX_ADC##x )
/* define which ADC to poll, see in sensor.h */
[ADC_CSENSE1] = { .config = ADC_CONF(0), .filter = rii_medium },
[ADC_CSENSE2] = { .config = ADC_CONF(1), .filter = rii_medium },
[ADC_CSENSE3] = { .config = ADC_CONF(2), .filter = rii_medium },
[ADC_CSENSE1] = { .config = ADC_CONF(0), .filter = rii_medium },
[ADC_CSENSE2] = { .config = ADC_CONF(1), .filter = rii_medium },
[ADC_CSENSE3] = { .config = ADC_CONF(2), .filter = rii_medium },
static void adc_event(int16_t result);
/* called every 10 ms, see init below */
static void adc_event(int16_t result);
/* called every 10 ms, see init below */
*/
static struct sensor_filter sensor_filter[SENSOR_MAX] = {
[S_COB_INSIDE_L] = { 5, 0, 4, 1, 0, 1 }, /* 0 */
[S_CAP2] = { 10, 0, 3, 7, 0, 0 }, /* 1 */
[S_COB_INSIDE_R] = { 5, 0, 4, 1, 0, 0 }, /* 2 */
[S_CAP4] = { 1, 0, 0, 1, 0, 0 }, /* 3 */
*/
static struct sensor_filter sensor_filter[SENSOR_MAX] = {
[S_COB_INSIDE_L] = { 5, 0, 4, 1, 0, 1 }, /* 0 */
[S_CAP2] = { 10, 0, 3, 7, 0, 0 }, /* 1 */
[S_COB_INSIDE_R] = { 5, 0, 4, 1, 0, 0 }, /* 2 */
[S_CAP4] = { 1, 0, 0, 1, 0, 0 }, /* 3 */
- [S_LCOB] = { 1, 0, 0, 1, 0, 0 }, /* 4 */
- [S_LEFT] = { 5, 0, 4, 1, 0, 0 }, /* 5 */
- [S_RIGHT] = { 5, 0, 4, 1, 0, 1 }, /* 6 */
- [S_RCOB] = { 1, 0, 0, 1, 0, 0 }, /* 7 */
+ [S_LCOB] = { 1, 0, 0, 1, 0, 1 }, /* 4 */
+ [S_CAP6] = { 5, 0, 4, 1, 0, 0 }, /* 5 */
+ [S_CAP7] = { 5, 0, 4, 1, 0, 1 }, /* 6 */
+ [S_RCOB] = { 1, 0, 0, 1, 0, 1 }, /* 7 */
[S_RESERVED1] = { 10, 0, 3, 7, 0, 0 }, /* 8 */
[S_RESERVED2] = { 10, 0, 3, 7, 0, 0 }, /* 9 */
[S_RESERVED3] = { 1, 0, 0, 1, 0, 0 }, /* 10 */
[S_RESERVED1] = { 10, 0, 3, 7, 0, 0 }, /* 8 */
[S_RESERVED2] = { 10, 0, 3, 7, 0, 0 }, /* 9 */
[S_RESERVED3] = { 1, 0, 0, 1, 0, 0 }, /* 10 */
* 0-3: PORTK 2->5 (cap1 -> cap4) (adc10 -> adc13)
* 4-5: PORTL 0->1 (cap5 -> cap6)
* 6-7: PORTE 3->4 (cap7 -> cap8)
* 0-3: PORTK 2->5 (cap1 -> cap4) (adc10 -> adc13)
* 4-5: PORTL 0->1 (cap5 -> cap6)
* 6-7: PORTE 3->4 (cap7 -> cap8)
+static uint8_t lcob_cpt = 0, rcob_cpt = 0;
+uint8_t cob_falling_edge(uint8_t side)
+{
+ uint8_t flags;
+
+ if (side == I2C_LEFT_SIDE) {
+ IRQ_LOCK(flags);
+ if (lcob_cpt == 0) {
+ IRQ_UNLOCK(flags);
+ return 0;
+ }
+ lcob_cpt = 0;
+ IRQ_UNLOCK(flags);
+ return 1;
+ }
+ else {
+ IRQ_LOCK(flags);
+ if (rcob_cpt == 0) {
+ IRQ_UNLOCK(flags);
+ return 0;
+ }
+ rcob_cpt = 0;
+ IRQ_UNLOCK(flags);
+ return 1;
+ }
+}
+
+static void cob_edge_manage(void)
+{
+ static uint8_t lprev, rprev;
+ uint8_t l, r;
+ l = sensor_get(S_LCOB);
+ r = sensor_get(S_RCOB);
+ /* falling edge */
+ if (lprev != 0 && l == 0)
+ lcob_cpt = 10;
+ if (rprev != 0 && r == 0)
+ rcob_cpt = 10;
+ if (lcob_cpt > 0)
+ lcob_cpt --;
+ if (rcob_cpt > 0)
+ rcob_cpt --;
+ lprev = l;
+ rprev = r;
+}
- scheduler_add_periodical_event_priority(do_sensors, NULL,
- 10000L / SCHEDULER_UNIT,
+ scheduler_add_periodical_event_priority(do_sensors, NULL,
+ 10000L / SCHEDULER_UNIT,