mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
update package/pikaRTDevice/pikaRTDevice_PWM.c.
This commit is contained in:
parent
0d2d21c84f
commit
324f73dae9
@ -3,21 +3,32 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
struct rt_device_pwm* PWM_getDevice(PikaObj* self) {
|
||||
#ifdef RT_USING_PWM
|
||||
char* name = obj_getStr(self, "name");
|
||||
rt_device_t pwm_device = rt_device_find(name);
|
||||
if(NULL == pwm_device){
|
||||
printf("[error] PWM: device \"%s\" no found.\r\n", name);
|
||||
}
|
||||
return (struct rt_device_pwm*)pwm_device;
|
||||
#else
|
||||
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PWM macro. \r\n");
|
||||
while(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pikaRTDevice_PWM_platformEnable(PikaObj* self) {
|
||||
#ifdef RT_USING_PWM
|
||||
struct rt_device_pwm* pwm_dev = PWM_getDevice(self);
|
||||
int ch = obj_getInt(self, "ch");
|
||||
rt_pwm_enable(pwm_dev, ch);
|
||||
#else
|
||||
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PWM macro. \r\n");
|
||||
while(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pikaRTDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
#ifdef RT_USING_PWM
|
||||
struct rt_device_pwm* pwm_dev = PWM_getDevice(self);
|
||||
int ch = obj_getInt(self, "ch");
|
||||
int freq = obj_getInt(self, "freq");
|
||||
@ -25,8 +36,17 @@ void pikaRTDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
int period = (int)((1.0 / (float)freq) * 1000 * 1000);
|
||||
int pulse = (int)((float)period * duty);
|
||||
rt_pwm_set(pwm_dev, ch, period, pulse);
|
||||
#else
|
||||
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PWM macro. \r\n");
|
||||
while(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pikaRTDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
#ifdef RT_USING_PWM
|
||||
pikaRTDevice_PWM_platformSetDuty(self);
|
||||
#else
|
||||
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PWM macro. \r\n");
|
||||
while(1);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user