bsp_pwm_led_ws2812.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "sdk_common.h"
  2. #include "SEGGER_RTT.h"
  3. #include "nrf_drv_pwm.h"
  4. #include "usr_config.h"
  5. #include "system.h"
  6. #include "nrf_gpio.h"
  7. #include "bsp_pwm.h"
  8. /********************** ±äÁ¿Çø *************************/
  9. static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
  10. static nrf_pwm_values_individual_t m_demo1_seq_values[]={
  11. {0},{0},{0},{0},{0},{0}
  12. };
  13. static nrf_pwm_sequence_t const m_demo1_seq =
  14. {
  15. .values.p_individual = m_demo1_seq_values,
  16. .length = NRF_PWM_VALUES_LENGTH(m_demo1_seq_values),
  17. .repeats = 0,
  18. .end_delay = 0
  19. };
  20. static void Pwm_init(void)
  21. {
  22. nrf_drv_pwm_config_t const config0 =
  23. {
  24. .output_pins =
  25. {
  26. PIN_LED_CONTROL, // channel 0
  27. NRF_DRV_PWM_PIN_NOT_USED,
  28. NRF_DRV_PWM_PIN_NOT_USED,
  29. NRF_DRV_PWM_PIN_NOT_USED
  30. },
  31. .irq_priority = APP_IRQ_PRIORITY_LOWEST,
  32. .base_clock = NRF_PWM_CLK_125kHz,
  33. .count_mode = NRF_PWM_MODE_UP,
  34. .top_value = 1,
  35. .load_mode = NRF_PWM_LOAD_INDIVIDUAL,
  36. .step_mode = NRF_PWM_STEP_AUTO
  37. };
  38. APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
  39. (void)nrf_drv_pwm_simple_playback(&m_pwm0, &m_demo1_seq, 1,
  40. NRF_DRV_PWM_FLAG_LOOP);
  41. }
  42. static void cb_pwmWakeup(uint32_t t)
  43. {
  44. Pwm_init();
  45. }
  46. static void cb_pwmSleep(uint32_t t)
  47. {
  48. nrfx_pwm_uninit(&m_pwm0);
  49. nrf_gpio_cfg_input(PIN_LED_CONTROL, NRF_GPIO_PIN_NOPULL);//IO
  50. }
  51. void Pwm_Initialize(void){
  52. Pwm_init();
  53. Wakeup_Regist(cb_pwmWakeup);
  54. Sleep_Regist(cb_pwmSleep);
  55. }