mbed-os
Fork of mbed-os by
targets/TARGET_RENESAS/TARGET_RZ_A1H/pinmap.c@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed Microcontroller Library |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2006-2013 ARM Limited |
elessair | 0:f269e3021894 | 3 | * |
elessair | 0:f269e3021894 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 5 | * you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 6 | * You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 7 | * |
elessair | 0:f269e3021894 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 9 | * |
elessair | 0:f269e3021894 | 10 | * Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 13 | * See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 14 | * limitations under the License. |
elessair | 0:f269e3021894 | 15 | */ |
elessair | 0:f269e3021894 | 16 | #include "pinmap.h" |
elessair | 0:f269e3021894 | 17 | #include "mbed_error.h" |
elessair | 0:f269e3021894 | 18 | #include "gpio_addrdefine.h" |
elessair | 0:f269e3021894 | 19 | |
elessair | 0:f269e3021894 | 20 | PinName gpio_multi_guard = (PinName)NC; /* If set pin name here, setting of the "pin" is just one time */ |
elessair | 0:f269e3021894 | 21 | |
elessair | 0:f269e3021894 | 22 | typedef struct { |
elessair | 0:f269e3021894 | 23 | PinName pin; |
elessair | 0:f269e3021894 | 24 | int function; |
elessair | 0:f269e3021894 | 25 | int pm; |
elessair | 0:f269e3021894 | 26 | } PinFunc; |
elessair | 0:f269e3021894 | 27 | |
elessair | 0:f269e3021894 | 28 | static const PinFunc PIPC_0_tbl[] = { |
elessair | 0:f269e3021894 | 29 | // pin func pm |
elessair | 0:f269e3021894 | 30 | {P4_0 , 2 , -1}, /* TIOC0A */ |
elessair | 0:f269e3021894 | 31 | {P5_0 , 6 , -1}, /* TIOC0A */ |
elessair | 0:f269e3021894 | 32 | {P7_0 , 7 , -1}, /* TIOC0A */ |
elessair | 0:f269e3021894 | 33 | {P10_4 , 2 , -1}, /* TIOC0A */ |
elessair | 0:f269e3021894 | 34 | {P4_1 , 2 , -1}, /* TIOC0B */ |
elessair | 0:f269e3021894 | 35 | {P5_1 , 6 , -1}, /* TIOC0B */ |
elessair | 0:f269e3021894 | 36 | {P7_1 , 7 , -1}, /* TIOC0B */ |
elessair | 0:f269e3021894 | 37 | {P10_5 , 2 , -1}, /* TIOC0B */ |
elessair | 0:f269e3021894 | 38 | {P4_2 , 2 , -1}, /* TIOC0C */ |
elessair | 0:f269e3021894 | 39 | {P5_5 , 6 , -1}, /* TIOC0C */ |
elessair | 0:f269e3021894 | 40 | {P7_2 , 7 , -1}, /* TIOC0C */ |
elessair | 0:f269e3021894 | 41 | {P10_6 , 2 , -1}, /* TIOC0C */ |
elessair | 0:f269e3021894 | 42 | {P4_3 , 2 , -1}, /* TIOC0D */ |
elessair | 0:f269e3021894 | 43 | {P5_7 , 6 , -1}, /* TIOC0D */ |
elessair | 0:f269e3021894 | 44 | {P7_3 , 7 , -1}, /* TIOC0D */ |
elessair | 0:f269e3021894 | 45 | {P10_7 , 2 , -1}, /* TIOC0D */ |
elessair | 0:f269e3021894 | 46 | {P2_11 , 5 , -1}, /* TIOC1A */ |
elessair | 0:f269e3021894 | 47 | {P6_0 , 5 , -1}, /* TIOC1A */ |
elessair | 0:f269e3021894 | 48 | {P7_4 , 7 , -1}, /* TIOC1A */ |
elessair | 0:f269e3021894 | 49 | {P8_8 , 5 , -1}, /* TIOC1A */ |
elessair | 0:f269e3021894 | 50 | {P9_7 , 4 , -1}, /* TIOC1A */ |
elessair | 0:f269e3021894 | 51 | {P10_8 , 2 , -1}, /* TIOC1A */ |
elessair | 0:f269e3021894 | 52 | {P2_12 , 8 , -1}, /* TIOC1B */ |
elessair | 0:f269e3021894 | 53 | {P5_2 , 6 , -1}, /* TIOC1B */ |
elessair | 0:f269e3021894 | 54 | {P6_1 , 5 , -1}, /* TIOC1B */ |
elessair | 0:f269e3021894 | 55 | {P7_5 , 7 , -1}, /* TIOC1B */ |
elessair | 0:f269e3021894 | 56 | {P8_9 , 5 , -1}, /* TIOC1B */ |
elessair | 0:f269e3021894 | 57 | {P10_9 , 2 , -1}, /* TIOC1B */ |
elessair | 0:f269e3021894 | 58 | {P2_1 , 6 , -1}, /* TIOC2A */ |
elessair | 0:f269e3021894 | 59 | {P6_2 , 6 , -1}, /* TIOC2A */ |
elessair | 0:f269e3021894 | 60 | {P7_6 , 7 , -1}, /* TIOC2A */ |
elessair | 0:f269e3021894 | 61 | {P8_14 , 4 , -1}, /* TIOC2A */ |
elessair | 0:f269e3021894 | 62 | {P10_10 , 2 , -1}, /* TIOC2A */ |
elessair | 0:f269e3021894 | 63 | {P2_2 , 6 , -1}, /* TIOC2B */ |
elessair | 0:f269e3021894 | 64 | {P6_3 , 6 , -1}, /* TIOC2B */ |
elessair | 0:f269e3021894 | 65 | {P7_7 , 7 , -1}, /* TIOC2B */ |
elessair | 0:f269e3021894 | 66 | {P8_15 , 4 , -1}, /* TIOC2B */ |
elessair | 0:f269e3021894 | 67 | {P10_11 , 2 , -1}, /* TIOC2B */ |
elessair | 0:f269e3021894 | 68 | {P10_11 , 2 , -1}, /* TIOC2B */ |
elessair | 0:f269e3021894 | 69 | {P3_4 , 6 , -1}, /* TIOC3A */ |
elessair | 0:f269e3021894 | 70 | {P7_8 , 7 , -1}, /* TIOC3A */ |
elessair | 0:f269e3021894 | 71 | {P8_10 , 4 , -1}, /* TIOC3A */ |
elessair | 0:f269e3021894 | 72 | {P3_5 , 6 , -1}, /* TIOC3B */ |
elessair | 0:f269e3021894 | 73 | {P7_9 , 7 , -1}, /* TIOC3B */ |
elessair | 0:f269e3021894 | 74 | {P8_11 , 4 , -1}, /* TIOC3B */ |
elessair | 0:f269e3021894 | 75 | {P3_6 , 6 , -1}, /* TIOC3C */ |
elessair | 0:f269e3021894 | 76 | {P5_3 , 6 , -1}, /* TIOC3C */ |
elessair | 0:f269e3021894 | 77 | {P7_10 , 7 , -1}, /* TIOC3C */ |
elessair | 0:f269e3021894 | 78 | {P8_12 , 4 , -1}, /* TIOC3C */ |
elessair | 0:f269e3021894 | 79 | {P3_7 , 6 , -1}, /* TIOC3D */ |
elessair | 0:f269e3021894 | 80 | {P5_4 , 6 , -1}, /* TIOC3D */ |
elessair | 0:f269e3021894 | 81 | {P7_11 , 7 , -1}, /* TIOC3D */ |
elessair | 0:f269e3021894 | 82 | {P8_13 , 4 , -1}, /* TIOC3D */ |
elessair | 0:f269e3021894 | 83 | {P3_8 , 6 , -1}, /* TIOC4A */ |
elessair | 0:f269e3021894 | 84 | {P4_4 , 3 , -1}, /* TIOC4A */ |
elessair | 0:f269e3021894 | 85 | {P7_12 , 7 , -1}, /* TIOC4A */ |
elessair | 0:f269e3021894 | 86 | {P11_0 , 2 , -1}, /* TIOC4A */ |
elessair | 0:f269e3021894 | 87 | {P3_9 , 6 , -1}, /* TIOC4B */ |
elessair | 0:f269e3021894 | 88 | {P4_5 , 3 , -1}, /* TIOC4B */ |
elessair | 0:f269e3021894 | 89 | {P7_13 , 7 , -1}, /* TIOC4B */ |
elessair | 0:f269e3021894 | 90 | {P11_1 , 2 , -1}, /* TIOC4B */ |
elessair | 0:f269e3021894 | 91 | {P3_10 , 6 , -1}, /* TIOC4C */ |
elessair | 0:f269e3021894 | 92 | {P4_6 , 3 , -1}, /* TIOC4C */ |
elessair | 0:f269e3021894 | 93 | {P7_14 , 7 , -1}, /* TIOC4C */ |
elessair | 0:f269e3021894 | 94 | {P11_2 , 2 , -1}, /* TIOC4C */ |
elessair | 0:f269e3021894 | 95 | {P3_11 , 6 , -1}, /* TIOC4D */ |
elessair | 0:f269e3021894 | 96 | {P4_7 , 3 , -1}, /* TIOC4D */ |
elessair | 0:f269e3021894 | 97 | {P7_15 , 7 , -1}, /* TIOC4D */ |
elessair | 0:f269e3021894 | 98 | {P11_3 , 2 , -1}, /* TIOC4D */ |
elessair | 0:f269e3021894 | 99 | {P5_7 , 1 , 1 }, /* TXOUT0M */ |
elessair | 0:f269e3021894 | 100 | {P5_6 , 1 , 1 }, /* TXOUT0P */ |
elessair | 0:f269e3021894 | 101 | {P5_5 , 1 , 1 }, /* TXOUT1M */ |
elessair | 0:f269e3021894 | 102 | {P5_4 , 1 , 1 }, /* TXOUT1P */ |
elessair | 0:f269e3021894 | 103 | {P5_3 , 1 , 1 }, /* TXOUT2M */ |
elessair | 0:f269e3021894 | 104 | {P5_2 , 1 , 1 }, /* TXOUT2P */ |
elessair | 0:f269e3021894 | 105 | {P5_1 , 1 , 1 }, /* TXCLKOUTM */ |
elessair | 0:f269e3021894 | 106 | {P5_0 , 1 , 1 }, /* TXCLKOUTP */ |
elessair | 0:f269e3021894 | 107 | {P2_11 , 4 , 0 }, /* SSITxD0 */ |
elessair | 0:f269e3021894 | 108 | {P4_7 , 5 , 0 }, /* SSITxD0 */ |
elessair | 0:f269e3021894 | 109 | {P7_4 , 6 , 0 }, /* SSITxD1 */ |
elessair | 0:f269e3021894 | 110 | {P10_15 , 2 , 0 }, /* SSITxD1 */ |
elessair | 0:f269e3021894 | 111 | {P4_15 , 6 , 0 }, /* SSITxD3 */ |
elessair | 0:f269e3021894 | 112 | {P7_11 , 2 , 0 }, /* SSITxD3 */ |
elessair | 0:f269e3021894 | 113 | {P2_7 , 4 , 0 }, /* SSITxD5 */ |
elessair | 0:f269e3021894 | 114 | {P4_11 , 5 , 0 }, /* SSITxD5 */ |
elessair | 0:f269e3021894 | 115 | {P8_10 , 8 , 0 }, /* SSITxD5 */ |
elessair | 0:f269e3021894 | 116 | {P3_7 , 8 , 0 }, /* WDTOVF */ |
elessair | 0:f269e3021894 | 117 | {NC , 0 , -1} |
elessair | 0:f269e3021894 | 118 | }; |
elessair | 0:f269e3021894 | 119 | |
elessair | 0:f269e3021894 | 120 | void pin_function(PinName pin, int function) { |
elessair | 0:f269e3021894 | 121 | if (pin == (PinName)NC) return; |
elessair | 0:f269e3021894 | 122 | |
elessair | 0:f269e3021894 | 123 | int n = pin >> 4; |
elessair | 0:f269e3021894 | 124 | int bitmask = 1<<(pin & 0xf); |
elessair | 0:f269e3021894 | 125 | const PinFunc * Pipc_0_func = PIPC_0_tbl; |
elessair | 0:f269e3021894 | 126 | int pipc_data = 1; |
elessair | 0:f269e3021894 | 127 | |
elessair | 0:f269e3021894 | 128 | if (gpio_multi_guard != pin) { |
elessair | 0:f269e3021894 | 129 | if (function == 0) { |
elessair | 0:f269e3021894 | 130 | // means GPIO mode |
elessair | 0:f269e3021894 | 131 | *PMC(n) &= ~bitmask; |
elessair | 0:f269e3021894 | 132 | } else { |
elessair | 0:f269e3021894 | 133 | // alt-function mode |
elessair | 0:f269e3021894 | 134 | --function; |
elessair | 0:f269e3021894 | 135 | |
elessair | 0:f269e3021894 | 136 | if (function & (1 << 2)) { *PFCAE(n) |= bitmask;}else { *PFCAE(n) &= ~bitmask;} |
elessair | 0:f269e3021894 | 137 | if (function & (1 << 1)) { *PFCE(n) |= bitmask;}else { *PFCE(n) &= ~bitmask;} |
elessair | 0:f269e3021894 | 138 | if (function & (1 << 0)) { *PFC(n) |= bitmask;}else { *PFC(n) &= ~bitmask;} |
elessair | 0:f269e3021894 | 139 | |
elessair | 0:f269e3021894 | 140 | while (Pipc_0_func->pin != NC) { |
elessair | 0:f269e3021894 | 141 | if ((Pipc_0_func->pin == pin) && ((Pipc_0_func->function - 1) == function)) { |
elessair | 0:f269e3021894 | 142 | pipc_data = 0; |
elessair | 0:f269e3021894 | 143 | if (Pipc_0_func->pm == 0) { |
elessair | 0:f269e3021894 | 144 | *PMSR(n) = (bitmask << 16) | 0; |
elessair | 0:f269e3021894 | 145 | } else if (Pipc_0_func->pm == 1) { |
elessair | 0:f269e3021894 | 146 | *PMSR(n) = (bitmask << 16) | bitmask; |
elessair | 0:f269e3021894 | 147 | } else { |
elessair | 0:f269e3021894 | 148 | // Do Nothing |
elessair | 0:f269e3021894 | 149 | } |
elessair | 0:f269e3021894 | 150 | break; |
elessair | 0:f269e3021894 | 151 | } |
elessair | 0:f269e3021894 | 152 | Pipc_0_func++; |
elessair | 0:f269e3021894 | 153 | } |
elessair | 0:f269e3021894 | 154 | if (pipc_data == 1) { |
elessair | 0:f269e3021894 | 155 | *PIPC(n) |= bitmask; |
elessair | 0:f269e3021894 | 156 | } else { |
elessair | 0:f269e3021894 | 157 | *PIPC(n) &= ~bitmask; |
elessair | 0:f269e3021894 | 158 | } |
elessair | 0:f269e3021894 | 159 | |
elessair | 0:f269e3021894 | 160 | if (P1_0 <= pin && pin <= P1_7 && function == 0) { |
elessair | 0:f269e3021894 | 161 | *PBDC(n) |= bitmask; |
elessair | 0:f269e3021894 | 162 | } |
elessair | 0:f269e3021894 | 163 | *PMC(n) |= bitmask; |
elessair | 0:f269e3021894 | 164 | } |
elessair | 0:f269e3021894 | 165 | } else { |
elessair | 0:f269e3021894 | 166 | gpio_multi_guard = (PinName)NC; |
elessair | 0:f269e3021894 | 167 | } |
elessair | 0:f269e3021894 | 168 | } |
elessair | 0:f269e3021894 | 169 | |
elessair | 0:f269e3021894 | 170 | void pin_mode(PinName pin, PinMode mode) { |
elessair | 0:f269e3021894 | 171 | // if (pin == (PinName)NC) { return; } |
elessair | 0:f269e3021894 | 172 | } |