luat_pwm_rtt.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "luat_base.h"
  2. #include "luat_pwm.h"
  3. #include "luat_log.h"
  4. #include "rtthread.h"
  5. #include "rthw.h"
  6. #include "rtdevice.h"
  7. #define DBG_TAG "luat.pwm"
  8. #define DBG_LVL DBG_WARN
  9. #include <rtdbg.h>
  10. #ifdef RT_USING_PWM
  11. #define DEVICE_ID_MAX 6
  12. static struct pwm_devs *pwm_devs[DEVICE_ID_MAX];
  13. static int luat_pwm_rtt_init() {
  14. char name[8];
  15. name[0] = 'p';
  16. name[1] = 'w';
  17. name[2] = 'm';
  18. name[4] = 0x00;
  19. // 搜索pwm0,pwm1,pwm2 ....
  20. for (size_t i = 0; i <= DEVICE_ID_MAX; i++)
  21. {
  22. name[3] = '0' + i;
  23. pwm_devs[i] = (struct rt_device_pwm *)rt_device_find(name);
  24. LOG_D("search pwm name=%s ptr=0x%08X", name, pwm_devs[i]);
  25. }
  26. // 看看有没有pwm
  27. if (pwm_devs[0] == RT_NULL) {
  28. pwm_devs[0] = (struct rt_device_pwm *)rt_device_find("pwm");
  29. LOG_D("search pwm name=%s ptr=0x%08X", "pwm", pwm_devs[0]);
  30. }
  31. }
  32. INIT_COMPONENT_EXPORT(luat_pwm_rtt_init);
  33. int luat_pwm_open(int channel, size_t period, size_t pulse) {
  34. if (channel < 0 || channel >= DEVICE_ID_MAX )
  35. return -1;
  36. return -1;
  37. }
  38. int luat_pwm_close(int channel) {
  39. return -1;
  40. }
  41. #endif