Add ALS support for Srf06 + CC13xx/CC26xxEM

This provides an example on how to use the CC13xx / CC26xx ADC
This commit is contained in:
George Oikonomou 2016-05-28 19:40:35 +01:00
parent 487547d8af
commit 2ec9c8ccf0
6 changed files with 170 additions and 9 deletions

View file

@ -3,6 +3,7 @@ CFLAGS += -DBOARD_SMARTRF06EB=1
CONTIKI_TARGET_DIRS += srf06
BOARD_SOURCEFILES += leds-arch.c srf06-sensors.c button-sensor.c board.c
BOARD_SOURCEFILES += als-sensor.c
PYTHON = python
BSL_FLAGS += -e -w -v

View file

@ -0,0 +1,105 @@
/*
* Copyright (c) 2016, University of Bristol - http://www.bris.ac.uk/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup srf06-common-peripherals
* @{
*
* \file
* Driver for the SmartRF06EB ALS when a CC13xx/CC26xxEM is mounted on it
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "lib/sensors.h"
#include "srf06/als-sensor.h"
#include "sys/timer.h"
#include "dev/adc-sensor.h"
#include "dev/aux-ctrl.h"
#include "ti-lib.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
static aux_consumer_module_t als_aux = {
.clocks = AUX_WUC_ADI_CLOCK | AUX_WUC_ANAIF_CLOCK | AUX_WUC_SMPH_CLOCK
};
/*---------------------------------------------------------------------------*/
static int
config(int type, int enable)
{
switch(type) {
case SENSORS_HW_INIT:
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR);
break;
case SENSORS_ACTIVE:
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR);
ti_lib_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO,
IOC_STD_OUTPUT);
ti_lib_gpio_dir_mode_set(BOARD_ALS_OUT, GPIO_DIR_MODE_IN);
if(enable) {
ti_lib_gpio_pin_write(BOARD_ALS_PWR, 1);
aux_ctrl_register_consumer(&als_aux);
ti_lib_aux_adc_select_input(ADC_COMPB_IN_AUXIO7);
clock_delay_usec(2000);
} else {
ti_lib_gpio_pin_write(BOARD_ALS_PWR, 0);
aux_ctrl_unregister_consumer(&als_aux);
}
break;
default:
break;
}
return 1;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
int val;
ti_lib_aux_adc_enable_sync(AUXADC_REF_VDDS_REL, AUXADC_SAMPLE_TIME_2P7_US,
AUXADC_TRIGGER_MANUAL);
ti_lib_aux_adc_gen_manual_trigger();
val = ti_lib_aux_adc_read_fifo();
ti_lib_aux_adc_disable();
return val;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 1;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(als_sensor, ALS_SENSOR, value, config, status);
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2016, University of Bristol - http://www.bris.ac.uk/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup srf06-common-peripherals
* @{
*
* \file
* Header file for the SmartRF06EB + CC13xx/CC26xxEM ALS Driver
*/
/*---------------------------------------------------------------------------*/
#ifndef ALS_SENSOR_H_
#define ALS_SENSOR_H_
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
/*---------------------------------------------------------------------------*/
#define ALS_SENSOR "ALS"
/*---------------------------------------------------------------------------*/
extern const struct sensors_sensor als_sensor;
/*---------------------------------------------------------------------------*/
#endif /* ALS_SENSOR_H_ */
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -45,7 +45,7 @@
#ifndef BOARD_PERIPHERALS_H_
#define BOARD_PERIPHERALS_H_
/*---------------------------------------------------------------------------*/
/* ToDo: Include things here */
#include "als-sensor.h"
/*---------------------------------------------------------------------------*/
#endif /* BOARD_PERIPHERALS_H_ */
/*---------------------------------------------------------------------------*/

View file

@ -46,6 +46,16 @@
#include <string.h>
/*---------------------------------------------------------------------------*/
static void
lpm_handler(uint8_t mode)
{
/* Ambient light sensor (off, output low) */
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR);
ti_lib_gpio_pin_write(BOARD_ALS_PWR, 0);
ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT);
ti_lib_ioc_io_port_pull_set(BOARD_IOID_ALS_OUT, IOC_NO_IOPULL);
}
/*---------------------------------------------------------------------------*/
static void
wakeup_handler(void)
{
/* Turn on the PERIPH PD */
@ -60,7 +70,7 @@ wakeup_handler(void)
* getting notified before deep sleep. All we need is to be notified when we
* wake up so we can turn power domains back on
*/
LPM_MODULE(srf_module, NULL, NULL, wakeup_handler, LPM_DOMAIN_NONE);
LPM_MODULE(srf_module, NULL, lpm_handler, wakeup_handler, LPM_DOMAIN_NONE);
/*---------------------------------------------------------------------------*/
static void
configure_unused_pins(void)
@ -72,12 +82,6 @@ configure_unused_pins(void)
/* Accelerometer (PWR output low, CSn output, high) */
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ACC_PWR);
ti_lib_gpio_pin_write(BOARD_ACC_PWR, 0);
/* Ambient light sensor (off, output low) */
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR);
ti_lib_gpio_pin_write(BOARD_ALS_PWR, 0);
ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT);
ti_lib_ioc_io_port_pull_set(BOARD_IOID_ALS_OUT, IOC_NO_IOPULL);
}
/*---------------------------------------------------------------------------*/
void

View file

@ -39,11 +39,12 @@
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "srf06/button-sensor.h"
#include "srf06/als-sensor.h"
#include <string.h>
/*---------------------------------------------------------------------------*/
/** \brief Exports a global symbol to be used by the sensor API */
SENSORS(&button_select_sensor, &button_left_sensor, &button_right_sensor,
&button_up_sensor, &button_down_sensor);
&button_up_sensor, &button_down_sensor, &als_sensor);
/*---------------------------------------------------------------------------*/
/** @} */