Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed_pinmap_common.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "hal/pinmap.h" 00017 #include "platform/mbed_error.h" 00018 00019 void pinmap_pinout(PinName pin, const PinMap *map) 00020 { 00021 if (pin == NC) { 00022 return; 00023 } 00024 00025 while (map->pin != NC) { 00026 if (map->pin == pin) { 00027 pin_function(pin, map->function); 00028 00029 pin_mode(pin, PullNone); 00030 return; 00031 } 00032 map++; 00033 } 00034 MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "could not pinout", pin); 00035 } 00036 00037 uint32_t pinmap_merge(uint32_t a, uint32_t b) 00038 { 00039 // both are the same (inc both NC) 00040 if (a == b) { 00041 return a; 00042 } 00043 00044 // one (or both) is not connected 00045 if (a == (uint32_t)NC) { 00046 return b; 00047 } 00048 if (b == (uint32_t)NC) { 00049 return a; 00050 } 00051 00052 // mis-match error case 00053 MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a); 00054 return (uint32_t)NC; 00055 } 00056 00057 uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map) 00058 { 00059 while (map->pin != NC) { 00060 if (map->pin == pin) { 00061 return map->peripheral; 00062 } 00063 map++; 00064 } 00065 return (uint32_t)NC; 00066 } 00067 00068 uint32_t pinmap_peripheral(PinName pin, const PinMap *map) 00069 { 00070 uint32_t peripheral = (uint32_t)NC; 00071 00072 if (pin == (PinName)NC) { 00073 return (uint32_t)NC; 00074 } 00075 peripheral = pinmap_find_peripheral(pin, map); 00076 if ((uint32_t)NC == peripheral) { // no mapping available 00077 MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral); 00078 } 00079 return peripheral; 00080 } 00081 00082 uint32_t pinmap_find_function(PinName pin, const PinMap *map) 00083 { 00084 while (map->pin != NC) { 00085 if (map->pin == pin) { 00086 return map->function; 00087 } 00088 map++; 00089 } 00090 return (uint32_t)NC; 00091 } 00092 00093 uint32_t pinmap_function(PinName pin, const PinMap *map) 00094 { 00095 uint32_t function = (uint32_t)NC; 00096 00097 if (pin == (PinName)NC) { 00098 return (uint32_t)NC; 00099 } 00100 function = pinmap_find_function(pin, map); 00101 if ((uint32_t)NC == function) { // no mapping available 00102 MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function); 00103 } 00104 return function; 00105 }
Generated on Tue Aug 9 2022 00:37:15 by
1.7.2