Daniel Vizcaya / Mbed OS 04_RTOS_Embebidos
Committer:
Bethory
Date:
Wed May 30 04:46:28 2018 +0000
Revision:
1:fcdb45ee95b9
Parent:
0:6ad07c9019fd
Entrega Final

Who changed what in which revision?

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