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