Programme d'utilisation des AX12 avec rajout de l'MX12
Fork of test_carteAToutFaire_PR by
mbed/DigitalOut.h@3:1bb26049bdd1, 2017-05-20 (annotated)
- Committer:
- R66Y
- Date:
- Sat May 20 15:23:58 2017 +0000
- Revision:
- 3:1bb26049bdd1
- Parent:
- 1:f3f702086a30
Programme de contr?le des AX12 avec rajout de l'MX12;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ClementBreteau | 1:f3f702086a30 | 1 | /* mbed Microcontroller Library - DigitalOut |
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_DIGITALOUT_H |
ClementBreteau | 1:f3f702086a30 | 6 | #define MBED_DIGITALOUT_H |
ClementBreteau | 1:f3f702086a30 | 7 | |
ClementBreteau | 1:f3f702086a30 | 8 | #include "platform.h" |
ClementBreteau | 1:f3f702086a30 | 9 | #include "PinNames.h" |
ClementBreteau | 1:f3f702086a30 | 10 | #include "PeripheralNames.h" |
ClementBreteau | 1:f3f702086a30 | 11 | #include "Base.h" |
ClementBreteau | 1:f3f702086a30 | 12 | |
ClementBreteau | 1:f3f702086a30 | 13 | namespace mbed { |
ClementBreteau | 1:f3f702086a30 | 14 | |
ClementBreteau | 1:f3f702086a30 | 15 | /* Class: DigitalOut |
ClementBreteau | 1:f3f702086a30 | 16 | * A digital output, used for setting the state of a pin |
ClementBreteau | 1:f3f702086a30 | 17 | * |
ClementBreteau | 1:f3f702086a30 | 18 | * Example: |
ClementBreteau | 1:f3f702086a30 | 19 | * > // Toggle a LED |
ClementBreteau | 1:f3f702086a30 | 20 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 21 | * > |
ClementBreteau | 1:f3f702086a30 | 22 | * > DigitalOut led(LED1); |
ClementBreteau | 1:f3f702086a30 | 23 | * > |
ClementBreteau | 1:f3f702086a30 | 24 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 25 | * > while(1) { |
ClementBreteau | 1:f3f702086a30 | 26 | * > led = !led; |
ClementBreteau | 1:f3f702086a30 | 27 | * > wait(0.2); |
ClementBreteau | 1:f3f702086a30 | 28 | * > } |
ClementBreteau | 1:f3f702086a30 | 29 | * > } |
ClementBreteau | 1:f3f702086a30 | 30 | */ |
ClementBreteau | 1:f3f702086a30 | 31 | class DigitalOut : public Base { |
ClementBreteau | 1:f3f702086a30 | 32 | |
ClementBreteau | 1:f3f702086a30 | 33 | public: |
ClementBreteau | 1:f3f702086a30 | 34 | |
ClementBreteau | 1:f3f702086a30 | 35 | /* Constructor: DigitalOut |
ClementBreteau | 1:f3f702086a30 | 36 | * Create a DigitalOut connected to the specified pin |
ClementBreteau | 1:f3f702086a30 | 37 | * |
ClementBreteau | 1:f3f702086a30 | 38 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 39 | * pin - DigitalOut pin to connect to |
ClementBreteau | 1:f3f702086a30 | 40 | */ |
ClementBreteau | 1:f3f702086a30 | 41 | DigitalOut(PinName pin, const char* name = NULL); |
ClementBreteau | 1:f3f702086a30 | 42 | |
ClementBreteau | 1:f3f702086a30 | 43 | /* Function: write |
ClementBreteau | 1:f3f702086a30 | 44 | * Set the output, specified as 0 or 1 (int) |
ClementBreteau | 1:f3f702086a30 | 45 | * |
ClementBreteau | 1:f3f702086a30 | 46 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 47 | * value - An integer specifying the pin output value, |
ClementBreteau | 1:f3f702086a30 | 48 | * 0 for logical 0 and 1 (or any other non-zero value) for logical 1 |
ClementBreteau | 1:f3f702086a30 | 49 | */ |
ClementBreteau | 1:f3f702086a30 | 50 | void write(int value) { |
ClementBreteau | 1:f3f702086a30 | 51 | |
ClementBreteau | 1:f3f702086a30 | 52 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
ClementBreteau | 1:f3f702086a30 | 53 | |
ClementBreteau | 1:f3f702086a30 | 54 | if(value) { |
ClementBreteau | 1:f3f702086a30 | 55 | _gpio->FIOSET = _mask; |
ClementBreteau | 1:f3f702086a30 | 56 | } else { |
ClementBreteau | 1:f3f702086a30 | 57 | _gpio->FIOCLR = _mask; |
ClementBreteau | 1:f3f702086a30 | 58 | } |
ClementBreteau | 1:f3f702086a30 | 59 | |
ClementBreteau | 1:f3f702086a30 | 60 | #elif defined(TARGET_LPC11U24) |
ClementBreteau | 1:f3f702086a30 | 61 | |
ClementBreteau | 1:f3f702086a30 | 62 | if(value) { |
ClementBreteau | 1:f3f702086a30 | 63 | LPC_GPIO->SET[_index] = _mask; |
ClementBreteau | 1:f3f702086a30 | 64 | } else { |
ClementBreteau | 1:f3f702086a30 | 65 | LPC_GPIO->CLR[_index] = _mask; |
ClementBreteau | 1:f3f702086a30 | 66 | } |
ClementBreteau | 1:f3f702086a30 | 67 | #endif |
ClementBreteau | 1:f3f702086a30 | 68 | |
ClementBreteau | 1:f3f702086a30 | 69 | } |
ClementBreteau | 1:f3f702086a30 | 70 | |
ClementBreteau | 1:f3f702086a30 | 71 | /* Function: read |
ClementBreteau | 1:f3f702086a30 | 72 | * Return the output setting, represented as 0 or 1 (int) |
ClementBreteau | 1:f3f702086a30 | 73 | * |
ClementBreteau | 1:f3f702086a30 | 74 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 75 | * returns - An integer representing the output setting of the pin, |
ClementBreteau | 1:f3f702086a30 | 76 | * 0 for logical 0 and 1 for logical 1 |
ClementBreteau | 1:f3f702086a30 | 77 | */ |
ClementBreteau | 1:f3f702086a30 | 78 | int read() { |
ClementBreteau | 1:f3f702086a30 | 79 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
ClementBreteau | 1:f3f702086a30 | 80 | return ((_gpio->FIOPIN & _mask) ? 1 : 0); |
ClementBreteau | 1:f3f702086a30 | 81 | #elif defined(TARGET_LPC11U24) |
ClementBreteau | 1:f3f702086a30 | 82 | return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0); |
ClementBreteau | 1:f3f702086a30 | 83 | #endif |
ClementBreteau | 1:f3f702086a30 | 84 | |
ClementBreteau | 1:f3f702086a30 | 85 | } |
ClementBreteau | 1:f3f702086a30 | 86 | |
ClementBreteau | 1:f3f702086a30 | 87 | |
ClementBreteau | 1:f3f702086a30 | 88 | #ifdef MBED_OPERATORS |
ClementBreteau | 1:f3f702086a30 | 89 | /* Function: operator= |
ClementBreteau | 1:f3f702086a30 | 90 | * A shorthand for <write> |
ClementBreteau | 1:f3f702086a30 | 91 | */ |
ClementBreteau | 1:f3f702086a30 | 92 | DigitalOut& operator= (int value) { |
ClementBreteau | 1:f3f702086a30 | 93 | write(value); |
ClementBreteau | 1:f3f702086a30 | 94 | return *this; |
ClementBreteau | 1:f3f702086a30 | 95 | } |
ClementBreteau | 1:f3f702086a30 | 96 | |
ClementBreteau | 1:f3f702086a30 | 97 | DigitalOut& operator= (DigitalOut& rhs) { |
ClementBreteau | 1:f3f702086a30 | 98 | write(rhs.read()); |
ClementBreteau | 1:f3f702086a30 | 99 | return *this; |
ClementBreteau | 1:f3f702086a30 | 100 | } |
ClementBreteau | 1:f3f702086a30 | 101 | |
ClementBreteau | 1:f3f702086a30 | 102 | |
ClementBreteau | 1:f3f702086a30 | 103 | /* Function: operator int() |
ClementBreteau | 1:f3f702086a30 | 104 | * A shorthand for <read> |
ClementBreteau | 1:f3f702086a30 | 105 | */ |
ClementBreteau | 1:f3f702086a30 | 106 | operator int() { |
ClementBreteau | 1:f3f702086a30 | 107 | return read(); |
ClementBreteau | 1:f3f702086a30 | 108 | } |
ClementBreteau | 1:f3f702086a30 | 109 | |
ClementBreteau | 1:f3f702086a30 | 110 | #endif |
ClementBreteau | 1:f3f702086a30 | 111 | |
ClementBreteau | 1:f3f702086a30 | 112 | #ifdef MBED_RPC |
ClementBreteau | 1:f3f702086a30 | 113 | virtual const struct rpc_method *get_rpc_methods(); |
ClementBreteau | 1:f3f702086a30 | 114 | static struct rpc_class *get_rpc_class(); |
ClementBreteau | 1:f3f702086a30 | 115 | #endif |
ClementBreteau | 1:f3f702086a30 | 116 | |
ClementBreteau | 1:f3f702086a30 | 117 | protected: |
ClementBreteau | 1:f3f702086a30 | 118 | |
ClementBreteau | 1:f3f702086a30 | 119 | PinName _pin; |
ClementBreteau | 1:f3f702086a30 | 120 | |
ClementBreteau | 1:f3f702086a30 | 121 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
ClementBreteau | 1:f3f702086a30 | 122 | LPC_GPIO_TypeDef *_gpio; |
ClementBreteau | 1:f3f702086a30 | 123 | #elif defined(TARGET_LPC11U24) |
ClementBreteau | 1:f3f702086a30 | 124 | int _index; |
ClementBreteau | 1:f3f702086a30 | 125 | #endif |
ClementBreteau | 1:f3f702086a30 | 126 | |
ClementBreteau | 1:f3f702086a30 | 127 | uint32_t _mask; |
ClementBreteau | 1:f3f702086a30 | 128 | |
ClementBreteau | 1:f3f702086a30 | 129 | |
ClementBreteau | 1:f3f702086a30 | 130 | }; |
ClementBreteau | 1:f3f702086a30 | 131 | |
ClementBreteau | 1:f3f702086a30 | 132 | } // namespace mbed |
ClementBreteau | 1:f3f702086a30 | 133 | |
ClementBreteau | 1:f3f702086a30 | 134 | #endif |