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 "smoh.h"
22 #include "skbd.h"
23 #include "skbd_reva.h"
24 #include "gpio.h"
25 #include "mxc_assert.h"
26 #include "mxc_pins.h"
27 #include "mxc_sys.h"
28 #include "mxc_lock.h"
29 
MXC_SKBD_PreInit(void)30 int MXC_SKBD_PreInit(void)
31 {
32     return MXC_SKBD_RevA_PreInit();
33 }
34 
MXC_SKBD_Init(mxc_skbd_config_t config)35 int MXC_SKBD_Init(mxc_skbd_config_t config)
36 {
37     /* Enable the SKBD clock i.e. just in case clock is disabled */
38     MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_CTB);
39     MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_SKBD);
40 
41     /* Set the SKBD GPIO configs */
42     MXC_GPIO_Config(&gpio_cfg_skbd_P2);
43 
44     return MXC_SKBD_RevA_Init((mxc_skbd_reva_regs_t *)MXC_SKBD, config);
45 }
46 
MXC_SKBD_EnableInterruptEvents(unsigned int events)47 int MXC_SKBD_EnableInterruptEvents(unsigned int events)
48 {
49     return MXC_SKBD_RevA_EnableInterruptEvents((mxc_skbd_reva_regs_t *)MXC_SKBD, events);
50 }
51 
MXC_SKBD_DisableInterruptEvents(unsigned int events)52 int MXC_SKBD_DisableInterruptEvents(unsigned int events)
53 {
54     return MXC_SKBD_RevA_DisableInterruptEvents((mxc_skbd_reva_regs_t *)MXC_SKBD, events);
55 }
56 
MXC_SKBD_ClearInterruptStatus(unsigned int status)57 int MXC_SKBD_ClearInterruptStatus(unsigned int status)
58 {
59     return MXC_SKBD_RevA_ClearInterruptStatus((mxc_skbd_reva_regs_t *)MXC_SKBD, status);
60 }
61 
MXC_SKBD_InterruptStatus(unsigned int * status)62 int MXC_SKBD_InterruptStatus(unsigned int *status)
63 {
64     return MXC_SKBD_RevA_InterruptStatus((mxc_skbd_reva_regs_t *)MXC_SKBD, status);
65 }
66 
MXC_SKBD_ReadKeys(mxc_skbd_keys_t * keys)67 int MXC_SKBD_ReadKeys(mxc_skbd_keys_t *keys)
68 {
69     return MXC_SKBD_RevA_ReadKeys((mxc_skbd_reva_regs_t *)MXC_SKBD, (mxc_skbd_reva_keys_t *)keys);
70 }
71 
MXC_SKBD_Close(void)72 int MXC_SKBD_Close(void)
73 {
74     /* Reset the SKBD controller */
75     MXC_SYS_Reset_Periph(MXC_SYS_RESET1_SKBD);
76 
77     /* Wait until SKBD reset completes */
78     while (MXC_F_GCR_RST1_SKBD & MXC_GCR->rst1) {}
79 
80     return MXC_SKBD_RevA_Close();
81 }
82 
MXC_SKBD_GetVersion(void)83 const char *MXC_SKBD_GetVersion(void)
84 {
85     return MXC_SKBD_REVA_VERSION_STRING;
86 }
87