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 - DigitalInOut
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_DIGITALINOUT_H
ClementBreteau 1:f3f702086a30 6 #define MBED_DIGITALINOUT_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: DigitalInOut
ClementBreteau 1:f3f702086a30 16 * A digital input/output, used for setting or reading a bi-directional pin
ClementBreteau 1:f3f702086a30 17 */
ClementBreteau 1:f3f702086a30 18 class DigitalInOut : public Base {
ClementBreteau 1:f3f702086a30 19
ClementBreteau 1:f3f702086a30 20 public:
ClementBreteau 1:f3f702086a30 21
ClementBreteau 1:f3f702086a30 22 /* Constructor: DigitalInOut
ClementBreteau 1:f3f702086a30 23 * Create a DigitalInOut connected to the specified pin
ClementBreteau 1:f3f702086a30 24 *
ClementBreteau 1:f3f702086a30 25 * Variables:
ClementBreteau 1:f3f702086a30 26 * pin - DigitalInOut pin to connect to
ClementBreteau 1:f3f702086a30 27 */
ClementBreteau 1:f3f702086a30 28 DigitalInOut(PinName pin, const char* name = NULL);
ClementBreteau 1:f3f702086a30 29
ClementBreteau 1:f3f702086a30 30 /* Function: write
ClementBreteau 1:f3f702086a30 31 * Set the output, specified as 0 or 1 (int)
ClementBreteau 1:f3f702086a30 32 *
ClementBreteau 1:f3f702086a30 33 * Variables:
ClementBreteau 1:f3f702086a30 34 * value - An integer specifying the pin output value,
ClementBreteau 1:f3f702086a30 35 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1
ClementBreteau 1:f3f702086a30 36 */
ClementBreteau 1:f3f702086a30 37 void write(int value) {
ClementBreteau 1:f3f702086a30 38 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
ClementBreteau 1:f3f702086a30 39
ClementBreteau 1:f3f702086a30 40 if(value) {
ClementBreteau 1:f3f702086a30 41 _gpio->FIOSET = _mask;
ClementBreteau 1:f3f702086a30 42 } else {
ClementBreteau 1:f3f702086a30 43 _gpio->FIOCLR = _mask;
ClementBreteau 1:f3f702086a30 44 }
ClementBreteau 1:f3f702086a30 45
ClementBreteau 1:f3f702086a30 46 #elif defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 47
ClementBreteau 1:f3f702086a30 48 if(value) {
ClementBreteau 1:f3f702086a30 49 LPC_GPIO->SET[_index] = _mask;
ClementBreteau 1:f3f702086a30 50 } else {
ClementBreteau 1:f3f702086a30 51 LPC_GPIO->CLR[_index] = _mask;
ClementBreteau 1:f3f702086a30 52 }
ClementBreteau 1:f3f702086a30 53 #endif
ClementBreteau 1:f3f702086a30 54 }
ClementBreteau 1:f3f702086a30 55
ClementBreteau 1:f3f702086a30 56 /* Function: read
ClementBreteau 1:f3f702086a30 57 * Return the output setting, represented as 0 or 1 (int)
ClementBreteau 1:f3f702086a30 58 *
ClementBreteau 1:f3f702086a30 59 * Variables:
ClementBreteau 1:f3f702086a30 60 * returns - An integer representing the output setting of the pin if it is an output,
ClementBreteau 1:f3f702086a30 61 * or read the input if set as an input
ClementBreteau 1:f3f702086a30 62 */
ClementBreteau 1:f3f702086a30 63 int read() {
ClementBreteau 1:f3f702086a30 64 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
ClementBreteau 1:f3f702086a30 65
ClementBreteau 1:f3f702086a30 66 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
ClementBreteau 1:f3f702086a30 67 #elif defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 68 return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0);
ClementBreteau 1:f3f702086a30 69 #endif
ClementBreteau 1:f3f702086a30 70 }
ClementBreteau 1:f3f702086a30 71
ClementBreteau 1:f3f702086a30 72
ClementBreteau 1:f3f702086a30 73 /* Function: output
ClementBreteau 1:f3f702086a30 74 * Set as an output
ClementBreteau 1:f3f702086a30 75 */
ClementBreteau 1:f3f702086a30 76 void output();
ClementBreteau 1:f3f702086a30 77
ClementBreteau 1:f3f702086a30 78 /* Function: input
ClementBreteau 1:f3f702086a30 79 * Set as an input
ClementBreteau 1:f3f702086a30 80 */
ClementBreteau 1:f3f702086a30 81 void input();
ClementBreteau 1:f3f702086a30 82
ClementBreteau 1:f3f702086a30 83 /* Function: mode
ClementBreteau 1:f3f702086a30 84 * Set the input pin mode
ClementBreteau 1:f3f702086a30 85 *
ClementBreteau 1:f3f702086a30 86 * Variables:
ClementBreteau 1:f3f702086a30 87 * mode - PullUp, PullDown, PullNone, OpenDrain
ClementBreteau 1:f3f702086a30 88 */
ClementBreteau 1:f3f702086a30 89 void mode(PinMode pull);
ClementBreteau 1:f3f702086a30 90
ClementBreteau 1:f3f702086a30 91 #ifdef MBED_OPERATORS
ClementBreteau 1:f3f702086a30 92 /* Function: operator=
ClementBreteau 1:f3f702086a30 93 * A shorthand for <write>
ClementBreteau 1:f3f702086a30 94 */
ClementBreteau 1:f3f702086a30 95 DigitalInOut& operator= (int value) {
ClementBreteau 1:f3f702086a30 96 write(value);
ClementBreteau 1:f3f702086a30 97 return *this;
ClementBreteau 1:f3f702086a30 98 }
ClementBreteau 1:f3f702086a30 99
ClementBreteau 1:f3f702086a30 100 DigitalInOut& operator= (DigitalInOut& rhs) {
ClementBreteau 1:f3f702086a30 101 write(rhs.read());
ClementBreteau 1:f3f702086a30 102 return *this;
ClementBreteau 1:f3f702086a30 103 }
ClementBreteau 1:f3f702086a30 104
ClementBreteau 1:f3f702086a30 105 /* Function: operator int()
ClementBreteau 1:f3f702086a30 106 * A shorthand for <read>
ClementBreteau 1:f3f702086a30 107 */
ClementBreteau 1:f3f702086a30 108 operator int() {
ClementBreteau 1:f3f702086a30 109 return read();
ClementBreteau 1:f3f702086a30 110 }
ClementBreteau 1:f3f702086a30 111 #endif
ClementBreteau 1:f3f702086a30 112
ClementBreteau 1:f3f702086a30 113 #ifdef MBED_RPC
ClementBreteau 1:f3f702086a30 114 virtual const struct rpc_method *get_rpc_methods();
ClementBreteau 1:f3f702086a30 115 static struct rpc_class *get_rpc_class();
ClementBreteau 1:f3f702086a30 116 #endif
ClementBreteau 1:f3f702086a30 117
ClementBreteau 1:f3f702086a30 118 protected:
ClementBreteau 1:f3f702086a30 119
ClementBreteau 1:f3f702086a30 120 PinName _pin;
ClementBreteau 1:f3f702086a30 121
ClementBreteau 1:f3f702086a30 122 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
ClementBreteau 1:f3f702086a30 123 LPC_GPIO_TypeDef *_gpio;
ClementBreteau 1:f3f702086a30 124 #elif defined(TARGET_LPC11U24)
ClementBreteau 1:f3f702086a30 125 int _index;
ClementBreteau 1:f3f702086a30 126 #endif
ClementBreteau 1:f3f702086a30 127
ClementBreteau 1:f3f702086a30 128 uint32_t _mask;
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