USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Sat Dec 16 10:26:48 2017 +0000
Revision:
11:b3f2a8bdac4d
Parent:
10:41552d038a69
A copy for D.S;

Who changed what in which revision?

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