blob: 8ad599eb4677246b19440dae9d6e33879ca89fd4 [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 Silverman8dc9fd42014-02-10 13:35:43 -080016 rewind(value_handle_);
Brian Silvermane364e382014-02-08 21:51:33 -080017 if (fputc(high ? '1' : '0', value_handle_) == EOF) {
Brian Silverman0aa48a92014-01-25 17:10:17 -080018 LOG(FATAL, "fputc(%c, %p) for pin (%d,%d) failed with %d: %s\n",
19 high ? '1': '0', value_handle_, bank_, pin_, errno, strerror(errno));
Daniel Pettid6ff3d52014-01-02 11:24:39 -080020 }
Brian Silverman8dc9fd42014-02-10 13:35:43 -080021 if (fflush(value_handle_) == EOF) {
22 LOG(FATAL, "fflush(%p) for pin (%d,%d) failed with %d: %s\n",
23 value_handle_, bank_, pin_, errno, strerror(errno));
24 }
Daniel Pettid6ff3d52014-01-02 11:24:39 -080025}
26
Daniel Pettife475252014-01-05 14:15:16 -080027} // namespace bbb