From 371752268051d6328626324fc021a440e572a55a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 18:06:05 +0100 Subject: [PATCH] Re-work the CC2538 driver to be a driver for the Srf06 ALS only --- .../{temp-sensor.c => cc2538-temp-sensor.c} | 3 +- .../{temp-sensor.h => cc2538-temp-sensor.h} | 8 ++--- .../dev/{adc-sensor.c => als-sensor.c} | 31 +++++-------------- .../dev/{adc-sensor.h => als-sensor.h} | 22 ++++++------- 4 files changed, 22 insertions(+), 42 deletions(-) rename cpu/cc2538/dev/{temp-sensor.c => cc2538-temp-sensor.c} (96%) rename cpu/cc2538/dev/{temp-sensor.h => cc2538-temp-sensor.h} (95%) rename platform/cc2538dk/dev/{adc-sensor.c => als-sensor.c} (82%) rename platform/cc2538dk/dev/{adc-sensor.h => als-sensor.h} (79%) diff --git a/cpu/cc2538/dev/temp-sensor.c b/cpu/cc2538/dev/cc2538-temp-sensor.c similarity index 96% rename from cpu/cc2538/dev/temp-sensor.c rename to cpu/cc2538/dev/cc2538-temp-sensor.c index abc52e42b..dd5dcba6c 100644 --- a/cpu/cc2538/dev/temp-sensor.c +++ b/cpu/cc2538/dev/cc2538-temp-sensor.c @@ -40,7 +40,6 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "lib/sensors.h" -#include "dev/temp-sensor.h" #include "dev/adc.h" #include "dev/cc2538-sensors.h" @@ -73,6 +72,6 @@ status(int type) return 1; } /*---------------------------------------------------------------------------*/ -SENSORS_SENSOR(temp_sensor, TEMP_SENSOR, value, configure, status); +SENSORS_SENSOR(cc2538_temp_sensor, TEMP_SENSOR, value, configure, status); /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/cpu/cc2538/dev/temp-sensor.h b/cpu/cc2538/dev/cc2538-temp-sensor.h similarity index 95% rename from cpu/cc2538/dev/temp-sensor.h rename to cpu/cc2538/dev/cc2538-temp-sensor.h index 7f20452db..b515c5042 100644 --- a/cpu/cc2538/dev/temp-sensor.h +++ b/cpu/cc2538/dev/cc2538-temp-sensor.h @@ -49,8 +49,8 @@ * Header file for the CC2538 on-chip temperature Sensor Driver */ /*---------------------------------------------------------------------------*/ -#ifndef TEMP_SENSOR_H_ -#define TEMP_SENSOR_H_ +#ifndef CC2538_TEMP_SENSOR_H_ +#define CC2538_TEMP_SENSOR_H_ /*---------------------------------------------------------------------------*/ #include "lib/sensors.h" /*---------------------------------------------------------------------------*/ @@ -61,9 +61,9 @@ #define TEMP_SENSOR "On-Chip Temperature" /** @} */ /*---------------------------------------------------------------------------*/ -extern const struct sensors_sensor temp_sensor; +extern const struct sensors_sensor cc2538_temp_sensor; /*---------------------------------------------------------------------------*/ -#endif /* TEMP_SENSOR_H_ */ +#endif /* CC2538_TEMP_SENSOR_H_ */ /*---------------------------------------------------------------------------*/ /** * @} diff --git a/platform/cc2538dk/dev/adc-sensor.c b/platform/cc2538dk/dev/als-sensor.c similarity index 82% rename from platform/cc2538dk/dev/adc-sensor.c rename to platform/cc2538dk/dev/als-sensor.c index 4c2f1f853..3630ac80e 100644 --- a/platform/cc2538dk/dev/adc-sensor.c +++ b/platform/cc2538dk/dev/als-sensor.c @@ -30,18 +30,18 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc2538dk-adc-sensor + * \addtogroup cc2538dk-als-sensor * @{ * * \file - * Driver for the SmartRF06EB ADC + * Driver for the SmartRF06EB ALS */ #include "contiki.h" #include "sys/clock.h" #include "dev/ioc.h" #include "dev/gpio.h" #include "dev/adc.h" -#include "dev/adc-sensor.h" +#include "dev/als-sensor.h" #include @@ -52,30 +52,15 @@ static int value(int type) { - uint8_t channel; + uint8_t channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_ALS_OUT_PIN; int16_t res; - switch(type) { - case ADC_SENSOR_VDD_3: - channel = SOC_ADC_ADCCON_CH_VDD_3; - break; - case ADC_SENSOR_TEMP: - channel = SOC_ADC_ADCCON_CH_TEMP; - break; - case ADC_SENSOR_ALS: - channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_ALS_OUT_PIN; - GPIO_SET_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); - clock_delay_usec(2000); - break; - default: - return 0; - } + GPIO_SET_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); + clock_delay_usec(2000); res = adc_get(channel, SOC_ADC_ADCCON_REF_INT, SOC_ADC_ADCCON_DIV_512); - if(type == ADC_SENSOR_ALS) { - GPIO_CLR_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); - } + GPIO_CLR_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); return res; } @@ -106,6 +91,6 @@ status(int type) return 1; } /*---------------------------------------------------------------------------*/ -SENSORS_SENSOR(adc_sensor, ADC_SENSOR, value, configure, status); +SENSORS_SENSOR(als_sensor, ALS_SENSOR, value, configure, status); /** @} */ diff --git a/platform/cc2538dk/dev/adc-sensor.h b/platform/cc2538dk/dev/als-sensor.h similarity index 79% rename from platform/cc2538dk/dev/adc-sensor.h rename to platform/cc2538dk/dev/als-sensor.h index b6d0efbdf..abed92e13 100644 --- a/platform/cc2538dk/dev/adc-sensor.h +++ b/platform/cc2538dk/dev/als-sensor.h @@ -33,33 +33,29 @@ * \addtogroup cc2538-smartrf-sensors * @{ * - * \defgroup cc2538dk-adc-sensor cc2538dk ADC Driver + * \defgroup cc2538dk-als-sensor cc2538dk ALS Driver * - * Driver for the SmartRF06EB ADC sensors + * Driver for the SmartRF06EB ALS sensor * @{ * * \file - * Header file for the cc2538dk ADC Driver + * Header file for the cc2538dk ALS Driver */ -#ifndef ADC_SENSOR_H_ -#define ADC_SENSOR_H_ +#ifndef ALS_SENSOR_H_ +#define ALS_SENSOR_H_ #include "lib/sensors.h" /*---------------------------------------------------------------------------*/ -/** \name ADC sensors +/** \name ALS sensor * @{ */ -#define ADC_SENSOR "ADC" - -#define ADC_SENSOR_VDD_3 0 /**< On-chip VDD / 3 */ -#define ADC_SENSOR_TEMP 1 /**< On-chip temperature */ -#define ADC_SENSOR_ALS 2 /**< Ambient light sensor */ +#define ALS_SENSOR "ALS" /** @} */ -extern const struct sensors_sensor adc_sensor; +extern const struct sensors_sensor als_sensor; -#endif /* ADC_SENSOR_H_ */ +#endif /* ALS_SENSOR_H_ */ /** * @}