mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-23 19:53:56 +08:00
* cleanup include path
* continue
* format includes
* fix testraw.cc
* remove include path from SConstruct
* regroup
* rebase master
* almost done
* apply review
* rename FileReader.xx to filereader.xx
* rename Unlogger.x->unlogger.x
* rename FrameReader.xx -> framereader.xx
* apply reviews
* ui.h
* continue
* fix framebuffer.cc build error:mv util.h up
* full path to msm_media_info
* fix qcom2 camerad
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 7222d0f20d
32 lines
939 B
C++
32 lines
939 B
C++
#include "selfdrive/common/gpio.h"
|
|
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "selfdrive/common/util.h"
|
|
|
|
// We assume that all pins have already been exported on boot,
|
|
// and that we have permission to write to them.
|
|
|
|
int gpio_init(int pin_nr, bool output){
|
|
char pin_dir_path[50];
|
|
int pin_dir_path_len = snprintf(pin_dir_path, sizeof(pin_dir_path),
|
|
"/sys/class/gpio/gpio%d/direction", pin_nr);
|
|
if(pin_dir_path_len <= 0){
|
|
return -1;
|
|
}
|
|
const char *value = output ? "out" : "in";
|
|
return util::write_file(pin_dir_path, (void*)value, strlen(value));
|
|
}
|
|
|
|
int gpio_set(int pin_nr, bool high){
|
|
char pin_val_path[50];
|
|
int pin_val_path_len = snprintf(pin_val_path, sizeof(pin_val_path),
|
|
"/sys/class/gpio/gpio%d/value", pin_nr);
|
|
if(pin_val_path_len <= 0){
|
|
return -1;
|
|
}
|
|
return util::write_file(pin_val_path, (void*)(high ? "1" : "0"), 1);
|
|
}
|