mbed

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Fri Feb 16 16:09:33 2018 +0000
Revision:
182:57724642e740
Parent:
173:7d866c31b3c5
mbed-dev library. Release version 159.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 173:7d866c31b3c5 1 /* mbed Microcontroller Library
AnnaBridge 173:7d866c31b3c5 2 * Copyright (c) 2015-2016 Nuvoton
AnnaBridge 173:7d866c31b3c5 3 *
AnnaBridge 173:7d866c31b3c5 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 173:7d866c31b3c5 5 * you may not use this file except in compliance with the License.
AnnaBridge 173:7d866c31b3c5 6 * You may obtain a copy of the License at
AnnaBridge 173:7d866c31b3c5 7 *
AnnaBridge 173:7d866c31b3c5 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 173:7d866c31b3c5 9 *
AnnaBridge 173:7d866c31b3c5 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 173:7d866c31b3c5 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 173:7d866c31b3c5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 173:7d866c31b3c5 13 * See the License for the specific language governing permissions and
AnnaBridge 173:7d866c31b3c5 14 * limitations under the License.
AnnaBridge 173:7d866c31b3c5 15 */
AnnaBridge 173:7d866c31b3c5 16
AnnaBridge 173:7d866c31b3c5 17 #include "mbed_assert.h"
AnnaBridge 173:7d866c31b3c5 18 #include "pinmap.h"
AnnaBridge 173:7d866c31b3c5 19 #include "PortNames.h"
AnnaBridge 173:7d866c31b3c5 20 #include "mbed_error.h"
AnnaBridge 173:7d866c31b3c5 21
AnnaBridge 173:7d866c31b3c5 22 /**
AnnaBridge 173:7d866c31b3c5 23 * Configure pin multi-function
AnnaBridge 173:7d866c31b3c5 24 */
AnnaBridge 173:7d866c31b3c5 25 void pin_function(PinName pin, int data)
AnnaBridge 173:7d866c31b3c5 26 {
AnnaBridge 173:7d866c31b3c5 27 MBED_ASSERT(pin != (PinName)NC);
AnnaBridge 173:7d866c31b3c5 28 uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
AnnaBridge 173:7d866c31b3c5 29 uint32_t port_index = NU_PINNAME_TO_PORT(pin);
AnnaBridge 173:7d866c31b3c5 30 __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
AnnaBridge 173:7d866c31b3c5 31 uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
AnnaBridge 173:7d866c31b3c5 32
AnnaBridge 173:7d866c31b3c5 33 // E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ;
AnnaBridge 173:7d866c31b3c5 34 *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
AnnaBridge 173:7d866c31b3c5 35 }
AnnaBridge 173:7d866c31b3c5 36
AnnaBridge 173:7d866c31b3c5 37 /**
AnnaBridge 173:7d866c31b3c5 38 * Configure pin pull-up/pull-down
AnnaBridge 173:7d866c31b3c5 39 */
AnnaBridge 173:7d866c31b3c5 40 void pin_mode(PinName pin, PinMode mode)
AnnaBridge 173:7d866c31b3c5 41 {
AnnaBridge 173:7d866c31b3c5 42 MBED_ASSERT(pin != (PinName)NC);
AnnaBridge 173:7d866c31b3c5 43 uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
AnnaBridge 173:7d866c31b3c5 44 uint32_t port_index = NU_PINNAME_TO_PORT(pin);
AnnaBridge 173:7d866c31b3c5 45 GPIO_T *gpio_base = NU_PORT_BASE(port_index);
AnnaBridge 173:7d866c31b3c5 46
AnnaBridge 173:7d866c31b3c5 47 uint32_t mode_intern = GPIO_MODE_INPUT;
AnnaBridge 173:7d866c31b3c5 48
AnnaBridge 173:7d866c31b3c5 49 switch (mode) {
AnnaBridge 173:7d866c31b3c5 50 case PullUp:
AnnaBridge 173:7d866c31b3c5 51 mode_intern = GPIO_MODE_INPUT;
AnnaBridge 173:7d866c31b3c5 52 break;
AnnaBridge 173:7d866c31b3c5 53
AnnaBridge 173:7d866c31b3c5 54 case PullDown:
AnnaBridge 173:7d866c31b3c5 55 case PullNone:
AnnaBridge 173:7d866c31b3c5 56 // NOTE: Not support
AnnaBridge 173:7d866c31b3c5 57 return;
AnnaBridge 173:7d866c31b3c5 58
AnnaBridge 173:7d866c31b3c5 59 case PushPull:
AnnaBridge 173:7d866c31b3c5 60 mode_intern = GPIO_MODE_OUTPUT;
AnnaBridge 173:7d866c31b3c5 61 break;
AnnaBridge 173:7d866c31b3c5 62
AnnaBridge 173:7d866c31b3c5 63 case OpenDrain:
AnnaBridge 173:7d866c31b3c5 64 mode_intern = GPIO_MODE_OPEN_DRAIN;
AnnaBridge 173:7d866c31b3c5 65 break;
AnnaBridge 173:7d866c31b3c5 66
AnnaBridge 173:7d866c31b3c5 67 case Quasi:
AnnaBridge 173:7d866c31b3c5 68 mode_intern = GPIO_MODE_QUASI;
AnnaBridge 173:7d866c31b3c5 69 break;
AnnaBridge 173:7d866c31b3c5 70 }
AnnaBridge 173:7d866c31b3c5 71
AnnaBridge 173:7d866c31b3c5 72 GPIO_SetMode(gpio_base, 1 << pin_index, mode_intern);
AnnaBridge 173:7d866c31b3c5 73 }