Modified InOut library
DigitalInOut2.h@3:edc96c27c5c2, 2014-10-14 (annotated)
- Committer:
- jmar11
- Date:
- Tue Oct 14 18:03:21 2014 +0000
- Revision:
- 3:edc96c27c5c2
- Parent:
- 2:291f43f0b5a2
null
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmar11 | 2:291f43f0b5a2 | 1 | #ifndef DIGITALINOUT2_H |
jmar11 | 2:291f43f0b5a2 | 2 | #define DIGITALINOUT2_H |
jmar11 | 0:1d15d1ea182e | 3 | |
jmar11 | 0:1d15d1ea182e | 4 | #include "platform.h" |
jmar11 | 0:1d15d1ea182e | 5 | |
jmar11 | 0:1d15d1ea182e | 6 | #include "gpio_api.h" |
jmar11 | 0:1d15d1ea182e | 7 | |
jmar11 | 0:1d15d1ea182e | 8 | namespace mbed { |
jmar11 | 0:1d15d1ea182e | 9 | |
jmar11 | 0:1d15d1ea182e | 10 | class DigitalInOut2 { |
jmar11 | 0:1d15d1ea182e | 11 | |
jmar11 | 0:1d15d1ea182e | 12 | public: |
jmar11 | 3:edc96c27c5c2 | 13 | gpio_t gpio; //in the stock DigitalInOut library this was protected |
jmar11 | 1:f3a86fb2a054 | 14 | |
jmar11 | 1:f3a86fb2a054 | 15 | DigitalInOut2(PinName pin) { |
jmar11 | 2:291f43f0b5a2 | 16 | gpio_init(&gpio, pin); |
jmar11 | 0:1d15d1ea182e | 17 | } |
jmar11 | 0:1d15d1ea182e | 18 | |
jmar11 | 0:1d15d1ea182e | 19 | void write(int value) { |
jmar11 | 0:1d15d1ea182e | 20 | gpio_write(&gpio, value); |
jmar11 | 0:1d15d1ea182e | 21 | } |
jmar11 | 2:291f43f0b5a2 | 22 | |
jmar11 | 0:1d15d1ea182e | 23 | int read() { |
jmar11 | 0:1d15d1ea182e | 24 | return gpio_read(&gpio); |
jmar11 | 0:1d15d1ea182e | 25 | } |
jmar11 | 0:1d15d1ea182e | 26 | |
jmar11 | 0:1d15d1ea182e | 27 | void output() { |
jmar11 | 0:1d15d1ea182e | 28 | gpio_dir(&gpio, PIN_OUTPUT); |
jmar11 | 0:1d15d1ea182e | 29 | } |
jmar11 | 2:291f43f0b5a2 | 30 | |
jmar11 | 0:1d15d1ea182e | 31 | void input() { |
jmar11 | 0:1d15d1ea182e | 32 | gpio_dir(&gpio, PIN_INPUT); |
jmar11 | 0:1d15d1ea182e | 33 | } |
jmar11 | 2:291f43f0b5a2 | 34 | |
jmar11 | 0:1d15d1ea182e | 35 | void mode(PinMode pull) { |
jmar11 | 0:1d15d1ea182e | 36 | gpio_mode(&gpio, pull); |
jmar11 | 0:1d15d1ea182e | 37 | } |
jmar11 | 0:1d15d1ea182e | 38 | |
jmar11 | 0:1d15d1ea182e | 39 | #ifdef MBED_OPERATORS |
jmar11 | 2:291f43f0b5a2 | 40 | |
jmar11 | 1:f3a86fb2a054 | 41 | DigitalInOut2& operator= (int value) { |
jmar11 | 0:1d15d1ea182e | 42 | write(value); |
jmar11 | 0:1d15d1ea182e | 43 | return *this; |
jmar11 | 0:1d15d1ea182e | 44 | } |
jmar11 | 0:1d15d1ea182e | 45 | |
jmar11 | 1:f3a86fb2a054 | 46 | DigitalInOut2& operator= (DigitalInOut2& rhs) { |
jmar11 | 0:1d15d1ea182e | 47 | write(rhs.read()); |
jmar11 | 0:1d15d1ea182e | 48 | return *this; |
jmar11 | 0:1d15d1ea182e | 49 | } |
jmar11 | 0:1d15d1ea182e | 50 | |
jmar11 | 0:1d15d1ea182e | 51 | operator int() { |
jmar11 | 0:1d15d1ea182e | 52 | return read(); |
jmar11 | 0:1d15d1ea182e | 53 | } |
jmar11 | 0:1d15d1ea182e | 54 | #endif |
jmar11 | 0:1d15d1ea182e | 55 | |
jmar11 | 0:1d15d1ea182e | 56 | }; |
jmar11 | 0:1d15d1ea182e | 57 | |
jmar11 | 2:291f43f0b5a2 | 58 | } |
jmar11 | 0:1d15d1ea182e | 59 | |
jmar11 | 0:1d15d1ea182e | 60 | #endif |