2021-10-01 20:00:15 +08:00
|
|
|
#include "PikaStdDevice_PWM.h"
|
|
|
|
#include "BaseObj.h"
|
|
|
|
|
|
|
|
void PikaStdDevice_PWM_init(PikaObj* self) {
|
|
|
|
obj_setStr(self, "pin", "PA8");
|
|
|
|
obj_setInt(self, "freq", 1000);
|
|
|
|
obj_setFloat(self, "duty", 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
|
|
|
|
obj_setStr(self, "pin", pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) {
|
|
|
|
obj_setInt(self, "freq", freq);
|
2021-11-06 19:11:25 +08:00
|
|
|
obj_run(self, "platformSetFrequency()");
|
2021-10-01 20:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdDevice_PWM_setDuty(PikaObj* self, float duty) {
|
|
|
|
obj_setFloat(self, "duty", duty);
|
2021-11-06 19:11:25 +08:00
|
|
|
obj_run(self, "platformSetDuty()");
|
2021-10-01 20:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdDevice_PWM_enable(PikaObj* self) {
|
2021-11-06 19:11:25 +08:00
|
|
|
obj_run(self, "platformEnable()");
|
2021-10-01 20:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float PikaStdDevice_PWM_getDuty(PikaObj* self) {
|
|
|
|
return obj_getFloat(self, "duty");
|
|
|
|
}
|
|
|
|
|
|
|
|
int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
|
|
|
|
return obj_getInt(self, "freq");
|
|
|
|
}
|
|
|
|
|
2021-11-06 19:11:25 +08:00
|
|
|
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
|
2021-10-01 20:00:15 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|
2021-11-06 19:11:25 +08:00
|
|
|
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
|
2021-10-01 20:00:15 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|
2021-11-06 19:11:25 +08:00
|
|
|
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
2021-10-01 20:00:15 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|