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