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