Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/hal/TARGET_Atmel/TARGET_SAM_CortexM0P/pinmap_function.c@64:41a834223ea3, 2016-02-15 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Feb 15 10:00:10 2016 +0000
- Revision:
- 64:41a834223ea3
- Parent:
- 18:da299f395b9e
Synchronized with git revision e641fd47cf2a6bafdbe87c743a39772f73edcbe7
Full URL: https://github.com/mbedmicro/mbed/commit/e641fd47cf2a6bafdbe87c743a39772f73edcbe7/
Fixed GCC Compiler warnings
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 15:a81a8d6c1dfe | 1 | /* mbed Microcontroller Library |
| mbed_official | 15:a81a8d6c1dfe | 2 | * Copyright (c) 2006-2015 ARM Limited |
| mbed_official | 15:a81a8d6c1dfe | 3 | * |
| mbed_official | 15:a81a8d6c1dfe | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| mbed_official | 15:a81a8d6c1dfe | 5 | * you may not use this file except in compliance with the License. |
| mbed_official | 15:a81a8d6c1dfe | 6 | * You may obtain a copy of the License at |
| mbed_official | 15:a81a8d6c1dfe | 7 | * |
| mbed_official | 15:a81a8d6c1dfe | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| mbed_official | 15:a81a8d6c1dfe | 9 | * |
| mbed_official | 15:a81a8d6c1dfe | 10 | * Unless required by applicable law or agreed to in writing, software |
| mbed_official | 15:a81a8d6c1dfe | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| mbed_official | 15:a81a8d6c1dfe | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| mbed_official | 15:a81a8d6c1dfe | 13 | * See the License for the specific language governing permissions and |
| mbed_official | 15:a81a8d6c1dfe | 14 | * limitations under the License. |
| mbed_official | 15:a81a8d6c1dfe | 15 | */ |
| mbed_official | 15:a81a8d6c1dfe | 16 | #include <stddef.h> |
| mbed_official | 15:a81a8d6c1dfe | 17 | |
| mbed_official | 15:a81a8d6c1dfe | 18 | #include "cmsis.h" |
| mbed_official | 15:a81a8d6c1dfe | 19 | #include "mbed_assert.h" |
| mbed_official | 15:a81a8d6c1dfe | 20 | #include "compiler.h" |
| mbed_official | 15:a81a8d6c1dfe | 21 | |
| mbed_official | 15:a81a8d6c1dfe | 22 | #include "pinmap_function.h" |
| mbed_official | 15:a81a8d6c1dfe | 23 | |
| mbed_official | 15:a81a8d6c1dfe | 24 | extern struct pwm_pin_channel pwn_pins[]; |
| mbed_official | 15:a81a8d6c1dfe | 25 | |
| mbed_official | 15:a81a8d6c1dfe | 26 | static uint32_t pinmap_merge_pins(uint32_t a, uint32_t b) |
| mbed_official | 15:a81a8d6c1dfe | 27 | { |
| mbed_official | 15:a81a8d6c1dfe | 28 | /* both are the same (inc both NC) */ |
| mbed_official | 15:a81a8d6c1dfe | 29 | if (a == b) |
| mbed_official | 15:a81a8d6c1dfe | 30 | return a; |
| mbed_official | 15:a81a8d6c1dfe | 31 | |
| mbed_official | 15:a81a8d6c1dfe | 32 | /* one (or both) is not connected */ |
| mbed_official | 15:a81a8d6c1dfe | 33 | if (a == (uint32_t)NC) |
| mbed_official | 15:a81a8d6c1dfe | 34 | return b; |
| mbed_official | 15:a81a8d6c1dfe | 35 | if (b == (uint32_t)NC) |
| mbed_official | 15:a81a8d6c1dfe | 36 | return a; |
| mbed_official | 15:a81a8d6c1dfe | 37 | |
| mbed_official | 15:a81a8d6c1dfe | 38 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 39 | } |
| mbed_official | 15:a81a8d6c1dfe | 40 | |
| mbed_official | 15:a81a8d6c1dfe | 41 | /** Find the SERCOM peripheral of given pin |
| mbed_official | 15:a81a8d6c1dfe | 42 | * |
| mbed_official | 15:a81a8d6c1dfe | 43 | * Find and return the SERCOM peripheral of input pin, either from default pads, or from extended pads |
| mbed_official | 15:a81a8d6c1dfe | 44 | * @param[in] pin1 First pin |
| mbed_official | 15:a81a8d6c1dfe | 45 | * @param[in] pad_select to select which pad is to be used first to find |
| mbed_official | 15:a81a8d6c1dfe | 46 | * @return SERCOM peripheral if found, else, NC |
| mbed_official | 15:a81a8d6c1dfe | 47 | */ |
| mbed_official | 15:a81a8d6c1dfe | 48 | uint32_t pinmap_find_peripheral_from_pad(PinName pin, enum sercom_pad_selection pad_select) |
| mbed_official | 15:a81a8d6c1dfe | 49 | { |
| mbed_official | 64:41a834223ea3 | 50 | uint32_t pin_sercom =(uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 51 | |
| mbed_official | 64:41a834223ea3 | 52 | if (pin == NC) return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 53 | |
| mbed_official | 15:a81a8d6c1dfe | 54 | if (pad_select == SERCOM_USE_EXTENDED_PAD) { |
| mbed_official | 15:a81a8d6c1dfe | 55 | pin_sercom = pinmap_find_peripheral(pin, PinMap_SERCOM_PADEx); |
| mbed_official | 15:a81a8d6c1dfe | 56 | } |
| mbed_official | 15:a81a8d6c1dfe | 57 | if (pin_sercom == (uint32_t)NC) { |
| mbed_official | 15:a81a8d6c1dfe | 58 | pin_sercom = pinmap_find_peripheral(pin, PinMap_SERCOM_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 59 | } |
| mbed_official | 15:a81a8d6c1dfe | 60 | |
| mbed_official | 15:a81a8d6c1dfe | 61 | return pin_sercom; |
| mbed_official | 15:a81a8d6c1dfe | 62 | } |
| mbed_official | 15:a81a8d6c1dfe | 63 | |
| mbed_official | 15:a81a8d6c1dfe | 64 | /** Find the common SERCOM shared by two pins |
| mbed_official | 15:a81a8d6c1dfe | 65 | * |
| mbed_official | 15:a81a8d6c1dfe | 66 | * Finds the common SERCOM index of two input pins. |
| mbed_official | 15:a81a8d6c1dfe | 67 | * Currently uses default pad only |
| mbed_official | 15:a81a8d6c1dfe | 68 | * @param[in] pin1 First pin |
| mbed_official | 15:a81a8d6c1dfe | 69 | * @param[in] pin2 Second pin |
| mbed_official | 15:a81a8d6c1dfe | 70 | * @return SERCOM index if found, else, NC |
| mbed_official | 15:a81a8d6c1dfe | 71 | */ |
| mbed_official | 15:a81a8d6c1dfe | 72 | uint32_t pinmap_merge_sercom(PinName pin1, PinName pin2) |
| mbed_official | 15:a81a8d6c1dfe | 73 | { |
| mbed_official | 15:a81a8d6c1dfe | 74 | uint32_t pin1_sercom, pin2_sercom; |
| mbed_official | 15:a81a8d6c1dfe | 75 | |
| mbed_official | 15:a81a8d6c1dfe | 76 | /* Using default pads for now */ |
| mbed_official | 15:a81a8d6c1dfe | 77 | pin1_sercom = pinmap_find_peripheral_from_pad(pin1, SERCOM_USE_DEFAULT_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 78 | if (pin1_sercom != (uint32_t)NC) { |
| mbed_official | 15:a81a8d6c1dfe | 79 | pin1_sercom &= 0x0F; |
| mbed_official | 15:a81a8d6c1dfe | 80 | } |
| mbed_official | 15:a81a8d6c1dfe | 81 | pin2_sercom = pinmap_find_peripheral_from_pad(pin2, SERCOM_USE_DEFAULT_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 82 | if (pin2_sercom != (uint32_t)NC) { |
| mbed_official | 15:a81a8d6c1dfe | 83 | pin2_sercom &= 0x0F; |
| mbed_official | 15:a81a8d6c1dfe | 84 | } |
| mbed_official | 15:a81a8d6c1dfe | 85 | |
| mbed_official | 15:a81a8d6c1dfe | 86 | return pinmap_merge_pins(pin1_sercom, pin2_sercom); |
| mbed_official | 15:a81a8d6c1dfe | 87 | } |
| mbed_official | 15:a81a8d6c1dfe | 88 | |
| mbed_official | 15:a81a8d6c1dfe | 89 | /** Find the common SERCOM shared by four pins |
| mbed_official | 15:a81a8d6c1dfe | 90 | * |
| mbed_official | 15:a81a8d6c1dfe | 91 | * Finds the common SERCOM index shared by four input pins. |
| mbed_official | 15:a81a8d6c1dfe | 92 | * @param[in] pin1 First pin |
| mbed_official | 15:a81a8d6c1dfe | 93 | * @param[in] pin2 Second pin |
| mbed_official | 15:a81a8d6c1dfe | 94 | * @param[in] pin3 Third pin |
| mbed_official | 15:a81a8d6c1dfe | 95 | * @param[in] pin4 Fourth pin |
| mbed_official | 15:a81a8d6c1dfe | 96 | * @return SERCOM index if found, else, NC |
| mbed_official | 15:a81a8d6c1dfe | 97 | */ |
| mbed_official | 15:a81a8d6c1dfe | 98 | uint32_t pinmap_find_sercom(PinName pin1, PinName pin2, PinName pin3, PinName pin4) |
| mbed_official | 15:a81a8d6c1dfe | 99 | { |
| mbed_official | 15:a81a8d6c1dfe | 100 | int i; |
| mbed_official | 15:a81a8d6c1dfe | 101 | uint32_t sercom_index[4]; |
| mbed_official | 64:41a834223ea3 | 102 | uint32_t pin_com = (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 103 | |
| mbed_official | 15:a81a8d6c1dfe | 104 | sercom_index[0] = pinmap_find_peripheral_from_pad(pin1, SERCOM_USE_DEFAULT_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 105 | sercom_index[1] = pinmap_find_peripheral_from_pad(pin2, SERCOM_USE_DEFAULT_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 106 | sercom_index[2] = pinmap_find_peripheral_from_pad(pin3, SERCOM_USE_DEFAULT_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 107 | sercom_index[3] = pinmap_find_peripheral_from_pad(pin4, SERCOM_USE_DEFAULT_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 108 | |
| mbed_official | 15:a81a8d6c1dfe | 109 | /* Find common SERCOM, if there are conflicts, return NC */ |
| mbed_official | 15:a81a8d6c1dfe | 110 | for (i=0; i<4; i++) { |
| mbed_official | 15:a81a8d6c1dfe | 111 | if (sercom_index[i] != (uint32_t)NC) { |
| mbed_official | 15:a81a8d6c1dfe | 112 | if (pin_com == (uint32_t)NC) { |
| mbed_official | 15:a81a8d6c1dfe | 113 | pin_com = sercom_index[i] & 0x0F; |
| mbed_official | 15:a81a8d6c1dfe | 114 | } else if (pin_com != (sercom_index[i] & 0x0F)) { |
| mbed_official | 64:41a834223ea3 | 115 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 116 | } |
| mbed_official | 15:a81a8d6c1dfe | 117 | } |
| mbed_official | 15:a81a8d6c1dfe | 118 | } |
| mbed_official | 15:a81a8d6c1dfe | 119 | |
| mbed_official | 15:a81a8d6c1dfe | 120 | return pin_com; |
| mbed_official | 15:a81a8d6c1dfe | 121 | } |
| mbed_official | 15:a81a8d6c1dfe | 122 | |
| mbed_official | 15:a81a8d6c1dfe | 123 | /** Find the MUX function of input pin specific to given SERCOM index |
| mbed_official | 15:a81a8d6c1dfe | 124 | * |
| mbed_official | 15:a81a8d6c1dfe | 125 | * @param[in] pin Pin whose function is to be found out |
| mbed_official | 15:a81a8d6c1dfe | 126 | * @param[in] sercom_index SERCOM index |
| mbed_official | 15:a81a8d6c1dfe | 127 | * @return MUX function if found, else, NC |
| mbed_official | 15:a81a8d6c1dfe | 128 | */ |
| mbed_official | 15:a81a8d6c1dfe | 129 | uint32_t pinmap_function_sercom(PinName pin, uint32_t sercom_index) |
| mbed_official | 15:a81a8d6c1dfe | 130 | { |
| mbed_official | 64:41a834223ea3 | 131 | uint32_t func = (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 132 | uint32_t index; |
| mbed_official | 15:a81a8d6c1dfe | 133 | sercom_index &= 0x0F; |
| mbed_official | 15:a81a8d6c1dfe | 134 | |
| mbed_official | 15:a81a8d6c1dfe | 135 | if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) { |
| mbed_official | 64:41a834223ea3 | 136 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 137 | } |
| mbed_official | 15:a81a8d6c1dfe | 138 | index = pinmap_peripheral(pin, PinMap_SERCOM_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 139 | if ((index & 0x0F) == sercom_index) { |
| mbed_official | 15:a81a8d6c1dfe | 140 | func = pinmap_function(pin, PinMap_SERCOM_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 141 | return func; |
| mbed_official | 15:a81a8d6c1dfe | 142 | } |
| mbed_official | 15:a81a8d6c1dfe | 143 | index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx); |
| mbed_official | 15:a81a8d6c1dfe | 144 | if ((index & 0x0F) == sercom_index) { |
| mbed_official | 15:a81a8d6c1dfe | 145 | func = pinmap_function(pin, PinMap_SERCOM_PADEx); |
| mbed_official | 15:a81a8d6c1dfe | 146 | return func; |
| mbed_official | 15:a81a8d6c1dfe | 147 | } |
| mbed_official | 64:41a834223ea3 | 148 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 149 | } |
| mbed_official | 15:a81a8d6c1dfe | 150 | |
| mbed_official | 15:a81a8d6c1dfe | 151 | /** Find the MUX pad of input pin specific to given SERCOM index |
| mbed_official | 15:a81a8d6c1dfe | 152 | * |
| mbed_official | 15:a81a8d6c1dfe | 153 | * @param[in] pin Pin whose function is to be found out |
| mbed_official | 15:a81a8d6c1dfe | 154 | * @param[in] sercom_index SERCOM index |
| mbed_official | 15:a81a8d6c1dfe | 155 | * @return MUX pad if found, else, NC |
| mbed_official | 15:a81a8d6c1dfe | 156 | */ |
| mbed_official | 15:a81a8d6c1dfe | 157 | uint32_t pinmap_pad_sercom(PinName pin, uint32_t sercom_index) |
| mbed_official | 15:a81a8d6c1dfe | 158 | { |
| mbed_official | 15:a81a8d6c1dfe | 159 | uint32_t index; |
| mbed_official | 15:a81a8d6c1dfe | 160 | sercom_index &= 0x0F; |
| mbed_official | 15:a81a8d6c1dfe | 161 | |
| mbed_official | 15:a81a8d6c1dfe | 162 | if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) { |
| mbed_official | 64:41a834223ea3 | 163 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 164 | } |
| mbed_official | 15:a81a8d6c1dfe | 165 | index = pinmap_peripheral(pin, PinMap_SERCOM_PAD); |
| mbed_official | 15:a81a8d6c1dfe | 166 | if ((index & 0x0F) == sercom_index) { |
| mbed_official | 15:a81a8d6c1dfe | 167 | return ((index >> 4) & 0x0F); |
| mbed_official | 15:a81a8d6c1dfe | 168 | } |
| mbed_official | 15:a81a8d6c1dfe | 169 | index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx); |
| mbed_official | 15:a81a8d6c1dfe | 170 | if ((index & 0x0F) == sercom_index) { |
| mbed_official | 15:a81a8d6c1dfe | 171 | return ((index >> 4) & 0x0F); |
| mbed_official | 15:a81a8d6c1dfe | 172 | } |
| mbed_official | 64:41a834223ea3 | 173 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 174 | } |
| mbed_official | 15:a81a8d6c1dfe | 175 | |
| mbed_official | 15:a81a8d6c1dfe | 176 | /** Find the MUX function of input pin specific to given SERCOM index |
| mbed_official | 15:a81a8d6c1dfe | 177 | * |
| mbed_official | 15:a81a8d6c1dfe | 178 | * @param[in] pin unused |
| mbed_official | 15:a81a8d6c1dfe | 179 | * @param[in] sercom_index SERCOM index |
| mbed_official | 15:a81a8d6c1dfe | 180 | * @return base address to SERCOM if found, else NC |
| mbed_official | 15:a81a8d6c1dfe | 181 | */ |
| mbed_official | 15:a81a8d6c1dfe | 182 | uint32_t pinmap_peripheral_sercom(PinName pin, uint32_t sercom_index) |
| mbed_official | 15:a81a8d6c1dfe | 183 | { |
| mbed_official | 15:a81a8d6c1dfe | 184 | uint32_t sercom_address[6] = { |
| mbed_official | 18:da299f395b9e | 185 | #if (SAMD21) || (SAMR21) |
| mbed_official | 15:a81a8d6c1dfe | 186 | 0x42000800UL, // Base address of SERCOM0 |
| mbed_official | 15:a81a8d6c1dfe | 187 | 0x42000C00UL, // Base address of SERCOM1 |
| mbed_official | 15:a81a8d6c1dfe | 188 | 0x42001000UL, // Base address of SERCOM2 |
| mbed_official | 15:a81a8d6c1dfe | 189 | 0x42001400UL, // Base address of SERCOM3 |
| mbed_official | 15:a81a8d6c1dfe | 190 | 0x42001800UL, // Base address of SERCOM4 |
| mbed_official | 15:a81a8d6c1dfe | 191 | 0x42001C00UL // Base address of SERCOM5 |
| mbed_official | 18:da299f395b9e | 192 | #elif (SAML21) |
| mbed_official | 18:da299f395b9e | 193 | 0x42000000UL, // Base address of SERCOM0 |
| mbed_official | 18:da299f395b9e | 194 | 0x42000400UL, // Base address of SERCOM1 |
| mbed_official | 18:da299f395b9e | 195 | 0x42000800UL, // Base address of SERCOM2 |
| mbed_official | 18:da299f395b9e | 196 | 0x42000C00UL, // Base address of SERCOM3 |
| mbed_official | 18:da299f395b9e | 197 | 0x42001000UL, // Base address of SERCOM4 |
| mbed_official | 18:da299f395b9e | 198 | 0x43000400UL // Base address of SERCOM5 |
| mbed_official | 18:da299f395b9e | 199 | #endif |
| mbed_official | 15:a81a8d6c1dfe | 200 | }; |
| mbed_official | 15:a81a8d6c1dfe | 201 | uint32_t index = sercom_index & 0x0F; |
| mbed_official | 15:a81a8d6c1dfe | 202 | |
| mbed_official | 15:a81a8d6c1dfe | 203 | if (index >= SERCOM_INST_NUM) { |
| mbed_official | 64:41a834223ea3 | 204 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 205 | } |
| mbed_official | 15:a81a8d6c1dfe | 206 | return sercom_address[(sercom_index&0x0F)]; |
| mbed_official | 15:a81a8d6c1dfe | 207 | } |
| mbed_official | 15:a81a8d6c1dfe | 208 | |
| mbed_official | 15:a81a8d6c1dfe | 209 | /** Find the channel index of a pin specific to a PWM instance |
| mbed_official | 15:a81a8d6c1dfe | 210 | * |
| mbed_official | 15:a81a8d6c1dfe | 211 | * @param[in] pin pin name |
| mbed_official | 15:a81a8d6c1dfe | 212 | * @param[in] pwm pwm peripheral (unused now) |
| mbed_official | 15:a81a8d6c1dfe | 213 | * @return Channel index of the specified pin |
| mbed_official | 15:a81a8d6c1dfe | 214 | */ |
| mbed_official | 15:a81a8d6c1dfe | 215 | uint32_t pinmap_channel_pwm(PinName pin, PWMName pwm) |
| mbed_official | 15:a81a8d6c1dfe | 216 | { |
| mbed_official | 15:a81a8d6c1dfe | 217 | struct pwm_pin_channel *pwm_ch = pwn_pins; |
| mbed_official | 15:a81a8d6c1dfe | 218 | |
| mbed_official | 15:a81a8d6c1dfe | 219 | while (pwm_ch->pin != NC) { |
| mbed_official | 15:a81a8d6c1dfe | 220 | if (pin == pwm_ch->pin) { |
| mbed_official | 15:a81a8d6c1dfe | 221 | return (uint32_t)pwm_ch->channel_index; |
| mbed_official | 15:a81a8d6c1dfe | 222 | } |
| mbed_official | 15:a81a8d6c1dfe | 223 | pwm_ch++; |
| mbed_official | 15:a81a8d6c1dfe | 224 | } |
| mbed_official | 64:41a834223ea3 | 225 | return (uint32_t)NC; |
| mbed_official | 15:a81a8d6c1dfe | 226 | } |
