Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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