Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
app_push_button.c
1 /*
2  * File: app_push_button.c
3  * Author: M91406
4  *
5  * Created on March 12, 2020, 12:10 PM
6  */
7 
8 
9 #include "config/hal.h"
10 #include "app_push_button.h"
11 #include "lcd/app_lcd.h"
12 
13 // PRIVATE VARIABLE DELARATIONS
14 
15 #define PUSH_BUTTON_DEBOUNCE_DELAY_DEFAULT 199 // Push Button needs to be pressed >20ms to trip a PUSH BUTTON switch event
16 #define PUSH_BUTTON_LONG_PRESS_DELAY_DEFAULT 4999 // Push Button needs to be pressed >500ms to trip a PUSH BUTTON switch event
17 
18 volatile PUSH_BUTTON_OBJECT_t push_button;
19 
20 // Push Button Events
21 volatile uint16_t appPushButton_EventButtonDown(void);
22 volatile uint16_t appPushButton_EventButtonPressed(void);
23 volatile uint16_t appPushButton_EventButtonLongPress(void);
24 volatile uint16_t appPushButton_EventButtonUp(void);
25 
26 
45 volatile uint16_t appPushButton_Initialize(void)
46 {
47  volatile uint16_t retval = 1;
48 
49  retval &= drv_PushButton_Initialize(&push_button);
50 
51  push_button.debounce_delay = PUSH_BUTTON_DEBOUNCE_DELAY_DEFAULT;
52  push_button.long_press_delay = PUSH_BUTTON_LONG_PRESS_DELAY_DEFAULT;
53  push_button.status.bits.enabled = true;
54 
57  push_button.event_pressed = NULL; // Event not used
59 
60  return(retval);
61 }
62 
63 
81 volatile uint16_t appPushButton_Execute(void)
82 {
83  volatile uint16_t retval = 1;
84 
85  retval &= drv_PushButton_Execute(&push_button);
86 
87  return(retval);
88 }
89 
90 
106 volatile uint16_t appPushButton_Dispose(void)
107 {
108  volatile uint16_t retval = 1;
109 
110  retval &= drv_PushButton_Dispose(&push_button);
111 
112  return(retval);
113 }
114 
115 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 // PRIVATE FUNCTIONS
117 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 
119 
135 volatile uint16_t appPushButton_EventButtonDown(void)
136 {
137  Nop();
138  return(1);
139 }
140 
141 
157 volatile uint16_t appPushButton_EventButtonUp(void)
158 {
159  Nop();
160  return(1);
161 }
162 
163 
179 volatile uint16_t appPushButton_EventButtonPressed(void)
180 {
181  Nop();
182  return(1);
183 }
184 
185 
201 volatile uint16_t appPushButton_EventButtonLongPress(void) {
202 
203  lcd.screen += 1; // increment screen index
204  if (lcd.screen > lcd.screens) // Roll-over after screen #2
205  lcd.screen = 0; // Reset to default view
206  return(1);
207 }
208 
209 
210 // end of file
appPushButton_Execute
volatile uint16_t appPushButton_Execute(void)
Executes the USER push button monitor.
Definition: app_push_button.c:81
drv_PushButton_Dispose
volatile uint16_t drv_PushButton_Dispose(volatile struct PUSH_BUTTON_OBJECT_s *pushbtn)
Initializes the push button device driver.
Definition: drv_push_button.c:153
PUSH_BUTTON_OBJECT_s::event_btn_up
volatile uint16_t(* event_btn_up)(void)
Function pointer to user function triggering a RELEASE event.
Definition: drv_push_button.h:116
PUSH_BUTTON_OBJECT_s::debounce_delay
volatile uint16_t debounce_delay
Number of call cycles until a switch event is triggered.
Definition: drv_push_button.h:111
appPushButton_EventButtonLongPress
volatile uint16_t appPushButton_EventButtonLongPress(void)
Push button event raised at the "is long pressed" detection.
Definition: app_push_button.c:201
PUSH_BUTTON_OBJECT_s::status
volatile struct PUSH_BUTTON_STATUS_s status
Status word of the switch object.
Definition: drv_push_button.h:110
drv_PushButton_Initialize
volatile uint16_t drv_PushButton_Initialize(volatile struct PUSH_BUTTON_OBJECT_s *pushbtn)
Initializes the push button device driver.
Definition: drv_push_button.c:38
PUSH_BUTTON_OBJECT_s
Push button function driver data object.
Definition: drv_push_button.h:108
appPushButton_EventButtonPressed
volatile uint16_t appPushButton_EventButtonPressed(void)
Push button event raised at the "is pressed" detection.
Definition: app_push_button.c:179
PUSH_BUTTON_OBJECT_s::event_btn_down
volatile uint16_t(* event_btn_down)(void)
Function pointer to user function triggering a PRESSED event.
Definition: drv_push_button.h:113
PUSH_BUTTON_STATUS_s::enabled
volatile bool enabled
Bit 15: Enables/disables the Switch button object.
Definition: drv_push_button.h:89
appPushButton_EventButtonUp
volatile uint16_t appPushButton_EventButtonUp(void)
Push button event raised at the "not pressed" transition.
Definition: app_push_button.c:157
appPushButton_Initialize
volatile uint16_t appPushButton_Initialize(void)
Initializes the USER push button on DPSK3.
Definition: app_push_button.c:45
PUSH_BUTTON_OBJECT_s::event_pressed
volatile uint16_t(* event_pressed)(void)
Function pointer to user function triggering a LONG_PRESS event.
Definition: drv_push_button.h:115
LCD_s::screen
volatile uint16_t screen
Definition: app_lcd.h:57
appPushButton_Dispose
volatile uint16_t appPushButton_Dispose(void)
Unloads the push button data object and frees its resources.
Definition: app_push_button.c:106
PUSH_BUTTON_OBJECT_s::event_long_press
volatile uint16_t(* event_long_press)(void)
Function pointer to user function triggering a LONG_PRESS event.
Definition: drv_push_button.h:114
LCD_s::screens
volatile uint16_t screens
Definition: app_lcd.h:58
appPushButton_EventButtonDown
volatile uint16_t appPushButton_EventButtonDown(void)
Push button event raised at the "pressed" transition.
Definition: app_push_button.c:135
PUSH_BUTTON_OBJECT_s::long_press_delay
volatile uint16_t long_press_delay
Number of call cycles until a "long press" switch event is triggered.
Definition: drv_push_button.h:112
drv_PushButton_Execute
volatile uint16_t drv_PushButton_Execute(volatile struct PUSH_BUTTON_OBJECT_s *pushbtn)
Initializes the push button device driver.
Definition: drv_push_button.c:70