Fork of mbed for KL05Z based smart sensor which has no crystal on the board, so MCG FEI mode is required.

Dependents:   smart-sensor-KL05Z-debug

Fork of mbed-src by Ermanno Brusadin

Committer:
r14793
Date:
Mon Jan 29 15:38:37 2018 +0000
Revision:
1:da408b460382
Parent:
0:0a673c671a56
changed KL05 MCG mode to FEI for smart sensor boards (no crystal)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ebrus 0:0a673c671a56 1 /* mbed Microcontroller Library
ebrus 0:0a673c671a56 2 * Copyright (c) 2006-2013 ARM Limited
ebrus 0:0a673c671a56 3 *
ebrus 0:0a673c671a56 4 * Licensed under the Apache License, Version 2.0 (the "License");
ebrus 0:0a673c671a56 5 * you may not use this file except in compliance with the License.
ebrus 0:0a673c671a56 6 * You may obtain a copy of the License at
ebrus 0:0a673c671a56 7 *
ebrus 0:0a673c671a56 8 * http://www.apache.org/licenses/LICENSE-2.0
ebrus 0:0a673c671a56 9 *
ebrus 0:0a673c671a56 10 * Unless required by applicable law or agreed to in writing, software
ebrus 0:0a673c671a56 11 * distributed under the License is distributed on an "AS IS" BASIS,
ebrus 0:0a673c671a56 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ebrus 0:0a673c671a56 13 * See the License for the specific language governing permissions and
ebrus 0:0a673c671a56 14 * limitations under the License.
ebrus 0:0a673c671a56 15 */
ebrus 0:0a673c671a56 16 #ifndef MBED_INTERRUPTIN_H
ebrus 0:0a673c671a56 17 #define MBED_INTERRUPTIN_H
ebrus 0:0a673c671a56 18
ebrus 0:0a673c671a56 19 #include "platform.h"
ebrus 0:0a673c671a56 20
ebrus 0:0a673c671a56 21 #if DEVICE_INTERRUPTIN
ebrus 0:0a673c671a56 22
ebrus 0:0a673c671a56 23 #include "gpio_api.h"
ebrus 0:0a673c671a56 24 #include "gpio_irq_api.h"
ebrus 0:0a673c671a56 25 #include "FunctionPointer.h"
ebrus 0:0a673c671a56 26
ebrus 0:0a673c671a56 27 namespace mbed {
ebrus 0:0a673c671a56 28
ebrus 0:0a673c671a56 29 /** A digital interrupt input, used to call a function on a rising or falling edge
ebrus 0:0a673c671a56 30 *
ebrus 0:0a673c671a56 31 * Example:
ebrus 0:0a673c671a56 32 * @code
ebrus 0:0a673c671a56 33 * // Flash an LED while waiting for events
ebrus 0:0a673c671a56 34 *
ebrus 0:0a673c671a56 35 * #include "mbed.h"
ebrus 0:0a673c671a56 36 *
ebrus 0:0a673c671a56 37 * InterruptIn event(p16);
ebrus 0:0a673c671a56 38 * DigitalOut led(LED1);
ebrus 0:0a673c671a56 39 *
ebrus 0:0a673c671a56 40 * void trigger() {
ebrus 0:0a673c671a56 41 * printf("triggered!\n");
ebrus 0:0a673c671a56 42 * }
ebrus 0:0a673c671a56 43 *
ebrus 0:0a673c671a56 44 * int main() {
ebrus 0:0a673c671a56 45 * event.rise(&trigger);
ebrus 0:0a673c671a56 46 * while(1) {
ebrus 0:0a673c671a56 47 * led = !led;
ebrus 0:0a673c671a56 48 * wait(0.25);
ebrus 0:0a673c671a56 49 * }
ebrus 0:0a673c671a56 50 * }
ebrus 0:0a673c671a56 51 * @endcode
ebrus 0:0a673c671a56 52 */
ebrus 0:0a673c671a56 53 class InterruptIn {
ebrus 0:0a673c671a56 54
ebrus 0:0a673c671a56 55 public:
ebrus 0:0a673c671a56 56
ebrus 0:0a673c671a56 57 /** Create an InterruptIn connected to the specified pin
ebrus 0:0a673c671a56 58 *
ebrus 0:0a673c671a56 59 * @param pin InterruptIn pin to connect to
ebrus 0:0a673c671a56 60 * @param name (optional) A string to identify the object
ebrus 0:0a673c671a56 61 */
ebrus 0:0a673c671a56 62 InterruptIn(PinName pin);
ebrus 0:0a673c671a56 63 virtual ~InterruptIn();
ebrus 0:0a673c671a56 64
ebrus 0:0a673c671a56 65 int read();
ebrus 0:0a673c671a56 66 #ifdef MBED_OPERATORS
ebrus 0:0a673c671a56 67 operator int();
ebrus 0:0a673c671a56 68
ebrus 0:0a673c671a56 69 #endif
ebrus 0:0a673c671a56 70
ebrus 0:0a673c671a56 71 /** Attach a function to call when a rising edge occurs on the input
ebrus 0:0a673c671a56 72 *
ebrus 0:0a673c671a56 73 * @param fptr A pointer to a void function, or 0 to set as none
ebrus 0:0a673c671a56 74 */
ebrus 0:0a673c671a56 75 void rise(void (*fptr)(void));
ebrus 0:0a673c671a56 76
ebrus 0:0a673c671a56 77 /** Attach a member function to call when a rising edge occurs on the input
ebrus 0:0a673c671a56 78 *
ebrus 0:0a673c671a56 79 * @param tptr pointer to the object to call the member function on
ebrus 0:0a673c671a56 80 * @param mptr pointer to the member function to be called
ebrus 0:0a673c671a56 81 */
ebrus 0:0a673c671a56 82 template<typename T>
ebrus 0:0a673c671a56 83 void rise(T* tptr, void (T::*mptr)(void)) {
ebrus 0:0a673c671a56 84 _rise.attach(tptr, mptr);
ebrus 0:0a673c671a56 85 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
ebrus 0:0a673c671a56 86 }
ebrus 0:0a673c671a56 87
ebrus 0:0a673c671a56 88 /** Attach a function to call when a falling edge occurs on the input
ebrus 0:0a673c671a56 89 *
ebrus 0:0a673c671a56 90 * @param fptr A pointer to a void function, or 0 to set as none
ebrus 0:0a673c671a56 91 */
ebrus 0:0a673c671a56 92 void fall(void (*fptr)(void));
ebrus 0:0a673c671a56 93
ebrus 0:0a673c671a56 94 /** Attach a member function to call when a falling edge occurs on the input
ebrus 0:0a673c671a56 95 *
ebrus 0:0a673c671a56 96 * @param tptr pointer to the object to call the member function on
ebrus 0:0a673c671a56 97 * @param mptr pointer to the member function to be called
ebrus 0:0a673c671a56 98 */
ebrus 0:0a673c671a56 99 template<typename T>
ebrus 0:0a673c671a56 100 void fall(T* tptr, void (T::*mptr)(void)) {
ebrus 0:0a673c671a56 101 _fall.attach(tptr, mptr);
ebrus 0:0a673c671a56 102 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
ebrus 0:0a673c671a56 103 }
ebrus 0:0a673c671a56 104
ebrus 0:0a673c671a56 105 /** Set the input pin mode
ebrus 0:0a673c671a56 106 *
ebrus 0:0a673c671a56 107 * @param mode PullUp, PullDown, PullNone
ebrus 0:0a673c671a56 108 */
ebrus 0:0a673c671a56 109 void mode(PinMode pull);
ebrus 0:0a673c671a56 110
ebrus 0:0a673c671a56 111 /** Enable IRQ. This method depends on hw implementation, might enable one
ebrus 0:0a673c671a56 112 * port interrupts. For further information, check gpio_irq_enable().
ebrus 0:0a673c671a56 113 */
ebrus 0:0a673c671a56 114 void enable_irq();
ebrus 0:0a673c671a56 115
ebrus 0:0a673c671a56 116 /** Disable IRQ. This method depends on hw implementation, might disable one
ebrus 0:0a673c671a56 117 * port interrupts. For further information, check gpio_irq_disable().
ebrus 0:0a673c671a56 118 */
ebrus 0:0a673c671a56 119 void disable_irq();
ebrus 0:0a673c671a56 120
ebrus 0:0a673c671a56 121 static void _irq_handler(uint32_t id, gpio_irq_event event);
ebrus 0:0a673c671a56 122
ebrus 0:0a673c671a56 123 protected:
ebrus 0:0a673c671a56 124 gpio_t gpio;
ebrus 0:0a673c671a56 125 gpio_irq_t gpio_irq;
ebrus 0:0a673c671a56 126
ebrus 0:0a673c671a56 127 FunctionPointer _rise;
ebrus 0:0a673c671a56 128 FunctionPointer _fall;
ebrus 0:0a673c671a56 129 };
ebrus 0:0a673c671a56 130
ebrus 0:0a673c671a56 131 } // namespace mbed
ebrus 0:0a673c671a56 132
ebrus 0:0a673c671a56 133 #endif
ebrus 0:0a673c671a56 134
ebrus 0:0a673c671a56 135 #endif