status_led.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "status_led.h"
  2. #include <Arduino.h>
  3. #if defined(OPK_BOARD_MDBT50Q_CX_40)
  4. #include <nrf_gpio.h>
  5. // The borrowed RX variant does not map the CX-40's active-low P0.08 LED.
  6. #define WAKE_LED_PIN NRF_GPIO_PIN_MAP(0, 8)
  7. #undef WAKE_LED_ON
  8. #define WAKE_LED_ON LOW
  9. #endif
  10. #define WAKE_LED_OFF ((WAKE_LED_ON) == HIGH ? LOW : HIGH)
  11. #define PULSE_MS 500u // wake flash duration
  12. static unsigned long g_pulseMs = 0;
  13. static bool g_lit = false;
  14. static void ledWrite(int level)
  15. {
  16. #if defined(OPK_BOARD_MDBT50Q_CX_40)
  17. nrf_gpio_pin_write(WAKE_LED_PIN, level);
  18. #else
  19. digitalWrite(WAKE_LED_PIN_A, level);
  20. digitalWrite(WAKE_LED_PIN_B, level);
  21. #endif
  22. }
  23. void ledInit()
  24. {
  25. #if defined(OPK_BOARD_MDBT50Q_CX_40)
  26. nrf_gpio_cfg_output(WAKE_LED_PIN);
  27. #else
  28. pinMode(WAKE_LED_PIN_A, OUTPUT);
  29. pinMode(WAKE_LED_PIN_B, OUTPUT);
  30. #endif
  31. ledWrite(WAKE_LED_OFF);
  32. }
  33. void ledWakePulse()
  34. {
  35. g_pulseMs = millis();
  36. g_lit = true;
  37. // light immediately at the remoteWakeup() call site, not on the next loop
  38. ledWrite(WAKE_LED_ON);
  39. }
  40. void ledTask()
  41. {
  42. if (g_lit && millis() - g_pulseMs >= PULSE_MS) {
  43. g_lit = false;
  44. ledWrite(WAKE_LED_OFF);
  45. }
  46. }