mirror of https://github.com/rusefi/wideband.git
pwm.cpp: allow external config
This commit is contained in:
parent
27995893ee
commit
70856151b7
|
@ -1,7 +1,5 @@
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
|
|
||||||
#include "hal.h"
|
|
||||||
|
|
||||||
Pwm::Pwm(PWMDriver& driver, uint8_t channel, uint32_t counterFrequency, uint32_t counterPeriod)
|
Pwm::Pwm(PWMDriver& driver, uint8_t channel, uint32_t counterFrequency, uint32_t counterPeriod)
|
||||||
: m_driver(&driver)
|
: m_driver(&driver)
|
||||||
, m_channel(channel)
|
, m_channel(channel)
|
||||||
|
@ -10,6 +8,14 @@ Pwm::Pwm(PWMDriver& driver, uint8_t channel, uint32_t counterFrequency, uint32_t
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pwm::Pwm(PWMDriver& driver)
|
||||||
|
: m_driver(&driver)
|
||||||
|
, m_channel(0)
|
||||||
|
, m_counterFrequency(0)
|
||||||
|
, m_counterPeriod(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Pwm::Start()
|
void Pwm::Start()
|
||||||
{
|
{
|
||||||
PWMConfig config = {
|
PWMConfig config = {
|
||||||
|
@ -32,6 +38,14 @@ void Pwm::Start()
|
||||||
pwmStart(m_driver, &config);
|
pwmStart(m_driver, &config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pwm::Start(PWMConfig *config)
|
||||||
|
{
|
||||||
|
m_counterFrequency = config->frequency;
|
||||||
|
m_counterPeriod = config->period;
|
||||||
|
|
||||||
|
pwmStart(m_driver, config);
|
||||||
|
}
|
||||||
|
|
||||||
float maxF(float i1, float i2) {
|
float maxF(float i1, float i2) {
|
||||||
return i1 > i2 ? i1 : i2;
|
return i1 > i2 ? i1 : i2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,19 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
/* for PWMConfig */
|
||||||
|
#include "hal.h"
|
||||||
|
|
||||||
struct PWMDriver;
|
struct PWMDriver;
|
||||||
|
|
||||||
class Pwm
|
class Pwm
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Pwm(PWMDriver& driver, uint8_t channel, uint32_t counterFrequency, uint32_t counterPeriod);
|
Pwm(PWMDriver& driver, uint8_t channel, uint32_t counterFrequency, uint32_t counterPeriod);
|
||||||
|
Pwm(PWMDriver& driver);
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
void Start(PWMConfig *config);
|
||||||
void SetDuty(float duty);
|
void SetDuty(float duty);
|
||||||
void SetDuty(int channel, float duty);
|
void SetDuty(int channel, float duty);
|
||||||
float GetLastDuty() const;
|
float GetLastDuty() const;
|
||||||
|
@ -17,7 +22,7 @@ public:
|
||||||
private:
|
private:
|
||||||
PWMDriver* const m_driver;
|
PWMDriver* const m_driver;
|
||||||
const uint8_t m_channel;
|
const uint8_t m_channel;
|
||||||
const uint32_t m_counterFrequency;
|
/* const */ uint32_t m_counterFrequency;
|
||||||
const uint16_t m_counterPeriod;
|
/* const */ uint16_t m_counterPeriod;
|
||||||
float m_dutyFloat;
|
float m_dutyFloat;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue