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