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/
api/PortInOut.h@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 | #ifndef MBED_PORTINOUT_H |
dudmuck | 336:1e18a06a987b | 17 | #define MBED_PORTINOUT_H |
dudmuck | 336:1e18a06a987b | 18 | |
dudmuck | 336:1e18a06a987b | 19 | #include "platform.h" |
dudmuck | 336:1e18a06a987b | 20 | |
dudmuck | 336:1e18a06a987b | 21 | #if DEVICE_PORTINOUT |
dudmuck | 336:1e18a06a987b | 22 | |
dudmuck | 336:1e18a06a987b | 23 | #include "port_api.h" |
dudmuck | 336:1e18a06a987b | 24 | |
dudmuck | 336:1e18a06a987b | 25 | namespace mbed { |
dudmuck | 336:1e18a06a987b | 26 | |
dudmuck | 336:1e18a06a987b | 27 | /** A multiple pin digital in/out used to set/read multiple bi-directional pins |
dudmuck | 336:1e18a06a987b | 28 | */ |
dudmuck | 336:1e18a06a987b | 29 | class PortInOut { |
dudmuck | 336:1e18a06a987b | 30 | public: |
dudmuck | 336:1e18a06a987b | 31 | |
dudmuck | 336:1e18a06a987b | 32 | /** Create an PortInOut, connected to the specified port |
dudmuck | 336:1e18a06a987b | 33 | * |
dudmuck | 336:1e18a06a987b | 34 | * @param port Port to connect to (Port0-Port5) |
dudmuck | 336:1e18a06a987b | 35 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
dudmuck | 336:1e18a06a987b | 36 | */ |
dudmuck | 336:1e18a06a987b | 37 | PortInOut(PortName port, int mask = 0xFFFFFFFF) { |
dudmuck | 336:1e18a06a987b | 38 | port_init(&_port, port, mask, PIN_INPUT); |
dudmuck | 336:1e18a06a987b | 39 | } |
dudmuck | 336:1e18a06a987b | 40 | |
dudmuck | 336:1e18a06a987b | 41 | /** Write the value to the output port |
dudmuck | 336:1e18a06a987b | 42 | * |
dudmuck | 336:1e18a06a987b | 43 | * @param value An integer specifying a bit to write for every corresponding port pin |
dudmuck | 336:1e18a06a987b | 44 | */ |
dudmuck | 336:1e18a06a987b | 45 | void write(int value) { |
dudmuck | 336:1e18a06a987b | 46 | port_write(&_port, value); |
dudmuck | 336:1e18a06a987b | 47 | } |
dudmuck | 336:1e18a06a987b | 48 | |
dudmuck | 336:1e18a06a987b | 49 | /** Read the value currently output on the port |
dudmuck | 336:1e18a06a987b | 50 | * |
dudmuck | 336:1e18a06a987b | 51 | * @returns |
dudmuck | 336:1e18a06a987b | 52 | * An integer with each bit corresponding to associated port pin setting |
dudmuck | 336:1e18a06a987b | 53 | */ |
dudmuck | 336:1e18a06a987b | 54 | int read() { |
dudmuck | 336:1e18a06a987b | 55 | return port_read(&_port); |
dudmuck | 336:1e18a06a987b | 56 | } |
dudmuck | 336:1e18a06a987b | 57 | |
dudmuck | 336:1e18a06a987b | 58 | /** Set as an output |
dudmuck | 336:1e18a06a987b | 59 | */ |
dudmuck | 336:1e18a06a987b | 60 | void output() { |
dudmuck | 336:1e18a06a987b | 61 | port_dir(&_port, PIN_OUTPUT); |
dudmuck | 336:1e18a06a987b | 62 | } |
dudmuck | 336:1e18a06a987b | 63 | |
dudmuck | 336:1e18a06a987b | 64 | /** Set as an input |
dudmuck | 336:1e18a06a987b | 65 | */ |
dudmuck | 336:1e18a06a987b | 66 | void input() { |
dudmuck | 336:1e18a06a987b | 67 | port_dir(&_port, PIN_INPUT); |
dudmuck | 336:1e18a06a987b | 68 | } |
dudmuck | 336:1e18a06a987b | 69 | |
dudmuck | 336:1e18a06a987b | 70 | /** Set the input pin mode |
dudmuck | 336:1e18a06a987b | 71 | * |
dudmuck | 336:1e18a06a987b | 72 | * @param mode PullUp, PullDown, PullNone, OpenDrain |
dudmuck | 336:1e18a06a987b | 73 | */ |
dudmuck | 336:1e18a06a987b | 74 | void mode(PinMode mode) { |
dudmuck | 336:1e18a06a987b | 75 | port_mode(&_port, mode); |
dudmuck | 336:1e18a06a987b | 76 | } |
dudmuck | 336:1e18a06a987b | 77 | |
dudmuck | 336:1e18a06a987b | 78 | /** A shorthand for write() |
dudmuck | 336:1e18a06a987b | 79 | */ |
dudmuck | 336:1e18a06a987b | 80 | PortInOut& operator= (int value) { |
dudmuck | 336:1e18a06a987b | 81 | write(value); |
dudmuck | 336:1e18a06a987b | 82 | return *this; |
dudmuck | 336:1e18a06a987b | 83 | } |
dudmuck | 336:1e18a06a987b | 84 | |
dudmuck | 336:1e18a06a987b | 85 | PortInOut& operator= (PortInOut& rhs) { |
dudmuck | 336:1e18a06a987b | 86 | write(rhs.read()); |
dudmuck | 336:1e18a06a987b | 87 | return *this; |
dudmuck | 336:1e18a06a987b | 88 | } |
dudmuck | 336:1e18a06a987b | 89 | |
dudmuck | 336:1e18a06a987b | 90 | /** A shorthand for read() |
dudmuck | 336:1e18a06a987b | 91 | */ |
dudmuck | 336:1e18a06a987b | 92 | operator int() { |
dudmuck | 336:1e18a06a987b | 93 | return read(); |
dudmuck | 336:1e18a06a987b | 94 | } |
dudmuck | 336:1e18a06a987b | 95 | |
dudmuck | 336:1e18a06a987b | 96 | private: |
dudmuck | 336:1e18a06a987b | 97 | port_t _port; |
dudmuck | 336:1e18a06a987b | 98 | }; |
dudmuck | 336:1e18a06a987b | 99 | |
dudmuck | 336:1e18a06a987b | 100 | } // namespace mbed |
dudmuck | 336:1e18a06a987b | 101 | |
dudmuck | 336:1e18a06a987b | 102 | #endif |
dudmuck | 336:1e18a06a987b | 103 | |
dudmuck | 336:1e18a06a987b | 104 | #endif |