mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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