52 lines
1.4 KiB
C
Raw Normal View History

2021-10-01 00:21:50 +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___init__(PikaObj* self) {
PikaStdDevice_PWM_init(self);
}
2021-10-01 00:21:50 +08:00
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-12-10 22:26:13 +08:00
obj_run(self, "platformSetFrequency()");
2021-10-01 00:21:50 +08:00
}
void PikaStdDevice_PWM_setDuty(PikaObj* self, float duty) {
obj_setFloat(self, "duty", duty);
2021-12-10 22:26:13 +08:00
obj_run(self, "platformSetDuty()");
2021-10-01 00:21:50 +08:00
}
void PikaStdDevice_PWM_enable(PikaObj* self) {
2021-12-10 22:26:13 +08:00
obj_run(self, "platformEnable()");
2021-10-01 00:21:50 +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-12-10 22:26:13 +08:00
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
2021-10-01 00:21:50 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2021-12-10 22:26:13 +08:00
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
2021-10-01 00:21:50 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2021-12-10 22:26:13 +08:00
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
2021-10-01 00:21:50 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}