1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 #include <stdio.h>
22 #include "qdec.h"
23 #include "qdec_regs.h"
24 #include "qdec_reva.h"
25 #include "mxc_device.h"
26 #include "mxc_errors.h"
27 #include "mxc_assert.h"
28 #include "mxc_sys.h"
29 #include "mcr_regs.h"
30 #include "mxc_lock.h"
31 #include "mxc_pins.h"
32 
MXC_QDEC_Init(mxc_qdec_req_t * req)33 int MXC_QDEC_Init(mxc_qdec_req_t *req)
34 {
35     MXC_SYS_Reset_Periph(MXC_SYS_RESET1_QDEC);
36     MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_QDEC);
37 
38     MXC_GPIO_Config(&gpio_cfg_qdec_in);
39     MXC_GPIO_Config(&gpio_cfg_qdec_out);
40 
41     return MXC_QDEC_RevA_Init((mxc_qdec_reva_regs_t *)MXC_QDEC, req);
42 }
43 
MXC_QDEC_Shutdown(void)44 int MXC_QDEC_Shutdown(void)
45 {
46     MXC_QDEC_RevA_Shutdown((mxc_qdec_reva_regs_t *)MXC_QDEC);
47 
48     MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_QDEC);
49 
50     return E_NO_ERROR;
51 }
52 
MXC_QDEC_EnableInt(uint32_t flags)53 void MXC_QDEC_EnableInt(uint32_t flags)
54 {
55     MXC_QDEC_RevA_EnableInt((mxc_qdec_reva_regs_t *)MXC_QDEC, flags);
56 }
57 
MXC_QDEC_DisableInt(uint32_t flags)58 void MXC_QDEC_DisableInt(uint32_t flags)
59 {
60     MXC_QDEC_RevA_DisableInt((mxc_qdec_reva_regs_t *)MXC_QDEC, flags);
61 }
62 
MXC_QDEC_GetFlags(void)63 int MXC_QDEC_GetFlags(void)
64 {
65     return MXC_QDEC_RevA_GetFlags((mxc_qdec_reva_regs_t *)MXC_QDEC);
66 }
67 
MXC_QDEC_ClearFlags(uint32_t flags)68 void MXC_QDEC_ClearFlags(uint32_t flags)
69 {
70     MXC_QDEC_RevA_ClearFlags((mxc_qdec_reva_regs_t *)MXC_QDEC, flags);
71 }
72 
MXC_QDEC_SetMaxCount(uint32_t maxCount)73 void MXC_QDEC_SetMaxCount(uint32_t maxCount)
74 {
75     MXC_QDEC_RevA_SetMaxCount((mxc_qdec_reva_regs_t *)MXC_QDEC, maxCount);
76 }
77 
MXC_QDEC_GetMaxCount(void)78 int MXC_QDEC_GetMaxCount(void)
79 {
80     return MXC_QDEC_RevA_GetMaxCount((mxc_qdec_reva_regs_t *)MXC_QDEC);
81 }
82 
MXC_QDEC_SetInitial(uint32_t initial)83 void MXC_QDEC_SetInitial(uint32_t initial)
84 {
85     MXC_QDEC_RevA_SetInitial((mxc_qdec_reva_regs_t *)MXC_QDEC, initial);
86 }
87 
MXC_QDEC_GetInitial(void)88 int MXC_QDEC_GetInitial(void)
89 {
90     return MXC_QDEC_RevA_GetInitial((mxc_qdec_reva_regs_t *)MXC_QDEC);
91 }
92 
MXC_QDEC_SetCompare(uint32_t compare)93 void MXC_QDEC_SetCompare(uint32_t compare)
94 {
95     MXC_QDEC_RevA_SetCompare((mxc_qdec_reva_regs_t *)MXC_QDEC, compare);
96 }
97 
MXC_QDEC_GetCompare(void)98 int MXC_QDEC_GetCompare(void)
99 {
100     return MXC_QDEC_RevA_GetCompare((mxc_qdec_reva_regs_t *)MXC_QDEC);
101 }
102 
MXC_QDEC_GetIndex(void)103 int MXC_QDEC_GetIndex(void)
104 {
105     return MXC_QDEC_RevA_GetIndex((mxc_qdec_reva_regs_t *)MXC_QDEC);
106 }
107 
MXC_QDEC_GetCapture(void)108 int MXC_QDEC_GetCapture(void)
109 {
110     return MXC_QDEC_RevA_GetCapture((mxc_qdec_reva_regs_t *)MXC_QDEC);
111 }
112 
MXC_QDEC_Handler(void)113 int MXC_QDEC_Handler(void)
114 {
115     return MXC_QDEC_RevA_Handler((mxc_qdec_reva_regs_t *)MXC_QDEC);
116 }
117 
MXC_QDEC_GetDirection(void)118 int MXC_QDEC_GetDirection(void)
119 {
120     return MXC_QDEC_RevA_GetDirection((mxc_qdec_reva_regs_t *)MXC_QDEC);
121 }
122 
MXC_QDEC_GetPosition(void)123 int MXC_QDEC_GetPosition(void)
124 {
125     return MXC_QDEC_RevA_GetPosition((mxc_qdec_reva_regs_t *)MXC_QDEC);
126 }
127