Contiki 2.6

button-sensor.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  */
00031 
00032 /**
00033  * \file
00034  *         Override core/dev/button-sensor.h
00035  *
00036  * \author
00037  *         George Oikonomou - <oikonomou@users.sourceforge.net>
00038  */
00039 
00040 #ifndef __BUTTON_SENSOR_H__
00041 #define __BUTTON_SENSOR_H__
00042 
00043 #include "contiki-conf.h"
00044 #include "lib/sensors.h"
00045 
00046 #define BUTTON_SENSOR "Button"
00047 
00048 /*
00049  * SmartRF Buttons
00050  * B1: P0_1, B2: Not Connected
00051  *
00052  * USB Dongle Buttons
00053  * B1: P1_2
00054  * B2: P1_3
00055  *
00056  */
00057 #if MODEL_CC2531
00058 #define BUTTON1_PORT 1
00059 #define BUTTON1_PIN  2
00060 #define BUTTON2_PORT 1
00061 #define BUTTON2_PIN  3
00062 #else
00063 #define BUTTON1_PORT 0
00064 #define BUTTON1_PIN  1
00065 #endif
00066 
00067 #ifdef BUTTON_SENSOR_CONF_ON
00068 #define BUTTON_SENSOR_ON BUTTON_SENSOR_CONF_ON
00069 #endif /* BUTTON_SENSOR_CONF_ON */
00070 
00071 #define button_sensor button_1_sensor
00072 extern const struct sensors_sensor button_1_sensor;
00073 extern const struct sensors_sensor button_2_sensor;
00074 
00075 #if BUTTON_SENSOR_ON
00076 #if MODEL_CC2531
00077 /* USB Dongle */
00078 /* Buttons: P1_2 & P1_3 - Port 1 ISR needed */
00079 void port_1_isr(void) __interrupt(P1INT_VECTOR);
00080 #define   BUTTON_SENSOR_ACTIVATE() do { \
00081     button_1_sensor.configure(SENSORS_ACTIVE, 1); \
00082     button_2_sensor.configure(SENSORS_ACTIVE, 1); \
00083 } while(0)
00084 
00085 #else /* MODEL_CC2531 */
00086 /* SmartRF */
00087 /* Button 1: P0_1 - Port 0 ISR needed */
00088 void port_0_isr(void) __interrupt(P0INT_VECTOR);
00089 #define   BUTTON_SENSOR_ACTIVATE() button_sensor.configure(SENSORS_ACTIVE, 1)
00090 #endif /* MODEL_CC2531 */
00091 
00092 #else /* BUTTON_SENSOR_ON */
00093 #define   BUTTON_SENSOR_ACTIVATE()
00094 #endif /* BUTTON_SENSOR_ON */
00095 
00096 /* Define macros for buttons */
00097 #define BUTTON_READ(b)           PORT_READ(BUTTON##b##_PORT, BUTTON##b##_PIN)
00098 #define BUTTON_FUNC_GPIO(b)      PORT_FUNC_GPIO(BUTTON##b##_PORT, BUTTON##b##_PIN)
00099 #define BUTTON_DIR_INPUT(b)      PORT_DIR_INPUT(BUTTON##b##_PORT, BUTTON##b##_PIN)
00100 #define BUTTON_IRQ_ENABLED(b)    PORT_IRQ_ENABLED(BUTTON##b##_PORT, BUTTON##b##_PIN)
00101 #define BUTTON_IRQ_CHECK(b)      PORT_IRQ_CHECK(BUTTON##b##_PORT, BUTTON##b##_PIN)
00102 #define BUTTON_IRQ_ENABLE(b)     PORT_IRQ_ENABLE(BUTTON##b##_PORT, BUTTON##b##_PIN)
00103 #define BUTTON_IRQ_DISABLE(b)    PORT_IRQ_DISABLE(BUTTON##b##_PORT, BUTTON##b##_PIN)
00104 #define BUTTON_IRQ_FLAG_OFF(b)   PORT_IRQ_FLAG_OFF(BUTTON##b##_PORT, BUTTON##b##_PIN)
00105 #define BUTTON_IRQ_ON_PRESS(b)   PORT_IRQ_EDGE_RISE(BUTTON##b##_PORT, BUTTON##b##_PIN)
00106 #define BUTTON_IRQ_ON_RELEASE(b) PORT_IRQ_EDGE_FALL(BUTTON##b##_PORT, BUTTON##b##_PIN)
00107 
00108 #endif /* __BUTTON_SENSOR_H__ */