Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
drv_push_button.h
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2  * and any derivatives exclusively with Microchip products.
3  *
4  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5  * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7  * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8  * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9  *
10  * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11  * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12  * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13  * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14  * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15  * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16  * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17  *
18  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19  * TERMS.
20  */
21 
22 /*
23  * File: led.h
24  * Author: M91406
25  * Comments: LCD application layer
26  * Revision history:
27  */
28 
29 // This is a guard condition so that contents of this file are not included
30 // more than once.
31 #ifndef SWITCH_BUTTON_DRIVER_H
32 #define SWITCH_BUTTON_DRIVER_H
33 
34 #include <xc.h> // include processor files - each processor file is guarded.
35 #include <stdint.h> // include standard integer data types
36 #include <stdbool.h> // include standard boolean data types
37 #include <stddef.h> // include standard definition data types
38 
39 
49 typedef enum SWITCH_STATUS_FLAGS_e{
50  SWITCH_STAT_PRESSED = 0b1100000000000001,
51  SWITCH_STAT_LONG_PRESS = 0b1110000000000001,
52  SWITCH_STAT_RELEASED = 0b1000000000000001
53 } SWITCH_STATUS_FLAGS_t;
54 
55 
70 typedef struct PUSH_BUTTON_STATUS_s{
71 
72  union {
73  struct{
74  volatile bool sw_event :1;
75  volatile unsigned :1;
76  volatile unsigned :1;
77  volatile unsigned :1;
78  volatile unsigned :1;
79  volatile unsigned :1;
80  volatile unsigned :1;
81  volatile unsigned :1;
82  volatile unsigned :1;
83  volatile unsigned :1;
84  volatile unsigned :1;
85  volatile unsigned :1;
86  volatile unsigned :1;
87  volatile bool long_press :1;
88  volatile bool pressed :1;
89  volatile bool enabled :1;
90  }__attribute__((packed)) bits;
91  volatile uint16_t value;
92  };
93 
95 
96 
107 // PUBLIC DATA TYPE DECLARATION
108 typedef struct PUSH_BUTTON_OBJECT_s{
109 
110  volatile struct PUSH_BUTTON_STATUS_s status;
111  volatile uint16_t debounce_delay;
112  volatile uint16_t long_press_delay;
113  volatile uint16_t (*event_btn_down)(void);
114  volatile uint16_t (*event_long_press)(void);
115  volatile uint16_t (*event_pressed)(void);
116  volatile uint16_t (*event_btn_up)(void);
117 
119 
120 
121 // PUBLIC FUNCTION PROTOTYPE DECLARATION
122 extern volatile uint16_t drv_PushButton_Initialize(volatile struct PUSH_BUTTON_OBJECT_s* pushbtn);
123 extern volatile uint16_t drv_PushButton_Execute(volatile struct PUSH_BUTTON_OBJECT_s* pushbtn);
124 extern volatile uint16_t drv_PushButton_Dispose(volatile struct PUSH_BUTTON_OBJECT_s* pushbtn);
125 
126 #endif /* SWITCH_BUTTON_DRIVER_H */
127 
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_STATUS_s::pressed
volatile bool pressed
Bit 14: Indicates if the button is pressed or not.
Definition: drv_push_button.h:88
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
PUSH_BUTTON_STATUS_s
Status word of the push button driver.
Definition: drv_push_button.h:70
PUSH_BUTTON_STATUS_s::long_press
volatile bool long_press
Bit 13: Indicates if switch has been pressed for a longer time.
Definition: drv_push_button.h:87
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
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::unsigned
volatile unsigned
Bit 1: (reserved)
Definition: drv_push_button.h:75
PUSH_BUTTON_STATUS_s::enabled
volatile bool enabled
Bit 15: Enables/disables the Switch button object.
Definition: drv_push_button.h:89
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
SWITCH_STATUS_FLAGS_e
SWITCH_STATUS_FLAGS_e
Enumeration of push button states.
Definition: drv_push_button.h:49
PUSH_BUTTON_STATUS_s::value
volatile uint16_t value
Status word.
Definition: drv_push_button.h:91
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
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
PUSH_BUTTON_STATUS_s::sw_event
volatile bool sw_event
Bit 0: Event bit indicating a state has changed (cleared automatically)
Definition: drv_push_button.h:74
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