Forked.
Fork of mbed-dev by
targets/TARGET_TOSHIBA/TARGET_TMPM066/pinmap.c@172:7d866c31b3c5, 2017-08-31 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Aug 31 17:27:04 2017 +0100
- Revision:
- 172:7d866c31b3c5
This updates the lib to the mbed lib v 150
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 172:7d866c31b3c5 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 172:7d866c31b3c5 | 2 | * (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2017 All rights reserved |
AnnaBridge | 172:7d866c31b3c5 | 3 | * |
AnnaBridge | 172:7d866c31b3c5 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 172:7d866c31b3c5 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 172:7d866c31b3c5 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 172:7d866c31b3c5 | 7 | * |
AnnaBridge | 172:7d866c31b3c5 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 172:7d866c31b3c5 | 9 | * |
AnnaBridge | 172:7d866c31b3c5 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 172:7d866c31b3c5 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 172:7d866c31b3c5 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 172:7d866c31b3c5 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 172:7d866c31b3c5 | 14 | * limitations under the License. |
AnnaBridge | 172:7d866c31b3c5 | 15 | */ |
AnnaBridge | 172:7d866c31b3c5 | 16 | #include "mbed_assert.h" |
AnnaBridge | 172:7d866c31b3c5 | 17 | #include "pinmap.h" |
AnnaBridge | 172:7d866c31b3c5 | 18 | #include "tmpm066_gpio.h" |
AnnaBridge | 172:7d866c31b3c5 | 19 | |
AnnaBridge | 172:7d866c31b3c5 | 20 | #define PIN_FUNC_MAX 6 |
AnnaBridge | 172:7d866c31b3c5 | 21 | |
AnnaBridge | 172:7d866c31b3c5 | 22 | void pin_function(PinName pin, int function) |
AnnaBridge | 172:7d866c31b3c5 | 23 | { |
AnnaBridge | 172:7d866c31b3c5 | 24 | uint32_t port = 0; |
AnnaBridge | 172:7d866c31b3c5 | 25 | uint8_t bit = 0; |
AnnaBridge | 172:7d866c31b3c5 | 26 | uint8_t i = 0; |
AnnaBridge | 172:7d866c31b3c5 | 27 | uint8_t func = 0; |
AnnaBridge | 172:7d866c31b3c5 | 28 | uint8_t dir = 0; |
AnnaBridge | 172:7d866c31b3c5 | 29 | |
AnnaBridge | 172:7d866c31b3c5 | 30 | // Assert that pin is valid |
AnnaBridge | 172:7d866c31b3c5 | 31 | MBED_ASSERT(pin != NC); |
AnnaBridge | 172:7d866c31b3c5 | 32 | |
AnnaBridge | 172:7d866c31b3c5 | 33 | // Calculate pin function and pin direction |
AnnaBridge | 172:7d866c31b3c5 | 34 | func = PIN_FUNC(function); |
AnnaBridge | 172:7d866c31b3c5 | 35 | dir = PIN_DIR(function); |
AnnaBridge | 172:7d866c31b3c5 | 36 | // Calculate port and pin position |
AnnaBridge | 172:7d866c31b3c5 | 37 | port = PIN_PORT(pin); |
AnnaBridge | 172:7d866c31b3c5 | 38 | bit = PIN_POS(pin); |
AnnaBridge | 172:7d866c31b3c5 | 39 | // Set function if function is in range |
AnnaBridge | 172:7d866c31b3c5 | 40 | if (func <= PIN_FUNC_MAX) { |
AnnaBridge | 172:7d866c31b3c5 | 41 | // Disable other functions |
AnnaBridge | 172:7d866c31b3c5 | 42 | for (i = 0; i < PIN_FUNC_MAX; i++) { |
AnnaBridge | 172:7d866c31b3c5 | 43 | if (i != (func - 1)) { |
AnnaBridge | 172:7d866c31b3c5 | 44 | GPIO_DisableFuncReg((GPIO_Port)port, i, (1 << bit)); |
AnnaBridge | 172:7d866c31b3c5 | 45 | } |
AnnaBridge | 172:7d866c31b3c5 | 46 | } |
AnnaBridge | 172:7d866c31b3c5 | 47 | // Set pin function |
AnnaBridge | 172:7d866c31b3c5 | 48 | if (func) { |
AnnaBridge | 172:7d866c31b3c5 | 49 | GPIO_EnableFuncReg((GPIO_Port)port, (uint8_t)(func - 1), (1 << bit)); |
AnnaBridge | 172:7d866c31b3c5 | 50 | } |
AnnaBridge | 172:7d866c31b3c5 | 51 | } |
AnnaBridge | 172:7d866c31b3c5 | 52 | |
AnnaBridge | 172:7d866c31b3c5 | 53 | // Set direction if direction is in range |
AnnaBridge | 172:7d866c31b3c5 | 54 | switch (dir) { |
AnnaBridge | 172:7d866c31b3c5 | 55 | case PIN_INPUT: |
AnnaBridge | 172:7d866c31b3c5 | 56 | GPIO_SetInputEnableReg((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 57 | GPIO_SetOutputEnableReg((GPIO_Port)port, (1 << bit), DISABLE); |
AnnaBridge | 172:7d866c31b3c5 | 58 | break; |
AnnaBridge | 172:7d866c31b3c5 | 59 | case PIN_OUTPUT: |
AnnaBridge | 172:7d866c31b3c5 | 60 | GPIO_SetOutputEnableReg((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 61 | GPIO_SetInputEnableReg((GPIO_Port)port, (1 << bit), DISABLE); |
AnnaBridge | 172:7d866c31b3c5 | 62 | break; |
AnnaBridge | 172:7d866c31b3c5 | 63 | case PIN_INOUT: |
AnnaBridge | 172:7d866c31b3c5 | 64 | GPIO_SetOutputEnableReg((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 65 | GPIO_SetInputEnableReg((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 66 | break; |
AnnaBridge | 172:7d866c31b3c5 | 67 | default: |
AnnaBridge | 172:7d866c31b3c5 | 68 | break; |
AnnaBridge | 172:7d866c31b3c5 | 69 | } |
AnnaBridge | 172:7d866c31b3c5 | 70 | } |
AnnaBridge | 172:7d866c31b3c5 | 71 | |
AnnaBridge | 172:7d866c31b3c5 | 72 | void pin_mode(PinName pin, PinMode mode) |
AnnaBridge | 172:7d866c31b3c5 | 73 | { |
AnnaBridge | 172:7d866c31b3c5 | 74 | uint32_t port = 0; |
AnnaBridge | 172:7d866c31b3c5 | 75 | uint8_t bit = 0; |
AnnaBridge | 172:7d866c31b3c5 | 76 | |
AnnaBridge | 172:7d866c31b3c5 | 77 | // Assert that pin is valid |
AnnaBridge | 172:7d866c31b3c5 | 78 | MBED_ASSERT(pin != NC); |
AnnaBridge | 172:7d866c31b3c5 | 79 | |
AnnaBridge | 172:7d866c31b3c5 | 80 | // Check if function is in range |
AnnaBridge | 172:7d866c31b3c5 | 81 | if (mode > OpenDrain) { |
AnnaBridge | 172:7d866c31b3c5 | 82 | return; |
AnnaBridge | 172:7d866c31b3c5 | 83 | } |
AnnaBridge | 172:7d866c31b3c5 | 84 | // Calculate port and pin position |
AnnaBridge | 172:7d866c31b3c5 | 85 | port = PIN_PORT(pin); |
AnnaBridge | 172:7d866c31b3c5 | 86 | bit = PIN_POS(pin); |
AnnaBridge | 172:7d866c31b3c5 | 87 | // Set pin mode |
AnnaBridge | 172:7d866c31b3c5 | 88 | switch (mode) { |
AnnaBridge | 172:7d866c31b3c5 | 89 | case PullNone: |
AnnaBridge | 172:7d866c31b3c5 | 90 | GPIO_SetPullUp((GPIO_Port)port, (1 << bit), DISABLE); |
AnnaBridge | 172:7d866c31b3c5 | 91 | GPIO_SetPullDown((GPIO_Port)port, (1 << bit), DISABLE); |
AnnaBridge | 172:7d866c31b3c5 | 92 | GPIO_SetOpenDrain((GPIO_Port)port, (1 << bit), DISABLE); |
AnnaBridge | 172:7d866c31b3c5 | 93 | break; |
AnnaBridge | 172:7d866c31b3c5 | 94 | case PullUp: |
AnnaBridge | 172:7d866c31b3c5 | 95 | GPIO_SetPullUp((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 96 | break; |
AnnaBridge | 172:7d866c31b3c5 | 97 | case PullDown: |
AnnaBridge | 172:7d866c31b3c5 | 98 | GPIO_SetPullDown((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 99 | break; |
AnnaBridge | 172:7d866c31b3c5 | 100 | case OpenDrain: |
AnnaBridge | 172:7d866c31b3c5 | 101 | GPIO_SetOpenDrain((GPIO_Port)port, (1 << bit), ENABLE); |
AnnaBridge | 172:7d866c31b3c5 | 102 | break; |
AnnaBridge | 172:7d866c31b3c5 | 103 | default: |
AnnaBridge | 172:7d866c31b3c5 | 104 | break; |
AnnaBridge | 172:7d866c31b3c5 | 105 | } |
AnnaBridge | 172:7d866c31b3c5 | 106 | } |