The code from https://github.com/vpcola/Nucleo

Committer:
sinrab
Date:
Wed Oct 08 11:00:24 2014 +0000
Revision:
0:5464d5e415e5
The code from https://github.com/vpcola/Nucleo

Who changed what in which revision?

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