blob: acb4295c602dc6e60ab1294e15dee054fa5241f7 [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 <string.h>
Brian Silvermane364e382014-02-08 21:51:33 -08005#include <unistd.h>
Daniel Pettid6ff3d52014-01-02 11:24:39 -08006
7#include "aos/common/logging/logging.h"
8
9namespace bbb {
10
Brian Silverman0aa48a92014-01-25 17:10:17 -080011Gpo::Gpo(int bank, int pin, bool initial_value)
12 : GpioPin(bank, pin, false, initial_value) {}
13
14void Gpo::Set(bool high) {
Brian Silverman8dc9fd42014-02-10 13:35:43 -080015 rewind(value_handle_);
Brian Silvermane364e382014-02-08 21:51:33 -080016 if (fputc(high ? '1' : '0', value_handle_) == EOF) {
Brian Silvermand7844882014-05-10 23:35:39 -070017 PLOG(FATAL, "fputc(%c, %p) for pin (%d,%d) failed",
18 high ? '1': '0', value_handle_, bank_, pin_);
Daniel Pettid6ff3d52014-01-02 11:24:39 -080019 }
Brian Silverman8dc9fd42014-02-10 13:35:43 -080020 if (fflush(value_handle_) == EOF) {
Brian Silvermand7844882014-05-10 23:35:39 -070021 PLOG(FATAL, "fflush(%p) for pin (%d,%d) failed",
22 value_handle_, bank_, pin_);
Brian Silverman8dc9fd42014-02-10 13:35:43 -080023 }
Daniel Pettid6ff3d52014-01-02 11:24:39 -080024}
25
Daniel Pettife475252014-01-05 14:15:16 -080026} // namespace bbb