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