blob: d17abe7308bb73bcb5c796671e6472ec257848a1 [file] [log] [blame]
Brian Silverman0aa48a92014-01-25 17:10:17 -08001#include "bbb/gpo.h"
Daniel Pettid6ff3d52014-01-02 11:24:39 -08002
3#include <stdio.h>
Brian Silverman0aa48a92014-01-25 17:10:17 -08004#include <errno.h>
5#include <string.h>
Brian Silvermane364e382014-02-08 21:51:33 -08006#include <unistd.h>
Daniel Pettid6ff3d52014-01-02 11:24:39 -08007
8#include "aos/common/logging/logging.h"
9
10namespace bbb {
11
Brian Silverman0aa48a92014-01-25 17:10:17 -080012Gpo::Gpo(int bank, int pin, bool initial_value)
13 : GpioPin(bank, pin, false, initial_value) {}
14
15void Gpo::Set(bool high) {
Brian Silvermane364e382014-02-08 21:51:33 -080016 // TODO(brians): Figure out why this breaks it.
17 //rewind(value_handle_);
18 if (fputc(high ? '1' : '0', value_handle_) == EOF) {
Brian Silverman0aa48a92014-01-25 17:10:17 -080019 LOG(FATAL, "fputc(%c, %p) for pin (%d,%d) failed with %d: %s\n",
20 high ? '1': '0', value_handle_, bank_, pin_, errno, strerror(errno));
Daniel Pettid6ff3d52014-01-02 11:24:39 -080021 }
Brian Silvermane364e382014-02-08 21:51:33 -080022 sync();
Daniel Pettid6ff3d52014-01-02 11:24:39 -080023}
24
Daniel Pettife475252014-01-05 14:15:16 -080025} // namespace bbb