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 /* **** Includes **** */
22 #include <stddef.h>
23 #include "mxc_sys.h"
24 #include "mxc_device.h"
25 #include "mxc_assert.h"
26 #include "mxc_pins.h"
27 #include "gpio.h"
28 #include "gpio_reva.h"
29 #include "gpio_common.h"
30 #include "uart.h"
31 #include "uart_revb.h"
32 #include "uart_common.h"
33 #include "mcr_regs.h"
34 #include "dma.h"
35 
36 /* **** Functions **** */
37 
MXC_AFE_GPIO_Config(const mxc_gpio_cfg_t * cfg)38 int MXC_AFE_GPIO_Config(const mxc_gpio_cfg_t *cfg)
39 {
40     int error;
41     mxc_gpio_regs_t *gpio = cfg->port;
42 
43     // Configure alternate function
44     error = MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)gpio, cfg->func, cfg->mask);
45 
46     if (error != E_NO_ERROR) {
47         return error;
48     }
49 
50     // Configure the pad
51     switch (cfg->pad) {
52     case MXC_GPIO_PAD_NONE:
53         gpio->padctrl0 &= ~cfg->mask;
54         gpio->padctrl1 &= ~cfg->mask;
55         break;
56 
57     case MXC_GPIO_PAD_PULL_UP:
58         gpio->padctrl0 |= cfg->mask;
59         gpio->padctrl1 |= cfg->mask;
60         gpio->ps |= cfg->mask;
61         break;
62 
63     case MXC_GPIO_PAD_PULL_DOWN:
64         gpio->padctrl0 |= cfg->mask;
65         gpio->padctrl1 |= cfg->mask;
66         gpio->ps &= ~cfg->mask;
67         break;
68 
69     default:
70         return E_BAD_PARAM;
71     }
72 
73     return E_NO_ERROR;
74 }
75