lol

Dependencies:   MMA8451Q

Fork of Application by Mateusz Kowalik

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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