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