zynq_7010/zynq_7010_code/DevUtil.cpp

30 lines
686 B
C++
Raw Permalink Normal View History

2023-07-17 03:29:37 +00:00
#include "DevUtil.h"
#include <fstream>
#define IOEXPORTPATH "/sys/class/gpio/export"
#define PWMEXPORTPATH "/sys/class/pwm/pwmchip%d/export"
int read_dev_i(std::string path) {
int val = -1;
std::ifstream ifin(path.c_str());
ifin >> val;
return val;
}
std::string read_dev_s(std::string path) {
std::string val;
std::ifstream ifin(path.c_str());
ifin >> val;
return val;
}
DeviceExport::DeviceExport()
{
int num = sizeof(ports) / sizeof(ports[0]);
for (int i = 0; i < num; i++)
write_dev(IOEXPORTPATH, ports[i]);
num = sizeof(pwms) / sizeof(pwms[0]);
for (int i = 0; i < num; i++)
write_dev(string_format(PWMEXPORTPATH, pwms[i]), 0);
}