![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/drivers/InterruptIn.cpp@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2006-2013 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | #include "drivers/InterruptIn.h" |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | #if DEVICE_INTERRUPTIN |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | namespace mbed { |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | // Note: This single-parameter constructor exists to maintain binary |
kadonotakashi | 0:8fdf9a60065b | 23 | // compatibility. |
kadonotakashi | 0:8fdf9a60065b | 24 | // If not for that, we could simplify by having only the 2-param |
kadonotakashi | 0:8fdf9a60065b | 25 | // constructor, with a default value for the PinMode. |
kadonotakashi | 0:8fdf9a60065b | 26 | InterruptIn::InterruptIn(PinName pin) : gpio(), |
kadonotakashi | 0:8fdf9a60065b | 27 | gpio_irq(), |
kadonotakashi | 0:8fdf9a60065b | 28 | _rise(NULL), |
kadonotakashi | 0:8fdf9a60065b | 29 | _fall(NULL) |
kadonotakashi | 0:8fdf9a60065b | 30 | { |
kadonotakashi | 0:8fdf9a60065b | 31 | // No lock needed in the constructor |
kadonotakashi | 0:8fdf9a60065b | 32 | irq_init(pin); |
kadonotakashi | 0:8fdf9a60065b | 33 | gpio_init_in(&gpio, pin); |
kadonotakashi | 0:8fdf9a60065b | 34 | } |
kadonotakashi | 0:8fdf9a60065b | 35 | |
kadonotakashi | 0:8fdf9a60065b | 36 | InterruptIn::InterruptIn(PinName pin, PinMode mode) : |
kadonotakashi | 0:8fdf9a60065b | 37 | gpio(), |
kadonotakashi | 0:8fdf9a60065b | 38 | gpio_irq(), |
kadonotakashi | 0:8fdf9a60065b | 39 | _rise(NULL), |
kadonotakashi | 0:8fdf9a60065b | 40 | _fall(NULL) |
kadonotakashi | 0:8fdf9a60065b | 41 | { |
kadonotakashi | 0:8fdf9a60065b | 42 | // No lock needed in the constructor |
kadonotakashi | 0:8fdf9a60065b | 43 | irq_init(pin); |
kadonotakashi | 0:8fdf9a60065b | 44 | gpio_init_in_ex(&gpio, pin, mode); |
kadonotakashi | 0:8fdf9a60065b | 45 | } |
kadonotakashi | 0:8fdf9a60065b | 46 | |
kadonotakashi | 0:8fdf9a60065b | 47 | void InterruptIn::irq_init(PinName pin) |
kadonotakashi | 0:8fdf9a60065b | 48 | { |
kadonotakashi | 0:8fdf9a60065b | 49 | gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); |
kadonotakashi | 0:8fdf9a60065b | 50 | } |
kadonotakashi | 0:8fdf9a60065b | 51 | |
kadonotakashi | 0:8fdf9a60065b | 52 | InterruptIn::~InterruptIn() |
kadonotakashi | 0:8fdf9a60065b | 53 | { |
kadonotakashi | 0:8fdf9a60065b | 54 | // No lock needed in the destructor |
kadonotakashi | 0:8fdf9a60065b | 55 | gpio_irq_free(&gpio_irq); |
kadonotakashi | 0:8fdf9a60065b | 56 | } |
kadonotakashi | 0:8fdf9a60065b | 57 | |
kadonotakashi | 0:8fdf9a60065b | 58 | int InterruptIn::read() |
kadonotakashi | 0:8fdf9a60065b | 59 | { |
kadonotakashi | 0:8fdf9a60065b | 60 | // Read only |
kadonotakashi | 0:8fdf9a60065b | 61 | return gpio_read(&gpio); |
kadonotakashi | 0:8fdf9a60065b | 62 | } |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | void InterruptIn::mode(PinMode pull) |
kadonotakashi | 0:8fdf9a60065b | 65 | { |
kadonotakashi | 0:8fdf9a60065b | 66 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 67 | gpio_mode(&gpio, pull); |
kadonotakashi | 0:8fdf9a60065b | 68 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 69 | } |
kadonotakashi | 0:8fdf9a60065b | 70 | |
kadonotakashi | 0:8fdf9a60065b | 71 | void InterruptIn::rise(Callback<void()> func) |
kadonotakashi | 0:8fdf9a60065b | 72 | { |
kadonotakashi | 0:8fdf9a60065b | 73 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 74 | if (func) { |
kadonotakashi | 0:8fdf9a60065b | 75 | _rise = func; |
kadonotakashi | 0:8fdf9a60065b | 76 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
kadonotakashi | 0:8fdf9a60065b | 77 | } else { |
kadonotakashi | 0:8fdf9a60065b | 78 | _rise = NULL; |
kadonotakashi | 0:8fdf9a60065b | 79 | gpio_irq_set(&gpio_irq, IRQ_RISE, 0); |
kadonotakashi | 0:8fdf9a60065b | 80 | } |
kadonotakashi | 0:8fdf9a60065b | 81 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 82 | } |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | void InterruptIn::fall(Callback<void()> func) |
kadonotakashi | 0:8fdf9a60065b | 85 | { |
kadonotakashi | 0:8fdf9a60065b | 86 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 87 | if (func) { |
kadonotakashi | 0:8fdf9a60065b | 88 | _fall = func; |
kadonotakashi | 0:8fdf9a60065b | 89 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
kadonotakashi | 0:8fdf9a60065b | 90 | } else { |
kadonotakashi | 0:8fdf9a60065b | 91 | _fall = NULL; |
kadonotakashi | 0:8fdf9a60065b | 92 | gpio_irq_set(&gpio_irq, IRQ_FALL, 0); |
kadonotakashi | 0:8fdf9a60065b | 93 | } |
kadonotakashi | 0:8fdf9a60065b | 94 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 95 | } |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) |
kadonotakashi | 0:8fdf9a60065b | 98 | { |
kadonotakashi | 0:8fdf9a60065b | 99 | InterruptIn *handler = (InterruptIn *)id; |
kadonotakashi | 0:8fdf9a60065b | 100 | switch (event) { |
kadonotakashi | 0:8fdf9a60065b | 101 | case IRQ_RISE: |
kadonotakashi | 0:8fdf9a60065b | 102 | if (handler->_rise) { |
kadonotakashi | 0:8fdf9a60065b | 103 | handler->_rise(); |
kadonotakashi | 0:8fdf9a60065b | 104 | } |
kadonotakashi | 0:8fdf9a60065b | 105 | break; |
kadonotakashi | 0:8fdf9a60065b | 106 | case IRQ_FALL: |
kadonotakashi | 0:8fdf9a60065b | 107 | if (handler->_fall) { |
kadonotakashi | 0:8fdf9a60065b | 108 | handler->_fall(); |
kadonotakashi | 0:8fdf9a60065b | 109 | } |
kadonotakashi | 0:8fdf9a60065b | 110 | break; |
kadonotakashi | 0:8fdf9a60065b | 111 | case IRQ_NONE: |
kadonotakashi | 0:8fdf9a60065b | 112 | break; |
kadonotakashi | 0:8fdf9a60065b | 113 | } |
kadonotakashi | 0:8fdf9a60065b | 114 | } |
kadonotakashi | 0:8fdf9a60065b | 115 | |
kadonotakashi | 0:8fdf9a60065b | 116 | void InterruptIn::enable_irq() |
kadonotakashi | 0:8fdf9a60065b | 117 | { |
kadonotakashi | 0:8fdf9a60065b | 118 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 119 | gpio_irq_enable(&gpio_irq); |
kadonotakashi | 0:8fdf9a60065b | 120 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 121 | } |
kadonotakashi | 0:8fdf9a60065b | 122 | |
kadonotakashi | 0:8fdf9a60065b | 123 | void InterruptIn::disable_irq() |
kadonotakashi | 0:8fdf9a60065b | 124 | { |
kadonotakashi | 0:8fdf9a60065b | 125 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 126 | gpio_irq_disable(&gpio_irq); |
kadonotakashi | 0:8fdf9a60065b | 127 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 128 | } |
kadonotakashi | 0:8fdf9a60065b | 129 | |
kadonotakashi | 0:8fdf9a60065b | 130 | InterruptIn::operator int() |
kadonotakashi | 0:8fdf9a60065b | 131 | { |
kadonotakashi | 0:8fdf9a60065b | 132 | // Underlying call is atomic |
kadonotakashi | 0:8fdf9a60065b | 133 | return read(); |
kadonotakashi | 0:8fdf9a60065b | 134 | } |
kadonotakashi | 0:8fdf9a60065b | 135 | |
kadonotakashi | 0:8fdf9a60065b | 136 | } // namespace mbed |
kadonotakashi | 0:8fdf9a60065b | 137 | |
kadonotakashi | 0:8fdf9a60065b | 138 | #endif |