Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

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