Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame^] | 1 | #include "gpo.h" |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | #include "aos/common/logging/logging.h" |
| 6 | |
| 7 | namespace bbb { |
| 8 | |
| 9 | Gpo::Gpo(int bank, int pin) { |
| 10 | // All the failures here are fatal, seeing as |
| 11 | // if we can't initialize the pin, we're probably |
| 12 | // screwed anyway. |
| 13 | if (!InitPin(bank, pin)) { |
| 14 | LOG(FATAL, "Failed to export the pin.\n"); |
| 15 | } |
| 16 | if (!DoPinDirSet(2)) { |
| 17 | LOG(FATAL, "Failed to make the pin an output.\n"); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | bool Gpo::DoSet(const int value) { |
| 22 | char val_path[64]; |
| 23 | snprintf(val_path, sizeof(val_path), "/sys/class/gpio/gpio%d/value", |
| 24 | kernel_pin_); |
| 25 | |
| 26 | if ((handle_ = fopen(val_path, "rb+")) == NULL) { |
| 27 | LOG(ERROR, "Unable open file for pin value setting.\n"); |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | fprintf(handle_, "%d", value); |
| 32 | fclose(handle_); |
| 33 | |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | } // namespace bbb |