Re-work the CC2538 driver to be a driver for the Srf06 ALS only

This commit is contained in:
George Oikonomou 2015-02-11 18:06:05 +01:00 committed by George Oikonomou
parent 06b0ee4a8b
commit 3717522680
4 changed files with 22 additions and 42 deletions

View File

@ -40,7 +40,6 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include "contiki.h" #include "contiki.h"
#include "lib/sensors.h" #include "lib/sensors.h"
#include "dev/temp-sensor.h"
#include "dev/adc.h" #include "dev/adc.h"
#include "dev/cc2538-sensors.h" #include "dev/cc2538-sensors.h"
@ -73,6 +72,6 @@ status(int type)
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(temp_sensor, TEMP_SENSOR, value, configure, status); SENSORS_SENSOR(cc2538_temp_sensor, TEMP_SENSOR, value, configure, status);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View File

@ -49,8 +49,8 @@
* Header file for the CC2538 on-chip temperature Sensor Driver * Header file for the CC2538 on-chip temperature Sensor Driver
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifndef TEMP_SENSOR_H_ #ifndef CC2538_TEMP_SENSOR_H_
#define TEMP_SENSOR_H_ #define CC2538_TEMP_SENSOR_H_
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include "lib/sensors.h" #include "lib/sensors.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -61,9 +61,9 @@
#define TEMP_SENSOR "On-Chip Temperature" #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_ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* @} * @}

View File

@ -30,18 +30,18 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
* \addtogroup cc2538dk-adc-sensor * \addtogroup cc2538dk-als-sensor
* @{ * @{
* *
* \file * \file
* Driver for the SmartRF06EB ADC * Driver for the SmartRF06EB ALS
*/ */
#include "contiki.h" #include "contiki.h"
#include "sys/clock.h" #include "sys/clock.h"
#include "dev/ioc.h" #include "dev/ioc.h"
#include "dev/gpio.h" #include "dev/gpio.h"
#include "dev/adc.h" #include "dev/adc.h"
#include "dev/adc-sensor.h" #include "dev/als-sensor.h"
#include <stdint.h> #include <stdint.h>
@ -52,30 +52,15 @@
static int static int
value(int type) value(int type)
{ {
uint8_t channel; uint8_t channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_ALS_OUT_PIN;
int16_t res; int16_t res;
switch(type) { GPIO_SET_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK);
case ADC_SENSOR_VDD_3: clock_delay_usec(2000);
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;
}
res = adc_get(channel, SOC_ADC_ADCCON_REF_INT, SOC_ADC_ADCCON_DIV_512); 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; return res;
} }
@ -106,6 +91,6 @@ status(int type)
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(adc_sensor, ADC_SENSOR, value, configure, status); SENSORS_SENSOR(als_sensor, ALS_SENSOR, value, configure, status);
/** @} */ /** @} */

View File

@ -33,33 +33,29 @@
* \addtogroup cc2538-smartrf-sensors * \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 * \file
* Header file for the cc2538dk ADC Driver * Header file for the cc2538dk ALS Driver
*/ */
#ifndef ADC_SENSOR_H_ #ifndef ALS_SENSOR_H_
#define ADC_SENSOR_H_ #define ALS_SENSOR_H_
#include "lib/sensors.h" #include "lib/sensors.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** \name ADC sensors /** \name ALS sensor
* @{ * @{
*/ */
#define ADC_SENSOR "ADC" #define ALS_SENSOR "ALS"
#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 */
/** @} */ /** @} */
extern const struct sensors_sensor adc_sensor; extern const struct sensors_sensor als_sensor;
#endif /* ADC_SENSOR_H_ */ #endif /* ALS_SENSOR_H_ */
/** /**
* @} * @}