]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20XX/pinmap.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_K20XX / pinmap.c
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2015 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 "pinmap.h"
18
19 void pin_function(PinName pin, int function) {
20     MBED_ASSERT(pin != (PinName)NC);
21
22     uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
23     uint32_t pin_n  = (uint32_t)(pin & 0x7C) >> 2;
24
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];
27
28     // pin mux bits: [10:8] -> 11100000000 = (0x700)
29     *pin_pcr = (*pin_pcr & ~0x700) | (function << 8);
30 }
31
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);
35
36     // pin pullup bits: [1:0] -> 11 = (0x3)
37     *pin_pcr = (*pin_pcr & ~0x3) | mode;
38 }