Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 11 11:49:50 2017 +0000
Revision:
1:f3f702086a30
test de la carte ? tout faire du petit robot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ClementBreteau 1:f3f702086a30 1 /* mbed Microcontroller Library - InterruptIn
ClementBreteau 1:f3f702086a30 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
ClementBreteau 1:f3f702086a30 3 */
ClementBreteau 1:f3f702086a30 4
ClementBreteau 1:f3f702086a30 5 #ifndef MBED_INTERRUPTIN_H
ClementBreteau 1:f3f702086a30 6 #define MBED_INTERRUPTIN_H
ClementBreteau 1:f3f702086a30 7
ClementBreteau 1:f3f702086a30 8 #include "device.h"
ClementBreteau 1:f3f702086a30 9
ClementBreteau 1:f3f702086a30 10 #if DEVICE_INTERRUPTIN
ClementBreteau 1:f3f702086a30 11
ClementBreteau 1:f3f702086a30 12 #include "platform.h"
ClementBreteau 1:f3f702086a30 13 #include "PinNames.h"
ClementBreteau 1:f3f702086a30 14 #include "PeripheralNames.h"
ClementBreteau 1:f3f702086a30 15 #include "Base.h"
ClementBreteau 1:f3f702086a30 16 #include "FunctionPointer.h"
ClementBreteau 1:f3f702086a30 17
ClementBreteau 1:f3f702086a30 18 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
ClementBreteau 1:f3f702086a30 19 #define CHANNEL_NUM 48
ClementBreteau 1:f3f702086a30 20 #elif defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 21 #define CHANNEL_NUM 8
ClementBreteau 1:f3f702086a30 22 #endif
ClementBreteau 1:f3f702086a30 23
ClementBreteau 1:f3f702086a30 24 namespace mbed {
ClementBreteau 1:f3f702086a30 25
ClementBreteau 1:f3f702086a30 26 /* Class: InterruptIn
ClementBreteau 1:f3f702086a30 27 * A digital interrupt input, used to call a function on a rising or falling edge
ClementBreteau 1:f3f702086a30 28 *
ClementBreteau 1:f3f702086a30 29 * Example:
ClementBreteau 1:f3f702086a30 30 * > // Flash an LED while waiting for events
ClementBreteau 1:f3f702086a30 31 * >
ClementBreteau 1:f3f702086a30 32 * > #include "mbed.h"
ClementBreteau 1:f3f702086a30 33 * >
ClementBreteau 1:f3f702086a30 34 * > InterruptIn event(p16);
ClementBreteau 1:f3f702086a30 35 * > DigitalOut led(LED1);
ClementBreteau 1:f3f702086a30 36 * >
ClementBreteau 1:f3f702086a30 37 * > void trigger() {
ClementBreteau 1:f3f702086a30 38 * > printf("triggered!\n");
ClementBreteau 1:f3f702086a30 39 * > }
ClementBreteau 1:f3f702086a30 40 * >
ClementBreteau 1:f3f702086a30 41 * > int main() {
ClementBreteau 1:f3f702086a30 42 * > event.rise(&trigger);
ClementBreteau 1:f3f702086a30 43 * > while(1) {
ClementBreteau 1:f3f702086a30 44 * > led = !led;
ClementBreteau 1:f3f702086a30 45 * > wait(0.25);
ClementBreteau 1:f3f702086a30 46 * > }
ClementBreteau 1:f3f702086a30 47 * > }
ClementBreteau 1:f3f702086a30 48 */
ClementBreteau 1:f3f702086a30 49 class InterruptIn : public Base {
ClementBreteau 1:f3f702086a30 50
ClementBreteau 1:f3f702086a30 51 public:
ClementBreteau 1:f3f702086a30 52
ClementBreteau 1:f3f702086a30 53 /* Constructor: InterruptIn
ClementBreteau 1:f3f702086a30 54 * Create an InterruptIn connected to the specified pin
ClementBreteau 1:f3f702086a30 55 *
ClementBreteau 1:f3f702086a30 56 * Variables:
ClementBreteau 1:f3f702086a30 57 * pin - InterruptIn pin to connect to
ClementBreteau 1:f3f702086a30 58 * name - (optional) A string to identify the object
ClementBreteau 1:f3f702086a30 59 */
ClementBreteau 1:f3f702086a30 60 InterruptIn(PinName pin, const char *name = NULL);
ClementBreteau 1:f3f702086a30 61 #if defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 62 virtual ~InterruptIn();
ClementBreteau 1:f3f702086a30 63 #endif
ClementBreteau 1:f3f702086a30 64
ClementBreteau 1:f3f702086a30 65 int read();
ClementBreteau 1:f3f702086a30 66 #ifdef MBED_OPERATORS
ClementBreteau 1:f3f702086a30 67 operator int();
ClementBreteau 1:f3f702086a30 68
ClementBreteau 1:f3f702086a30 69 #endif
ClementBreteau 1:f3f702086a30 70
ClementBreteau 1:f3f702086a30 71 /* Function: rise
ClementBreteau 1:f3f702086a30 72 * Attach a function to call when a rising edge occurs on the input
ClementBreteau 1:f3f702086a30 73 *
ClementBreteau 1:f3f702086a30 74 * Variables:
ClementBreteau 1:f3f702086a30 75 * fptr - A pointer to a void function, or 0 to set as none
ClementBreteau 1:f3f702086a30 76 */
ClementBreteau 1:f3f702086a30 77 void rise(void (*fptr)(void));
ClementBreteau 1:f3f702086a30 78
ClementBreteau 1:f3f702086a30 79 /* Function: rise
ClementBreteau 1:f3f702086a30 80 * Attach a member function to call when a rising edge occurs on the input
ClementBreteau 1:f3f702086a30 81 *
ClementBreteau 1:f3f702086a30 82 * Variables:
ClementBreteau 1:f3f702086a30 83 * tptr - pointer to the object to call the member function on
ClementBreteau 1:f3f702086a30 84 * mptr - pointer to the member function to be called
ClementBreteau 1:f3f702086a30 85 */
ClementBreteau 1:f3f702086a30 86 template<typename T>
ClementBreteau 1:f3f702086a30 87 void rise(T* tptr, void (T::*mptr)(void)) {
ClementBreteau 1:f3f702086a30 88 _rise.attach(tptr, mptr);
ClementBreteau 1:f3f702086a30 89 setup_interrupt(1, 1);
ClementBreteau 1:f3f702086a30 90 }
ClementBreteau 1:f3f702086a30 91
ClementBreteau 1:f3f702086a30 92 /* Function: fall
ClementBreteau 1:f3f702086a30 93 * Attach a function to call when a falling edge occurs on the input
ClementBreteau 1:f3f702086a30 94 *
ClementBreteau 1:f3f702086a30 95 * Variables:
ClementBreteau 1:f3f702086a30 96 * fptr - A pointer to a void function, or 0 to set as none
ClementBreteau 1:f3f702086a30 97 */
ClementBreteau 1:f3f702086a30 98 void fall(void (*fptr)(void));
ClementBreteau 1:f3f702086a30 99
ClementBreteau 1:f3f702086a30 100 /* Function: fall
ClementBreteau 1:f3f702086a30 101 * Attach a member function to call when a falling edge occurs on the input
ClementBreteau 1:f3f702086a30 102 *
ClementBreteau 1:f3f702086a30 103 * Variables:
ClementBreteau 1:f3f702086a30 104 * tptr - pointer to the object to call the member function on
ClementBreteau 1:f3f702086a30 105 * mptr - pointer to the member function to be called
ClementBreteau 1:f3f702086a30 106 */
ClementBreteau 1:f3f702086a30 107 template<typename T>
ClementBreteau 1:f3f702086a30 108 void fall(T* tptr, void (T::*mptr)(void)) {
ClementBreteau 1:f3f702086a30 109 _fall.attach(tptr, mptr);
ClementBreteau 1:f3f702086a30 110 setup_interrupt(0, 1);
ClementBreteau 1:f3f702086a30 111 }
ClementBreteau 1:f3f702086a30 112
ClementBreteau 1:f3f702086a30 113 /* Function: mode
ClementBreteau 1:f3f702086a30 114 * Set the input pin mode
ClementBreteau 1:f3f702086a30 115 *
ClementBreteau 1:f3f702086a30 116 * Variables:
ClementBreteau 1:f3f702086a30 117 * mode - PullUp, PullDown, PullNone
ClementBreteau 1:f3f702086a30 118 */
ClementBreteau 1:f3f702086a30 119 void mode(PinMode pull);
ClementBreteau 1:f3f702086a30 120
ClementBreteau 1:f3f702086a30 121 static InterruptIn *_irq_objects[CHANNEL_NUM];
ClementBreteau 1:f3f702086a30 122
ClementBreteau 1:f3f702086a30 123 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
ClementBreteau 1:f3f702086a30 124 static void _irq();
ClementBreteau 1:f3f702086a30 125 #elif defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 126 static void handle_interrupt_in(unsigned int channel);
ClementBreteau 1:f3f702086a30 127 static void _irq0(); static void _irq1();
ClementBreteau 1:f3f702086a30 128 static void _irq2(); static void _irq3();
ClementBreteau 1:f3f702086a30 129 static void _irq4(); static void _irq5();
ClementBreteau 1:f3f702086a30 130 static void _irq6(); static void _irq7();
ClementBreteau 1:f3f702086a30 131 #endif
ClementBreteau 1:f3f702086a30 132
ClementBreteau 1:f3f702086a30 133 protected:
ClementBreteau 1:f3f702086a30 134 PinName _pin;
ClementBreteau 1:f3f702086a30 135 #if defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 136 Channel _channel;
ClementBreteau 1:f3f702086a30 137 #endif
ClementBreteau 1:f3f702086a30 138 FunctionPointer _rise;
ClementBreteau 1:f3f702086a30 139 FunctionPointer _fall;
ClementBreteau 1:f3f702086a30 140
ClementBreteau 1:f3f702086a30 141 void setup_interrupt(int rising, int enable);
ClementBreteau 1:f3f702086a30 142
ClementBreteau 1:f3f702086a30 143 };
ClementBreteau 1:f3f702086a30 144
ClementBreteau 1:f3f702086a30 145 } // namespace mbed
ClementBreteau 1:f3f702086a30 146
ClementBreteau 1:f3f702086a30 147 #endif
ClementBreteau 1:f3f702086a30 148
ClementBreteau 1:f3f702086a30 149 #endif