-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicopwm.h
39 lines (32 loc) · 897 Bytes
/
picopwm.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
#include <string>
#include "hardware/clocks.h"
#include "hardware/pwm.h"
#include "pico/stdlib.h"
class PicoPwmBaseException : public std::exception {
protected:
std::string _msg;
public:
PicoPwmBaseException(std::string message = "PWM exception occurred") { _msg = message; };
virtual const char* what() const throw() { return _msg.c_str(); }
};
class PicoPwm {
protected:
const int TOP_MAX = 65534;
uint8_t pin = 0;
uint8_t slice_num = 0;
uint8_t channel = 0;
uint32_t duty = 0;
uint32_t div = 0;
uint16_t top = 0;
public:
PicoPwm(uint8_t pin);
~PicoPwm();
void setFrequency(uint32_t frequency);
void setDuty(uint32_t duty);
void setDutyPercentage(uint8_t percentage);
void setInverted(bool inverted_a, bool inverted_b);
uint8_t getPin();
uint8_t getSlice();
uint8_t getChannel();
void stop();
};