Biomimetics MBED Library w/ Added Support for CAN3

Dependents:   CAN_TEST SPIne_Plus_DYNO_SENSORS SPIne_Plus_v2 SPIne_Plus_Dyno_v2

Committer:
adimmit
Date:
Tue Mar 09 20:33:24 2021 +0000
Revision:
3:993b4d6ff61e
Parent:
0:083111ae2a11
added CAN3

Who changed what in which revision?

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