Digital Power Starter Kit 3 Firmware
dsPIC33C Boost 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 /***********************************************************************************
40  * @ingroup lib-layer-push-button-properties-public
41  * @enum SWITCH_STATUS_FLAGS_e
42  * @brief Enumeration of push button states
43  * @details
44  * This enumeration lists the different conditions of the push button connected
45  * to the specified GPIO of the device, which can be detecting by this push button
46  * function driver.
47  ***********************************************************************************/
48 
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 /***********************************************************************************
56  * @ingroup lib-layer-push-button-properties-public
57  * @struct PUSH_BUTTON_STATUS_s
58  * @memberof PUSH_BUTTON_OBJECT_s
59  * @extends PUSH_BUTTON_OBJECT_s
60  * @brief Status word of the push button driver
61  * @details
62  * The status word of the push button function driver allows asynchronous
63  * monitoring of the push button status, encoding the detection of short and
64  * long press as well as the immediate switch event.
65  *
66  * In addition, an Enable control bit is provided to allow external code modules
67  * to turn the monitoring of the push-button input on or off.
68  **********************************************************************************/
69 
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 /***********************************************************************************
97  * @ingroup lib-layer-push-button-properties-public
98  * @struct PUSH_BUTTON_OBJECT_s
99  * @brief Push button function driver data object
100  * @details
101  * The Push Button function driver data object is used to store the user
102  * configuration of a push-button. Thus, multiple push button objects can be
103  * defined, which will be individually monitored by the drv_PushButton_Execute
104  * function.
105  **********************************************************************************/
106 
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 
volatile uint16_t long_press_delay
Number of call cycles until a "long press" switch event is triggered.
volatile uint16_t(* event_pressed)(void)
Function pointer to user function triggering a LONG_PRESS event.
volatile uint16_t(* event_long_press)(void)
Function pointer to user function triggering a LONG_PRESS event.
volatile uint16_t debounce_delay
Number of call cycles until a switch event is triggered.
volatile unsigned
Bit 1: (reserved)
volatile struct PUSH_BUTTON_STATUS_s status
Status word of the switch object.
volatile bool long_press
Bit 13: Indicates if switch has been pressed for a longer time.
volatile uint16_t value
Status word.
volatile bool sw_event
Bit 0: Event bit indicating a state has changed (cleared automatically)
volatile uint16_t(* event_btn_up)(void)
Function pointer to user function triggering a RELEASE event.
volatile bool pressed
Bit 14: Indicates if the button is pressed or not.
volatile bool enabled
Bit 15: Enables/disables the Switch button object.
volatile uint16_t(* event_btn_down)(void)
Function pointer to user function triggering a PRESSED event.