Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/hal/mbed_pinmap_common.c@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2006-2013 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 5 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 6 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 7 | * |
marcozecchini | 0:9fca2b23d0ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 9 | * |
marcozecchini | 0:9fca2b23d0ba | 10 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 13 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 14 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 15 | */ |
marcozecchini | 0:9fca2b23d0ba | 16 | #include "hal/pinmap.h" |
marcozecchini | 0:9fca2b23d0ba | 17 | #include "platform/mbed_error.h" |
marcozecchini | 0:9fca2b23d0ba | 18 | |
marcozecchini | 0:9fca2b23d0ba | 19 | void pinmap_pinout(PinName pin, const PinMap *map) { |
marcozecchini | 0:9fca2b23d0ba | 20 | if (pin == NC) |
marcozecchini | 0:9fca2b23d0ba | 21 | return; |
marcozecchini | 0:9fca2b23d0ba | 22 | |
marcozecchini | 0:9fca2b23d0ba | 23 | while (map->pin != NC) { |
marcozecchini | 0:9fca2b23d0ba | 24 | if (map->pin == pin) { |
marcozecchini | 0:9fca2b23d0ba | 25 | pin_function(pin, map->function); |
marcozecchini | 0:9fca2b23d0ba | 26 | |
marcozecchini | 0:9fca2b23d0ba | 27 | pin_mode(pin, PullNone); |
marcozecchini | 0:9fca2b23d0ba | 28 | return; |
marcozecchini | 0:9fca2b23d0ba | 29 | } |
marcozecchini | 0:9fca2b23d0ba | 30 | map++; |
marcozecchini | 0:9fca2b23d0ba | 31 | } |
marcozecchini | 0:9fca2b23d0ba | 32 | error("could not pinout"); |
marcozecchini | 0:9fca2b23d0ba | 33 | } |
marcozecchini | 0:9fca2b23d0ba | 34 | |
marcozecchini | 0:9fca2b23d0ba | 35 | uint32_t pinmap_merge(uint32_t a, uint32_t b) { |
marcozecchini | 0:9fca2b23d0ba | 36 | // both are the same (inc both NC) |
marcozecchini | 0:9fca2b23d0ba | 37 | if (a == b) |
marcozecchini | 0:9fca2b23d0ba | 38 | return a; |
marcozecchini | 0:9fca2b23d0ba | 39 | |
marcozecchini | 0:9fca2b23d0ba | 40 | // one (or both) is not connected |
marcozecchini | 0:9fca2b23d0ba | 41 | if (a == (uint32_t)NC) |
marcozecchini | 0:9fca2b23d0ba | 42 | return b; |
marcozecchini | 0:9fca2b23d0ba | 43 | if (b == (uint32_t)NC) |
marcozecchini | 0:9fca2b23d0ba | 44 | return a; |
marcozecchini | 0:9fca2b23d0ba | 45 | |
marcozecchini | 0:9fca2b23d0ba | 46 | // mis-match error case |
marcozecchini | 0:9fca2b23d0ba | 47 | error("pinmap mis-match"); |
marcozecchini | 0:9fca2b23d0ba | 48 | return (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 49 | } |
marcozecchini | 0:9fca2b23d0ba | 50 | |
marcozecchini | 0:9fca2b23d0ba | 51 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { |
marcozecchini | 0:9fca2b23d0ba | 52 | while (map->pin != NC) { |
marcozecchini | 0:9fca2b23d0ba | 53 | if (map->pin == pin) |
marcozecchini | 0:9fca2b23d0ba | 54 | return map->peripheral; |
marcozecchini | 0:9fca2b23d0ba | 55 | map++; |
marcozecchini | 0:9fca2b23d0ba | 56 | } |
marcozecchini | 0:9fca2b23d0ba | 57 | return (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 58 | } |
marcozecchini | 0:9fca2b23d0ba | 59 | |
marcozecchini | 0:9fca2b23d0ba | 60 | uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { |
marcozecchini | 0:9fca2b23d0ba | 61 | uint32_t peripheral = (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 62 | |
marcozecchini | 0:9fca2b23d0ba | 63 | if (pin == (PinName)NC) |
marcozecchini | 0:9fca2b23d0ba | 64 | return (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 65 | peripheral = pinmap_find_peripheral(pin, map); |
marcozecchini | 0:9fca2b23d0ba | 66 | if ((uint32_t)NC == peripheral) // no mapping available |
marcozecchini | 0:9fca2b23d0ba | 67 | error("pinmap not found for peripheral"); |
marcozecchini | 0:9fca2b23d0ba | 68 | return peripheral; |
marcozecchini | 0:9fca2b23d0ba | 69 | } |
marcozecchini | 0:9fca2b23d0ba | 70 | |
marcozecchini | 0:9fca2b23d0ba | 71 | uint32_t pinmap_find_function(PinName pin, const PinMap* map) { |
marcozecchini | 0:9fca2b23d0ba | 72 | while (map->pin != NC) { |
marcozecchini | 0:9fca2b23d0ba | 73 | if (map->pin == pin) |
marcozecchini | 0:9fca2b23d0ba | 74 | return map->function; |
marcozecchini | 0:9fca2b23d0ba | 75 | map++; |
marcozecchini | 0:9fca2b23d0ba | 76 | } |
marcozecchini | 0:9fca2b23d0ba | 77 | return (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 78 | } |
marcozecchini | 0:9fca2b23d0ba | 79 | |
marcozecchini | 0:9fca2b23d0ba | 80 | uint32_t pinmap_function(PinName pin, const PinMap* map) { |
marcozecchini | 0:9fca2b23d0ba | 81 | uint32_t function = (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 82 | |
marcozecchini | 0:9fca2b23d0ba | 83 | if (pin == (PinName)NC) |
marcozecchini | 0:9fca2b23d0ba | 84 | return (uint32_t)NC; |
marcozecchini | 0:9fca2b23d0ba | 85 | function = pinmap_find_function(pin, map); |
marcozecchini | 0:9fca2b23d0ba | 86 | if ((uint32_t)NC == function) // no mapping available |
marcozecchini | 0:9fca2b23d0ba | 87 | error("pinmap not found for function"); |
marcozecchini | 0:9fca2b23d0ba | 88 | return function; |
marcozecchini | 0:9fca2b23d0ba | 89 | } |