blob: 5926a7cc40bd003c72e3c0d3b9696a86bc9bccf3 [file] [log] [blame]
Daniel Pettid6ff3d52014-01-02 11:24:39 -08001#include "gpo.h"
2
3#include <stdio.h>
4
5#include "aos/common/logging/logging.h"
6
7namespace bbb {
8
9Gpo::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
21bool 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