-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcPWM.h
107 lines (92 loc) · 2.51 KB
/
cPWM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// $Id$
/**
* @file cPWM.h
* Simple C++ class wrapper for beaglebone PWM eHRPWM interface header file
*
* @author claus
* Created on: Jun 13, 2012
* Author: claus http://quadrotordiaries.blogspot.com
*
*/
// $Log$
#ifndef CPWM_H_
#define CPWM_H_
#include <fstream>
namespace cPWM {
class cPWM {
public:
enum Polarity
{
ActiveHigh,
ActiveLow
};
private:
int id;
int dutyA;
int dutyB;
int period;
int freq_Hz;
enum cPWM::Polarity polarityA;
enum cPWM::Polarity polarityB;
int runA;
int runB;
/*****************************************
*
* sysfs tree:
*
ehrpwm.0:0
│ ├── duty_ns
│ ├── period_ns
│ ├── polarity
│ ├── request
│ ├── run
├── ehrpwm.0:1 -> ../../devices/platform/omap/ehrpwm.0/pwm/ehrpwm.0:1
│ ├── duty_ns
│ ├── period_ns
│ ├── polarity
│ ├── request
│ ├── run
*
std::stringstream sysfs_file;
Define files to match sysfs tree:
*/
#define SYSFS_EHRPWM_PREFIX "/sys/class/pwm/ehrpwm."
#define SYSFS_EHRPWM_SUFFIX_A ":0"
#define SYSFS_EHRPWM_SUFFIX_B ":1"
#define SYSFS_EHRPWM_DUTY_NS "duty_ns"
#define SYSFS_EHRPWM_DUTY_PERCENT "duty_percent"
#define SYSFS_EHRPWM_PERIOD_NS "period_ns"
#define SYSFS_EHRPWM_PERIOD_FREQ "period_freq"
#define SYSFS_EHRPWM_POLARITY "polarity"
#define SYSFS_EHRPWM_RUN "run"
#define SYSFS_EHRPWM_REQUEST "request"
std::ofstream sysfsfid_dutyA_ns;
std::ofstream sysfsfid_dutyA_percent;
std::ofstream sysfsfid_dutyB_ns;
std::ofstream sysfsfid_dutyB_percent;
std::ofstream sysfsfid_period_ns;
std::ofstream sysfsfid_period_freq;
std::ofstream sysfsfid_polarityA;
std::ofstream sysfsfid_runA;
std::ofstream sysfsfid_requestA;
std::ofstream sysfsfid_polarityB;
std::ofstream sysfsfid_runB;
std::ofstream sysfsfid_requestB;
public:
cPWM(int id);
virtual ~cPWM();
void DutyA_ns(unsigned int nanoseconds);
void DutyA_percent(unsigned int percent); //TODO: check if floats are possible
void DutyB_ns(unsigned int nanoseconds);
void DutyB_percent(unsigned int percent); //TODO: check if floats are possible
void Period_ns(unsigned int nanoseconds);
void Period_freq(unsigned int freq_Hz);
void PolarityA(cPWM::Polarity polarity);
void RunA();
void StopA();
void PolarityB(cPWM::Polarity polarity);
void RunB();
void StopB();
};
} /* namespace cPWM */
#endif /* CPWM_H_ */