Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
drivers/InterruptIn.cpp@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 167:1657b442184c | 1 | /* mbed Microcontroller Library |
thedo | 167:1657b442184c | 2 | * Copyright (c) 2006-2013 ARM Limited |
thedo | 167:1657b442184c | 3 | * |
thedo | 167:1657b442184c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 167:1657b442184c | 5 | * you may not use this file except in compliance with the License. |
thedo | 167:1657b442184c | 6 | * You may obtain a copy of the License at |
thedo | 167:1657b442184c | 7 | * |
thedo | 167:1657b442184c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 167:1657b442184c | 9 | * |
thedo | 167:1657b442184c | 10 | * Unless required by applicable law or agreed to in writing, software |
thedo | 167:1657b442184c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 167:1657b442184c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 167:1657b442184c | 13 | * See the License for the specific language governing permissions and |
thedo | 167:1657b442184c | 14 | * limitations under the License. |
thedo | 167:1657b442184c | 15 | */ |
thedo | 167:1657b442184c | 16 | #include "drivers/InterruptIn.h" |
thedo | 167:1657b442184c | 17 | |
thedo | 167:1657b442184c | 18 | #if DEVICE_INTERRUPTIN |
thedo | 167:1657b442184c | 19 | |
thedo | 167:1657b442184c | 20 | namespace mbed { |
thedo | 167:1657b442184c | 21 | |
thedo | 167:1657b442184c | 22 | static void donothing() {} |
thedo | 167:1657b442184c | 23 | |
thedo | 167:1657b442184c | 24 | InterruptIn::InterruptIn(PinName pin) : gpio(), |
thedo | 167:1657b442184c | 25 | gpio_irq(), |
thedo | 167:1657b442184c | 26 | _rise(), |
thedo | 167:1657b442184c | 27 | _fall() { |
thedo | 167:1657b442184c | 28 | // No lock needed in the constructor |
thedo | 167:1657b442184c | 29 | |
thedo | 167:1657b442184c | 30 | _rise = donothing; |
thedo | 167:1657b442184c | 31 | _fall = donothing; |
thedo | 167:1657b442184c | 32 | |
thedo | 167:1657b442184c | 33 | gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); |
thedo | 167:1657b442184c | 34 | gpio_init_in(&gpio, pin); |
thedo | 167:1657b442184c | 35 | } |
thedo | 167:1657b442184c | 36 | |
thedo | 167:1657b442184c | 37 | InterruptIn::~InterruptIn() { |
thedo | 167:1657b442184c | 38 | // No lock needed in the destructor |
thedo | 167:1657b442184c | 39 | gpio_irq_free(&gpio_irq); |
thedo | 167:1657b442184c | 40 | } |
thedo | 167:1657b442184c | 41 | |
thedo | 167:1657b442184c | 42 | int InterruptIn::read() { |
thedo | 167:1657b442184c | 43 | // Read only |
thedo | 167:1657b442184c | 44 | return gpio_read(&gpio); |
thedo | 167:1657b442184c | 45 | } |
thedo | 167:1657b442184c | 46 | |
thedo | 167:1657b442184c | 47 | void InterruptIn::mode(PinMode pull) { |
thedo | 167:1657b442184c | 48 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 49 | gpio_mode(&gpio, pull); |
thedo | 167:1657b442184c | 50 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 51 | } |
thedo | 167:1657b442184c | 52 | |
thedo | 167:1657b442184c | 53 | void InterruptIn::rise(Callback<void()> func) { |
thedo | 167:1657b442184c | 54 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 55 | if (func) { |
thedo | 167:1657b442184c | 56 | _rise = func; |
thedo | 167:1657b442184c | 57 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
thedo | 167:1657b442184c | 58 | } else { |
thedo | 167:1657b442184c | 59 | _rise = donothing; |
thedo | 167:1657b442184c | 60 | gpio_irq_set(&gpio_irq, IRQ_RISE, 0); |
thedo | 167:1657b442184c | 61 | } |
thedo | 167:1657b442184c | 62 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 63 | } |
thedo | 167:1657b442184c | 64 | |
thedo | 167:1657b442184c | 65 | void InterruptIn::fall(Callback<void()> func) { |
thedo | 167:1657b442184c | 66 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 67 | if (func) { |
thedo | 167:1657b442184c | 68 | _fall = func; |
thedo | 167:1657b442184c | 69 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
thedo | 167:1657b442184c | 70 | } else { |
thedo | 167:1657b442184c | 71 | _fall = donothing; |
thedo | 167:1657b442184c | 72 | gpio_irq_set(&gpio_irq, IRQ_FALL, 0); |
thedo | 167:1657b442184c | 73 | } |
thedo | 167:1657b442184c | 74 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 75 | } |
thedo | 167:1657b442184c | 76 | |
thedo | 167:1657b442184c | 77 | void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) { |
thedo | 167:1657b442184c | 78 | InterruptIn *handler = (InterruptIn*)id; |
thedo | 167:1657b442184c | 79 | switch (event) { |
thedo | 167:1657b442184c | 80 | case IRQ_RISE: handler->_rise(); break; |
thedo | 167:1657b442184c | 81 | case IRQ_FALL: handler->_fall(); break; |
thedo | 167:1657b442184c | 82 | case IRQ_NONE: break; |
thedo | 167:1657b442184c | 83 | } |
thedo | 167:1657b442184c | 84 | } |
thedo | 167:1657b442184c | 85 | |
thedo | 167:1657b442184c | 86 | void InterruptIn::enable_irq() { |
thedo | 167:1657b442184c | 87 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 88 | gpio_irq_enable(&gpio_irq); |
thedo | 167:1657b442184c | 89 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 90 | } |
thedo | 167:1657b442184c | 91 | |
thedo | 167:1657b442184c | 92 | void InterruptIn::disable_irq() { |
thedo | 167:1657b442184c | 93 | core_util_critical_section_enter(); |
thedo | 167:1657b442184c | 94 | gpio_irq_disable(&gpio_irq); |
thedo | 167:1657b442184c | 95 | core_util_critical_section_exit(); |
thedo | 167:1657b442184c | 96 | } |
thedo | 167:1657b442184c | 97 | |
thedo | 167:1657b442184c | 98 | InterruptIn::operator int() { |
thedo | 167:1657b442184c | 99 | // Underlying call is atomic |
thedo | 167:1657b442184c | 100 | return read(); |
thedo | 167:1657b442184c | 101 | } |
thedo | 167:1657b442184c | 102 | |
thedo | 167:1657b442184c | 103 | } // namespace mbed |
thedo | 167:1657b442184c | 104 | |
thedo | 167:1657b442184c | 105 | #endif |
thedo | 167:1657b442184c | 106 |