]>
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
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "mbed_assert.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"
24 uint32_t gpio_set(PinName pin
) {
25 MBED_ASSERT(pin
!= (PinName
)NC
);
26 uint32_t pin_num
= pin
& 0xFF;
28 pin_function(pin
, (int)kPortMuxAsGpio
);
32 void gpio_init(gpio_t
*obj
, PinName pin
) {
34 if (pin
== (PinName
)NC
)
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
);
44 void gpio_mode(gpio_t
*obj
, PinMode mode
) {
45 pin_mode(obj
->pin
, mode
);
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;
56 GPIO_HAL_SetPinDir(gpio_addrs
[port
], pin_num
, kGpioDigitalInput
);
59 GPIO_HAL_SetPinDir(gpio_addrs
[port
], pin_num
, kGpioDigitalOutput
);