]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c
Merge commit 'fdc38ef3f92af7adeeb4de49550d8838c8a39b5c'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / gpio_api.c
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "mbed_assert.h"
17 #include "gpio_api.h"
18 #include "pinmap.h"
19 #include "fsl_port_hal.h"
20 #include "fsl_gpio_hal.h"
21 #include "fsl_sim_hal.h"
22 #include "fsl_clock_manager.h"
23
24 uint32_t gpio_set(PinName pin) {
25 MBED_ASSERT(pin != (PinName)NC);
26 uint32_t pin_num = pin & 0xFF;
27
28 pin_function(pin, (int)kPortMuxAsGpio);
29 return 1 << pin_num;
30 }
31
32 void gpio_init(gpio_t *obj, PinName pin) {
33 obj->pin = pin;
34 if (pin == (PinName)NC)
35 return;
36
37 uint32_t port = pin >> GPIO_PORT_SHIFT;
38 uint32_t port_addrs[] = PORT_BASE_ADDRS;
39 uint32_t pin_num = pin & 0xFF;
40 CLOCK_SYS_EnablePortClock(port);
41 PORT_HAL_SetMuxMode(port_addrs[port], pin_num, kPortMuxAsGpio);
42 }
43
44 void gpio_mode(gpio_t *obj, PinMode mode) {
45 pin_mode(obj->pin, mode);
46 }
47
48 void gpio_dir(gpio_t *obj, PinDirection direction) {
49 MBED_ASSERT(obj->pin != (PinName)NC);
50 uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
51 uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
52 uint32_t pin_num = obj->pin & 0xFF;
53
54 switch (direction) {
55 case PIN_INPUT:
56 GPIO_HAL_SetPinDir(gpio_addrs[port], pin_num, kGpioDigitalInput);
57 break;
58 case PIN_OUTPUT:
59 GPIO_HAL_SetPinDir(gpio_addrs[port], pin_num, kGpioDigitalOutput);
60 break;
61 }
62 }
Imprint / Impressum