[352] | 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 |
|
---|
[374] | 19 | void pinmap_pinout(PinName pin, const PinMap *map)
|
---|
| 20 | {
|
---|
| 21 | if (pin == NC) {
|
---|
[352] | 22 | return;
|
---|
[374] | 23 | }
|
---|
[352] | 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 | }
|
---|
[374] | 34 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "could not pinout", pin);
|
---|
[352] | 35 | }
|
---|
| 36 |
|
---|
[374] | 37 | uint32_t pinmap_merge(uint32_t a, uint32_t b)
|
---|
| 38 | {
|
---|
[352] | 39 | // both are the same (inc both NC)
|
---|
[374] | 40 | if (a == b) {
|
---|
[352] | 41 | return a;
|
---|
[374] | 42 | }
|
---|
[352] | 43 |
|
---|
| 44 | // one (or both) is not connected
|
---|
[374] | 45 | if (a == (uint32_t)NC) {
|
---|
[352] | 46 | return b;
|
---|
[374] | 47 | }
|
---|
| 48 | if (b == (uint32_t)NC) {
|
---|
[352] | 49 | return a;
|
---|
[374] | 50 | }
|
---|
[352] | 51 |
|
---|
| 52 | // mis-match error case
|
---|
[374] | 53 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
|
---|
[352] | 54 | return (uint32_t)NC;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[374] | 57 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map)
|
---|
| 58 | {
|
---|
[352] | 59 | while (map->pin != NC) {
|
---|
[374] | 60 | if (map->pin == pin) {
|
---|
[352] | 61 | return map->peripheral;
|
---|
[374] | 62 | }
|
---|
[352] | 63 | map++;
|
---|
| 64 | }
|
---|
| 65 | return (uint32_t)NC;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[374] | 68 | uint32_t pinmap_peripheral(PinName pin, const PinMap *map)
|
---|
| 69 | {
|
---|
[352] | 70 | uint32_t peripheral = (uint32_t)NC;
|
---|
| 71 |
|
---|
[374] | 72 | if (pin == (PinName)NC) {
|
---|
[352] | 73 | return (uint32_t)NC;
|
---|
[374] | 74 | }
|
---|
[352] | 75 | peripheral = pinmap_find_peripheral(pin, map);
|
---|
[374] | 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 | }
|
---|
[352] | 79 | return peripheral;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[374] | 82 | uint32_t pinmap_find_function(PinName pin, const PinMap *map)
|
---|
| 83 | {
|
---|
[352] | 84 | while (map->pin != NC) {
|
---|
[374] | 85 | if (map->pin == pin) {
|
---|
[352] | 86 | return map->function;
|
---|
[374] | 87 | }
|
---|
[352] | 88 | map++;
|
---|
| 89 | }
|
---|
| 90 | return (uint32_t)NC;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[374] | 93 | uint32_t pinmap_function(PinName pin, const PinMap *map)
|
---|
| 94 | {
|
---|
[352] | 95 | uint32_t function = (uint32_t)NC;
|
---|
| 96 |
|
---|
[374] | 97 | if (pin == (PinName)NC) {
|
---|
[352] | 98 | return (uint32_t)NC;
|
---|
[374] | 99 | }
|
---|
[352] | 100 | function = pinmap_find_function(pin, map);
|
---|
[374] | 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 | }
|
---|
[352] | 104 | return function;
|
---|
| 105 | }
|
---|