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/InterruptIn.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_INTERRUPTIN_H |
dudmuck | 336:1e18a06a987b | 17 | #define MBED_INTERRUPTIN_H |
dudmuck | 336:1e18a06a987b | 18 | |
dudmuck | 336:1e18a06a987b | 19 | #include "platform.h" |
dudmuck | 336:1e18a06a987b | 20 | |
dudmuck | 336:1e18a06a987b | 21 | #if DEVICE_INTERRUPTIN |
dudmuck | 336:1e18a06a987b | 22 | |
dudmuck | 336:1e18a06a987b | 23 | #include "gpio_api.h" |
dudmuck | 336:1e18a06a987b | 24 | #include "gpio_irq_api.h" |
dudmuck | 336:1e18a06a987b | 25 | #include "FunctionPointer.h" |
dudmuck | 336:1e18a06a987b | 26 | |
dudmuck | 336:1e18a06a987b | 27 | namespace mbed { |
dudmuck | 336:1e18a06a987b | 28 | |
dudmuck | 336:1e18a06a987b | 29 | /** A digital interrupt input, used to call a function on a rising or falling edge |
dudmuck | 336:1e18a06a987b | 30 | * |
dudmuck | 336:1e18a06a987b | 31 | * Example: |
dudmuck | 336:1e18a06a987b | 32 | * @code |
dudmuck | 336:1e18a06a987b | 33 | * // Flash an LED while waiting for events |
dudmuck | 336:1e18a06a987b | 34 | * |
dudmuck | 336:1e18a06a987b | 35 | * #include "mbed.h" |
dudmuck | 336:1e18a06a987b | 36 | * |
dudmuck | 336:1e18a06a987b | 37 | * InterruptIn event(p16); |
dudmuck | 336:1e18a06a987b | 38 | * DigitalOut led(LED1); |
dudmuck | 336:1e18a06a987b | 39 | * |
dudmuck | 336:1e18a06a987b | 40 | * void trigger() { |
dudmuck | 336:1e18a06a987b | 41 | * printf("triggered!\n"); |
dudmuck | 336:1e18a06a987b | 42 | * } |
dudmuck | 336:1e18a06a987b | 43 | * |
dudmuck | 336:1e18a06a987b | 44 | * int main() { |
dudmuck | 336:1e18a06a987b | 45 | * event.rise(&trigger); |
dudmuck | 336:1e18a06a987b | 46 | * while(1) { |
dudmuck | 336:1e18a06a987b | 47 | * led = !led; |
dudmuck | 336:1e18a06a987b | 48 | * wait(0.25); |
dudmuck | 336:1e18a06a987b | 49 | * } |
dudmuck | 336:1e18a06a987b | 50 | * } |
dudmuck | 336:1e18a06a987b | 51 | * @endcode |
dudmuck | 336:1e18a06a987b | 52 | */ |
dudmuck | 336:1e18a06a987b | 53 | class InterruptIn { |
dudmuck | 336:1e18a06a987b | 54 | |
dudmuck | 336:1e18a06a987b | 55 | public: |
dudmuck | 336:1e18a06a987b | 56 | |
dudmuck | 336:1e18a06a987b | 57 | /** Create an InterruptIn connected to the specified pin |
dudmuck | 336:1e18a06a987b | 58 | * |
dudmuck | 336:1e18a06a987b | 59 | * @param pin InterruptIn pin to connect to |
dudmuck | 336:1e18a06a987b | 60 | * @param name (optional) A string to identify the object |
dudmuck | 336:1e18a06a987b | 61 | */ |
dudmuck | 336:1e18a06a987b | 62 | InterruptIn(PinName pin); |
dudmuck | 336:1e18a06a987b | 63 | virtual ~InterruptIn(); |
dudmuck | 336:1e18a06a987b | 64 | |
dudmuck | 336:1e18a06a987b | 65 | int read(); |
dudmuck | 336:1e18a06a987b | 66 | #ifdef MBED_OPERATORS |
dudmuck | 336:1e18a06a987b | 67 | operator int(); |
dudmuck | 336:1e18a06a987b | 68 | |
dudmuck | 336:1e18a06a987b | 69 | #endif |
dudmuck | 336:1e18a06a987b | 70 | |
dudmuck | 336:1e18a06a987b | 71 | /** Attach a function to call when a rising edge occurs on the input |
dudmuck | 336:1e18a06a987b | 72 | * |
dudmuck | 336:1e18a06a987b | 73 | * @param fptr A pointer to a void function, or 0 to set as none |
dudmuck | 336:1e18a06a987b | 74 | */ |
dudmuck | 336:1e18a06a987b | 75 | void rise(void (*fptr)(void)); |
dudmuck | 336:1e18a06a987b | 76 | |
dudmuck | 336:1e18a06a987b | 77 | /** Attach a member function to call when a rising edge occurs on the input |
dudmuck | 336:1e18a06a987b | 78 | * |
dudmuck | 336:1e18a06a987b | 79 | * @param tptr pointer to the object to call the member function on |
dudmuck | 336:1e18a06a987b | 80 | * @param mptr pointer to the member function to be called |
dudmuck | 336:1e18a06a987b | 81 | */ |
dudmuck | 336:1e18a06a987b | 82 | template<typename T> |
dudmuck | 336:1e18a06a987b | 83 | void rise(T* tptr, void (T::*mptr)(void)) { |
dudmuck | 336:1e18a06a987b | 84 | _rise.attach(tptr, mptr); |
dudmuck | 336:1e18a06a987b | 85 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
dudmuck | 336:1e18a06a987b | 86 | } |
dudmuck | 336:1e18a06a987b | 87 | |
dudmuck | 336:1e18a06a987b | 88 | /** Attach a function to call when a falling edge occurs on the input |
dudmuck | 336:1e18a06a987b | 89 | * |
dudmuck | 336:1e18a06a987b | 90 | * @param fptr A pointer to a void function, or 0 to set as none |
dudmuck | 336:1e18a06a987b | 91 | */ |
dudmuck | 336:1e18a06a987b | 92 | void fall(void (*fptr)(void)); |
dudmuck | 336:1e18a06a987b | 93 | |
dudmuck | 336:1e18a06a987b | 94 | /** Attach a member function to call when a falling edge occurs on the input |
dudmuck | 336:1e18a06a987b | 95 | * |
dudmuck | 336:1e18a06a987b | 96 | * @param tptr pointer to the object to call the member function on |
dudmuck | 336:1e18a06a987b | 97 | * @param mptr pointer to the member function to be called |
dudmuck | 336:1e18a06a987b | 98 | */ |
dudmuck | 336:1e18a06a987b | 99 | template<typename T> |
dudmuck | 336:1e18a06a987b | 100 | void fall(T* tptr, void (T::*mptr)(void)) { |
dudmuck | 336:1e18a06a987b | 101 | _fall.attach(tptr, mptr); |
dudmuck | 336:1e18a06a987b | 102 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
dudmuck | 336:1e18a06a987b | 103 | } |
dudmuck | 336:1e18a06a987b | 104 | |
dudmuck | 336:1e18a06a987b | 105 | /** Set the input pin mode |
dudmuck | 336:1e18a06a987b | 106 | * |
dudmuck | 336:1e18a06a987b | 107 | * @param mode PullUp, PullDown, PullNone |
dudmuck | 336:1e18a06a987b | 108 | */ |
dudmuck | 336:1e18a06a987b | 109 | void mode(PinMode pull); |
dudmuck | 336:1e18a06a987b | 110 | |
dudmuck | 336:1e18a06a987b | 111 | /** Enable IRQ. This method depends on hw implementation, might enable one |
dudmuck | 336:1e18a06a987b | 112 | * port interrupts. For further information, check gpio_irq_enable(). |
dudmuck | 336:1e18a06a987b | 113 | */ |
dudmuck | 336:1e18a06a987b | 114 | void enable_irq(); |
dudmuck | 336:1e18a06a987b | 115 | |
dudmuck | 336:1e18a06a987b | 116 | /** Disable IRQ. This method depends on hw implementation, might disable one |
dudmuck | 336:1e18a06a987b | 117 | * port interrupts. For further information, check gpio_irq_disable(). |
dudmuck | 336:1e18a06a987b | 118 | */ |
dudmuck | 336:1e18a06a987b | 119 | void disable_irq(); |
dudmuck | 336:1e18a06a987b | 120 | |
dudmuck | 336:1e18a06a987b | 121 | static void _irq_handler(uint32_t id, gpio_irq_event event); |
dudmuck | 336:1e18a06a987b | 122 | |
dudmuck | 336:1e18a06a987b | 123 | protected: |
dudmuck | 336:1e18a06a987b | 124 | gpio_t gpio; |
dudmuck | 336:1e18a06a987b | 125 | gpio_irq_t gpio_irq; |
dudmuck | 336:1e18a06a987b | 126 | |
dudmuck | 336:1e18a06a987b | 127 | FunctionPointer _rise; |
dudmuck | 336:1e18a06a987b | 128 | FunctionPointer _fall; |
dudmuck | 336:1e18a06a987b | 129 | }; |
dudmuck | 336:1e18a06a987b | 130 | |
dudmuck | 336:1e18a06a987b | 131 | } // namespace mbed |
dudmuck | 336:1e18a06a987b | 132 | |
dudmuck | 336:1e18a06a987b | 133 | #endif |
dudmuck | 336:1e18a06a987b | 134 | |
dudmuck | 336:1e18a06a987b | 135 | #endif |