strat des robots
Fork of CRAC-Strat_2017 by
mbed/PortIn.h@0:ad97421fb1fb, 2016-04-13 (annotated)
- Committer:
- antbig
- Date:
- Wed Apr 13 22:04:54 2016 +0000
- Revision:
- 0:ad97421fb1fb
Ajout interruption fin de match
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
antbig | 0:ad97421fb1fb | 1 | /* mbed Microcontroller Library - PortInOut |
antbig | 0:ad97421fb1fb | 2 | * Copyright (c) 2006-2011 ARM Limited. All rights reserved. |
antbig | 0:ad97421fb1fb | 3 | */ |
antbig | 0:ad97421fb1fb | 4 | |
antbig | 0:ad97421fb1fb | 5 | #ifndef MBED_PORTIN_H |
antbig | 0:ad97421fb1fb | 6 | #define MBED_PORTIN_H |
antbig | 0:ad97421fb1fb | 7 | |
antbig | 0:ad97421fb1fb | 8 | #include "device.h" |
antbig | 0:ad97421fb1fb | 9 | |
antbig | 0:ad97421fb1fb | 10 | #if DEVICE_PORTIN |
antbig | 0:ad97421fb1fb | 11 | |
antbig | 0:ad97421fb1fb | 12 | #include "PortNames.h" |
antbig | 0:ad97421fb1fb | 13 | #include "PinNames.h" |
antbig | 0:ad97421fb1fb | 14 | |
antbig | 0:ad97421fb1fb | 15 | namespace mbed { |
antbig | 0:ad97421fb1fb | 16 | |
antbig | 0:ad97421fb1fb | 17 | /* Class: PortIn |
antbig | 0:ad97421fb1fb | 18 | * A multiple pin digital input |
antbig | 0:ad97421fb1fb | 19 | * |
antbig | 0:ad97421fb1fb | 20 | * Example: |
antbig | 0:ad97421fb1fb | 21 | * > // Switch on an LED if any of mbed pins 21-26 is high |
antbig | 0:ad97421fb1fb | 22 | * > |
antbig | 0:ad97421fb1fb | 23 | * > #include "mbed.h" |
antbig | 0:ad97421fb1fb | 24 | * > |
antbig | 0:ad97421fb1fb | 25 | * > PortIn p(Port2, 0x0000003F); // p21-p26 |
antbig | 0:ad97421fb1fb | 26 | * > DigitalOut ind(LED4); |
antbig | 0:ad97421fb1fb | 27 | * > |
antbig | 0:ad97421fb1fb | 28 | * > int main() { |
antbig | 0:ad97421fb1fb | 29 | * > while(1) { |
antbig | 0:ad97421fb1fb | 30 | * > int pins = p.read(); |
antbig | 0:ad97421fb1fb | 31 | * > if(pins) { |
antbig | 0:ad97421fb1fb | 32 | * > ind = 1; |
antbig | 0:ad97421fb1fb | 33 | * > } else { |
antbig | 0:ad97421fb1fb | 34 | * > ind = 0; |
antbig | 0:ad97421fb1fb | 35 | * > } |
antbig | 0:ad97421fb1fb | 36 | * > } |
antbig | 0:ad97421fb1fb | 37 | * > } |
antbig | 0:ad97421fb1fb | 38 | */ |
antbig | 0:ad97421fb1fb | 39 | class PortIn { |
antbig | 0:ad97421fb1fb | 40 | public: |
antbig | 0:ad97421fb1fb | 41 | |
antbig | 0:ad97421fb1fb | 42 | /* Constructor: PortIn |
antbig | 0:ad97421fb1fb | 43 | * Create an PortIn, connected to the specified port |
antbig | 0:ad97421fb1fb | 44 | * |
antbig | 0:ad97421fb1fb | 45 | * Variables: |
antbig | 0:ad97421fb1fb | 46 | * port - Port to connect to (Port0-Port5) |
antbig | 0:ad97421fb1fb | 47 | * mask - A bitmask to identify which bits in the port should be included (0 - ignore) |
antbig | 0:ad97421fb1fb | 48 | */ |
antbig | 0:ad97421fb1fb | 49 | PortIn(PortName port, int mask = 0xFFFFFFFF); |
antbig | 0:ad97421fb1fb | 50 | |
antbig | 0:ad97421fb1fb | 51 | /* Function: read |
antbig | 0:ad97421fb1fb | 52 | * Read the value currently output on the port |
antbig | 0:ad97421fb1fb | 53 | * |
antbig | 0:ad97421fb1fb | 54 | * Variables: |
antbig | 0:ad97421fb1fb | 55 | * returns - An integer with each bit corresponding to associated port pin setting |
antbig | 0:ad97421fb1fb | 56 | */ |
antbig | 0:ad97421fb1fb | 57 | int read(); |
antbig | 0:ad97421fb1fb | 58 | |
antbig | 0:ad97421fb1fb | 59 | /* Function: mode |
antbig | 0:ad97421fb1fb | 60 | * Set the input pin mode |
antbig | 0:ad97421fb1fb | 61 | * |
antbig | 0:ad97421fb1fb | 62 | * Variables: |
antbig | 0:ad97421fb1fb | 63 | * mode - PullUp, PullDown, PullNone, OpenDrain |
antbig | 0:ad97421fb1fb | 64 | */ |
antbig | 0:ad97421fb1fb | 65 | void mode(PinMode mode); |
antbig | 0:ad97421fb1fb | 66 | |
antbig | 0:ad97421fb1fb | 67 | /* Function: operator int() |
antbig | 0:ad97421fb1fb | 68 | * A shorthand for <read> |
antbig | 0:ad97421fb1fb | 69 | */ |
antbig | 0:ad97421fb1fb | 70 | operator int() { |
antbig | 0:ad97421fb1fb | 71 | return read(); |
antbig | 0:ad97421fb1fb | 72 | } |
antbig | 0:ad97421fb1fb | 73 | |
antbig | 0:ad97421fb1fb | 74 | private: |
antbig | 0:ad97421fb1fb | 75 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
antbig | 0:ad97421fb1fb | 76 | LPC_GPIO_TypeDef *_gpio; |
antbig | 0:ad97421fb1fb | 77 | #endif |
antbig | 0:ad97421fb1fb | 78 | PortName _port; |
antbig | 0:ad97421fb1fb | 79 | uint32_t _mask; |
antbig | 0:ad97421fb1fb | 80 | }; |
antbig | 0:ad97421fb1fb | 81 | |
antbig | 0:ad97421fb1fb | 82 | } // namespace mbed |
antbig | 0:ad97421fb1fb | 83 | |
antbig | 0:ad97421fb1fb | 84 | #endif |
antbig | 0:ad97421fb1fb | 85 | |
antbig | 0:ad97421fb1fb | 86 | #endif |