Morpheus / target-freescale-ksdk

Fork of target-freescale-ksdk by -deleted-

Committer:
screamer
Date:
Wed Mar 23 21:26:50 2016 +0000
Revision:
0:e4d670b91a9a
Initial revision

Who changed what in which revision?

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