Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
buttons.c
1
/*
2
* Copyright (c) 2019, George Oikonomou - http://www.spd.gr
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of the copyright holder nor the names of its
15
* contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29
* OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*---------------------------------------------------------------------------*/
32
#include "contiki.h"
33
#include "
dev/button-hal.h
"
34
#include "lib/simEnvChange.h"
35
36
#include <stdint.h>
37
#include <string.h>
38
/*---------------------------------------------------------------------------*/
39
/* Log configuration */
40
#include "
sys/log.h
"
41
#define LOG_MODULE "Cooja Button"
42
#define LOG_LEVEL LOG_LEVEL_NONE
43
/*---------------------------------------------------------------------------*/
44
/* Variables required by the Cooja button interface */
45
char
simButtonChanged;
46
char
simButtonIsDown;
47
char
simButtonIsActive = 1;
48
/*---------------------------------------------------------------------------*/
49
/* The cooja virtual button on pin COOJA_BTN_PIN, active low */
50
BUTTON_HAL_BUTTON(button_user,
"User button"
, COOJA_BTN_PIN,
51
GPIO_HAL_PIN_CFG_PULL_UP,
BUTTON_HAL_ID_BUTTON_ZERO
,
true
);
52
/*---------------------------------------------------------------------------*/
53
BUTTON_HAL_BUTTONS(&button_user);
54
/*---------------------------------------------------------------------------*/
55
static
void
56
doInterfaceActionsBeforeTick(
void
)
57
{
58
if
(simButtonChanged) {
59
LOG_DBG(
"Cooja button changed. simButtonIsDown=%u, "
, simButtonIsDown);
60
/*
61
* First check what the simulator wants us to do: press or release. Based
62
* on that, set the correct state for COOJA_BTN_PIN.
63
*/
64
if
(simButtonIsDown) {
65
/* The button is active low, so clear the pin when pressed */
66
LOG_DBG_(
"clearing pin"
);
67
gpio_hal_arch_no_port_clear_pin
(COOJA_BTN_PIN);
68
}
else
{
69
LOG_DBG_(
"setting pin"
);
70
gpio_hal_arch_no_port_set_pin
(COOJA_BTN_PIN);
71
}
72
73
/*
74
* Subsequently, simply raise a virtual edge event on the pin, but only if
75
* the interrupt is "enabled"
76
*/
77
if
(
gpio_hal_arch_no_port_pin_cfg_get
(COOJA_BTN_PIN) & GPIO_HAL_PIN_CFG_INT_ENABLE) {
78
LOG_DBG_(
", triggering edge event"
);
79
gpio_hal_event_handler(
gpio_hal_pin_to_mask
(COOJA_BTN_PIN));
80
}
81
LOG_DBG_(
"\n"
);
82
}
83
84
simButtonChanged = 0;
85
}
86
/*---------------------------------------------------------------------------*/
87
COOJA_PRE_TICK_ACTION(COOJA_BUTTON_INIT_PRIO, doInterfaceActionsBeforeTick);
button-hal.h
Header file for the button HAL.
BUTTON_HAL_ID_BUTTON_ZERO
#define BUTTON_HAL_ID_BUTTON_ZERO
Optional button IDs.
Definition
button-hal.h:134
gpio_hal_arch_no_port_pin_cfg_get
gpio_hal_pin_cfg_t gpio_hal_arch_no_port_pin_cfg_get(gpio_hal_pin_t pin)
Read the configuration of a GPIO pin.
Definition
gpio-hal-arch.c:97
gpio_hal_arch_no_port_clear_pin
void gpio_hal_arch_no_port_clear_pin(gpio_hal_pin_t pin)
Clear a GPIO pin (logical low).
Definition
gpio-hal-arch.c:132
gpio_hal_arch_no_port_set_pin
void gpio_hal_arch_no_port_set_pin(gpio_hal_pin_t pin)
Set a GPIO pin to logical high.
Definition
gpio-hal-arch.c:120
gpio_hal_pin_to_mask
#define gpio_hal_pin_to_mask(pin)
Convert a pin to a pin mask.
Definition
gpio-hal.h:255
log.h
Header file for the logging system.
arch
platform
cooja
dev
buttons.c
Generated on
for Contiki-NG by
1.17.0