mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-21 22:53:52 +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>
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);
|
|
}
|