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