mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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