Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Pmods/PmodIOXP/ADP5589.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ADP5589.h
3 * @brief Header File for ADP5589 Driver.
4 * @author ATofan ([email protected])
5 ********************************************************************************
6 * Copyright 2012(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 ********************************************************************************
40 * SVN Revision: $WCREV$
41 *******************************************************************************/
42
43 /*****************************************************************************/
44 /***************************** Include Files *********************************/
45 /*****************************************************************************/
46 #include "xil_types.h"
47 #include "xparameters.h"
48
49 /*****************************************************************************/
50 /******************* ADP5589 Registers Definitions ***************************/
51 /*****************************************************************************/
52 // ADP5589 IIC Address
53 #define I2C_BASEADDR XPAR_AXI_IIC_1_BASEADDR
54 #define ADP5589_I2C_ADDR 0x34
55 // Register address
56 #define IDReg 0x00
57 #define INTStatusReg 0x01
58 #define StatusReg 0x02
59 #define FIFO1Reg 0x03
60 #define FIFO2Reg 0x04
61 #define FIFO3Reg 0x05
62 #define FIFO4Reg 0x06
63 #define FIFO5Reg 0x07
64 #define FIFO6Reg 0x08
65 #define FIFO7Reg 0x09
66 #define FIFO8Reg 0x0A
67 #define FIFO9Reg 0x0B
68 #define FIFO10Reg 0x0C
69 #define FIFO11Reg 0x0D
70 #define FIFO12Reg 0x0E
71 #define FIFO13Reg 0x0F
72 #define FIFO14Reg 0x10
73 #define FIFO15Reg 0x11
74 #define FIFO16Reg 0x12
75 #define GPIIntStatAReg 0x13
76 #define GPIIntStatBReg 0x14
77 #define GPIIntStatCReg 0x15
78 #define GPIStatAReg 0x16
79 #define GPIStatBReg 0x17
80 #define GPIStatCReg 0x18
81 #define RPullConfigAReg 0x19
82 #define RPullConfigBReg 0x1A
83 #define RPullConfigCReg 0x1B
84 #define RPullConfigDReg 0x1C
85 #define RPullConfigEReg 0x1D
86 #define GPIIntLevelAReg 0x1E
87 #define GPIIntLevelBReg 0x1F
88 #define GPIIntLevelCReg 0x20
89 #define GPIEventEnAReg 0x21
90 #define GPIEventEnBReg 0x22
91 #define GPIEventEnCReg 0x23
92 #define GPIIntEnAReg 0x24
93 #define GPIIntEnBReg 0x25
94 #define GPIIntEnCReg 0x26
95 #define DbDisAReg 0x27
96 #define DbDisBReg 0x28
97 #define DbDisCReg 0x29
98 #define GPODataOutAReg 0x2A
99 #define GPODataOutBReg 0x2B
100 #define GPODataOutCReg 0x2C
101 #define GPOOutModeAReg 0x2D
102 #define GPOOutModeBReg 0x2E
103 #define GPOOutModeCReg 0x2F
104 #define GPIODirAReg 0x30
105 #define GPIODirBReg 0x31
106 #define GPIODirCReg 0x32
107 #define Unlock1Reg 0x33
108 #define Unlock2Reg 0x34
109 #define ExtLockEvReg 0x35
110 #define UnlockTimerReg 0x36
111 #define LockCfgReg 0x37
112 #define Reset1EvAReg 0x38
113 #define Reset1EvBReg 0x39
114 #define Reset1EvCReg 0x3A
115 #define Reset2EvAReg 0x3B
116 #define Reset2EvBReg 0x3C
117 #define ResetCfgReg 0x3D
118 #define PWMOfstLowReg 0x3E
119 #define PWMOfstHighReg 0x3F
120 #define PWMOntLowReg 0x40
121 #define PWMOntHighReg 0x41
122 #define PWMCfgReg 0x42
123 #define ClkDivCfgReg 0x43
124 #define Logic1CfgReg 0x44
125 #define Logic2CfgReg 0x45
126 #define LogicFFCfgReg 0x46
127 #define LogicIntEvEnReg 0x47
128 #define PollTimeCfgReg 0x48
129 #define PinCfgAReg 0x49
130 #define PinCfgBReg 0x4A
131 #define PinCfgCReg 0x4B
132 #define PinCfgDReg 0x4C
133 #define GenCfgBReg 0x4D
134 #define IntENReg 0x4E
135 /*****************************************************************************/
136 /******************* ADP5589 Registers Bits **********************************/
137 /*****************************************************************************/
138 // ID Register 0x00
139 #define MAN_ID 4
140 #define REV_ID 0
141 // INT_STATUS Register 0x01
142 #define LOGIC2_INT 5
143 #define LOGIC1_INT 4
144 #define LOCK_INT 3
145 #define OVERFLOW_INT 2
146 #define GPI_INT 1
147 #define EVENT_INT 0
148 // Status Register 0x02
149 #define LOGIC2_STAT 7
150 #define LOGIC1_STAT 6
151 #define LOCK_STAT 5
152 #define EC 0
153 // FIFO_1 Register 0x03
154 #define EVENT1_STATE 7
155 #define EVENT1_ID 0
156 // FIFO_2 Register 0x04
157 #define EVENT2_STATE 7
158 #define EVENT2_ID 0
159 // FIFO_3 Register 0x05
160 #define EVENT3_STATE 7
161 #define EVENT3_ID 0
162 // FIFO_4 Register 0x06
163 #define EVENT4_STATE 7
164 #define EVENT4_ID 0
165 // FIFO_5 Register 0x07
166 #define EVENT5_STATE 7
167 #define EVENT5_ID 0
168 // FIFO_6 Register 0x08
169 #define EVENT6_STATE 7
170 #define EVENT6_ID 0
171 // FIFO_7 Register 0x09
172 #define EVENT7_STATE 7
173 #define EVENT7_ID 0
174 // FIFO_8 Register 0x0A
175 #define EVENT8_STATE 7
176 #define EVENT8_ID 0
177 // FIFO_9 Register 0x0B
178 #define EVENT9_STATE 7
179 #define EVENT9_ID 0
180 // FIFO_10 Register 0x0C
181 #define EVENT10_STATE 7
182 #define EVENT10_ID 0
183 // FIFO_11 Register 0x0D
184 #define EVENT11_STATE 7
185 #define EVENT11_ID 0
186 // FIFO_12 Register 0x0E
187 #define EVENT12_STATE 7
188 #define EVENT12_ID 0
189 // FIFO_13 Register 0x0F
190 #define EVENT13_STATE 7
191 #define EVENT13_ID 0
192 // FIFO_14 Register 0x10
193 #define EVENT14_STATE 7
194 #define EVENT14_ID 0
195 // FIFO_15 Register 0x11
196 #define EVENT15_STATE 7
197 #define EVENT15_ID 0
198 // FIFO_16 Register 0x12
199 #define EVENT16_STATE 7
200 #define EVENT16_ID 0
201 // GPI_INT_STAT_A Register 0x13
202 #define GPI_8_INT 7
203 #define GPI_7_INT 6
204 #define GPI_6_INT 5
205 #define GPI_5_INT 4
206 #define GPI_4_INT 3
207 #define GPI_3_INT 2
208 #define GPI_2_INT 1
209 #define GPI_1_INT 0
210 // GPI_INT_STAT_B Register 0x14
211 #define GPI_16_INT 7
212 #define GPI_15_INT 6
213 #define GPI_14_INT 5
214 #define GPI_13_INT 4
215 #define GPI_12_INT 3
216 #define GPI_11_INT 2
217 #define GPI_10_INT 1
218 #define GPI_9_INT 0
219 // GPI_INT_STAT_C Register 0x15
220 #define GPI_19_INT 2
221 #define GPI_18_INT 1
222 #define GPI_17_INT 0
223 // GPI_STATUS_A Register 0x16
224 #define GPI_8_STAT 7
225 #define GPI_7_STAT 6
226 #define GPI_6_STAT 5
227 #define GPI_5_STAT 4
228 #define GPI_4_STAT 3
229 #define GPI_3_STAT 2
230 #define GPI_2_STAT 1
231 #define GPI_1_STAT 0
232 // GPI_STATUS_B Register 0x17
233 #define GPI_16_STAT 7
234 #define GPI_15_STAT 6
235 #define GPI_14_STAT 5
236 #define GPI_13_STAT 4
237 #define GPI_12_STAT 3
238 #define GPI_11_STAT 2
239 #define GPI_10_STAT 1
240 #define GPI_9_STAT 0
241 // GPI_STATUS_C Register 0x18
242 #define GPI_19_STAT 2
243 #define GPI_18_STAT 1
244 #define GPI_17_STAT 0
245 // RPULL_CONFIG_A Register 0x19
246 #define R3_PULL_CFG 6
247 #define R2_PULL_CFG 4
248 #define R1_PULL_CFG 2
249 #define R0_PULL_CFG 0
250 // RPULL_CONFIG_B Register 0x1A
251 #define R7_PULL_CFG 6
252 #define R6_PULL_CFG 4
253 #define R5_PULL_CFG 2
254 #define R4_PULL_CFG 0
255 // RPULL_CONFIG_C Register 0x1B
256 #define C3_PULL_CFG 6
257 #define C2_PULL_CFG 4
258 #define C1_PULL_CFG 2
259 #define C0_PULL_CFG 0
260 // RPULL_CONFIG_D Register 0x1C
261 #define C7_PULL_CFG 6
262 #define C6_PULL_CFG 4
263 #define C5_PULL_CFG 2
264 #define C4_PULL_CFG 0
265 // RPULL_CONFIG_D Register 0x1D
266 #define C10_PULL_CFG 4
267 #define C9_PULL_CFG 2
268 #define C8_PULL_CFG 0
269 // GPI_INT_LEVEL_A Register 0x1E
270 #define GPI_8_INT_LEVEL 7
271 #define GPI_7_INT_LEVEL 6
272 #define GPI_6_INT_LEVEL 5
273 #define GPI_5_INT_LEVEL 4
274 #define GPI_4_INT_LEVEL 3
275 #define GPI_3_INT_LEVEL 2
276 #define GPI_2_INT_LEVEL 1
277 #define GPI_1_INT_LEVEL 0
278 // GPI_INT_LEVEL_B Register 0x1F
279 #define GPI_16_INT_LEVEL 7
280 #define GPI_15_INT_LEVEL 6
281 #define GPI_14_INT_LEVEL 5
282 #define GPI_13_INT_LEVEL 4
283 #define GPI_12_INT_LEVEL 3
284 #define GPI_11_INT_LEVEL 2
285 #define GPI_10_INT_LEVEL 1
286 #define GPI_9_INT_LEVEL 0
287 // GPI_INT_LEVEL_C Register 0x20
288 #define GPI_19_INT_LEVEL 2
289 #define GPI_18_INT_LEVEL 1
290 #define GPI_17_INT_LEVEL 0
291 // GPI_EVENT_EN_A Register 0x21
292 #define GPI_8_EVENT_EN 7
293 #define GPI_7_EVENT_EN 6
294 #define GPI_6_EVENT_EN 5
295 #define GPI_5_EVENT_EN 4
296 #define GPI_4_EVENT_EN 3
297 #define GPI_3_EVENT_EN 2
298 #define GPI_2_EVENT_EN 1
299 #define GPI_1_EVENT_EN 0
300 // GPI_EVENT_EN_B Register 0x22
301 #define GPI_16_EVENT_EN 7
302 #define GPI_15_EVENT_EN 6
303 #define GPI_14_EVENT_EN 5
304 #define GPI_13_EVENT_EN 4
305 #define GPI_12_EVENT_EN 3
306 #define GPI_11_EVENT_EN 2
307 #define GPI_10_EVENT_EN 1
308 #define GPI_9_EVENT_EN 0
309 // GPI_EVENT_EN_C Register 0x23
310 #define GPI_19_EVENT_EN 2
311 #define GPI_18_EVENT_EN 1
312 #define GPI_17_EVENT_EN 0
313 // GPI_INTERRUPT_EN_A Register 0x24
314 #define GPI_8_INT_EN 7
315 #define GPI_7_INT_EN 6
316 #define GPI_6_INT_EN 5
317 #define GPI_5_INT_EN 4
318 #define GPI_4_INT_EN 3
319 #define GPI_3_INT_EN 2
320 #define GPI_2_INT_EN 1
321 #define GPI_1_INT_EN 0
322 // GPI_INTERRUPT_EN_B Register 0x25
323 #define GPI_16_INT_EN 7
324 #define GPI_15_INT_EN 6
325 #define GPI_14_INT_EN 5
326 #define GPI_13_INT_EN 4
327 #define GPI_12_INT_EN 3
328 #define GPI_11_INT_EN 2
329 #define GPI_10_INT_EN 1
330 #define GPI_9_INT_EN 0
331 // GPI_INTERRUPT_EN_C Register 0x26
332 #define GPI_19_INT_EN 2
333 #define GPI_18_INT_EN 1
334 #define GPI_17_INT_EN 0
335 // DEBOUNCE_DIS_A Register 0x27
336 #define GPI_8_DEB_DIS 7
337 #define GPI_7_DEB_DIS 6
338 #define GPI_6_DEB_DIS 5
339 #define GPI_5_DEB_DIS 4
340 #define GPI_4_DEB_DIS 3
341 #define GPI_3_DEB_DIS 2
342 #define GPI_2_DEB_DIS 1
343 #define GPI_1_DEB_DIS 0
344 // DEBOUNCE_DIS_B Register 0x28
345 #define GPI_16_DEB_DIS 7
346 #define GPI_15_DEB_DIS 6
347 #define GPI_14_DEB_DIS 5
348 #define GPI_13_DEB_DIS 4
349 #define GPI_12_DEB_DIS 3
350 #define GPI_11_DEB_DIS 2
351 #define GPI_10_DEB_DIS 1
352 #define GPI_9_DEB_DIS 0
353 // DEBOUNCE_DIS_C Register 0x29
354 #define GPI_19_DEB_DIS 2
355 #define GPI_18_DEB_DIS 1
356 #define GPI_17_DEB_DIS 0
357 // GPO_DATA_OUT_A Register 0x2A
358 #define GPO_8_DATA 7
359 #define GPO_7_DATA 6
360 #define GPO_6_DATA 5
361 #define GPO_5_DATA 4
362 #define GPO_4_DATA 3
363 #define GPO_3_DATA 2
364 #define GPO_2_DATA 1
365 #define GPO_1_DATA 0
366 // GPO_DATA_OUT_B Register 0x2B
367 #define GPO_16_DATA 7
368 #define GPO_15_DATA 6
369 #define GPO_14_DATA 5
370 #define GPO_13_DATA 4
371 #define GPO_12_DATA 3
372 #define GPO_11_DATA 2
373 #define GPO_10_DATA 1
374 #define GPO_9_DATA 0
375 // GPO_DATA_OUT_C Register 0x2C
376 #define GPO_19_DATA 2
377 #define GPO_18_DATA 1
378 #define GPO_17_DATA 0
379 // GPO_OUT_MODE_A Register 0x2D
380 #define GPO_8_OUT_MODE 7
381 #define GPO_7_OUT_MODE 6
382 #define GPO_6_OUT_MODE 5
383 #define GPO_5_OUT_MODE 4
384 #define GPO_4_OUT_MODE 3
385 #define GPO_3_OUT_MODE 2
386 #define GPO_2_OUT_MODE 1
387 #define GPO_1_OUT_MODE 0
388 // GPO_OUT_MODE_B Register 0x2E
389 #define GPO_16_OUT_MODE 7
390 #define GPO_15_OUT_MODE 6
391 #define GPO_14_OUT_MODE 5
392 #define GPO_13_OUT_MODE 4
393 #define GPO_12_OUT_MODE 3
394 #define GPO_11_OUT_MODE 2
395 #define GPO_10_OUT_MODE 1
396 #define GPO_9_OUT_MODE 0
397 // GPO_OUT_MODE_C Register 0x2F
398 #define GPO_19_OUT_MODE 2
399 #define GPO_18_OUT_MODE 1
400 #define GPO_17_OUT_MODE 0
401 // GPO_DATA_OUT_A Register 0x30
402 #define GPO_8_DIR 7
403 #define GPO_7_DIR 6
404 #define GPO_6_DIR 5
405 #define GPO_5_DIR 4
406 #define GPO_4_DIR 3
407 #define GPO_3_DIR 2
408 #define GPO_2_DIR 1
409 #define GPO_1_DIR 0
410 // GPO_DATA_OUT_B Register 0x31
411 #define GPO_16_DIR 7
412 #define GPO_15_DIR 6
413 #define GPO_14_DIR 5
414 #define GPO_13_DIR 4
415 #define GPO_12_DIR 3
416 #define GPO_11_DIR 2
417 #define GPO_10_DIR 1
418 #define GPO_9_DIR 0
419 // GPO_DATA_OUT_C Register 0x32
420 #define GPO_19_DIR 2
421 #define GPO_18_DIR 1
422 #define GPO_17_DIR 0
423 // UNLOCK1 Register 0x33
424 #define UNLOCK1_STATE 7
425 #define UNLOCK1 0
426 // UNLOCK2 Register 0x34
427 #define UNLOCK2_STATE 7
428 #define UNLOCK2 0
429 // EXT_LOCK_EVENT Register 0x35
430 #define EXT_LOCK_STATE 7
431 #define EXT_LOCK_EVENT 0
432 // UNLOCK_TIMERS Register 0x36
433 #define INT_MASK_TIMER 3
434 #define UNLOCK_TIMER 0
435 // LOCK_CFG Register 0x37
436 #define LOCK_EN 0
437 // RESET1_EVENT_A Register 0x38
438 #define RESET1_EVENT_A_LVL 7
439 #define RESET1_EVENT_A 0
440 // RESET1_EVENT_B Register 0x39
441 #define RESET1_EVENT_B_LVL 7
442 #define RESET1_EVENT_B 0
443 // RESET1_EVENT_A Register 0x3A
444 #define RESET1_EVENT_C_LVL 7
445 #define RESET1_EVENT_C 0
446 // RESET2_EVENT_A Register 0x3B
447 #define RESET2_EVENT_A_LVL 7
448 #define RESET2_EVENT_A 0
449 // RESET2_EVENT_B Register 0x3C
450 #define RESET2_EVENT_B_LVL 7
451 #define RESET2_EVENT_B 0
452 // RESET_CFG Register 0x3D
453 #define RESET2_POL 7
454 #define RESET1_POL 6
455 #define RST_PASSTHRU_EN 5
456 #define RESET_TRIGGER_RIME 2
457 #define RESET_PULSE_WIDTH 0
458 // PWM_OFST_LOW Register 0x3E
459 #define PWM_OFST_LOW_BYTE 0
460 // PWM_OFST_HIGH Register 0x3F
461 #define PWM_OFST_HIGH_BYTE 0
462 // PWM_ONT_LOW Register 0x40
463 #define PWM_ONT_LOW_BYTE 0
464 // PWM_ONT_HIGH Register 0x41
465 #define PWM_ONT_HIGH_BYTE 0
466 // PWM_CFG Register 0x42
467 #define PWM_IN_AND 2
468 #define PWM_MODE 1
469 #define PWM_EN 0
470 // CLOCK_DIV_CFG Register 0x43
471 #define CLK_INV 6
472 #define CLK_DIV 1
473 #define CLK_DIV_EN 0
474 // LOGIC_1_CFG Register 0x44
475 #define LY1_INV 6
476 #define LC1_INV 5
477 #define LB1_INV 4
478 #define LA1_INV 3
479 #define LOGIC1_SEL 0
480 // LOGIC_2_CFG Register 0x45
481 #define LY1_CASCADE 7
482 #define LY2_INV 6
483 #define LC2_INV 5
484 #define LB2_INV 4
485 #define LA2_INV 3
486 #define LOGIC2_SEL 0
487 // LOGIC_FF_CFG Register 0x46
488 #define FF2_SET 3
489 #define FF2_CLR 2
490 #define FF1_SET 1
491 #define FF1_CLR 0
492 // LOGIC_INT_EVENT_EN Register 0x47
493 #define LY2_DBNC_DIS 5
494 #define LOGIC2_EVENT_EN 4
495 #define LOGIC2_INT_LEVEL 3
496 #define LY1_DBNC_DIS 2
497 #define LOGIC1_EVENT_EN 1
498 #define LOGIC1_INT_LEVEL 0
499 // POLL_TIME_CFG Register 0x48
500 #define KEY_POLL_TIME 0
501 // PIN_CONFIG_A Register 0x49
502 #define R7_CONFIG 7
503 #define R6_CONFIG 6
504 #define R5_CONFIG 5
505 #define R4_CONFIG 4
506 #define R3_CONFIG 3
507 #define R2_CONFIG 2
508 #define R1_CONFIG 1
509 #define R0_CONFIG 0
510 // PIN_CONFIG_C Register 0x4A
511 #define C7_CONFIG 7
512 #define C6_CONFIG 6
513 #define C5_CONFIG 5
514 #define C4_CONFIG 4
515 #define C3_CONFIG 3
516 #define C2_CONFIG 2
517 #define C1_CONFIG 1
518 #define C0_CONFIG 0
519 // PIN_CONFIG_C Register 0x4B
520 #define C10_CONFIG 2
521 #define C9_CONFIG 1
522 #define C8_CONFIG 0
523 // PIN_CONFIG_D Register 0x4C
524 #define PULL_SELECT 7
525 #define C4_EXTEND_CFG 6
526 #define R4_EXTEND_CFG 5
527 #define C6_EXTEND_CFG 4
528 #define R3_EXTEND_CFG 2
529 #define C9_EXTEND_CFG 1
530 #define R0_EXTEND_CFG 0
531 // GENERAL_CFG_B Register 0x4D
532 #define OSC_EN 7
533 #define CORE_FREQ 5
534 #define LCK_TRK_LOGIC 4
535 #define LCK_TRK_GPI 3
536 #define INT_CFG 1
537 #define RST_CFG 0
538 // INT_EN Register 0x4E
539 #define LOGIC2_IEN 5
540 #define LOGIC1_IEN 4
541 #define LOCK_IEN 3
542 #define OVERFLOW_IEN 2
543 #define GPI_IEN 1
544 #define EVENT_IEN 0
545
546 /*****************************************************************************/
547 /************************ Functions Declarations *****************************/
548 /*****************************************************************************/
549 char KeyDecode(int rxData);
550 void FlushFIFO(void);
551 void ADP5589_Init(void);
552 void ADP5589_KeyDecodeTest(void);
553 void ADP5589_KeyLockTest(void);
554 void DemoProgram(void);