Created OD common pwm class
This commit is contained in:
40
firmware/src/board/pwm.cpp
Normal file
40
firmware/src/board/pwm.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/**** Includes ****/
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "mcu/mcu_hal.h"
|
||||||
|
#include "pwm.h"
|
||||||
|
|
||||||
|
using namespace board;
|
||||||
|
|
||||||
|
/**** Private definitions ****/
|
||||||
|
/**** Private constants ****/
|
||||||
|
/**** Private variables ****/
|
||||||
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
|
/**** Public function definitions ****/
|
||||||
|
board::PWMout::PWMout(uint8_t pwm_ch)
|
||||||
|
{
|
||||||
|
this->pwm_ch = pwm_ch;
|
||||||
|
this->write(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
board::PWMout::~PWMout(void)
|
||||||
|
{
|
||||||
|
this->write(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void board::PWMout::write(uint8_t duty)
|
||||||
|
{
|
||||||
|
// Convert percent to 16b duty cycle
|
||||||
|
uint16_t dc = util::percent_to_16b(duty);
|
||||||
|
|
||||||
|
// Set PWM
|
||||||
|
mcu::pwm_write(this->pwm_ch, dc);
|
||||||
|
this->last_duty = duty;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t board::PWMout::get_set_duty(void)
|
||||||
|
{
|
||||||
|
return this->last_duty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**** Private function definitions ****/
|
||||||
31
firmware/src/board/pwm.h
Normal file
31
firmware/src/board/pwm.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef PWM_H_
|
||||||
|
#define PWM_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace board {
|
||||||
|
|
||||||
|
/**** Public definitions ****/
|
||||||
|
class PWMout
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
uint8_t pwm_ch;
|
||||||
|
uint8_t last_duty;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PWMout(uint8_t pwm_ch);
|
||||||
|
~PWMout(void);
|
||||||
|
|
||||||
|
void write(uint8_t duty);
|
||||||
|
uint8_t get_set_duty(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**** Public function declarations ****/
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} //namespace
|
||||||
|
|
||||||
|
#endif /* PWM_H_ */
|
||||||
Reference in New Issue
Block a user