Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HardwarePWM.h
1 /*
2  * File: HardwarePWM.h
3  * Original Author: https://github.com/hrsavla
4  *
5  * This HW_PWM library enables Sming framework user to use ESP SDK PWM API
6  * Period of PWM is fixed to 1000ms / Frequency = 1khz
7  * Duty at 100% = 22222. Duty at 0% = 0
8  * You can use function setPeriod() to change frequency/period.
9  * Calculate the Duty as per the formulae give in ESP8266 SDK
10  * Duty = (Period *1000)/45
11  *
12  * PWM can be generated on upto 8 pins (ie All pins except pin 16)
13  * Created on August 17, 2015, 2:27 PM
14  */
20 #ifndef HARDWAREPWM_H
21 #define HARDWAREPWM_H
22 
23 #include "ESP8266EX.h"
24 #include "../Wiring/WiringFrameworkDependencies.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 #include <pwm.h>
30 #ifdef __cplusplus
31 }
32 #endif
33 
34 #define PWM_BAD_CHANNEL 0xff
35 
36 class HardwarePWM {
38 public:
43  HardwarePWM(uint8 *pins, uint8 no_of_pins);
44  virtual ~HardwarePWM();
45 
51  bool analogWrite(uint8 pin, uint32 duty);
52 
58  bool setDuty(uint8 pin, uint32 duty);
59 
64  uint32 getDuty(uint8 pin);
65 
70  void setPeriod(uint32 period);
71 
75  uint32 getPeriod(void);
76 
81  uint8 getChannel(uint8 pin);
82 
87  uint32 getMaxDuty();
88 protected:
89 
90 private:
91  uint8 channel_count;
92  uint8 channels[PWM_CHANNEL_NUM_MAX];
93  uint32 maxduty;
94 };
95 
97 #endif /* HARDWAREPWM_H */
uint32 getDuty(uint8 pin)
Get PWM duty cycle.
bool analogWrite(uint8 pin, uint32 duty)
Set PWM duty cycle.
bool setDuty(uint8 pin, uint32 duty)
Set PWM duty cycle.
Hardware pulse width modulation.
Definition: HardwarePWM.h:37
uint32 getMaxDuty()
Get the maximum duty cycle value.
HardwarePWM(uint8 *pins, uint8 no_of_pins)
Instantiate hardware PWM object.
uint32 getPeriod(void)
Get PWM period.
uint8 getChannel(uint8 pin)
Get channel number for a pin.
void setPeriod(uint32 period)
Set PWM period.