Contiki-NG
als-sensor.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, University of Bristol - http://www.bris.ac.uk/
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup srf06-common-peripherals
33 * @{
34 *
35 * \file
36 * Driver for the SmartRF06EB ALS when a CC13xx/CC26xxEM is mounted on it
37 */
38/*---------------------------------------------------------------------------*/
39#include "contiki.h"
40#include "lib/sensors.h"
41#include "srf06/als-sensor.h"
42#include "sys/timer.h"
43#include "dev/adc-sensor.h"
44#include "dev/aux-ctrl.h"
45
46#include "ti-lib.h"
47
48#include <stdint.h>
49/*---------------------------------------------------------------------------*/
50static aux_consumer_module_t als_aux = {
51 .clocks = AUX_WUC_ADI_CLOCK | AUX_WUC_ANAIF_CLOCK | AUX_WUC_SMPH_CLOCK
52};
53/*---------------------------------------------------------------------------*/
54static int
55config(int type, int enable)
56{
57 switch(type) {
58 case SENSORS_HW_INIT:
59 ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR);
60 break;
61 case SENSORS_ACTIVE:
62 ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR);
63 ti_lib_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO,
64 IOC_STD_OUTPUT);
65 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT);
66
67 if(enable) {
68 ti_lib_gpio_set_dio(BOARD_IOID_ALS_PWR);
70 ti_lib_aux_adc_select_input(ADC_COMPB_IN_AUXIO7);
71 clock_delay_usec(2000);
72 } else {
73 ti_lib_gpio_clear_dio(BOARD_IOID_ALS_PWR);
75 }
76 break;
77 default:
78 break;
79 }
80 return 1;
81}
82/*---------------------------------------------------------------------------*/
83static int
84value(int type)
85{
86 int val;
87
88 ti_lib_aux_adc_enable_sync(AUXADC_REF_VDDS_REL, AUXADC_SAMPLE_TIME_2P7_US,
89 AUXADC_TRIGGER_MANUAL);
90 ti_lib_aux_adc_gen_manual_trigger();
91 val = ti_lib_aux_adc_read_fifo();
92 ti_lib_aux_adc_disable();
93
94 return val;
95}
96/*---------------------------------------------------------------------------*/
97static int
98status(int type)
99{
100 return 1;
101}
102/*---------------------------------------------------------------------------*/
103SENSORS_SENSOR(als_sensor, ALS_SENSOR, value, config, status);
104/*---------------------------------------------------------------------------*/
105/** @} */
Header file for the CC13xx/CC26xx ADC driver.
Header file for the management of the CC13xx/CC26xx AUX domain.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definition: clock.c:150
const struct sensors_sensor als_sensor
Exports a global symbol to be used by the sensor API.
void aux_ctrl_unregister_consumer(aux_consumer_module_t *consumer)
Deregister a module that no longer requires access to the AUX power domain.
Definition: aux-ctrl.c:61
void aux_ctrl_register_consumer(aux_consumer_module_t *consumer)
Register a module that no longer requires access to the AUX power domain.
Definition: aux-ctrl.c:44
The data structure to be used for modules that require access to AUX.
Definition: aux-ctrl.h:62
Header file with macros which rename TI CC26xxware functions.
Timer library header file.