blob: 29c5ee6aa1f5e186369b185a418a92b8cade9b82 [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
Daniel Pettife475252014-01-05 14:15:16 -080021bool Gpo::Set(const bool high) {
Daniel Pettid6ff3d52014-01-02 11:24:39 -080022 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
Daniel Pettife475252014-01-05 14:15:16 -080031 fprintf(handle_, "%d", high);
Daniel Pettid6ff3d52014-01-02 11:24:39 -080032 fclose(handle_);
33
34 return true;
35}
36
Daniel Pettife475252014-01-05 14:15:16 -080037} // namespace bbb