mbed library sources
Fork of mbed-src by
capi/pinmap_common.c
- Committer:
- mbed_official
- Date:
- 2012-11-20
- Revision:
- 0:fd0d7bdfcdc2
- Child:
- 2:143cac498751
File content as of revision 0:fd0d7bdfcdc2:
/* mbed Microcontroller Library * Copyright (c) 2006-2012 ARM Limited * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "pinmap.h" #include "error.h" void pinmap_pinout(PinName pin, const PinMap *map) { if (pin == NC) return; while (map->pin != NC) { if (map->pin == pin) { pin_function(pin, map->function); pin_mode(pin, PullNone); return; } map++; } error("could not pinout"); } uint32_t pinmap_merge(uint32_t a, uint32_t b) { // both are the same (inc both NC) if (a == b) return a; // one (or both) is not connected if (a == (uint32_t)NC) return b; if (b == (uint32_t)NC) return a; // mis-match error case error("pinmap mis-match"); return (uint32_t)NC; } uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { if (pin == (uint32_t)NC) return (uint32_t)NC; while (map->pin != NC) { if (map->pin == pin) return map->peripheral; map++; } // no mapping available error("pinmap not found for peripheral"); return (uint32_t)NC; }