Use the GPIO HAL for Zoul sensor drivers

This commit is contained in:
George Oikonomou 2018-02-25 23:01:03 +00:00
parent 2138eb08d6
commit cab38d9ea8
5 changed files with 57 additions and 21 deletions

View File

@ -40,6 +40,7 @@
#include "contiki.h" #include "contiki.h"
#include "ac-dimmer.h" #include "ac-dimmer.h"
#include "dev/gpio.h" #include "dev/gpio.h"
#include "dev/gpio-hal.h"
#include "lib/sensors.h" #include "lib/sensors.h"
#include "dev/ioc.h" #include "dev/ioc.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -76,12 +77,16 @@ PROCESS_THREAD(ac_dimmer_int_process, ev, data)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
dimmer_zero_cross_int_handler(uint8_t port, uint8_t pin) dimmer_zero_cross_int_handler(gpio_hal_pin_mask_t pin_mask)
{ {
if((port == DIMMER_SYNC_PORT) && (pin == DIMMER_SYNC_PIN)) {
process_poll(&ac_dimmer_int_process); process_poll(&ac_dimmer_int_process);
} }
} /*---------------------------------------------------------------------------*/
static gpio_hal_event_handler_t dimmer_handler = {
.next = NULL,
.handler = dimmer_zero_cross_int_handler,
.pin_mask = gpio_hal_pin_to_mask(DIMMER_SYNC_PIN) << (DIMMER_SYNC_PORT << 3),
};
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
status(int type) status(int type)
@ -128,8 +133,7 @@ configure(int type, int value)
GPIO_DETECT_EDGE(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK); GPIO_DETECT_EDGE(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
GPIO_TRIGGER_SINGLE_EDGE(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK); GPIO_TRIGGER_SINGLE_EDGE(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
GPIO_DETECT_RISING(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK); GPIO_DETECT_RISING(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
gpio_register_callback(dimmer_zero_cross_int_handler, DIMMER_SYNC_PORT, gpio_hal_register_handler(&dimmer_handler);
DIMMER_SYNC_PIN);
/* Spin process until an interrupt is received */ /* Spin process until an interrupt is received */
process_start(&ac_dimmer_int_process, NULL); process_start(&ac_dimmer_int_process, NULL);

View File

@ -44,6 +44,7 @@
#include "contiki.h" #include "contiki.h"
#include "dev/i2c.h" #include "dev/i2c.h"
#include "dev/grove-gyro.h" #include "dev/grove-gyro.h"
#include "dev/gpio-hal.h"
#include "lib/sensors.h" #include "lib/sensors.h"
#include "dev/watchdog.h" #include "dev/watchdog.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -458,11 +459,17 @@ PROCESS_THREAD(grove_gyro_int_process, ev, data)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
grove_gyro_interrupt_handler(uint8_t port, uint8_t pin) grove_gyro_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
{ {
process_poll(&grove_gyro_int_process); process_poll(&grove_gyro_int_process);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static gpio_hal_event_handler_t gyro_handler = {
.next = NULL,
.handler = grove_gyro_interrupt_handler,
.pin_mask = gpio_hal_pin_to_mask(I2C_INT_PIN) << (I2C_INT_PORT << 3),
};
/*---------------------------------------------------------------------------*/
static int static int
value(int type) value(int type)
{ {
@ -593,8 +600,7 @@ configure(int type, int value)
GPIO_DETECT_EDGE(GROVE_GYRO_INT_PORT_BASE, GROVE_GYRO_INT_PIN_MASK); GPIO_DETECT_EDGE(GROVE_GYRO_INT_PORT_BASE, GROVE_GYRO_INT_PIN_MASK);
GPIO_TRIGGER_SINGLE_EDGE(GROVE_GYRO_INT_PORT_BASE, GROVE_GYRO_INT_PIN_MASK); GPIO_TRIGGER_SINGLE_EDGE(GROVE_GYRO_INT_PORT_BASE, GROVE_GYRO_INT_PIN_MASK);
GPIO_DETECT_FALLING(GROVE_GYRO_INT_PORT_BASE, GROVE_GYRO_INT_PIN_MASK); GPIO_DETECT_FALLING(GROVE_GYRO_INT_PORT_BASE, GROVE_GYRO_INT_PIN_MASK);
gpio_register_callback(grove_gyro_interrupt_handler, I2C_INT_PORT, gpio_hal_register_handler(&gyro_handler);
I2C_INT_PIN);
/* Spin process until an interrupt is received */ /* Spin process until an interrupt is received */
process_start(&grove_gyro_int_process, NULL); process_start(&grove_gyro_int_process, NULL);

View File

@ -47,6 +47,7 @@
#include "lib/sensors.h" #include "lib/sensors.h"
#include "dev/sys-ctrl.h" #include "dev/sys-ctrl.h"
#include "dev/gpio.h" #include "dev/gpio.h"
#include "dev/gpio-hal.h"
#include "dev/ioc.h" #include "dev/ioc.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define DEBUG 0 #define DEBUG 0
@ -76,11 +77,17 @@ PROCESS_THREAD(motion_int_process, ev, data)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
motion_interrupt_handler(uint8_t port, uint8_t pin) motion_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
{ {
process_poll(&motion_int_process); process_poll(&motion_int_process);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static gpio_hal_event_handler_t motion_handler = {
.next = NULL,
.handler = motion_interrupt_handler,
.pin_mask = gpio_hal_pin_to_mask(MOTION_SENSOR_PIN) << (MOTION_SENSOR_PORT << 3),
};
/*---------------------------------------------------------------------------*/
static int static int
status(int type) status(int type)
{ {
@ -113,8 +120,7 @@ configure(int type, int value)
GPIO_DETECT_RISING(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK); GPIO_DETECT_RISING(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
GPIO_TRIGGER_SINGLE_EDGE(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK); GPIO_TRIGGER_SINGLE_EDGE(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
ioc_set_over(MOTION_SENSOR_PORT, MOTION_SENSOR_PIN, IOC_OVERRIDE_DIS); ioc_set_over(MOTION_SENSOR_PORT, MOTION_SENSOR_PIN, IOC_OVERRIDE_DIS);
gpio_register_callback(motion_interrupt_handler, MOTION_SENSOR_PORT, gpio_hal_register_handler(&motion_handler);
MOTION_SENSOR_PIN);
process_start(&motion_int_process, NULL); process_start(&motion_int_process, NULL);

View File

@ -43,6 +43,7 @@
#include "contiki.h" #include "contiki.h"
#include "dev/i2c.h" #include "dev/i2c.h"
#include "dev/gpio.h" #include "dev/gpio.h"
#include "dev/gpio-hal.h"
#include "dev/zoul-sensors.h" #include "dev/zoul-sensors.h"
#include "lib/sensors.h" #include "lib/sensors.h"
#include "tsl256x.h" #include "tsl256x.h"
@ -255,7 +256,7 @@ PROCESS_THREAD(tsl256x_int_process, ev, data)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
tsl256x_interrupt_handler(uint8_t port, uint8_t pin) tsl256x_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
{ {
/* There's no alert/interruption flag to check, clear the interruption by /* There's no alert/interruption flag to check, clear the interruption by
* writting to the CLEAR bit in the COMMAND register * writting to the CLEAR bit in the COMMAND register
@ -263,6 +264,12 @@ tsl256x_interrupt_handler(uint8_t port, uint8_t pin)
process_poll(&tsl256x_int_process); process_poll(&tsl256x_int_process);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static gpio_hal_event_handler_t tsl256x_handler = {
.next = NULL,
.handler = tsl256x_interrupt_handler,
.pin_mask = gpio_hal_pin_to_mask(I2C_INT_PIN) << (I2C_INT_PORT << 3),
};
/*---------------------------------------------------------------------------*/
static int static int
configure(int type, int value) configure(int type, int value)
{ {
@ -440,7 +447,7 @@ configure(int type, int value)
GPIO_DETECT_EDGE(TSL256X_INT_PORT_BASE, TSL256X_INT_PIN_MASK); GPIO_DETECT_EDGE(TSL256X_INT_PORT_BASE, TSL256X_INT_PIN_MASK);
GPIO_TRIGGER_SINGLE_EDGE(TSL256X_INT_PORT_BASE, TSL256X_INT_PIN_MASK); GPIO_TRIGGER_SINGLE_EDGE(TSL256X_INT_PORT_BASE, TSL256X_INT_PIN_MASK);
GPIO_DETECT_FALLING(TSL256X_INT_PORT_BASE, TSL256X_INT_PIN_MASK); GPIO_DETECT_FALLING(TSL256X_INT_PORT_BASE, TSL256X_INT_PIN_MASK);
gpio_register_callback(tsl256x_interrupt_handler, I2C_INT_PORT, I2C_INT_PIN); gpio_hal_register_handler(&tsl256x_handler);
/* Spin process until an interrupt is received */ /* Spin process until an interrupt is received */
process_start(&tsl256x_int_process, NULL); process_start(&tsl256x_int_process, NULL);

View File

@ -51,6 +51,7 @@
#include "lib/sensors.h" #include "lib/sensors.h"
#include "dev/sys-ctrl.h" #include "dev/sys-ctrl.h"
#include "dev/gpio.h" #include "dev/gpio.h"
#include "dev/gpio-hal.h"
#include "dev/ioc.h" #include "dev/ioc.h"
#include "sys/timer.h" #include "sys/timer.h"
#include "sys/ctimer.h" #include "sys/ctimer.h"
@ -292,8 +293,22 @@ PROCESS_THREAD(weather_meter_int_process, ev, data)
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void weather_meter_interrupt_handler(gpio_hal_pin_mask_t pin_mask);
/*---------------------------------------------------------------------------*/
static gpio_hal_event_handler_t rain_handler = {
.next = NULL,
.handler = weather_meter_interrupt_handler,
.pin_mask = gpio_hal_pin_to_mask(RAIN_GAUGE_SENSOR_PIN) << (RAIN_GAUGE_SENSOR_PORT << 3),
};
/*---------------------------------------------------------------------------*/
static gpio_hal_event_handler_t anemometer_handler = {
.next = NULL,
.handler = weather_meter_interrupt_handler,
.pin_mask = gpio_hal_pin_to_mask(ANEMOMETER_SENSOR_PIN) << (ANEMOMETER_SENSOR_PORT << 3),
};
/*---------------------------------------------------------------------------*/
static void static void
weather_meter_interrupt_handler(uint8_t port, uint8_t pin) weather_meter_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
{ {
uint32_t aux; uint32_t aux;
@ -308,10 +323,10 @@ weather_meter_interrupt_handler(uint8_t port, uint8_t pin)
* value * value
*/ */
if((port == ANEMOMETER_SENSOR_PORT) && (pin == ANEMOMETER_SENSOR_PIN)) { if(pin_mask == rain_handler.pin_mask) {
weather_sensors.anemometer.ticks++; weather_sensors.anemometer.ticks++;
process_post(&weather_meter_int_process, anemometer_int_event, NULL); process_post(&weather_meter_int_process, anemometer_int_event, NULL);
} else if((port == RAIN_GAUGE_SENSOR_PORT) && (pin == RAIN_GAUGE_SENSOR_PIN)) { } else if(pin_mask == anemometer_handler.pin_mask) {
weather_sensors.rain_gauge.ticks++; weather_sensors.rain_gauge.ticks++;
aux = weather_sensors.rain_gauge.ticks * WEATHER_METER_AUX_RAIN_MM; aux = weather_sensors.rain_gauge.ticks * WEATHER_METER_AUX_RAIN_MM;
aux /= 1000; aux /= 1000;
@ -427,8 +442,7 @@ configure(int type, int value)
GPIO_TRIGGER_SINGLE_EDGE(ANEMOMETER_SENSOR_PORT_BASE, GPIO_TRIGGER_SINGLE_EDGE(ANEMOMETER_SENSOR_PORT_BASE,
ANEMOMETER_SENSOR_PIN_MASK); ANEMOMETER_SENSOR_PIN_MASK);
ioc_set_over(ANEMOMETER_SENSOR_PORT, ANEMOMETER_SENSOR_PIN, IOC_OVERRIDE_DIS); ioc_set_over(ANEMOMETER_SENSOR_PORT, ANEMOMETER_SENSOR_PIN, IOC_OVERRIDE_DIS);
gpio_register_callback(weather_meter_interrupt_handler, ANEMOMETER_SENSOR_PORT, gpio_hal_register_handler(&anemometer_handler);
ANEMOMETER_SENSOR_PIN);
/* Configure rain gauge interruption */ /* Configure rain gauge interruption */
GPIO_SOFTWARE_CONTROL(RAIN_GAUGE_SENSOR_PORT_BASE, RAIN_GAUGE_SENSOR_PIN_MASK); GPIO_SOFTWARE_CONTROL(RAIN_GAUGE_SENSOR_PORT_BASE, RAIN_GAUGE_SENSOR_PIN_MASK);
@ -437,8 +451,7 @@ configure(int type, int value)
GPIO_TRIGGER_SINGLE_EDGE(RAIN_GAUGE_SENSOR_PORT_BASE, GPIO_TRIGGER_SINGLE_EDGE(RAIN_GAUGE_SENSOR_PORT_BASE,
RAIN_GAUGE_SENSOR_PIN_MASK); RAIN_GAUGE_SENSOR_PIN_MASK);
ioc_set_over(RAIN_GAUGE_SENSOR_PORT, RAIN_GAUGE_SENSOR_PIN, IOC_OVERRIDE_DIS); ioc_set_over(RAIN_GAUGE_SENSOR_PORT, RAIN_GAUGE_SENSOR_PIN, IOC_OVERRIDE_DIS);
gpio_register_callback(weather_meter_interrupt_handler, RAIN_GAUGE_SENSOR_PORT, gpio_hal_register_handler(&rain_handler);
RAIN_GAUGE_SENSOR_PIN);
process_start(&weather_meter_int_process, NULL); process_start(&weather_meter_int_process, NULL);