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