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