mbed library sources
Fork of mbed-src by
common/InterruptIn.cpp@9:0ce32e54c9a7, 2013-06-10 (annotated)
- Committer:
- emilmont
- Date:
- Mon Jun 10 16:03:00 2013 +0100
- Revision:
- 9:0ce32e54c9a7
- Parent:
- cpp/InterruptIn.cpp@2:143cac498751
- Child:
- 10:3bc89ef62ce7
Refactoring of the mbed SDK:
- Provide a well defined HAL and API
- Keep separated the HAL implementations for the different targets
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:fd0d7bdfcdc2 | 1 | /* mbed Microcontroller Library |
emilmont | 2:143cac498751 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 0:fd0d7bdfcdc2 | 3 | * |
emilmont | 2:143cac498751 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
emilmont | 2:143cac498751 | 5 | * you may not use this file except in compliance with the License. |
emilmont | 2:143cac498751 | 6 | * You may obtain a copy of the License at |
mbed_official | 0:fd0d7bdfcdc2 | 7 | * |
emilmont | 2:143cac498751 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 0:fd0d7bdfcdc2 | 9 | * |
emilmont | 2:143cac498751 | 10 | * Unless required by applicable law or agreed to in writing, software |
emilmont | 2:143cac498751 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
emilmont | 2:143cac498751 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
emilmont | 2:143cac498751 | 13 | * See the License for the specific language governing permissions and |
emilmont | 2:143cac498751 | 14 | * limitations under the License. |
mbed_official | 0:fd0d7bdfcdc2 | 15 | */ |
mbed_official | 0:fd0d7bdfcdc2 | 16 | #include "InterruptIn.h" |
mbed_official | 0:fd0d7bdfcdc2 | 17 | |
mbed_official | 0:fd0d7bdfcdc2 | 18 | #if DEVICE_INTERRUPTIN |
mbed_official | 0:fd0d7bdfcdc2 | 19 | |
mbed_official | 0:fd0d7bdfcdc2 | 20 | namespace mbed { |
mbed_official | 0:fd0d7bdfcdc2 | 21 | |
mbed_official | 0:fd0d7bdfcdc2 | 22 | InterruptIn::InterruptIn(PinName pin) { |
emilmont | 2:143cac498751 | 23 | gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); |
mbed_official | 0:fd0d7bdfcdc2 | 24 | gpio_init(&gpio, pin, PIN_INPUT); |
mbed_official | 0:fd0d7bdfcdc2 | 25 | } |
mbed_official | 0:fd0d7bdfcdc2 | 26 | |
mbed_official | 0:fd0d7bdfcdc2 | 27 | InterruptIn::~InterruptIn() { |
mbed_official | 0:fd0d7bdfcdc2 | 28 | gpio_irq_free(&gpio_irq); |
mbed_official | 0:fd0d7bdfcdc2 | 29 | } |
mbed_official | 0:fd0d7bdfcdc2 | 30 | |
emilmont | 2:143cac498751 | 31 | int InterruptIn::read() { |
mbed_official | 0:fd0d7bdfcdc2 | 32 | return gpio_read(&gpio); |
mbed_official | 0:fd0d7bdfcdc2 | 33 | } |
mbed_official | 0:fd0d7bdfcdc2 | 34 | |
mbed_official | 0:fd0d7bdfcdc2 | 35 | void InterruptIn::mode(PinMode pull) { |
mbed_official | 0:fd0d7bdfcdc2 | 36 | gpio_mode(&gpio, pull); |
mbed_official | 0:fd0d7bdfcdc2 | 37 | } |
mbed_official | 0:fd0d7bdfcdc2 | 38 | |
mbed_official | 0:fd0d7bdfcdc2 | 39 | void InterruptIn::rise(void (*fptr)(void)) { |
mbed_official | 0:fd0d7bdfcdc2 | 40 | if (fptr) { |
mbed_official | 0:fd0d7bdfcdc2 | 41 | _rise.attach(fptr); |
mbed_official | 0:fd0d7bdfcdc2 | 42 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
mbed_official | 0:fd0d7bdfcdc2 | 43 | } else { |
mbed_official | 0:fd0d7bdfcdc2 | 44 | gpio_irq_set(&gpio_irq, IRQ_RISE, 0); |
mbed_official | 0:fd0d7bdfcdc2 | 45 | } |
mbed_official | 0:fd0d7bdfcdc2 | 46 | } |
mbed_official | 0:fd0d7bdfcdc2 | 47 | |
mbed_official | 0:fd0d7bdfcdc2 | 48 | void InterruptIn::fall(void (*fptr)(void)) { |
mbed_official | 0:fd0d7bdfcdc2 | 49 | if (fptr) { |
mbed_official | 0:fd0d7bdfcdc2 | 50 | _fall.attach(fptr); |
mbed_official | 0:fd0d7bdfcdc2 | 51 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
mbed_official | 0:fd0d7bdfcdc2 | 52 | } else { |
mbed_official | 0:fd0d7bdfcdc2 | 53 | gpio_irq_set(&gpio_irq, IRQ_FALL, 0); |
mbed_official | 0:fd0d7bdfcdc2 | 54 | } |
mbed_official | 0:fd0d7bdfcdc2 | 55 | } |
mbed_official | 0:fd0d7bdfcdc2 | 56 | |
mbed_official | 0:fd0d7bdfcdc2 | 57 | void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) { |
mbed_official | 0:fd0d7bdfcdc2 | 58 | InterruptIn *handler = (InterruptIn*)id; |
mbed_official | 0:fd0d7bdfcdc2 | 59 | switch (event) { |
mbed_official | 0:fd0d7bdfcdc2 | 60 | case IRQ_RISE: handler->_rise.call(); break; |
mbed_official | 0:fd0d7bdfcdc2 | 61 | case IRQ_FALL: handler->_fall.call(); break; |
mbed_official | 0:fd0d7bdfcdc2 | 62 | case IRQ_NONE: break; |
mbed_official | 0:fd0d7bdfcdc2 | 63 | } |
mbed_official | 0:fd0d7bdfcdc2 | 64 | } |
mbed_official | 0:fd0d7bdfcdc2 | 65 | |
mbed_official | 0:fd0d7bdfcdc2 | 66 | #ifdef MBED_OPERATORS |
mbed_official | 0:fd0d7bdfcdc2 | 67 | InterruptIn::operator int() { |
mbed_official | 0:fd0d7bdfcdc2 | 68 | return read(); |
mbed_official | 0:fd0d7bdfcdc2 | 69 | } |
mbed_official | 0:fd0d7bdfcdc2 | 70 | #endif |
mbed_official | 0:fd0d7bdfcdc2 | 71 | |
mbed_official | 0:fd0d7bdfcdc2 | 72 | } // namespace mbed |
mbed_official | 0:fd0d7bdfcdc2 | 73 | |
mbed_official | 0:fd0d7bdfcdc2 | 74 | #endif |