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