mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_TOSHIBA/TARGET_TMPM3HQ/pinmap.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 189:f392fc9709a3 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 189:f392fc9709a3 | 2 | * (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved |
AnnaBridge | 189:f392fc9709a3 | 3 | * |
AnnaBridge | 189:f392fc9709a3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 189:f392fc9709a3 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 189:f392fc9709a3 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 189:f392fc9709a3 | 7 | * |
AnnaBridge | 189:f392fc9709a3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 189:f392fc9709a3 | 9 | * |
AnnaBridge | 189:f392fc9709a3 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 189:f392fc9709a3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 189:f392fc9709a3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 189:f392fc9709a3 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 189:f392fc9709a3 | 14 | * limitations under the License. |
AnnaBridge | 189:f392fc9709a3 | 15 | */ |
AnnaBridge | 189:f392fc9709a3 | 16 | #include "mbed_assert.h" |
AnnaBridge | 189:f392fc9709a3 | 17 | #include "pinmap.h" |
AnnaBridge | 189:f392fc9709a3 | 18 | #include "gpio_include.h" |
AnnaBridge | 189:f392fc9709a3 | 19 | |
AnnaBridge | 189:f392fc9709a3 | 20 | void pin_function(PinName pin, int function) |
AnnaBridge | 189:f392fc9709a3 | 21 | { |
AnnaBridge | 189:f392fc9709a3 | 22 | int port = 0; |
AnnaBridge | 189:f392fc9709a3 | 23 | uint8_t bit = 0; |
AnnaBridge | 189:f392fc9709a3 | 24 | uint8_t func = 0; |
AnnaBridge | 189:f392fc9709a3 | 25 | uint8_t dir = 0; |
AnnaBridge | 189:f392fc9709a3 | 26 | uint32_t port_base = 0; |
AnnaBridge | 189:f392fc9709a3 | 27 | uint32_t mode_base = 0; |
AnnaBridge | 189:f392fc9709a3 | 28 | |
AnnaBridge | 189:f392fc9709a3 | 29 | // Assert that pin is valid |
AnnaBridge | 189:f392fc9709a3 | 30 | MBED_ASSERT(pin != NC); |
AnnaBridge | 189:f392fc9709a3 | 31 | |
AnnaBridge | 189:f392fc9709a3 | 32 | // Calculate pin function and pin direction |
AnnaBridge | 189:f392fc9709a3 | 33 | func = PIN_FUNC(function); |
AnnaBridge | 189:f392fc9709a3 | 34 | dir = PIN_DIR(function); |
AnnaBridge | 189:f392fc9709a3 | 35 | |
AnnaBridge | 189:f392fc9709a3 | 36 | // Calculate port and pin position |
AnnaBridge | 189:f392fc9709a3 | 37 | port = PIN_PORT(pin); |
AnnaBridge | 189:f392fc9709a3 | 38 | bit = PIN_POS(pin); |
AnnaBridge | 189:f392fc9709a3 | 39 | |
AnnaBridge | 189:f392fc9709a3 | 40 | port_base = BITBAND_PORT_BASE(port); |
AnnaBridge | 189:f392fc9709a3 | 41 | // Initialization PxFR OFF |
AnnaBridge | 189:f392fc9709a3 | 42 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR1); |
AnnaBridge | 189:f392fc9709a3 | 43 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 44 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR2); |
AnnaBridge | 189:f392fc9709a3 | 45 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 46 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR3); |
AnnaBridge | 189:f392fc9709a3 | 47 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 48 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR4); |
AnnaBridge | 189:f392fc9709a3 | 49 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 50 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR5); |
AnnaBridge | 189:f392fc9709a3 | 51 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 52 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR6); |
AnnaBridge | 189:f392fc9709a3 | 53 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 54 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR7); |
AnnaBridge | 189:f392fc9709a3 | 55 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 56 | |
AnnaBridge | 189:f392fc9709a3 | 57 | // Initialize Input |
AnnaBridge | 189:f392fc9709a3 | 58 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_CR); |
AnnaBridge | 189:f392fc9709a3 | 59 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 60 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_IE); |
AnnaBridge | 189:f392fc9709a3 | 61 | BITBAND_PORT_SET(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 62 | |
AnnaBridge | 189:f392fc9709a3 | 63 | switch (func) { |
AnnaBridge | 189:f392fc9709a3 | 64 | case 0: |
AnnaBridge | 189:f392fc9709a3 | 65 | break; |
AnnaBridge | 189:f392fc9709a3 | 66 | case 1: |
AnnaBridge | 189:f392fc9709a3 | 67 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR1); |
AnnaBridge | 189:f392fc9709a3 | 68 | break; |
AnnaBridge | 189:f392fc9709a3 | 69 | case 2: |
AnnaBridge | 189:f392fc9709a3 | 70 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR2); |
AnnaBridge | 189:f392fc9709a3 | 71 | break; |
AnnaBridge | 189:f392fc9709a3 | 72 | case 3: |
AnnaBridge | 189:f392fc9709a3 | 73 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR3); |
AnnaBridge | 189:f392fc9709a3 | 74 | break; |
AnnaBridge | 189:f392fc9709a3 | 75 | case 4: |
AnnaBridge | 189:f392fc9709a3 | 76 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR4); |
AnnaBridge | 189:f392fc9709a3 | 77 | break; |
AnnaBridge | 189:f392fc9709a3 | 78 | case 5: |
AnnaBridge | 189:f392fc9709a3 | 79 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR5); |
AnnaBridge | 189:f392fc9709a3 | 80 | break; |
AnnaBridge | 189:f392fc9709a3 | 81 | case 6: |
AnnaBridge | 189:f392fc9709a3 | 82 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR6); |
AnnaBridge | 189:f392fc9709a3 | 83 | break; |
AnnaBridge | 189:f392fc9709a3 | 84 | case 7: |
AnnaBridge | 189:f392fc9709a3 | 85 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_FR7); |
AnnaBridge | 189:f392fc9709a3 | 86 | break; |
AnnaBridge | 189:f392fc9709a3 | 87 | default: |
AnnaBridge | 189:f392fc9709a3 | 88 | break; |
AnnaBridge | 189:f392fc9709a3 | 89 | } |
AnnaBridge | 189:f392fc9709a3 | 90 | |
AnnaBridge | 189:f392fc9709a3 | 91 | if (func != 0) { |
AnnaBridge | 189:f392fc9709a3 | 92 | BITBAND_PORT_SET(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 93 | } |
AnnaBridge | 189:f392fc9709a3 | 94 | if (dir == PIN_OUTPUT) { |
AnnaBridge | 189:f392fc9709a3 | 95 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_IE); |
AnnaBridge | 189:f392fc9709a3 | 96 | BITBAND_PORT_CLR(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 97 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_CR); |
AnnaBridge | 189:f392fc9709a3 | 98 | BITBAND_PORT_SET(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 99 | } else if (dir == PIN_INOUT) { |
AnnaBridge | 189:f392fc9709a3 | 100 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_IE); |
AnnaBridge | 189:f392fc9709a3 | 101 | BITBAND_PORT_SET(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 102 | mode_base = BITBAND_PORT_MODE_BASE(port_base, GPIO_Mode_CR); |
AnnaBridge | 189:f392fc9709a3 | 103 | BITBAND_PORT_SET(mode_base, bit); |
AnnaBridge | 189:f392fc9709a3 | 104 | } |
AnnaBridge | 189:f392fc9709a3 | 105 | } |
AnnaBridge | 189:f392fc9709a3 | 106 | |
AnnaBridge | 189:f392fc9709a3 | 107 | void pin_mode(PinName pin, PinMode mode) |
AnnaBridge | 189:f392fc9709a3 | 108 | { |
AnnaBridge | 189:f392fc9709a3 | 109 | int port = 0; |
AnnaBridge | 189:f392fc9709a3 | 110 | uint8_t bit = 0; |
AnnaBridge | 189:f392fc9709a3 | 111 | uint8_t val = 0; |
AnnaBridge | 189:f392fc9709a3 | 112 | |
AnnaBridge | 189:f392fc9709a3 | 113 | // Assert that pin is valid |
AnnaBridge | 189:f392fc9709a3 | 114 | MBED_ASSERT(pin != NC); |
AnnaBridge | 189:f392fc9709a3 | 115 | |
AnnaBridge | 189:f392fc9709a3 | 116 | // Check if function is in range |
AnnaBridge | 189:f392fc9709a3 | 117 | if (mode > OpenDrain) { |
AnnaBridge | 189:f392fc9709a3 | 118 | return; |
AnnaBridge | 189:f392fc9709a3 | 119 | } |
AnnaBridge | 189:f392fc9709a3 | 120 | |
AnnaBridge | 189:f392fc9709a3 | 121 | // Calculate port and pin position |
AnnaBridge | 189:f392fc9709a3 | 122 | port = PIN_PORT(pin); |
AnnaBridge | 189:f392fc9709a3 | 123 | bit = PIN_POS(pin); |
AnnaBridge | 189:f392fc9709a3 | 124 | val = (1 << bit); |
AnnaBridge | 189:f392fc9709a3 | 125 | |
AnnaBridge | 189:f392fc9709a3 | 126 | switch (port) { |
AnnaBridge | 189:f392fc9709a3 | 127 | case PortA: |
AnnaBridge | 189:f392fc9709a3 | 128 | if (mode == OpenDrain) TSB_PA->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 129 | else if (mode == PullUp) TSB_PA->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 130 | else if (mode == PullDown || mode == PullDefault) TSB_PA->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 131 | break; |
AnnaBridge | 189:f392fc9709a3 | 132 | case PortB: |
AnnaBridge | 189:f392fc9709a3 | 133 | if (mode == OpenDrain) TSB_PB->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 134 | else if (mode == PullUp) TSB_PB->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 135 | else if (mode == PullDown || mode == PullDefault) TSB_PB->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 136 | break; |
AnnaBridge | 189:f392fc9709a3 | 137 | case PortC: |
AnnaBridge | 189:f392fc9709a3 | 138 | if (mode == OpenDrain) TSB_PC->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 139 | else if (mode == PullUp) TSB_PC->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 140 | else if (mode == PullDown || mode == PullDefault) TSB_PC->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 141 | break; |
AnnaBridge | 189:f392fc9709a3 | 142 | case PortD: |
AnnaBridge | 189:f392fc9709a3 | 143 | if (mode == OpenDrain) TSB_PD->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 144 | else if (mode == PullUp) TSB_PD->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 145 | else if (mode == PullDown || mode == PullDefault) TSB_PD->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 146 | break; |
AnnaBridge | 189:f392fc9709a3 | 147 | case PortE: |
AnnaBridge | 189:f392fc9709a3 | 148 | if (mode == OpenDrain) TSB_PE->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 149 | else if (mode == PullUp) TSB_PE->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 150 | else if (mode == PullDown || mode == PullDefault) TSB_PE->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 151 | break; |
AnnaBridge | 189:f392fc9709a3 | 152 | case PortF: |
AnnaBridge | 189:f392fc9709a3 | 153 | if (mode == OpenDrain) TSB_PF->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 154 | else if (mode == PullUp) TSB_PF->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 155 | else if (mode == PullDown || mode == PullDefault) TSB_PF->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 156 | break; |
AnnaBridge | 189:f392fc9709a3 | 157 | case PortG: |
AnnaBridge | 189:f392fc9709a3 | 158 | if (mode == OpenDrain) TSB_PG->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 159 | else if (mode == PullUp) TSB_PG->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 160 | else if (mode == PullDown || mode == PullDefault) TSB_PG->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 161 | break; |
AnnaBridge | 189:f392fc9709a3 | 162 | case PortH: |
AnnaBridge | 189:f392fc9709a3 | 163 | if (mode == PullDown) TSB_PH->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 164 | break; |
AnnaBridge | 189:f392fc9709a3 | 165 | case PortJ: |
AnnaBridge | 189:f392fc9709a3 | 166 | if (mode == OpenDrain) TSB_PJ->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 167 | else if (mode == PullUp) TSB_PJ->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 168 | else if (mode == PullDown || mode == PullDefault) TSB_PJ->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 169 | break; |
AnnaBridge | 189:f392fc9709a3 | 170 | case PortK: |
AnnaBridge | 189:f392fc9709a3 | 171 | if (mode == OpenDrain) TSB_PK->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 172 | else if (mode == PullUp) TSB_PK->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 173 | else if (mode == PullDown || mode == PullDefault) TSB_PK->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 174 | break; |
AnnaBridge | 189:f392fc9709a3 | 175 | case PortL: |
AnnaBridge | 189:f392fc9709a3 | 176 | if (mode == OpenDrain) TSB_PL->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 177 | else if (mode == PullUp) TSB_PL->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 178 | else if (mode == PullDown || mode == PullDefault) TSB_PL->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 179 | break; |
AnnaBridge | 189:f392fc9709a3 | 180 | case PortM: |
AnnaBridge | 189:f392fc9709a3 | 181 | if (mode == OpenDrain) TSB_PM->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 182 | else if (mode == PullUp) TSB_PM->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 183 | else if (mode == PullDown || mode == PullDefault) TSB_PM->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 184 | break; |
AnnaBridge | 189:f392fc9709a3 | 185 | case PortN: |
AnnaBridge | 189:f392fc9709a3 | 186 | if (mode == OpenDrain) TSB_PN->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 187 | else if (mode == PullUp) TSB_PN->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 188 | else if (mode == PullDown || mode == PullDefault) TSB_PN->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 189 | break; |
AnnaBridge | 189:f392fc9709a3 | 190 | case PortP: |
AnnaBridge | 189:f392fc9709a3 | 191 | if (mode == OpenDrain) TSB_PP->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 192 | else if (mode == PullUp) TSB_PP->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 193 | else if (mode == PullDown || mode == PullDefault) TSB_PP->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 194 | break; |
AnnaBridge | 189:f392fc9709a3 | 195 | case PortR: |
AnnaBridge | 189:f392fc9709a3 | 196 | if (mode == OpenDrain) TSB_PR->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 197 | else if (mode == PullUp) TSB_PR->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 198 | else if (mode == PullDown || mode == PullDefault) TSB_PR->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 199 | break; |
AnnaBridge | 189:f392fc9709a3 | 200 | case PortT: |
AnnaBridge | 189:f392fc9709a3 | 201 | if (mode == OpenDrain) TSB_PT->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 202 | else if (mode == PullUp) TSB_PT->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 203 | else if (mode == PullDown || mode == PullDefault) TSB_PT->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 204 | break; |
AnnaBridge | 189:f392fc9709a3 | 205 | case PortU: |
AnnaBridge | 189:f392fc9709a3 | 206 | if (mode == OpenDrain) TSB_PU->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 207 | else if (mode == PullUp) TSB_PU->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 208 | else if (mode == PullDown || mode == PullDefault) TSB_PU->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 209 | break; |
AnnaBridge | 189:f392fc9709a3 | 210 | case PortV: |
AnnaBridge | 189:f392fc9709a3 | 211 | if (mode == OpenDrain) TSB_PV->OD |= val; |
AnnaBridge | 189:f392fc9709a3 | 212 | else if (mode == PullUp) TSB_PV->PUP |= val; |
AnnaBridge | 189:f392fc9709a3 | 213 | else if (mode == PullDown || mode == PullDefault) TSB_PV->PDN |= val; |
AnnaBridge | 189:f392fc9709a3 | 214 | break; |
AnnaBridge | 189:f392fc9709a3 | 215 | default: |
AnnaBridge | 189:f392fc9709a3 | 216 | break; |
AnnaBridge | 189:f392fc9709a3 | 217 | } |
AnnaBridge | 189:f392fc9709a3 | 218 | } |