Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
libs/Pin.h@3:f151d08d335c, 2014-03-02 (annotated)
- Committer:
- Bigcheese
- Date:
- Sun Mar 02 06:33:08 2014 +0000
- Revision:
- 3:f151d08d335c
- Parent:
- 2:1df0b61d3b5a
Bunch of stuff. Need to locally merge in updated USB changes.
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 | |
Bigcheese | 3:f151d08d335c | 4 | #include "mbed.h" |
Bigcheese | 3:f151d08d335c | 5 | |
scachat | 0:31e91bb0ef3c | 6 | #include <stdlib.h> |
Michael J. Spencer |
2:1df0b61d3b5a | 7 | #include <stdio.h> |
scachat | 0:31e91bb0ef3c | 8 | #include <string> |
scachat | 0:31e91bb0ef3c | 9 | |
Michael J. Spencer |
2:1df0b61d3b5a | 10 | class Pin { |
scachat | 0:31e91bb0ef3c | 11 | public: |
Michael J. Spencer |
2:1df0b61d3b5a | 12 | Pin(); |
Michael J. Spencer |
2:1df0b61d3b5a | 13 | |
Michael J. Spencer |
2:1df0b61d3b5a | 14 | Pin* from_string(std::string value); |
Michael J. Spencer |
2:1df0b61d3b5a | 15 | |
Michael J. Spencer |
2:1df0b61d3b5a | 16 | inline bool connected(){ |
Bigcheese | 3:f151d08d335c | 17 | return name != NC; |
Michael J. Spencer |
2:1df0b61d3b5a | 18 | } |
scachat | 0:31e91bb0ef3c | 19 | |
Michael J. Spencer |
2:1df0b61d3b5a | 20 | inline Pin* as_output(){ |
Bigcheese | 3:f151d08d335c | 21 | gpio_dir(&pin, PIN_OUTPUT); |
Michael J. Spencer |
2:1df0b61d3b5a | 22 | return this; |
Michael J. Spencer |
2:1df0b61d3b5a | 23 | } |
Michael J. Spencer |
2:1df0b61d3b5a | 24 | |
Michael J. Spencer |
2:1df0b61d3b5a | 25 | inline Pin* as_input(){ |
Bigcheese | 3:f151d08d335c | 26 | gpio_dir(&pin, PIN_INPUT); |
scachat | 0:31e91bb0ef3c | 27 | return this; |
scachat | 0:31e91bb0ef3c | 28 | } |
scachat | 0:31e91bb0ef3c | 29 | |
Michael J. Spencer |
2:1df0b61d3b5a | 30 | Pin* as_open_drain(void); |
Michael J. Spencer |
2:1df0b61d3b5a | 31 | |
Michael J. Spencer |
2:1df0b61d3b5a | 32 | Pin* as_repeater(void); |
Michael J. Spencer |
2:1df0b61d3b5a | 33 | |
Michael J. Spencer |
2:1df0b61d3b5a | 34 | Pin* pull_up(void); |
scachat | 0:31e91bb0ef3c | 35 | |
Michael J. Spencer |
2:1df0b61d3b5a | 36 | Pin* pull_down(void); |
Michael J. Spencer |
2:1df0b61d3b5a | 37 | |
Michael J. Spencer |
2:1df0b61d3b5a | 38 | Pin* pull_none(void); |
scachat | 0:31e91bb0ef3c | 39 | |
Michael J. Spencer |
2:1df0b61d3b5a | 40 | inline bool get(){ |
Bigcheese | 3:f151d08d335c | 41 | return this->inverting ^ gpio_read(&pin); |
scachat | 0:31e91bb0ef3c | 42 | } |
scachat | 0:31e91bb0ef3c | 43 | |
Michael J. Spencer |
2:1df0b61d3b5a | 44 | inline void set(bool value) |
Michael J. Spencer |
2:1df0b61d3b5a | 45 | { |
Bigcheese | 3:f151d08d335c | 46 | gpio_write(&pin, value ^ this->inverting); |
scachat | 0:31e91bb0ef3c | 47 | } |
scachat | 0:31e91bb0ef3c | 48 | |
Bigcheese | 3:f151d08d335c | 49 | PinName name; |
Michael J. Spencer |
2:1df0b61d3b5a | 50 | bool inverting; |
Bigcheese | 3:f151d08d335c | 51 | gpio_t pin; |
scachat | 0:31e91bb0ef3c | 52 | }; |
scachat | 0:31e91bb0ef3c | 53 | |
Michael J. Spencer |
2:1df0b61d3b5a | 54 | |
Michael J. Spencer |
2:1df0b61d3b5a | 55 | |
Michael J. Spencer |
2:1df0b61d3b5a | 56 | |
scachat | 0:31e91bb0ef3c | 57 | #endif |