Contiki-NG
Files | Macros | Functions

Files

file  button-sensor.c
 Driver for nRF52 DK buttons.
 
file  button-sensor.h
 Header file for the nRF52dk button driver.
 

Macros

#define DEBOUNCE_DURATION   (CLOCK_SECOND >> 5)
 Delay before button state is assumed to be stable.
 
#define BUTTON_SENSOR_VALUE_STATE   0
 Can be passed to value() function to get current button state.
 
#define BUTTON_SENSOR_VALUE_DURATION   1
 Can be passed to value() function to get low state duration.
 

Functions

static void gpiote_event_handler (nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
 Button toggle handler. More...
 
static int config (int type, int c, nrf_drv_gpiote_pin_t pin)
 Configuration function for the button sensor for all buttons. More...
 
static int config_button_1 (int type, int value)
 Configuration function for button 1. More...
 
static int config_button_2 (int type, int value)
 Configuration function for button 2. More...
 
static int config_button_3 (int type, int value)
 Configuration function for button 3. More...
 
static int config_button_4 (int type, int value)
 Configuration function for button 4. More...
 
static int value (int type, nrf_drv_gpiote_pin_t pin)
 Return current state of a button. More...
 
static int value_button_1 (int type)
 Return current state of a button 1. More...
 
static int value_button_2 (int type)
 Return current state of a button 2. More...
 
static int value_button_3 (int type)
 Return current state of a button 3. More...
 
static int value_button_4 (int type)
 Return current state of a button 4. More...
 
static int status (int type, nrf_drv_gpiote_pin_t pin)
 Get status of a given button. More...
 
static int status_button_1 (int type)
 Status function for button 1. More...
 
static int status_button_2 (int type)
 Status function for button 2. More...
 
static int status_button_3 (int type)
 Status function for button 3. More...
 
static int status_button_4 (int type)
 Status function for button 3. More...
 

Detailed Description

Function Documentation

◆ config()

static int config ( int  type,
int  c,
nrf_drv_gpiote_pin_t  pin 
)
static

Configuration function for the button sensor for all buttons.

Parameters
typeif SENSORS_HW_INIT is passed the function will initialize given button if SENSORS_ACTIVE is passed then c parameter defines whether button should be set active or inactive
c0 to disable the button, non-zero: enable
pinGPIOE pin number

Definition at line 111 of file button-sensor.c.

Referenced by config_button_1(), config_button_2(), config_button_3(), config_button_4(), gpio_hal_arch_no_port_pin_cfg_get(), gpio_hal_arch_no_port_pin_cfg_set(), and uart0_init().

◆ config_button_1()

static int config_button_1 ( int  type,
int  value 
)
static

Configuration function for button 1.

Parameters
typepassed to config() as-is
valuepassed to config() as-is
Returns
same as config() return value

Definition at line 146 of file button-sensor.c.

References config().

◆ config_button_2()

static int config_button_2 ( int  type,
int  value 
)
static

Configuration function for button 2.

Parameters
typepassed to config() as-is
valuepassed to config() as-is
Returns
same as config() return value

Definition at line 159 of file button-sensor.c.

References config().

◆ config_button_3()

static int config_button_3 ( int  type,
int  value 
)
static

Configuration function for button 3.

Parameters
typepassed to config() as-is
valuepassed to config() as-is
Returns
same as config() return value

Definition at line 172 of file button-sensor.c.

References config().

◆ config_button_4()

static int config_button_4 ( int  type,
int  value 
)
static

Configuration function for button 4.

Parameters
typepassed to config() as-is
valuepassed to config() as-is
Returns
same as config() return value

Definition at line 185 of file button-sensor.c.

References config().

◆ gpiote_event_handler()

static void gpiote_event_handler ( nrf_drv_gpiote_pin_t  pin,
nrf_gpiote_polarity_t  action 
)
static

Button toggle handler.

Parameters
pinGPIO pin which has been triggered
actiontoggle direction

Definition at line 75 of file button-sensor.c.

References clock_time(), DEBOUNCE_DURATION, timer_expired(), and timer_set().

◆ status()

static int status ( int  type,
nrf_drv_gpiote_pin_t  pin 
)
static

Get status of a given button.

Parameters
typeSENSORS_ACTIVE or SENSORS_READY
pinGPIOE pin number
Returns
1 if the button's port interrupt is enabled

Definition at line 265 of file button-sensor.c.

Referenced by status_button_1(), status_button_2(), status_button_3(), and status_button_4().

◆ status_button_1()

static int status_button_1 ( int  type)
static

Status function for button 1.

Parameters
typepassed to state() as-is
Returns
value returned by state()

Definition at line 283 of file button-sensor.c.

References status().

◆ status_button_2()

static int status_button_2 ( int  type)
static

Status function for button 2.

Parameters
typepassed to state() as-is
Returns
value returned by state()

Definition at line 294 of file button-sensor.c.

References status().

◆ status_button_3()

static int status_button_3 ( int  type)
static

Status function for button 3.

Parameters
typepassed to state() as-is
Returns
value returned by state()

Definition at line 305 of file button-sensor.c.

References status().

◆ status_button_4()

static int status_button_4 ( int  type)
static

Status function for button 3.

Parameters
typepassed to state() as-is
Returns
value returned by state()

Definition at line 316 of file button-sensor.c.

References status().

◆ value()

static int value ( int  type,
nrf_drv_gpiote_pin_t  pin 
)
static

Return current state of a button.

Parameters
typepass BUTTON_SENSOR_VALUE_STATE to get current button state or BUTTON_SENSOR_VALUE_DURATION to get active state duration
pinGPIOE pin number
Return values
BUTTON_SENSOR_VALUE_PRESSED
BUTTON_SENSOR_VALUE_RELEASEDwhen type is BUTTON_SENSOR_VALUE_STATE
durationActive state duration in clock ticks

Definition at line 201 of file button-sensor.c.

References BUTTON_SENSOR_VALUE_STATE.

Referenced by value_button_1(), value_button_2(), value_button_3(), and value_button_4().

◆ value_button_1()

static int value_button_1 ( int  type)
static

Return current state of a button 1.

Parameters
typepassed to value() as-is
Returns
same as value returned by value()

Definition at line 220 of file button-sensor.c.

References value().

◆ value_button_2()

static int value_button_2 ( int  type)
static

Return current state of a button 2.

Parameters
typepassed to value() as-is
Returns
same as value returned by value()

Definition at line 231 of file button-sensor.c.

References value().

◆ value_button_3()

static int value_button_3 ( int  type)
static

Return current state of a button 3.

Parameters
typepassed to value() as-is
Returns
same as value returned by value()

Definition at line 242 of file button-sensor.c.

References value().

◆ value_button_4()

static int value_button_4 ( int  type)
static

Return current state of a button 4.

Parameters
typepassed to value() as-is
Returns
same as value returned by value()

Definition at line 253 of file button-sensor.c.

References value().