Zolertia Re-Mote platform ported to Contiki, developed whitin RERUM FP7 European project (grant #609094).

The port was done jointly by Zolertia and George Oikonomou (University of Bristol).
This commit is contained in:
Antonio Lignan 2015-02-04 22:13:44 +01:00
parent 2cee62eb33
commit 330e450ba4
33 changed files with 4002 additions and 0 deletions

View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 2015, Zolertia
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-antenna
* @{
*
* Driver for the Re-Mote 2.4Ghz antenna switch, to enable either the internal
* ceramic antenna or an external one connected to the uFL connector
* @{
*
* \file
* Driver for the Re-Mote 2.4Ghz antenna switch
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/gpio.h"
#include "antenna-sw.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define ANTENNA_2_4GHZ_SW_PORT_BASE GPIO_PORT_TO_BASE(ANTENNA_2_4GHZ_SW_PORT)
#define ANTENNA_2_4GHZ_SW_PIN_MASK GPIO_PIN_MASK(ANTENNA_2_4GHZ_SW_PIN)
/*---------------------------------------------------------------------------*/
static uint8_t initialized = 0;
/*---------------------------------------------------------------------------*/
void
antenna_sw_config(void)
{
/* Software controlled */
GPIO_SOFTWARE_CONTROL(ANTENNA_2_4GHZ_SW_PORT_BASE,
ANTENNA_2_4GHZ_SW_PIN_MASK);
/* Set pin to output */
GPIO_SET_OUTPUT(ANTENNA_2_4GHZ_SW_PORT_BASE, ANTENNA_2_4GHZ_SW_PIN_MASK);
/* Set the antenna selector to a default position */
GPIO_CLR_PIN(ANTENNA_2_4GHZ_SW_PORT_BASE, ANTENNA_2_4GHZ_SW_PIN_MASK);
initialized = 1;
}
/*---------------------------------------------------------------------------*/
int
antenna_sw_select(uint8_t val)
{
if(!initialized) {
return ANTENNA_SW_SELECT_ERROR;
}
if(val != ANTENNA_SW_SELECT_INTERNAL && val != ANTENNA_SW_SELECT_EXTERNAL) {
return ANTENNA_SW_SELECT_ERROR;
}
/* Set the antenna selector */
GPIO_WRITE_PIN(ANTENNA_2_4GHZ_SW_PORT_BASE, ANTENNA_2_4GHZ_SW_PIN_MASK, val);
return val;
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2015, Zolertia
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote
* @{
*
* \defgroup remote-antenna Re-Mote Antenna switch
*
* Driver for the Re-Mote 2.4Ghz antenna switch, to enable either the internal
* ceramic antenna or an external one connected to the uFL connector
* @{
*
* \file
* Header file for the Re-Mote 2.4Ghz antenna switch Driver
*/
/* -------------------------------------------------------------------------- */
#ifndef ANTENNA_SW_H_
#define ANTENNA_SW_H_
/* -------------------------------------------------------------------------- */
#include <stdint.h>
/* -------------------------------------------------------------------------- */
#define ANTENNA_SW_SELECT_EXTERNAL 0xFF
#define ANTENNA_SW_SELECT_INTERNAL 0x00
#define ANTENNA_SW_SELECT_ERROR -1
/* -------------------------------------------------------------------------- */
/**
* \brief Init function for the antenna switch
*
* The Re-Mote platform allows to programatically select between the 2.4Ghz
* internal or external antenna.
* The function is set to enable using the internal ceramic antenna as default,
* it should be called from the contiki-main initialization process.
*
* \return ignored
*/
void antenna_sw_config(void);
/**
* \brief Function to select between the internal or external 2.4Ghz antenna
*
* \param val Select antenna.
* External: ANTENNA_SW_SELECT_EXTERNAL or
* Internal (ceramic): ANTENNA_SW_SELECT_INTERNAL
* \return the selected antenna position, or ANTENNA_SW_SELECT_ERROR if not
* previously configured
*/
int antenna_sw_select(uint8_t val);
/* -------------------------------------------------------------------------- */
#endif /* ifndef ANTENNA_SW_H_ */
/* -------------------------------------------------------------------------- */
/**
* @}
* @}
*/

278
platform/remote/dev/board.h Normal file
View file

@ -0,0 +1,278 @@
/*
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
* 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 remote
* @{
*
* \defgroup remote-peripherals Re-Mote Peripherals
*
* Defines related to the Re-Mote
*
* This file provides connectivity information on LEDs, Buttons, UART and
* other Re-Mote peripherals
*
* This file can be used as the basis to configure other platforms using the
* cc2538 SoC.
* @{
*
* \file
* Header file with definitions related to the I/O connections on the Zolertia's
* Re-Mote platform, cc2538-based
*
* \note Do not include this file directly. It gets included by contiki-conf
* after all relevant directives have been set.
*/
#ifndef BOARD_H_
#define BOARD_H_
#include "dev/gpio.h"
#include "dev/nvic.h"
/*---------------------------------------------------------------------------*/
/** \name Re-Mote LED configuration
*
* LEDs on the Re-mote are connected as follows:
* - LED1 (Red) -> PD2
* - LED2 (Blue) -> PC3
* - LED3 (Green) -> PD5
*
* LED1 routed also to JP5 connector
* LED2 shares the same pin with Watchdog WDI pulse and routed to JP8 connector
* LED3 routed also to JP5 connector
* @{
*/
/*---------------------------------------------------------------------------*/
/* Some files include leds.h before us, so we need to get rid of defaults in
* leds.h before we provide correct definitions */
#undef LEDS_GREEN
#undef LEDS_YELLOW
#undef LEDS_BLUE
#undef LEDS_RED
#undef LEDS_CONF_ALL
/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */
#define LEDS_GREEN 1 /**< LED1 (Green) -> PD5 */
#define LEDS_BLUE 2 /**< LED2 (Blue) -> PC3 */
#define LEDS_RED 4 /**< LED3 (Red) -> PD2 */
#define LEDS_CONF_ALL 7
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (3) */
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (5) */
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (6) */
#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (7) */
/* Notify various examples that we have LEDs */
#define PLATFORM_HAS_LEDS 1
/** @} */
/*---------------------------------------------------------------------------*/
/** \name USB configuration
*
* The USB pullup is enabled by an external resistor, not mapped to a GPIO
*/
#ifdef USB_PULLUP_PORT
#undef USB_PULLUP_PORT
#endif
#ifdef USB_PULLUP_PIN
#undef USB_PULLUP_PIN
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/** \name UART configuration
*
* On the Re-Mote, the UART is connected to the following ports/pins
* - UART0:
* - RX: PA0
* - TX: PA1
* - UART1:
* - RX: PC6
* - TX: PC5
* - CTS:
* - RTS:
* We configure the port to use UART0 and UART1, CTS/RTS only for UART1,
* both without a HW pull-up resistor
* @{
*/
#define UART0_RX_PORT GPIO_A_NUM
#define UART0_RX_PIN 0
#define UART0_TX_PORT GPIO_A_NUM
#define UART0_TX_PIN 1
#define UART1_RX_PORT GPIO_C_NUM
#define UART1_RX_PIN 6
#define UART1_TX_PORT GPIO_C_NUM
#define UART1_TX_PIN 5
#define UART1_CTS_PORT GPIO_C_NUM
#define UART1_CTS_PIN 1
#define UART1_RTS_PORT GPIO_C_NUM
#define UART1_RTS_PIN 2
/** @} */
/*---------------------------------------------------------------------------*/
/** \name Re-Mote Button configuration
*
* Buttons on the Re-Mote are connected as follows:
* - BUTTON_USER -> PA3, S1 user button, shared with bootloader
* - BUTTON_RESET -> RESET_N line, S2 reset both CC2538 and CoP
* - BUTTON_VBAT -> Power switch, not mounted by default
* @{
*/
/** BUTTON_USER -> PA3 */
#define BUTTON_USER_PORT GPIO_A_NUM
#define BUTTON_USER_PIN 3
#define BUTTON_USER_VECTOR NVIC_INT_GPIO_PORT_A
/* Notify various examples that we have Buttons */
#define PLATFORM_HAS_BUTTON 1
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name ADC configuration
*
* These values configure which CC2538 pins and ADC channels to use for the ADC
* inputs. By default the Re-Mote allows two out-of-the-box ADC ports with a
* phidget-like 3-pin connector (GND/3V3/ADC)
*
* ADC inputs can only be on port A.
* @{
*/
#define ADC_PHIDGET_PORT GPIO_A_NUM /**< Phidget GPIO control port */
#define ADC_PHIDGET_ADC2_PIN 6 /**< ADC2 to PA6, 3V3 */
#define ADC_PHIDGET_ADC3_PIN 7 /**< ADC3 to PA7, 3V3 */
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name SPI (SSI0) configuration
*
* These values configure which CC2538 pins to use for the SPI (SSI0) lines,
* shared with the CC1120 RF transceiver
* TX -> MOSI, RX -> MISO
* @{
*/
#define SPI0_CLK_PORT GPIO_D_NUM
#define SPI0_CLK_PIN 1
#define SPI0_TX_PORT GPIO_D_NUM
#define SPI0_TX_PIN 0
#define SPI0_RX_PORT GPIO_C_NUM
#define SPI0_RX_PIN 4
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name SPI (SSI1) configuration
*
* These values configure which CC2538 pins to use for the SPI (SSI1) lines,
* shared with the microSD, not routed anywhere.
* TX -> MOSI, RX -> MISO
* @{
*/
#define SPI1_CLK_PORT GPIO_B_NUM
#define SPI1_CLK_PIN 5
#define SPI1_TX_PORT GPIO_C_NUM
#define SPI1_TX_PIN 7
#define SPI1_RX_PORT GPIO_A_NUM
#define SPI1_RX_PIN 4
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name I2C configuration
*
* These values configure which CC2538 pins to use for the I2C lines, shared
* with the TMP102 built-in temperature sensor
* @{
*/
#define I2C_SCL_PORT GPIO_B_NUM
#define I2C_SCL_PIN 1
#define I2C_SDA_PORT GPIO_B_NUM
#define I2C_SDA_PIN 0
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Antenna switch configuration
*
* These values configure the required pin to drive the antenna switch, to
* use either the built-in ceramic antenna or an external one over the uFL
* connector
* - Internal antenna: LOW
* - External antenna: HIGH
* @{
*/
#define ANTENNA_2_4GHZ_SW_PORT GPIO_D_NUM
#define ANTENNA_2_4GHZ_SW_PIN 4
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name CC1120/CC1200 configuration
*
* These values configure the required pins to drive the CC1120/CC1200
* @{
*/
#define CC1120_SPI_SCLK_PORT SPI0_CLK_PORT
#define CC1120_SPI_SCLK_PIN SPI0_CLK_PIN
#define CC1120_SPI_MOSI_PORT SPIO0_TX_PORT
#define CC1120_SPI_MOSI_PIN SPIO0_TX_PIN
#define CC1120_SPI_MISO_PORT SPIO0_RX_PORT
#define CC1120_SPI_MISO_PIN SPIO0_RX_PIN
#define CC1120_SPI_CSN_PORT GPIO_D_NUM
#define CC1120_SPI_CSN_PIN 3
#define CC1120_GDO0_PORT GPIO_B_NUM
#define CC1120_GDO0_PIN 4
#define CC1120_GDO2_PORT GPIO_B_NUM
#define CC1120_GDO2_PIN 3
#define CC1120_RESET_PORT GPIO_B_NUM
#define CC1120_RESET_PIN 2
#define CC1120_GPIO0_VECTOR NVIC_INT_GPIO_PORT_B
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name microSD configuration
*
* These values configure the required pins to drive the built-in microSD
* external module, to be used with SSI1
* @{
*/
#define USD_CLK_PORT SPI1_CLK_PORT
#define USD_CLK_PIN SPI1_CLK_PIN
#define USD_MOSI_PORT SPI1_TX_PORT
#define USD_MOSI_PIN SPI1_TX_PIN
#define USD_MISO_PORT SPI1_RX_PORT
#define USD_MISO_PIN SPI1_RX_PIN
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Device string used on startup
* @{
*/
#define BOARD_STRING "Zolertia Re-Mote platform"
/** @} */
#endif /* BOARD_H_ */
/**
* @}
* @}
*/

View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote-button-sensor
* @{
*
* \file
* Driver for the Re-Mote user button
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/nvic.h"
#include "dev/ioc.h"
#include "dev/gpio.h"
#include "dev/button-sensor.h"
#include "sys/timer.h"
#include "sys/ctimer.h"
#include "sys/process.h"
#include <stdint.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
#define BUTTON_USER_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_USER_PORT)
#define BUTTON_USER_PIN_MASK GPIO_PIN_MASK(BUTTON_USER_PIN)
/*---------------------------------------------------------------------------*/
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 4)
static struct timer debouncetimer;
/*---------------------------------------------------------------------------*/
static clock_time_t press_duration = 0;
static struct ctimer press_counter;
static uint8_t press_event_counter;
process_event_t button_press_duration_exceeded;
/*---------------------------------------------------------------------------*/
static void
duration_exceeded_callback(void *data)
{
press_event_counter++;
process_post(PROCESS_BROADCAST, button_press_duration_exceeded,
&press_event_counter);
ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
NULL);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Retrieves the value of the button pin
* \param type Returns the pin level or the counter of press duration events.
* type == BUTTON_SENSOR_VALUE_TYPE_LEVEL or
* type == BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION
* respectively
*/
static int
value(int type)
{
switch(type) {
case BUTTON_SENSOR_VALUE_TYPE_LEVEL:
return GPIO_READ_PIN(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
case BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION:
return press_event_counter;
}
return 0;
}
/*---------------------------------------------------------------------------*/
/**
* \brief Callback registered with the GPIO module. Gets fired with a button
* port/pin generates an interrupt
* \param port The port number that generated the interrupt
* \param pin The pin number that generated the interrupt. This is the pin
* absolute number (i.e. 0, 1, ..., 7), not a mask
*/
static void
btn_callback(uint8_t port, uint8_t pin)
{
if(!timer_expired(&debouncetimer)) {
return;
}
timer_set(&debouncetimer, DEBOUNCE_DURATION);
if(press_duration) {
press_event_counter = 0;
if(value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == BUTTON_SENSOR_PRESSED_LEVEL) {
ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
NULL);
} else {
ctimer_stop(&press_counter);
}
}
sensors_changed(&button_sensor);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Init function for the User button.
* \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
* or 0 respectively)
*
* \param value Depends on the value of the type argument
* \return Depends on the value of the type argument
*/
static int
config_user(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
button_press_duration_exceeded = process_alloc_event();
/* Software controlled */
GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
/* Set pin to input */
GPIO_SET_INPUT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
/* Enable edge detection */
GPIO_DETECT_EDGE(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
/* Both Edges */
GPIO_TRIGGER_BOTH_EDGES(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);
gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN);
break;
case SENSORS_ACTIVE:
if(value) {
GPIO_ENABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
nvic_interrupt_enable(BUTTON_USER_VECTOR);
} else {
GPIO_DISABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
nvic_interrupt_disable(BUTTON_USER_VECTOR);
}
return value;
case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL:
press_duration = (clock_time_t)value;
break;
default:
break;
}
return 1;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, config_user, NULL);
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote-sensors
* @{
*
* \defgroup remote-button-sensor Re-Mote User Button Driver
*
* Driver for the Re-Mote user button
*
* The Re-Mote button will generate a sensors_changed event on press as well
* as on release.
*
* Unlike many other platforms, the Re-Mote user button has the ability to
* generate events when the user keeps the button pressed. The user can
* configure the button driver with a timer interval in clock ticks. When the
* button is kept pressed, the driver will then generate a broadcast event
* each time the interval passes. For example the driver can be configured to
* generate an event every second while the button is kept pressed. This
* functionality can be enabled through the configure() function, by passing
* BUTTON_SENSOR_CONFIG_TYPE_INTERVAL as the type argument.
* @{
*
* \file
* Header file for the Re-Mote User Button Driver
*/
/*---------------------------------------------------------------------------*/
#ifndef BUTTON_SENSOR_H_
#define BUTTON_SENSOR_H_
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
/*---------------------------------------------------------------------------*/
#define BUTTON_SENSOR "Button"
extern const struct sensors_sensor button_sensor;
/*---------------------------------------------------------------------------*/
extern process_event_t button_press_duration_exceeded;
/*---------------------------------------------------------------------------*/
#define BUTTON_SENSOR_CONFIG_TYPE_INTERVAL 0x0100
#define BUTTON_SENSOR_VALUE_TYPE_LEVEL 0
#define BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION 1
#define BUTTON_SENSOR_PRESSED_LEVEL 0
#define BUTTON_SENSOR_RELEASED_LEVEL 8
/*---------------------------------------------------------------------------*/
#endif /* BUTTON_SENSOR_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 2015, Zolertia
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-led-strip
* @{
*
* Driver to control a bright LED strip powered at 3VDC, drawing power directly
* from the battery power supply. An example on how to adapt 12VDC LED strips
* to 3VDC is provided at http://www.hackster.io/zolertia
* @{
*
* \file
* Driver for the Re-Mote bright LED strip Driver
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/gpio.h"
#include "led-strip.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#ifndef LED_STRIP_PORT
#define LED_STRIP_PORT GPIO_A_NUM
#endif
#ifndef LED_STRIP_PIN
#define LED_STRIP_PIN 6
#endif
#define LED_STRIP_PORT_BASE GPIO_PORT_TO_BASE(LED_STRIP_PORT)
#define LED_STRIP_PIN_MASK GPIO_PIN_MASK(LED_STRIP_PIN)
/*---------------------------------------------------------------------------*/
static uint8_t initialized = 0;
/*---------------------------------------------------------------------------*/
void
led_strip_config(void)
{
/* Software controlled */
GPIO_SOFTWARE_CONTROL(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK);
/* Set pin to output */
GPIO_SET_OUTPUT(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK);
/* Set the antenna selector to a default position */
GPIO_SET_PIN(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK);
initialized = 1;
}
/*---------------------------------------------------------------------------*/
int
led_strip_switch(uint8_t val)
{
if(!initialized) {
return LED_STRIP_ERROR;
}
if(val != LED_STRIP_ON && val != LED_STRIP_OFF) {
return LED_STRIP_ERROR;
}
/* Set the LED to ON or OFF */
GPIO_WRITE_PIN(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK, val);
return val;
}
/*---------------------------------------------------------------------------*/
int
led_strip_get(void)
{
if(!initialized) {
return LED_STRIP_ERROR;
}
/* Inverse logic, return ON if the pin is low */
if(GPIO_READ_PIN(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK)) {
return LED_STRIP_OFF;
}
return LED_STRIP_ON;
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 2015, Zolertia
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-sensors
* @{
*
* \defgroup remote-led-strip Re-Mote LED strip driver
*
* Driver to control a bright LED strip powered at 3VDC, drawing power directly
* from the battery power supply. An example on how to adapt 12VDC LED strips
* to 3VDC is provided at http://www.hackster.io/zolertia
* @{
*
* \file
* Header file for the Re-Mote bright LED strip Driver
*/
/* -------------------------------------------------------------------------- */
#ifndef LED_STRIP_H_
#define LED_STRIP_H_
/* -------------------------------------------------------------------------- */
#include <stdint.h>
/* -------------------------------------------------------------------------- */
#define LED_STRIP_OFF 0xFF
#define LED_STRIP_ON 0x00
#define LED_STRIP_ERROR -1
/* -------------------------------------------------------------------------- */
/**
* \brief Init function for the bright LED strip driver
*
* The LED strip driver allows to lighten up any application using up to 4
* LEDs 3VDC-powered per strip
* The function is set to power OFF the LEDs as default,
* it should be called from the contiki-main initialization process.
*
* \return ignored
*/
void led_strip_config(void);
/**
* \brief Function to turn ON/OFF the LED strip
*
* \param val Set ON/OFF (LED_STRIP_ON or LED_STRIP_OFF)
* \return the selected antenna position, or LED_STRIP_ERROR if not
* previously configured
*/
int led_strip_switch(uint8_t val);
/**
* \brief Function to get the LED strip current state
*
* \return Current LED strip state or LED_STRIP_ERROR if not
* previously configured
*/
int led_strip_get(void);
/* -------------------------------------------------------------------------- */
#endif /* ifndef LED_STRIP_H_ */
/* -------------------------------------------------------------------------- */
/**
* @}
* @}
*/

View file

@ -0,0 +1,111 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote
* @{
*
* \defgroup remote-leds Re-Mote LED driver
*
* LED driver implementation for the Re-Mote platform
* @{
*
* \file
* LED driver implementation for the Re-Mote platform
*/
#include "contiki.h"
#include "reg.h"
#include "dev/leds.h"
#include "dev/gpio.h"
/*---------------------------------------------------------------------------*/
#define LED_GREEN_PORT GPIO_D_BASE
#define LED_GREEN_PIN (1 << 5)
#define LED_BLUE_PORT GPIO_C_BASE
#define LED_BLUE_PIN (1 << 3)
#define LED_RED_PORT GPIO_D_BASE
#define LED_RED_PIN (1 << 2)
#define PORT_D_LEDS (LED_RED_PIN | LED_GREEN_PIN)
#define PORT_C_LEDS LED_BLUE_PIN
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
/* Initialize LED1 (Red) and LED3 (Green) */
GPIO_SET_OUTPUT(GPIO_D_BASE, PORT_D_LEDS);
GPIO_SET_PIN(GPIO_D_BASE, PORT_D_LEDS);
/* Initialize LED2 - Blue */
GPIO_SET_OUTPUT(GPIO_C_BASE, PORT_C_LEDS);
GPIO_SET_PIN(GPIO_C_BASE, PORT_C_LEDS);
}
/*---------------------------------------------------------------------------*/
unsigned char
leds_arch_get(void)
{
uint8_t mask_leds;
mask_leds = GPIO_READ_PIN(LED_GREEN_PORT, LED_GREEN_PIN) == 0? LEDS_GREEN : 0;
mask_leds |= GPIO_READ_PIN(LED_BLUE_PORT, LED_BLUE_PIN) == 0? LEDS_BLUE : 0;
mask_leds |= GPIO_READ_PIN(LED_RED_PORT, LED_RED_PIN) == 0? LEDS_RED : 0;
return mask_leds;
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(unsigned char leds)
{
if(leds & LEDS_GREEN) {
GPIO_CLR_PIN(LED_GREEN_PORT, LED_GREEN_PIN);
} else {
GPIO_SET_PIN(LED_GREEN_PORT, LED_GREEN_PIN);
}
if(leds & LEDS_BLUE) {
GPIO_CLR_PIN(LED_BLUE_PORT, LED_BLUE_PIN);
} else {
GPIO_SET_PIN(LED_BLUE_PORT, LED_BLUE_PIN);
}
if(leds & LEDS_RED) {
GPIO_CLR_PIN(LED_RED_PORT, LED_RED_PIN);
} else {
GPIO_SET_PIN(LED_RED_PORT, LED_RED_PIN);
}
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,286 @@
/*
* Copyright (c) 2015, Zolertia
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-mp3-wtv020sd
* @{
*
* Driver to control the MP3 WTV020SD board in MP3 mode (GPIO based) and the
* 2-line serial mode (CLK/DI). Loop Mode and Key Modes not implemented.
* More product information available at:
* http://avrproject.ru/chasy-budilnik/WTV020SD.pdf
* An example on how to wire with a sound power amplifier and speakers at
* http://www.hackster.io/zolertia
* @{
*
* \file
* Header file for the MP3 WTV020SD driver
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/gpio.h"
#include "mp3-wtv020sd.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/*
* The WTV020SD can be used in MP3 mode (GPIO-controlled) or 2-line mode (CLK
* and DATA line). The following pin-out can be implemented without reusing
* the pins as below (in 2-line mode the CLK/DATA functions replace the VOL+/-
* keys, others remain the same), but this would require more GPIOs to
* interface all functions, so we chose the configuration that uses the less
* number of GPIOs, and emulate all functions available in each mode
*/
#ifndef MP3_WTV020SD_P07_PORT
#define MP3_WTV020SD_P07_PORT GPIO_B_NUM
#endif
#ifndef MP3_WTV020SD_P07_PIN
#define MP3_WTV020SD_P07_PIN 0
#endif
#ifndef MP3_WTV020SD_P02_PORT
#define MP3_WTV020SD_P02_PORT GPIO_B_NUM
#endif
#ifndef MP3_WTV020SD_P02_PIN
#define MP3_WTV020SD_P02_PIN 1
#endif
#ifndef MP3_WTV020SD_P06_PORT
#define MP3_WTV020SD_P06_PORT GPIO_C_NUM
#endif
#ifndef MP3_WTV020SD_P06_PIN
#define MP3_WTV020SD_P06_PIN 1
#endif
#ifndef MP3_WTV020SD_P04_PORT
#define MP3_WTV020SD_P04_PORT GPIO_B_NUM
#endif
#ifndef MP3_WTV020SD_P04_PIN
#define MP3_WTV020SD_P04_PIN 0
#endif
#ifndef MP3_WTV020SD_P05_PORT
#define MP3_WTV020SD_P05_PORT GPIO_B_NUM
#endif
#ifndef MP3_WTV020SD_P05_PIN
#define MP3_WTV020SD_P05_PIN 1
#endif
#ifndef MP3_WTV020SD_RESET_PORT
#define MP3_WTV020SD_RESET_PORT GPIO_B_NUM
#endif
#ifndef MP3_WTV020SD_RESET_PIN
#define MP3_WTV020SD_RESET_PIN 1
#endif
/* The BUSY pin is shared between operation modes */
#define MP3_BUSY_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P06_PORT)
#define MP3_BUSY_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P06_PIN)
#define MP3_PLAY_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P07_PORT)
#define MP3_PLAY_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P07_PIN)
#define MP3_NEXT_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P02_PORT)
#define MP3_NEXT_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P02_PIN)
#define MP3_RESET_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_RESET_PORT)
#define MP3_RESET_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_RESET_PIN)
#define MP3_CLK_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P04_PORT)
#define MP3_CLK_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P04_PIN)
#define MP3_DATA_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P05_PORT)
#define MP3_DATA_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P05_PIN)
/*---------------------------------------------------------------------------*/
static uint8_t initialized = 0;
static int mp3_line_command(uint16_t cmd);
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_config(uint8_t mode)
{
if(mode != MP3_WTV020SD_GPIO_MODE && mode != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
if(mode == MP3_WTV020SD_GPIO_MODE) {
GPIO_SOFTWARE_CONTROL(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
GPIO_SET_OUTPUT(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
GPIO_SOFTWARE_CONTROL(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
GPIO_SET_OUTPUT(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
GPIO_SET_PIN(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
} else {
GPIO_SOFTWARE_CONTROL(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
GPIO_SET_OUTPUT(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
GPIO_SOFTWARE_CONTROL(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
GPIO_SET_OUTPUT(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
GPIO_SOFTWARE_CONTROL(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
GPIO_SET_OUTPUT(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
GPIO_SET_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
}
GPIO_SOFTWARE_CONTROL(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK);
GPIO_SET_INPUT(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK);
initialized = mode;
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_gpio_play(void)
{
if(initialized != MP3_WTV020SD_GPIO_MODE) {
return MP3_WTV020SD_ERROR;
}
GPIO_CLR_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_gpio_stop(void)
{
if(initialized != MP3_WTV020SD_GPIO_MODE) {
return MP3_WTV020SD_ERROR;
}
GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_gpio_next(void)
{
if(initialized != MP3_WTV020SD_GPIO_MODE) {
return MP3_WTV020SD_ERROR;
}
GPIO_CLR_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
clock_delay_usec(MP3_USEC_DELAY);
GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_busy(void)
{
if((initialized != MP3_WTV020SD_GPIO_MODE) &&
(initialized != MP3_WTV020SD_LINE_MODE)) {
return MP3_WTV020SD_ERROR;
}
if(GPIO_READ_PIN(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK)) {
return MP3_WTV020SD_BUSY;
}
return MP3_WTV020SD_IDLE;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_reset(void)
{
if(initialized != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
GPIO_CLR_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
GPIO_CLR_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
clock_delay_usec(MP3_USEC_DELAY);
GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
clock_delay_usec(MP3_USEC_RESET_DELAY);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_sync_play(uint16_t track)
{
if(initialized != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
mp3_line_command(track);
while(mp3_wtv020sd_busy());
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_async_play(uint16_t track)
{
if(initialized != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
mp3_line_command(track);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_stop(void)
{
if(initialized != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
mp3_line_command(MP3_WTV020SD_STOP_VAL);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_pause(void)
{
if(initialized != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
mp3_line_command(MP3_WTV020SD_PLAY_PAUSE_VAL);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
int
mp3_line_command(uint16_t cmd)
{
uint16_t mask;
if(initialized != MP3_WTV020SD_LINE_MODE) {
return MP3_WTV020SD_ERROR;
}
GPIO_CLR_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
clock_delay_usec(MP3_USEC_CMD_DELAY / 10);
for(mask = 0x8000; mask > 0; mask >> 1) {
GPIO_CLR_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
clock_delay_usec(MP3_USEC_CMD_DELAY / 2);
if(cmd & mask) {
GPIO_SET_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
} else {
GPIO_CLR_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
}
clock_delay_usec(MP3_USEC_CMD_DELAY / 2);
GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
clock_delay_usec(MP3_USEC_CMD_DELAY);
if(mask > 0x0001) {
clock_delay_usec(MP3_USEC_CMD_DELAY / 10);
}
}
clock_delay_usec(MP3_USEC_CMD_DELAY / 8);
return MP3_WTV020SD_SUCCESS;
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,159 @@
/*
* Copyright (c) 2015, Zolertia
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-sensors
* @{
*
* \defgroup remote-mp3-wtv020sd Re-Mote MP3 WTV020SD driver
*
* Driver to control the MP3 WTV020SD board in MP3 mode (GPIO based) and the
* 2-line serial mode (CLK/DI). Loop Mode and Key Modes not implemented.
* More product information available at:
* http://avrproject.ru/chasy-budilnik/WTV020SD.pdf
* An example on how to wire with a sound power amplifier and speakers at
* http://www.hackster.io/zolertia
* Based on the Arduino Wtv020sd16p library
* @{
*
* \file
* Header file for the MP3 WTV020SD driver
*/
/* -------------------------------------------------------------------------- */
#ifndef MP3_WTV020SD_H_
#define MP3_WTV020SD_H_
/* -------------------------------------------------------------------------- */
#include <stdint.h>
/* -------------------------------------------------------------------------- */
#define MP3_WTV020SD_ERROR -1
#define MP3_WTV020SD_SUCCESS 0x00
#define MP3_WTV020SD_GPIO_MODE 0x01
#define MP3_WTV020SD_LINE_MODE 0x02
#define MP3_WTV020SD_IDLE 0x00
#define MP3_WTV020SD_BUSY 0x0F
/* -------------------------------------------------------------------------- */
#define MP3_WTV020SD_PLAY_PAUSE_VAL 0xFFFE
#define MP3_WTV020SD_STOP_VAL 0xFFFF
#define MP3_WTV020SD_VOLUME_MIN 0xFFF0
#define MP3_WTV020SD_VOLUME_MAX 0xFFF7
/* -------------------------------------------------------------------------- */
#define MP3_USEC_DELAY 1000
#define MP3_USEC_CMD_DELAY 100
#define MP3_USEC_RESET_DELAY ((MP3_USEC_DELAY) * 30)
/* -------------------------------------------------------------------------- */
#define MP3_TRACK_BASE 0 /* 0000.ad4 */
/* -------------------------------------------------------------------------- */
/**
* \brief Init function for the MP3 driver
*
* Configures the pins required to operate in either driver mode
*
* \param mode drive the board using GPIOs or the two-line mode, using
* either MP3_WTV020SD_GPIO_MODE or MP3_WTV020SD_LINE_MODE
* \return MP3_WTV020SD_ERROR if invalid mode selected, otherwise it
* will return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_config(uint8_t mode);
/**
* \brief Function to play a current track
*
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_gpio_play(void);
/**
* \brief Function to stop a current track
*
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_gpio_stop(void);
/**
* \brief Advances and play the next track, wraps over the playlist
*
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_gpio_next(void);
/**
* \brief Get the current status of the device (playing/stopped)
*
* \return MP3_WTV020SD_BUSY if a track is playing, otherwise it will
* return MP3_WTV020SD_IDLE
*/
int mp3_wtv020sd_busy(void);
/**
* \brief Trigger a module reset
*
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_reset(void);
/**
* \brief Plays the selected track and waits until it stops
*
* \param track forwards and play the selected track, starting from
* MP3_TRACK_BASE (0000.ad4) up to MP3_TRACK_BASE + 511
* (0511.ad4)
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_sync_play(uint16_t track);
/**
* \brief Plays the selected track and returns immediately
*
* \param track forwards and play the selected track, starting from
* MP3_TRACK_BASE (0000.ad4) up to MP3_TRACK_BASE + 511
* (0511.ad4)
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_async_play(uint16_t track);
/**
* \brief Stops the current track
*
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_stop(void);
/**
* \brief Pauses the current track
*
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
* return MP3_WTV020SD_SUCCESS
*/
int mp3_wtv020sd_pause(void);
/* -------------------------------------------------------------------------- */
#endif /* ifndef MP3_WTV020SD_H_ */
/* -------------------------------------------------------------------------- */
/**
* @}
* @}
*/

View file

@ -0,0 +1,125 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote-phidget-sensor
* @{
*
* \file
* Generic driver for the Re-Mote Phidget/ADC sensors
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/clock.h"
#include "dev/ioc.h"
#include "dev/gpio.h"
#include "dev/adc.h"
#include "dev/phidget-sensor.h"
#include "dev/remote-sensors.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define ADC_PHIDGET_PORT_BASE GPIO_PORT_TO_BASE(ADC_PHIDGET_PORT)
#define ADC_PHIDGET_ADC2_PIN_MASK GPIO_PIN_MASK(ADC_PHIDGET_ADC2_PIN)
#define ADC_PHIDGET_ADC3_PIN_MASK GPIO_PIN_MASK(ADC_PHIDGET_ADC3_PIN)
/*---------------------------------------------------------------------------*/
static uint8_t decimation_rate;
/*---------------------------------------------------------------------------*/
static int
set_decimation_rate(uint8_t rate)
{
switch(rate) {
case SOC_ADC_ADCCON_DIV_64:
case SOC_ADC_ADCCON_DIV_128:
case SOC_ADC_ADCCON_DIV_256:
case SOC_ADC_ADCCON_DIV_512:
decimation_rate = rate;
break;
default:
return REMOTE_SENSORS_ERROR;
}
return decimation_rate;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
uint8_t channel;
int16_t res;
switch(type) {
case PHIDGET_SENSORS_ADC2:
channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_PHIDGET_ADC2_PIN;
break;
case PHIDGET_SENSORS_ADC3:
channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_PHIDGET_ADC3_PIN;
break;
default:
return REMOTE_SENSORS_ERROR;
}
res = adc_get(channel, SOC_ADC_ADCCON_REF_INT, decimation_rate);
return res;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
GPIO_SOFTWARE_CONTROL(GPIO_A_BASE, ADC_PHIDGET_ADC2_PIN_MASK);
GPIO_SET_INPUT(GPIO_A_BASE, ADC_PHIDGET_ADC2_PIN_MASK);
ioc_set_over(GPIO_A_NUM, ADC_PHIDGET_ADC2_PIN, IOC_OVERRIDE_ANA);
GPIO_SOFTWARE_CONTROL(GPIO_A_BASE, ADC_PHIDGET_ADC3_PIN_MASK);
GPIO_SET_INPUT(GPIO_A_BASE, ADC_PHIDGET_ADC3_PIN_MASK);
ioc_set_over(GPIO_A_NUM, ADC_PHIDGET_ADC3_PIN, IOC_OVERRIDE_ANA);
adc_init();
set_decimation_rate(SOC_ADC_ADCCON_DIV_512);
break;
case REMOTE_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE:
return set_decimation_rate((uint8_t)value);
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 1;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(phidget_sensor, PHIDGET_SENSOR, value, configure, status);
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote-sensors
* @{
*
* \defgroup remote-phidget-sensor Re-Mote Generic Phidget Sensor
*
* Driver for the Re-Mote phidget ADC sensor
*
* This driver supports phidgets connected to both the ADC2 and AND3 channels.
* This is controlled by the type argument of the value() function. Possible
* choices are:
* - PHIDGET_SENSORS_ADC2 (channel 2)
* - PHIDGET_SENSORS_ADC3 (channel 3)
*
* The decimation rate can be set by passing
* REMOTE_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE as the type argument to the
* configure() function and then specifying the rate through the value
* argument. Valid values are:
* - SOC_ADC_ADCCON_DIV_64 (64 bit rate)
* - SOC_ADC_ADCCON_DIV_128 (128 bit rate)
* - SOC_ADC_ADCCON_DIV_256 (256 bit rate)
* - SOC_ADC_ADCCON_DIV_512 (512 bit rate)
* @{
*
* \file
* Header file for the Re-Mote Generic Driver for Phidget/ADC sensors
*/
/*---------------------------------------------------------------------------*/
#ifndef PHIDGET_SENSOR_H_
#define PHIDGET_SENSOR_H_
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
#include "dev/soc-adc.h"
/*---------------------------------------------------------------------------*/
/**
* \name Generic phidget sensor
* @{
*/
#define PHIDGET_SENSOR "Phidget ADC"
#define PHIDGET_SENSORS_ADC2 2 /**< 3V3 ADC phidget-like connector ADC2 */
#define PHIDGET_SENSORS_ADC3 3 /**< 3V3 ADC phidget-like connector ADC3 */
/** @} */
/*---------------------------------------------------------------------------*/
extern const struct sensors_sensor phidget_sensor;
/*---------------------------------------------------------------------------*/
#endif /* PHIDGET_SENSOR_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote-sensors
* @{
*
* Generic module controlling sensors on the Re-Mote platform
* @{
*
* \file
* Implementation of a generic module controlling Re-Mote sensors
*/
#include "contiki.h"
#include "dev/cc2538-sensors.h"
#include "dev/button-sensor.h"
#include "dev/phidget-sensor.h"
#include <string.h>
/*---------------------------------------------------------------------------*/
/* TODO: include the tmp102 sensor as well */
/*---------------------------------------------------------------------------*/
/** \brief Exports global symbols for the sensor API */
SENSORS(&button_sensor, &vdd3_sensor, &cc2538_temp_sensor, &phidget_sensor);
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.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 remote
* @{
*
* \defgroup remote-sensors Re-Mote Sensors
*
* Generic module controlling sensors on the Re-Mote platform
* @{
*
* \file
* Implementation of a generic module controlling Re-Mote sensors
*/
/*---------------------------------------------------------------------------*/
#ifndef REMOTE_SENSORS_H_
#define REMOTE_SENSORS_H_
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
#include "dev/cc2538-sensors.h"
#include "dev/button-sensor.h"
#include "dev/phidget-sensor.h"
/*---------------------------------------------------------------------------*/
/**
* \name ReMote sensor constants
*
* These constants are used by various sensors on the ReMote. They can be used
* to configure ADC decimation rate (where applicable).
* @{
*/
#define REMOTE_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE 0x0100 /**< Change decimation rate (used with configure()) */
#define REMOTE_SENSORS_ERROR CC2538_SENSORS_ERROR /**< Error */
/** @} */
/*---------------------------------------------------------------------------*/
#endif /* REMOTE_SENSORS_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

138
platform/remote/dev/sht25.c Normal file
View file

@ -0,0 +1,138 @@
/*
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup remote-sht25-sensor
* @{
*
* \file
* SHT25 temperature and humidity sensor driver
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/i2c.h"
#include "dev/sht25.h"
#include "lib/sensors.h"
/*---------------------------------------------------------------------------*/
#warning I2C SDA AND SCL are inverted in JP8 connector, inverted in init() call
/*---------------------------------------------------------------------------*/
static uint8_t enabled;
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
if(type != SENSORS_ACTIVE) {
return SHT25_ERROR;
}
if(value) {
i2c_init(I2C_SCL_PORT, I2C_SCL_PIN, I2C_SDA_PORT, I2C_SDA_PIN,
I2C_SCL_NORMAL_BUS_SPEED);
}
enabled = value;
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return enabled;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static uint16_t
sht25_read_reg(uint8_t reg, uint8_t *buf, uint8_t regNum)
{
if(i2c_single_send(SHT25_ADDR, reg) == I2C_MASTER_ERR_NONE) {
if(i2c_burst_receive(SHT25_ADDR, buf, regNum) == I2C_MASTER_ERR_NONE) {
return SHT25_SUCCESS;
}
}
return SHT25_ERROR;
}
/*---------------------------------------------------------------------------*/
static int16_t
sht25_convert(uint8_t variable, uint16_t value)
{
int16_t rd;
uint32_t buff;
buff = (uint32_t)value;
if(variable == SHT25_VAL_TEMP) {
buff *= 17572;
buff = buff >> 16;
rd = (int16_t)buff - 4685;
} else {
buff *= 12500;
buff = buff >> 16;
rd = (int16_t)buff - 600;
rd = (rd > 10000) ? 10000 : rd;
}
return rd;
}
/*---------------------------------------------------------------------------*/
static int16_t
sht25_read(uint8_t variable, uint16_t *rd)
{
uint8_t buf[2];
uint16_t raw;
if((variable != SHT25_VAL_TEMP) && (variable != SHT25_VAL_HUM)) {
return SHT25_ERROR;
}
if (sht25_read_reg(variable, buf, 2) == SHT25_SUCCESS){
raw = (buf[0] << 8) + buf[1];
*rd = sht25_convert(variable, raw);
return SHT25_SUCCESS;
}
return SHT25_ERROR;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
uint16_t val;
if (sht25_read(type, &val) == SHT25_SUCCESS){
return val;
}
return SHT25_ERROR;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(sht25, SHT25_SENSOR, value, configure, status);
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup remote-sensors
* @{
*
* \defgroup remote-sht25-sensor Re-Mote SHT25 digital temperature sensor
* @{
*
* \file
* SHT25 temperature and humidity sensor driver
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
#ifndef SHT25_H_
#define SHT25_H_
/* -------------------------------------------------------------------------- */
#define SHT25_ADDR 0x40
#define SHT25_TEMP_HOLD 0xE3
#define SHT25_HUM_HOLD 0xE5
#define SHT25_TEMP_NO_HOLD 0xF3
#define SHT25_HUM_NO_HOLD 0xF5
#define SHT2X_UREG_WRITE 0xE6
#define SHT2X_UREG_READ 0xE7
#define SHT2X_SOFT_RESET 0XFE
#define SHT2X_NULL 0x00
/* -------------------------------------------------------------------------- */
#define SHT2X_RES_14T_12RH 0x00
#define SHT2X_RES_12T_08RH 0x01
#define SHT2X_RES_13T_10RH 0x80
#define SHT2X_RES_11T_11RH 0x81
#define SHT2X_HEATER_ON 0x04
#define SHT2X_HEATER_OFF 0x00
#define SHT2X_OTP_RELOAD_EN 0x00
#define SHT2X_OTP_RELOAD_DIS 0x02
/* -------------------------------------------------------------------------- */
#define SHT25_VAL_TEMP SHT25_TEMP_HOLD
#define SHT25_VAL_HUM SHT25_HUM_HOLD
#define SHT25_ERROR -1
#define SHT25_SUCCESS 0x00
/* -------------------------------------------------------------------------- */
#define SHT25_SENSOR "SHT25 Sensor"
/* -------------------------------------------------------------------------- */
extern const struct sensors_sensor sht25;
/* -------------------------------------------------------------------------- */
#endif /* ifndef SHT25_H_ */
/**
* @}
* @}
*/

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-tmp102-sensor
* @{
*
* \file
* Driver for the Re-Mote TMP102 temperature sensor
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/i2c.h"
#include "tmp102.h"
void
tmp102_init(void)
{
i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);
}
/*---------------------------------------------------------------------------*/
uint8_t
tmp102_read(uint16_t *data)
{
uint8_t buf[2];
uint16_t temp;
/* Write to the temperature register to trigger a reading */
if(i2c_single_send(TMP102_ADDR, TMP102_TEMP) == I2C_MASTER_ERR_NONE) {
/* Read two bytes only */
if(i2c_burst_receive(TMP102_ADDR, buf, 2) == I2C_MASTER_ERR_NONE) {
temp = (buf[0] << 8) + buf[1];
if(temp > 2047) {
temp -= (1 << 12);
}
temp *= 0.625;
*data = temp;
return I2C_MASTER_ERR_NONE;
}
}
return i2c_master_error();
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup remote-sensors
* @{
*
* \defgroup remote-tmp102-sensor Re-Mote TMP102 Sensor
*
* Driver for the Re-Mote TMP102 sensor
*
* The TMP102 driver returns the converted temperature value in centiCelsius
* with 2 digits precision, to get Celsius just divide by 100.
* @{
*
* \file
* Header file for the Re-Mote TMP102 Sensor Driver
*/
/*---------------------------------------------------------------------------*/
#ifndef TMP102_H_
#define TMP102_H_
#include <stdio.h>
#include "i2c.h"
/* -------------------------------------------------------------------------- */
/**
* \name Generic TMP102 sensor
* @{
*/
/* -------------------------------------------------------------------------- */
#define TMP102_ADDR 0x48 /**< TMP102 slave address */
#define TMP102_TEMP 0x00 /**< TMP102 temperature data register */
/** @} */
/* -------------------------------------------------------------------------- */
#endif /* ifndef TMP102_H_ */
/*---------------------------------------------------------------------------*/
/** \brief Initialiser for the TMP102 sensor driver */
void tmp102_init(void);
/** \brief Get a temperature reading from the TMP102 sensor */
uint8_t tmp102_read(uint16_t *data);
/**
* @}
* @}
*/

View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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 remote-tsl2563-sensor
* @{
*
* \file
* Driver for the Re-Mote external TSL2563 light sensor (Ziglet)
*
* \author
* Antonio Lignan <alinan@zolertia.com>
* Toni Lozano <tlozano@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/i2c.h"
#include "lib/sensors.h"
#include "tsl2563.h"
/*---------------------------------------------------------------------------*/
#warning I2C SDA AND SCL are inverted in JP8 connector, inverted in init() call
/*---------------------------------------------------------------------------*/
static uint8_t enabled;
/*---------------------------------------------------------------------------*/
static uint16_t
calculateLux(uint8_t *buf)
{
uint32_t ch0, ch1 = 0;
uint32_t aux = (1 << 14);
uint32_t ratio, lratio, tmp = 0;
uint16_t buffer[2];
buffer[0] = (buf[1] << 8 | (buf[0]));
buffer[1] = (buf[3] << 8 | (buf[2]));
ch0 = (buffer[0] * aux) >> 10;
ch1 = (buffer[1] * aux) >> 10;
ratio = (ch1 << 10);
ratio = ratio / ch0;
lratio = (ratio + 1) >> 1;
if((lratio >= 0) && (lratio <= K1T)) {
tmp = (ch0 * B1T) - (ch1 * M1T);
} else if(lratio <= K2T) {
tmp = (ch0 * B2T) - (ch1 * M2T);
} else if(lratio <= K3T) {
tmp = (ch0 * B3T) - (ch1 * M3T);
} else if(lratio <= K4T) {
tmp = (ch0 * B4T) - (ch1 * M4T);
} else if(lratio <= K5T) {
tmp = (ch0 * B5T) - (ch1 * M5T);
} else if(lratio <= K6T) {
tmp = (ch0 * B6T) - (ch1 * M6T);
} else if(lratio <= K7T) {
tmp = (ch0 * B7T) - (ch1 * M7T);
} else if(lratio > K8T) {
tmp = (ch0 * B8T) - (ch1 * M8T);
}
if(tmp < 0) {
tmp = 0;
}
tmp += (1 << 13);
return tmp >> 14;
}
/*---------------------------------------------------------------------------*/
static int
tsl2563_read_reg(uint8_t reg, uint8_t *buf, uint8_t regNum)
{
if(i2c_single_send(TSL2563_ADDR, reg) == I2C_MASTER_ERR_NONE) {
if(i2c_burst_receive(TSL2563_ADDR, buf, regNum) == I2C_MASTER_ERR_NONE) {
return TSL2563_SUCCESS;
}
}
return TSL2563_ERROR;
}
/*---------------------------------------------------------------------------*/
static int
light_ziglet_on(void)
{
if(i2c_single_send(TSL2563_ADDR, (uint8_t)TSL2563_PWRN) == I2C_MASTER_ERR_NONE) {
return TSL2563_SUCCESS;
}
return TSL2563_ERROR;
}
/*---------------------------------------------------------------------------*/
static int
light_ziglet_off(void)
{
if(i2c_single_send(TSL2563_ADDR, (uint8_t)TSL2563_PWROFF) == I2C_MASTER_ERR_NONE) {
return TSL2563_SUCCESS;
}
return TSL2563_ERROR;
}
/*---------------------------------------------------------------------------*/
static int
light_ziglet_read(uint16_t *lux)
{
uint8_t buf[4];
if(light_ziglet_on() == TSL2563_SUCCESS) {
if(tsl2563_read_reg(TSL2563_READ, buf, 4) == TSL2563_SUCCESS) {
*lux = calculateLux(buf);
return light_ziglet_off();
}
}
return TSL2563_ERROR;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
if(type != SENSORS_ACTIVE) {
return TSL2563_ERROR;
}
enabled = value;
if(value) {
i2c_init(I2C_SCL_PORT, I2C_SCL_PIN, I2C_SDA_PORT, I2C_SDA_PIN,
I2C_SCL_NORMAL_BUS_SPEED);
} else {
light_ziglet_off();
}
return TSL2563_SUCCESS;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return enabled;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
uint16_t lux;
if(type == TSL2563_VAL_READ) {
if(light_ziglet_read(&lux) != TSL2563_ERROR) {
return lux;
}
}
return TSL2563_ERROR;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(tsl2563, TSL2563_SENSOR, value, configure, status);
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,111 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup remote-sensors
* @{
*
* \defgroup remote-tsl2563-sensor Re-Mote TSL2563 Sensor
*
* Driver for the Re-Mote TSL2563 sensor
*
* The TSL2563 driver returns the converted light value value in lux
* @{
*
* \file
* Header file for the Re-Mote external TSL2563 Sensor Driver
*
* \author
* Antonio Lignan <alinan@zolertia.com>
* Toni Lozano <tlozano@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#ifndef LIGHT_SENSOR_H_
#define LIGHT_SENSOR_H_
#include <stdio.h>
#include "lib/sensors.h"
#include "i2c.h"
/* -------------------------------------------------------------------------- */
/**
* \name TSL2563 digital Light sensor
* @{
*/
/* -------------------------------------------------------------------------- */
#define TSL2563_ADDR 0x39 /**< TSL2563 slave address */
/* -------------------------------------------------------------------------- */
#define TSL2563_READ 0xAC /**< TSL2563 read register */
#define TSL2563_PWRN 0x03 /**< TSL2563 enable register */
#define TSL2563_PWROFF 0x00 /**< TSL2563 Power OFF */
/* -------------------------------------------------------------------------- */
#define K1T 0X0040 /**< Calibration values (hardcoded) */
#define B1T 0x01f2
#define M1T 0x01b2
#define K2T 0x0080
#define B2T 0x0214
#define M2T 0x02d1
#define K3T 0x00c0
#define B3T 0x023f
#define M3T 0x037b
#define K4T 0x0100
#define B4T 0x0270
#define M4T 0x03fe
#define K5T 0x0138
#define B5T 0x016f
#define M5T 0x01fc
#define K6T 0x019a
#define B6T 0x00d2
#define M6T 0x00fb
#define K7T 0x029a
#define B7T 0x0018
#define M7T 0x0012
#define K8T 0x029a
#define B8T 0x0000
#define M8T 0x0000
/** @} */
/* -------------------------------------------------------------------------- */
#define TSL2563_SUCCESS 0x00
#define TSL2563_LIGHT 0x01
#define TSL2563_ERROR -1
/* -------------------------------------------------------------------------- */
#define TSL2563_VAL_READ 0x01
/* -------------------------------------------------------------------------- */
#define TSL2563_SENSOR "TSL2563 Light Sensor"
/* -------------------------------------------------------------------------- */
extern const struct sensors_sensor tsl2563;
/* -------------------------------------------------------------------------- */
#endif
/* -------------------------------------------------------------------------- */
/**
* @}
* @}
*/