mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
hal/mbed_pinmap_common.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 187:0387e8f68319
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /* mbed Microcontroller Library |
<> | 149:156823d33999 | 2 | * Copyright (c) 2006-2013 ARM Limited |
AnnaBridge | 189:f392fc9709a3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
<> | 149:156823d33999 | 4 | * |
<> | 149:156823d33999 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 149:156823d33999 | 6 | * you may not use this file except in compliance with the License. |
<> | 149:156823d33999 | 7 | * You may obtain a copy of the License at |
<> | 149:156823d33999 | 8 | * |
<> | 149:156823d33999 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 149:156823d33999 | 10 | * |
<> | 149:156823d33999 | 11 | * Unless required by applicable law or agreed to in writing, software |
<> | 149:156823d33999 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 149:156823d33999 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 149:156823d33999 | 14 | * See the License for the specific language governing permissions and |
<> | 149:156823d33999 | 15 | * limitations under the License. |
<> | 149:156823d33999 | 16 | */ |
<> | 149:156823d33999 | 17 | #include "hal/pinmap.h" |
<> | 149:156823d33999 | 18 | #include "platform/mbed_error.h" |
<> | 149:156823d33999 | 19 | |
AnnaBridge | 187:0387e8f68319 | 20 | void pinmap_pinout(PinName pin, const PinMap *map) |
AnnaBridge | 187:0387e8f68319 | 21 | { |
AnnaBridge | 187:0387e8f68319 | 22 | if (pin == NC) { |
<> | 149:156823d33999 | 23 | return; |
AnnaBridge | 187:0387e8f68319 | 24 | } |
<> | 149:156823d33999 | 25 | |
<> | 149:156823d33999 | 26 | while (map->pin != NC) { |
<> | 149:156823d33999 | 27 | if (map->pin == pin) { |
<> | 149:156823d33999 | 28 | pin_function(pin, map->function); |
<> | 149:156823d33999 | 29 | |
<> | 149:156823d33999 | 30 | pin_mode(pin, PullNone); |
<> | 149:156823d33999 | 31 | return; |
<> | 149:156823d33999 | 32 | } |
<> | 149:156823d33999 | 33 | map++; |
<> | 149:156823d33999 | 34 | } |
Anna Bridge |
186:707f6e361f3e | 35 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "could not pinout", pin); |
<> | 149:156823d33999 | 36 | } |
<> | 149:156823d33999 | 37 | |
AnnaBridge | 187:0387e8f68319 | 38 | uint32_t pinmap_merge(uint32_t a, uint32_t b) |
AnnaBridge | 187:0387e8f68319 | 39 | { |
<> | 149:156823d33999 | 40 | // both are the same (inc both NC) |
AnnaBridge | 187:0387e8f68319 | 41 | if (a == b) { |
<> | 149:156823d33999 | 42 | return a; |
AnnaBridge | 187:0387e8f68319 | 43 | } |
<> | 149:156823d33999 | 44 | |
<> | 149:156823d33999 | 45 | // one (or both) is not connected |
AnnaBridge | 187:0387e8f68319 | 46 | if (a == (uint32_t)NC) { |
<> | 149:156823d33999 | 47 | return b; |
AnnaBridge | 187:0387e8f68319 | 48 | } |
AnnaBridge | 187:0387e8f68319 | 49 | if (b == (uint32_t)NC) { |
<> | 149:156823d33999 | 50 | return a; |
AnnaBridge | 187:0387e8f68319 | 51 | } |
<> | 149:156823d33999 | 52 | |
<> | 149:156823d33999 | 53 | // mis-match error case |
Anna Bridge |
186:707f6e361f3e | 54 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a); |
<> | 149:156823d33999 | 55 | return (uint32_t)NC; |
<> | 149:156823d33999 | 56 | } |
<> | 149:156823d33999 | 57 | |
AnnaBridge | 187:0387e8f68319 | 58 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map) |
AnnaBridge | 187:0387e8f68319 | 59 | { |
<> | 149:156823d33999 | 60 | while (map->pin != NC) { |
AnnaBridge | 187:0387e8f68319 | 61 | if (map->pin == pin) { |
<> | 149:156823d33999 | 62 | return map->peripheral; |
AnnaBridge | 187:0387e8f68319 | 63 | } |
<> | 149:156823d33999 | 64 | map++; |
<> | 149:156823d33999 | 65 | } |
<> | 149:156823d33999 | 66 | return (uint32_t)NC; |
<> | 149:156823d33999 | 67 | } |
<> | 149:156823d33999 | 68 | |
AnnaBridge | 187:0387e8f68319 | 69 | uint32_t pinmap_peripheral(PinName pin, const PinMap *map) |
AnnaBridge | 187:0387e8f68319 | 70 | { |
<> | 149:156823d33999 | 71 | uint32_t peripheral = (uint32_t)NC; |
<> | 149:156823d33999 | 72 | |
AnnaBridge | 187:0387e8f68319 | 73 | if (pin == (PinName)NC) { |
<> | 149:156823d33999 | 74 | return (uint32_t)NC; |
AnnaBridge | 187:0387e8f68319 | 75 | } |
<> | 149:156823d33999 | 76 | peripheral = pinmap_find_peripheral(pin, map); |
AnnaBridge | 187:0387e8f68319 | 77 | if ((uint32_t)NC == peripheral) { // no mapping available |
Anna Bridge |
186:707f6e361f3e | 78 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral); |
AnnaBridge | 187:0387e8f68319 | 79 | } |
<> | 149:156823d33999 | 80 | return peripheral; |
<> | 149:156823d33999 | 81 | } |
<> | 149:156823d33999 | 82 | |
AnnaBridge | 187:0387e8f68319 | 83 | uint32_t pinmap_find_function(PinName pin, const PinMap *map) |
AnnaBridge | 187:0387e8f68319 | 84 | { |
<> | 149:156823d33999 | 85 | while (map->pin != NC) { |
AnnaBridge | 187:0387e8f68319 | 86 | if (map->pin == pin) { |
<> | 149:156823d33999 | 87 | return map->function; |
AnnaBridge | 187:0387e8f68319 | 88 | } |
<> | 149:156823d33999 | 89 | map++; |
<> | 149:156823d33999 | 90 | } |
<> | 149:156823d33999 | 91 | return (uint32_t)NC; |
<> | 149:156823d33999 | 92 | } |
<> | 149:156823d33999 | 93 | |
AnnaBridge | 187:0387e8f68319 | 94 | uint32_t pinmap_function(PinName pin, const PinMap *map) |
AnnaBridge | 187:0387e8f68319 | 95 | { |
<> | 149:156823d33999 | 96 | uint32_t function = (uint32_t)NC; |
<> | 149:156823d33999 | 97 | |
AnnaBridge | 187:0387e8f68319 | 98 | if (pin == (PinName)NC) { |
<> | 149:156823d33999 | 99 | return (uint32_t)NC; |
AnnaBridge | 187:0387e8f68319 | 100 | } |
<> | 149:156823d33999 | 101 | function = pinmap_find_function(pin, map); |
AnnaBridge | 187:0387e8f68319 | 102 | if ((uint32_t)NC == function) { // no mapping available |
Anna Bridge |
186:707f6e361f3e | 103 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function); |
AnnaBridge | 187:0387e8f68319 | 104 | } |
<> | 149:156823d33999 | 105 | return function; |
<> | 149:156823d33999 | 106 | } |