Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
Loading...
Searching...
No Matches
cascoda_btn.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023, Cascoda Ltd.
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 are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28/*
29 * Button / LED Functions for Cascoda UI
30*/
31
32#ifndef CASCODA_BTN_H
33#define CASCODA_BTN_H
34
37#include "ca821x_api.h"
38#include "ca821x_error.h"
39
40/* max. number of LED/Button pairs on board */
41#define NUM_LEDBTN 5
42
43/* minimum press time for additional de-bouncing in [ms] */
44#define BTN_MIN_PRESS_TIME 5
45
46#ifndef BTN_SHARED_SENSE_DELAY
47#define BTN_SHARED_SENSE_DELAY 2
48#endif
49
50/* Execute short press callback when pressed or on release
51 * Note: BTN_SHORTPRESS_RELEASED should only be used when
52 * the same button is being registered with a long press
53 * callback.
54 */
60
61/* Button state */
67
68/* pin types */
76
77/* Whether an interrupt is registered for the pin or not */
83
84/* dvbd callback type definition */
85typedef void (*btn_callback)(void* context);
86
106
107/* Map from Button declaration to actual module pin number */
108extern uint8_t registeredPinMappings[];
109
110/* functions */
111
118ca_error Btn_RegisterLEDOutput(uint8_t ledBtn);
119
126ca_error Btn_RegisterButtonInput(uint8_t ledBtn);
127
135
143
151
158ca_error Btn_DeRegister(uint8_t ledBtn);
159
169ca_error Btn_SetButtonShortPressCallback(uint8_t ledBtn, btn_callback callback, void* context, uint8_t shortPressMode);
170
180ca_error Btn_SetButtonLongPressCallback(uint8_t ledBtn, btn_callback callback, void* context, uint32_t timeThreshold);
181
191ca_error Btn_SetButtonHoldCallback(uint8_t ledBtn, btn_callback callback, void* context, uint32_t TimeInterval);
192
200ca_error Btn_SetLED(uint8_t ledBtn, uint8_t val);
201
209ca_error Btn_Sense(uint8_t ledBtn, uint8_t* val);
210
218ca_error Btn_SenseOutput(uint8_t ledBtn, uint8_t* val);
219
226
233ca_error Btn_HandleButtonCallbacks(btn_callback_info* callback, uint8_t pressed);
234
239void Btn_IncrementGPIOWakeup(void);
240
247
252void Btn_SetSleepPermanently(void);
253
259bool Btn_CanSleep(void);
260
266ca_error Btn_Sleep(enum wakeup_mode keep_radio_off_on_wakeup, uint32_t aSleepTime, struct ca821x_dev *pDeviceRef);
267
268#endif // CASCODA_BTN_H
The main ca821x-api include file.
Global error declarations for use across the Cascoda SDK.
ca_error Btn_RegisterButtonInput(uint8_t ledBtn)
Register button input.
Definition cascoda_btn.c:88
ca_error Btn_HandleButtonCallbacks(btn_callback_info *callback, uint8_t pressed)
Process the button callbacks and timing.
Definition cascoda_btn.c:323
ca_error Btn_DeRegister(uint8_t ledBtn)
De-Register an LED or Button Pin.
Definition cascoda_btn.c:180
ca_error Btn_SenseOutput(uint8_t ledBtn, uint8_t *val)
Get the output state of the LED.
Definition cascoda_btn.c:272
ca_error Btn_DecrementGPIOWakeup(void)
One fewer GPIO is now being used for wakeup.
Definition cascoda_btn.c:388
ca_error Btn_SetButtonShortPressCallback(uint8_t ledBtn, btn_callback callback, void *context, uint8_t shortPressMode)
Set a callback function to a button when it is short pressed.
Definition cascoda_btn.c:200
bool Btn_CanSleep(void)
Check if all buttons have been handled.
Definition cascoda_btn.c:411
ca_error Btn_RegisterSharedButtonLED(uint8_t ledBtn)
Register button as shared input/output.
Definition cascoda_btn.c:134
ca_error Btn_PollButtons(void)
Main polling function to activate callbacks for any buttons that are currently being pressed.
Definition cascoda_btn.c:279
btn_shortpress_mode
Definition cascoda_btn.h:56
@ BTN_SHORTPRESS_RELEASED
Definition cascoda_btn.h:58
@ BTN_SHORTPRESS_PRESSED
Definition cascoda_btn.h:57
void Btn_SetSleepPermanently(void)
Register that the device will be put to sleep permanently.
Definition cascoda_btn.c:404
void Btn_IncrementGPIOWakeup(void)
One additional GPIO is now being used for wakeup.
Definition cascoda_btn.c:381
ca_error Btn_SetLED(uint8_t ledBtn, uint8_t val)
Set the state of the LED.
Definition cascoda_btn.c:227
void(* btn_callback)(void *context)
Definition cascoda_btn.h:85
btn_pin_int
Definition cascoda_btn.h:79
@ PIN_INTERRUPT
Definition cascoda_btn.h:81
@ PIN_NO_INTERRUPT
Definition cascoda_btn.h:80
ca_error Btn_RegisterLEDOutput(uint8_t ledBtn)
Register LED output (open drain).
Definition cascoda_btn.c:73
ca_error Btn_Sleep(enum wakeup_mode keep_radio_off_on_wakeup, uint32_t aSleepTime, struct ca821x_dev *pDeviceRef)
Put board to sleep / powerdown.
Definition cascoda_btn.c:426
ca_error Btn_SetButtonHoldCallback(uint8_t ledBtn, btn_callback callback, void *context, uint32_t TimeInterval)
Set a callback function to a button when it is held.
Definition cascoda_btn.c:218
uint8_t registeredPinMappings[]
Definition cascoda_btn.c:40
ca_error Btn_Sense(uint8_t ledBtn, uint8_t *val)
Get the state of the LED/Button.
Definition cascoda_btn.c:234
ca_error Btn_RegisterSharedIRQButtonLED(uint8_t ledBtn)
Register button as shared input/output with interrupt (for sleepy devices).
Definition cascoda_btn.c:156
btn_button_state
Definition cascoda_btn.h:63
@ BTN_PRESSED
Definition cascoda_btn.h:64
@ BTN_RELEASED
Definition cascoda_btn.h:65
ca_error Btn_RegisterButtonIRQInput(uint8_t ledBtn)
Register button input with interrupt (for sleepy devices).
Definition cascoda_btn.c:110
ca_error Btn_SetButtonLongPressCallback(uint8_t ledBtn, btn_callback callback, void *context, uint32_t timeThreshold)
Set a callback function to a button when it is long pressed.
Definition cascoda_btn.c:209
btn_pin_type
Definition cascoda_btn.h:70
@ PINTYPE_BTN
Definition cascoda_btn.h:73
@ PINTYPE_SHARED
Definition cascoda_btn.h:74
@ PINTYPE_LED
Definition cascoda_btn.h:72
@ PINTYPE_NONE
Definition cascoda_btn.h:71
Declaration of EVBME Functions.
Type definitions used by Cascoda baremetal drivers.
wakeup_mode
Definitions for Wakeup after Powerdown.
Definition cascoda_evbme.h:72
ca_error
Cascoda error type.
Definition ca821x_error.h:51
Callbacks and associated timers for the buttons.
Definition cascoda_btn.h:89
void * shortPressContext
Context for shortPressCallback.
Definition cascoda_btn.h:91
void * holdContext
Context for holdCallback.
Definition cascoda_btn.h:97
btn_callback shortPressCallback
Callback function for a short button press.
Definition cascoda_btn.h:90
uint32_t longPressTimeThreshold
Time limit [ms] above which a button press is considered a long press.
Definition cascoda_btn.h:100
uint32_t holdTimeLast
Time [ms] when hold callback was last called.
Definition cascoda_btn.h:102
uint8_t lastState
Last button state.
Definition cascoda_btn.h:103
uint32_t currentPressTime
Time [ms] when the button has been pressed.
Definition cascoda_btn.h:99
void * longPressContext
Context for longPressCallback.
Definition cascoda_btn.h:94
btn_callback holdCallback
Callback function for when the button is held.
Definition cascoda_btn.h:96
btn_callback longPressCallback
Callback function for a long button press.
Definition cascoda_btn.h:93
uint8_t shortPressMode
Short Press callback when pressed or on release.
Definition cascoda_btn.h:104
uint32_t holdTimeInterval
Time interval [ms] for triggering the hold function.
Definition cascoda_btn.h:101
CA-821x Device reference struct.
Definition ca821x_api.h:164