1 /*
2  * Copyright (c) 2021-2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 
9 #ifndef HPM_BUTN_H
10 #define HPM_BUTN_H
11 
12 typedef struct {
13     __RW uint32_t BTN_STATUS;                  /* 0x0: Button status */
14     __RW uint32_t BTN_IRQ_MASK;                /* 0x4: Button interrupt mask */
15     __RW uint32_t LED_INTENSE;                 /* 0x8: Debounce setting */
16 } BUTN_Type;
17 
18 
19 /* Bitfield definition for register: BTN_STATUS */
20 /*
21  * XWCLICK (RW)
22  *
23  * wake button click status when power button held, write 1 to clear flag
24  * bit0: clicked
25  * bit1: double clicked
26  * bit2: tripple clicked
27  */
28 #define BUTN_BTN_STATUS_XWCLICK_MASK (0x70000000UL)
29 #define BUTN_BTN_STATUS_XWCLICK_SHIFT (28U)
30 #define BUTN_BTN_STATUS_XWCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_XWCLICK_SHIFT) & BUTN_BTN_STATUS_XWCLICK_MASK)
31 #define BUTN_BTN_STATUS_XWCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_XWCLICK_MASK) >> BUTN_BTN_STATUS_XWCLICK_SHIFT)
32 
33 /*
34  * WCLICK (RW)
35  *
36  * wake button click status, write 1 to clear flag
37  * bit0: clicked
38  * bit1: double clicked
39  * bit2: tripple clicked
40  */
41 #define BUTN_BTN_STATUS_WCLICK_MASK (0x7000000UL)
42 #define BUTN_BTN_STATUS_WCLICK_SHIFT (24U)
43 #define BUTN_BTN_STATUS_WCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_WCLICK_SHIFT) & BUTN_BTN_STATUS_WCLICK_MASK)
44 #define BUTN_BTN_STATUS_WCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_WCLICK_MASK) >> BUTN_BTN_STATUS_WCLICK_SHIFT)
45 
46 /*
47  * XPCLICK (RW)
48  *
49  * power button click status when wake button held, write 1 to clear flag
50  * bit0: clicked
51  * bit1: double clicked
52  * bit2: tripple clicked
53  */
54 #define BUTN_BTN_STATUS_XPCLICK_MASK (0x700000UL)
55 #define BUTN_BTN_STATUS_XPCLICK_SHIFT (20U)
56 #define BUTN_BTN_STATUS_XPCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_XPCLICK_SHIFT) & BUTN_BTN_STATUS_XPCLICK_MASK)
57 #define BUTN_BTN_STATUS_XPCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_XPCLICK_MASK) >> BUTN_BTN_STATUS_XPCLICK_SHIFT)
58 
59 /*
60  * PCLICK (RW)
61  *
62  * power button click status, write 1 to clear flag
63  * bit0: clicked
64  * bit1: double clicked
65  * bit2: tripple clicked
66  */
67 #define BUTN_BTN_STATUS_PCLICK_MASK (0x70000UL)
68 #define BUTN_BTN_STATUS_PCLICK_SHIFT (16U)
69 #define BUTN_BTN_STATUS_PCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_PCLICK_SHIFT) & BUTN_BTN_STATUS_PCLICK_MASK)
70 #define BUTN_BTN_STATUS_PCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_PCLICK_MASK) >> BUTN_BTN_STATUS_PCLICK_SHIFT)
71 
72 /*
73  * DBTN (RW)
74  *
75  * Dual button press status, write 1 to clear flag
76  * bit0: button pressed
77  * bit1: button confirmd
78  * bit2: button long pressed
79  * bit3: button long long pressed
80  */
81 #define BUTN_BTN_STATUS_DBTN_MASK (0xF00U)
82 #define BUTN_BTN_STATUS_DBTN_SHIFT (8U)
83 #define BUTN_BTN_STATUS_DBTN_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_DBTN_SHIFT) & BUTN_BTN_STATUS_DBTN_MASK)
84 #define BUTN_BTN_STATUS_DBTN_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_DBTN_MASK) >> BUTN_BTN_STATUS_DBTN_SHIFT)
85 
86 /*
87  * WBTN (RW)
88  *
89  * Wake button press status, write 1 to clear flag
90  * bit0: button pressed
91  * bit1: button confirmd
92  * bit2: button long pressed
93  * bit3: button long long pressed
94  */
95 #define BUTN_BTN_STATUS_WBTN_MASK (0xF0U)
96 #define BUTN_BTN_STATUS_WBTN_SHIFT (4U)
97 #define BUTN_BTN_STATUS_WBTN_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_WBTN_SHIFT) & BUTN_BTN_STATUS_WBTN_MASK)
98 #define BUTN_BTN_STATUS_WBTN_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_WBTN_MASK) >> BUTN_BTN_STATUS_WBTN_SHIFT)
99 
100 /*
101  * PBTN (RW)
102  *
103  * Power button press status, write 1 to clear flag
104  * bit0: button pressed
105  * bit1: button confirmd
106  * bit2: button long pressed
107  * bit3: button long long pressed
108  */
109 #define BUTN_BTN_STATUS_PBTN_MASK (0xFU)
110 #define BUTN_BTN_STATUS_PBTN_SHIFT (0U)
111 #define BUTN_BTN_STATUS_PBTN_SET(x) (((uint32_t)(x) << BUTN_BTN_STATUS_PBTN_SHIFT) & BUTN_BTN_STATUS_PBTN_MASK)
112 #define BUTN_BTN_STATUS_PBTN_GET(x) (((uint32_t)(x) & BUTN_BTN_STATUS_PBTN_MASK) >> BUTN_BTN_STATUS_PBTN_SHIFT)
113 
114 /* Bitfield definition for register: BTN_IRQ_MASK */
115 /*
116  * XWCLICK (RW)
117  *
118  * wake button click status when power button held interrupt enable
119  * bit0: clicked
120  * bit1: double clicked
121  * bit2: tripple clicked
122  */
123 #define BUTN_BTN_IRQ_MASK_XWCLICK_MASK (0x70000000UL)
124 #define BUTN_BTN_IRQ_MASK_XWCLICK_SHIFT (28U)
125 #define BUTN_BTN_IRQ_MASK_XWCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_XWCLICK_SHIFT) & BUTN_BTN_IRQ_MASK_XWCLICK_MASK)
126 #define BUTN_BTN_IRQ_MASK_XWCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_XWCLICK_MASK) >> BUTN_BTN_IRQ_MASK_XWCLICK_SHIFT)
127 
128 /*
129  * WCLICK (RW)
130  *
131  * wake button click interrupt enable
132  * bit0: clicked
133  * bit1: double clicked
134  * bit2: tripple clicked
135  */
136 #define BUTN_BTN_IRQ_MASK_WCLICK_MASK (0x7000000UL)
137 #define BUTN_BTN_IRQ_MASK_WCLICK_SHIFT (24U)
138 #define BUTN_BTN_IRQ_MASK_WCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_WCLICK_SHIFT) & BUTN_BTN_IRQ_MASK_WCLICK_MASK)
139 #define BUTN_BTN_IRQ_MASK_WCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_WCLICK_MASK) >> BUTN_BTN_IRQ_MASK_WCLICK_SHIFT)
140 
141 /*
142  * XPCLICK (RW)
143  *
144  * power button click status when wake button held interrupt enable
145  * bit0: clicked
146  * bit1: double clicked
147  * bit2: tripple clicked
148  */
149 #define BUTN_BTN_IRQ_MASK_XPCLICK_MASK (0x700000UL)
150 #define BUTN_BTN_IRQ_MASK_XPCLICK_SHIFT (20U)
151 #define BUTN_BTN_IRQ_MASK_XPCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_XPCLICK_SHIFT) & BUTN_BTN_IRQ_MASK_XPCLICK_MASK)
152 #define BUTN_BTN_IRQ_MASK_XPCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_XPCLICK_MASK) >> BUTN_BTN_IRQ_MASK_XPCLICK_SHIFT)
153 
154 /*
155  * PCLICK (RW)
156  *
157  * power button click interrupt enable
158  * bit0: clicked
159  * bit1: double clicked
160  * bit2: tripple clicked
161  */
162 #define BUTN_BTN_IRQ_MASK_PCLICK_MASK (0x70000UL)
163 #define BUTN_BTN_IRQ_MASK_PCLICK_SHIFT (16U)
164 #define BUTN_BTN_IRQ_MASK_PCLICK_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_PCLICK_SHIFT) & BUTN_BTN_IRQ_MASK_PCLICK_MASK)
165 #define BUTN_BTN_IRQ_MASK_PCLICK_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_PCLICK_MASK) >> BUTN_BTN_IRQ_MASK_PCLICK_SHIFT)
166 
167 /*
168  * DBTN (RW)
169  *
170  * Dual button press interrupt enable
171  * bit0: button pressed
172  * bit1: button confirmd
173  * bit2: button long pressed
174  * bit3: button long long pressed
175  */
176 #define BUTN_BTN_IRQ_MASK_DBTN_MASK (0xF00U)
177 #define BUTN_BTN_IRQ_MASK_DBTN_SHIFT (8U)
178 #define BUTN_BTN_IRQ_MASK_DBTN_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_DBTN_SHIFT) & BUTN_BTN_IRQ_MASK_DBTN_MASK)
179 #define BUTN_BTN_IRQ_MASK_DBTN_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_DBTN_MASK) >> BUTN_BTN_IRQ_MASK_DBTN_SHIFT)
180 
181 /*
182  * WBTN (RW)
183  *
184  * Wake button press interrupt enable
185  * bit0: button pressed
186  * bit1: button confirmd
187  * bit2: button long pressed
188  * bit3: button long long pressed
189  */
190 #define BUTN_BTN_IRQ_MASK_WBTN_MASK (0xF0U)
191 #define BUTN_BTN_IRQ_MASK_WBTN_SHIFT (4U)
192 #define BUTN_BTN_IRQ_MASK_WBTN_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_WBTN_SHIFT) & BUTN_BTN_IRQ_MASK_WBTN_MASK)
193 #define BUTN_BTN_IRQ_MASK_WBTN_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_WBTN_MASK) >> BUTN_BTN_IRQ_MASK_WBTN_SHIFT)
194 
195 /*
196  * PBTN (RW)
197  *
198  * Power button press interrupt enable
199  * bit0: button pressed
200  * bit1: button confirmd
201  * bit2: button long pressed
202  * bit3: button long long pressed
203  */
204 #define BUTN_BTN_IRQ_MASK_PBTN_MASK (0xFU)
205 #define BUTN_BTN_IRQ_MASK_PBTN_SHIFT (0U)
206 #define BUTN_BTN_IRQ_MASK_PBTN_SET(x) (((uint32_t)(x) << BUTN_BTN_IRQ_MASK_PBTN_SHIFT) & BUTN_BTN_IRQ_MASK_PBTN_MASK)
207 #define BUTN_BTN_IRQ_MASK_PBTN_GET(x) (((uint32_t)(x) & BUTN_BTN_IRQ_MASK_PBTN_MASK) >> BUTN_BTN_IRQ_MASK_PBTN_SHIFT)
208 
209 /* Bitfield definition for register: LED_INTENSE */
210 /*
211  * RLED (RW)
212  *
213  * Rbutton brightness 0
214  */
215 #define BUTN_LED_INTENSE_RLED_MASK (0xF0000UL)
216 #define BUTN_LED_INTENSE_RLED_SHIFT (16U)
217 #define BUTN_LED_INTENSE_RLED_SET(x) (((uint32_t)(x) << BUTN_LED_INTENSE_RLED_SHIFT) & BUTN_LED_INTENSE_RLED_MASK)
218 #define BUTN_LED_INTENSE_RLED_GET(x) (((uint32_t)(x) & BUTN_LED_INTENSE_RLED_MASK) >> BUTN_LED_INTENSE_RLED_SHIFT)
219 
220 /*
221  * PLED (RW)
222  *
223  * Pbutton brightness 0
224  */
225 #define BUTN_LED_INTENSE_PLED_MASK (0xFU)
226 #define BUTN_LED_INTENSE_PLED_SHIFT (0U)
227 #define BUTN_LED_INTENSE_PLED_SET(x) (((uint32_t)(x) << BUTN_LED_INTENSE_PLED_SHIFT) & BUTN_LED_INTENSE_PLED_MASK)
228 #define BUTN_LED_INTENSE_PLED_GET(x) (((uint32_t)(x) & BUTN_LED_INTENSE_PLED_MASK) >> BUTN_LED_INTENSE_PLED_SHIFT)
229 
230 
231 
232 
233 #endif /* HPM_BUTN_H */
234