Contiki-NG
adc-zoul.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Zolertia - http://www.zolertia.com
3 * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32/*---------------------------------------------------------------------------*/
33/**
34 * \addtogroup zoul-sensors
35 * @{
36 *
37 * \defgroup zoul-adc-interface Zoul Generic ADC interface
38 *
39 * Driver for the Zoul ADC interface
40 *
41 * This driver supports analogue sensors connected to ADC1, ADC2, ADC3,
42 * ADC4, ADC5 and ADC6 inputs. ADC6 is shared with the user button, so disable
43 * user button if ADC6 is needed.
44 * This is controlled by the type argument of the value() function. Possible
45 * choices are:
46 *
47 * - ZOUL_SENSORS_ADC1
48 * - ZOUL_SENSORS_ADC2
49 * - ZOUL_SENSORS_ADC3
50 * - ZOUL_SENSORS_ADC4
51 * - ZOUL_SENSORS_ADC5
52 * - ZOUL_SENSORS_ADC6
53 *
54 * To initialize the ADC sensors use the configure() function, using as first
55 * argument SENSORS_HW_INIT, and choose which ADC channels to enable passing as
56 * second argument any single or combined (sum) values as below:
57 *
58 * - Either use multiple values (i.e ZOUL_SENSORS_ADC1 + ZOUL_SENSORS_ADC2)
59 * - ZOUL_SENSORS_ADC_ALL (all channels above)
60 *
61 * Using an invalid combination will return ZOUL_SENSORS_ERROR.
62 *
63 * The decimation rate can be set by passing
64 * ZOUL_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE as the type argument to the
65 * configure() function and then specifying the rate through the value
66 * argument. Valid values are:
67 *
68 * - SOC_ADC_ADCCON_DIV_64 (64 bit rate)
69 * - SOC_ADC_ADCCON_DIV_128 (128 bit rate)
70 * - SOC_ADC_ADCCON_DIV_256 (256 bit rate)
71 * - SOC_ADC_ADCCON_DIV_512 (512 bit rate)
72 * @{
73 *
74 * \file
75 * Header file for the Zoul ADC interface
76 */
77/*---------------------------------------------------------------------------*/
78#ifndef ADC_ZOUL_H_
79#define ADC_ZOUL_H_
80/*---------------------------------------------------------------------------*/
81#include "lib/sensors.h"
82#include "dev/soc-adc.h"
83/*---------------------------------------------------------------------------*/
84/**
85 * \name Generic ADC sensors
86 * @{
87 */
88#define ADC_ZOUL "ADC sensor interface"
89#define ADC_SENSORS_PORT_BASE GPIO_PORT_TO_BASE(ADC_SENSORS_PORT)
90
91#ifdef ADC_SENSORS_CONF_REFERENCE
92#define ADC_SENSORS_REFERENCE ADC_SENSORS_CONF_REFERENCE
93#else
94#define ADC_SENSORS_REFERENCE SOC_ADC_ADCCON_REF_AVDD5
95#endif
96
97/*
98 * PA0-PA3 are hardcoded to UART0 and the user button for most Zolertia
99 * platforms, the following assumes PA0-1 shall not be used as ADC input, else
100 * re-write the below definitions
101 */
102#define ZOUL_SENSORS_ADC_MIN 2 /**< PA1 pin mask */
103
104/* ADC phidget-like connector ADC1 */
105#if ADC_SENSORS_ADC1_PIN >= ZOUL_SENSORS_ADC_MIN
106#define ZOUL_SENSORS_ADC1 GPIO_PIN_MASK(ADC_SENSORS_ADC1_PIN)
107#else
108#define ZOUL_SENSORS_ADC1 0
109#endif
110/* ADC phidget-like connector ADC2 */
111#if ADC_SENSORS_ADC2_PIN >= ZOUL_SENSORS_ADC_MIN
112#define ZOUL_SENSORS_ADC2 GPIO_PIN_MASK(ADC_SENSORS_ADC2_PIN)
113#else
114#define ZOUL_SENSORS_ADC2 0
115#endif
116/* ADC phidget-like connector ADC3 */
117#if ADC_SENSORS_ADC3_PIN >= ZOUL_SENSORS_ADC_MIN
118#define ZOUL_SENSORS_ADC3 GPIO_PIN_MASK(ADC_SENSORS_ADC3_PIN)
119#else
120#define ZOUL_SENSORS_ADC3 0
121#endif
122/* ADC phidget-like connector ADC4 */
123#if ADC_SENSORS_ADC4_PIN >= ZOUL_SENSORS_ADC_MIN
124#define ZOUL_SENSORS_ADC4 GPIO_PIN_MASK(ADC_SENSORS_ADC4_PIN)
125#else
126#define ZOUL_SENSORS_ADC4 0
127#endif
128/* ADC phidget-like connector ADC5 */
129#if ADC_SENSORS_ADC5_PIN >= ZOUL_SENSORS_ADC_MIN
130#define ZOUL_SENSORS_ADC5 GPIO_PIN_MASK(ADC_SENSORS_ADC5_PIN)
131#else
132#define ZOUL_SENSORS_ADC5 0
133#endif
134
135/* ADC phidget-like connector ADC6 */
136#if ADC_SENSORS_ADC6_PIN >= ZOUL_SENSORS_ADC_MIN
137#define ZOUL_SENSORS_ADC6 GPIO_PIN_MASK(ADC_SENSORS_ADC6_PIN)
138#else
139#define ZOUL_SENSORS_ADC6 0
140#endif
141/*
142 * This is safe as the disabled sensors should have a zero value thus not
143 * affecting the mask operations
144 */
145#define ZOUL_SENSORS_ADC_ALL (ZOUL_SENSORS_ADC1 + ZOUL_SENSORS_ADC2 + \
146 ZOUL_SENSORS_ADC3 + ZOUL_SENSORS_ADC4 + \
147 ZOUL_SENSORS_ADC5 + ZOUL_SENSORS_ADC6)
148/** @} */
149/*---------------------------------------------------------------------------*/
150extern const struct sensors_sensor adc_zoul;
151/*---------------------------------------------------------------------------*/
152#endif /* ADC_ZOUL_H_ */
153/*---------------------------------------------------------------------------*/
154/**
155 * @}
156 * @}
157 */
158
Header file with register declarations for the cc2538 ADC and H/W RNG.