1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2015 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 void pin_function(PinName pin, int function) {
20 MBED_ASSERT(pin != (PinName)NC);
22 uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
23 uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
25 SIM->SCGC5 |= 1 << (SIM_SCGC5_PORTA_SHIFT + port_n);
26 __IO uint32_t* pin_pcr = &(((PORT_Type *)(PORTA_BASE + 0x1000 * port_n)))->PCR[pin_n];
28 // pin mux bits: [10:8] -> 11100000000 = (0x700)
29 *pin_pcr = (*pin_pcr & ~0x700) | (function << 8);
32 void pin_mode(PinName pin, PinMode mode) {
33 MBED_ASSERT(pin != (PinName)NC);
34 __IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);
36 // pin pullup bits: [1:0] -> 11 = (0x3)
37 *pin_pcr = (*pin_pcr & ~0x3) | mode;