Mbed SDK for XRange SX1272 LoRa module
Dependents: XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver
SX1272 LoRa RF module
https://www.netblocks.eu/xrange-sx1272-lora-datasheet/
common/pinmap_common.c@339:ac6f3fd999f3, 2016-01-07 (annotated)
- Committer:
- netblocks
- Date:
- Thu Jan 07 13:01:25 2016 +0000
- Revision:
- 339:ac6f3fd999f3
- Parent:
- 336:1e18a06a987b
HSE_VALUE set for XTAL 16Mhz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudmuck | 336:1e18a06a987b | 1 | /* mbed Microcontroller Library |
dudmuck | 336:1e18a06a987b | 2 | * Copyright (c) 2006-2013 ARM Limited |
dudmuck | 336:1e18a06a987b | 3 | * |
dudmuck | 336:1e18a06a987b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dudmuck | 336:1e18a06a987b | 5 | * you may not use this file except in compliance with the License. |
dudmuck | 336:1e18a06a987b | 6 | * You may obtain a copy of the License at |
dudmuck | 336:1e18a06a987b | 7 | * |
dudmuck | 336:1e18a06a987b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dudmuck | 336:1e18a06a987b | 9 | * |
dudmuck | 336:1e18a06a987b | 10 | * Unless required by applicable law or agreed to in writing, software |
dudmuck | 336:1e18a06a987b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dudmuck | 336:1e18a06a987b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dudmuck | 336:1e18a06a987b | 13 | * See the License for the specific language governing permissions and |
dudmuck | 336:1e18a06a987b | 14 | * limitations under the License. |
dudmuck | 336:1e18a06a987b | 15 | */ |
dudmuck | 336:1e18a06a987b | 16 | #include "pinmap.h" |
dudmuck | 336:1e18a06a987b | 17 | #include "mbed_error.h" |
dudmuck | 336:1e18a06a987b | 18 | |
dudmuck | 336:1e18a06a987b | 19 | void pinmap_pinout(PinName pin, const PinMap *map) { |
dudmuck | 336:1e18a06a987b | 20 | if (pin == NC) |
dudmuck | 336:1e18a06a987b | 21 | return; |
dudmuck | 336:1e18a06a987b | 22 | |
dudmuck | 336:1e18a06a987b | 23 | while (map->pin != NC) { |
dudmuck | 336:1e18a06a987b | 24 | if (map->pin == pin) { |
dudmuck | 336:1e18a06a987b | 25 | pin_function(pin, map->function); |
dudmuck | 336:1e18a06a987b | 26 | |
dudmuck | 336:1e18a06a987b | 27 | pin_mode(pin, PullNone); |
dudmuck | 336:1e18a06a987b | 28 | return; |
dudmuck | 336:1e18a06a987b | 29 | } |
dudmuck | 336:1e18a06a987b | 30 | map++; |
dudmuck | 336:1e18a06a987b | 31 | } |
dudmuck | 336:1e18a06a987b | 32 | error("could not pinout"); |
dudmuck | 336:1e18a06a987b | 33 | } |
dudmuck | 336:1e18a06a987b | 34 | |
dudmuck | 336:1e18a06a987b | 35 | uint32_t pinmap_merge(uint32_t a, uint32_t b) { |
dudmuck | 336:1e18a06a987b | 36 | // both are the same (inc both NC) |
dudmuck | 336:1e18a06a987b | 37 | if (a == b) |
dudmuck | 336:1e18a06a987b | 38 | return a; |
dudmuck | 336:1e18a06a987b | 39 | |
dudmuck | 336:1e18a06a987b | 40 | // one (or both) is not connected |
dudmuck | 336:1e18a06a987b | 41 | if (a == (uint32_t)NC) |
dudmuck | 336:1e18a06a987b | 42 | return b; |
dudmuck | 336:1e18a06a987b | 43 | if (b == (uint32_t)NC) |
dudmuck | 336:1e18a06a987b | 44 | return a; |
dudmuck | 336:1e18a06a987b | 45 | |
dudmuck | 336:1e18a06a987b | 46 | // mis-match error case |
dudmuck | 336:1e18a06a987b | 47 | error("pinmap mis-match"); |
dudmuck | 336:1e18a06a987b | 48 | return (uint32_t)NC; |
dudmuck | 336:1e18a06a987b | 49 | } |
dudmuck | 336:1e18a06a987b | 50 | |
dudmuck | 336:1e18a06a987b | 51 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { |
dudmuck | 336:1e18a06a987b | 52 | while (map->pin != NC) { |
dudmuck | 336:1e18a06a987b | 53 | if (map->pin == pin) |
dudmuck | 336:1e18a06a987b | 54 | return map->peripheral; |
dudmuck | 336:1e18a06a987b | 55 | map++; |
dudmuck | 336:1e18a06a987b | 56 | } |
dudmuck | 336:1e18a06a987b | 57 | return (uint32_t)NC; |
dudmuck | 336:1e18a06a987b | 58 | } |
dudmuck | 336:1e18a06a987b | 59 | |
dudmuck | 336:1e18a06a987b | 60 | uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { |
dudmuck | 336:1e18a06a987b | 61 | uint32_t peripheral = (uint32_t)NC; |
dudmuck | 336:1e18a06a987b | 62 | |
dudmuck | 336:1e18a06a987b | 63 | if (pin == (PinName)NC) |
dudmuck | 336:1e18a06a987b | 64 | return (uint32_t)NC; |
dudmuck | 336:1e18a06a987b | 65 | peripheral = pinmap_find_peripheral(pin, map); |
dudmuck | 336:1e18a06a987b | 66 | if ((uint32_t)NC == peripheral) // no mapping available |
dudmuck | 336:1e18a06a987b | 67 | error("pinmap not found for peripheral"); |
dudmuck | 336:1e18a06a987b | 68 | return peripheral; |
dudmuck | 336:1e18a06a987b | 69 | } |