Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
libs/Pin.h@1:ab59fc9af055, 2014-03-01 (annotated)
- Committer:
- Bigcheese
- Date:
- Sat Mar 01 02:37:29 2014 +0000
- Revision:
- 1:ab59fc9af055
- Parent:
- 0:31e91bb0ef3c
- Child:
- 2:1df0b61d3b5a
fghfh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scachat | 0:31e91bb0ef3c | 1 | #ifndef PIN_H |
scachat | 0:31e91bb0ef3c | 2 | #define PIN_H |
scachat | 0:31e91bb0ef3c | 3 | |
scachat | 0:31e91bb0ef3c | 4 | #include <stdlib.h> |
scachat | 0:31e91bb0ef3c | 5 | #include "mbed.h" // smoothed mbed.h lib |
scachat | 0:31e91bb0ef3c | 6 | #include "libs/Kernel.h" |
scachat | 0:31e91bb0ef3c | 7 | #include "libs/utils.h" |
scachat | 0:31e91bb0ef3c | 8 | #include <string> |
scachat | 0:31e91bb0ef3c | 9 | |
scachat | 0:31e91bb0ef3c | 10 | class Pin{ |
scachat | 0:31e91bb0ef3c | 11 | public: |
Bigcheese | 1:ab59fc9af055 | 12 | Pin() { } |
scachat | 0:31e91bb0ef3c | 13 | |
scachat | 0:31e91bb0ef3c | 14 | Pin* from_string(std::string value){ |
Bigcheese | 1:ab59fc9af055 | 15 | gpio_init(&pin, A0, PIN_INPUT); |
scachat | 0:31e91bb0ef3c | 16 | return this; |
scachat | 0:31e91bb0ef3c | 17 | } |
scachat | 0:31e91bb0ef3c | 18 | |
scachat | 0:31e91bb0ef3c | 19 | inline Pin* as_output(){ |
Bigcheese | 1:ab59fc9af055 | 20 | gpio_dir(&pin, PIN_OUTPUT); |
scachat | 0:31e91bb0ef3c | 21 | return this; |
scachat | 0:31e91bb0ef3c | 22 | } |
scachat | 0:31e91bb0ef3c | 23 | |
scachat | 0:31e91bb0ef3c | 24 | inline Pin* as_input(){ |
Bigcheese | 1:ab59fc9af055 | 25 | gpio_dir(&pin, PIN_INPUT); |
scachat | 0:31e91bb0ef3c | 26 | return this; |
scachat | 0:31e91bb0ef3c | 27 | } |
scachat | 0:31e91bb0ef3c | 28 | |
scachat | 0:31e91bb0ef3c | 29 | inline Pin* as_open_drain(){ |
Bigcheese | 1:ab59fc9af055 | 30 | gpio_mode(&pin, OpenDrain); |
scachat | 0:31e91bb0ef3c | 31 | return this; |
scachat | 0:31e91bb0ef3c | 32 | } |
scachat | 0:31e91bb0ef3c | 33 | |
scachat | 0:31e91bb0ef3c | 34 | inline bool get(){ |
Bigcheese | 1:ab59fc9af055 | 35 | return this->inverting ^ gpio_read(&pin); |
scachat | 0:31e91bb0ef3c | 36 | } |
scachat | 0:31e91bb0ef3c | 37 | |
scachat | 0:31e91bb0ef3c | 38 | inline void set(bool value){ |
scachat | 0:31e91bb0ef3c | 39 | value = this->inverting ^ value; |
Bigcheese | 1:ab59fc9af055 | 40 | gpio_write(&pin, value); |
scachat | 0:31e91bb0ef3c | 41 | } |
scachat | 0:31e91bb0ef3c | 42 | |
scachat | 0:31e91bb0ef3c | 43 | bool inverting; |
Bigcheese | 1:ab59fc9af055 | 44 | gpio_t pin; |
scachat | 0:31e91bb0ef3c | 45 | }; |
scachat | 0:31e91bb0ef3c | 46 | |
scachat | 0:31e91bb0ef3c | 47 | #endif |