Created OD common pwm class

This commit is contained in:
2024-04-10 15:45:17 +03:00
parent 0b9d6fa780
commit 6d5c8d226f
2 changed files with 71 additions and 0 deletions

View 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
View 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_ */