PixRacerLED.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "PixRacerLED.h"
  14. #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
  15. #ifndef HAL_GPIO_A_LED_PIN
  16. #define HAL_GPIO_A_LED_PIN -1
  17. #endif
  18. #ifndef HAL_GPIO_B_LED_PIN
  19. #define HAL_GPIO_B_LED_PIN -1
  20. #endif
  21. #ifndef HAL_GPIO_C_LED_PIN
  22. #define HAL_GPIO_C_LED_PIN -1
  23. #endif
  24. extern const AP_HAL::HAL& hal;
  25. PixRacerLED::PixRacerLED() :
  26. RGBLed(0, 1, 1, 1)
  27. {
  28. }
  29. bool PixRacerLED::hw_init(void)
  30. {
  31. // when HAL_GPIO_LED_ON is 0 then we must not use pinMode()
  32. // as it could remove the OPENDRAIN attribute on the pin
  33. #if HAL_GPIO_LED_ON != 0
  34. hal.gpio->pinMode(HAL_GPIO_A_LED_PIN, HAL_GPIO_OUTPUT);
  35. hal.gpio->pinMode(HAL_GPIO_B_LED_PIN, HAL_GPIO_OUTPUT);
  36. hal.gpio->pinMode(HAL_GPIO_C_LED_PIN, HAL_GPIO_OUTPUT);
  37. #endif
  38. hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
  39. hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF);
  40. hal.gpio->write(HAL_GPIO_C_LED_PIN, HAL_GPIO_LED_OFF);
  41. return true;
  42. }
  43. bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b)
  44. {
  45. hal.gpio->write(HAL_GPIO_A_LED_PIN, (r > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
  46. hal.gpio->write(HAL_GPIO_B_LED_PIN, (g > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
  47. hal.gpio->write(HAL_GPIO_C_LED_PIN, (b > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
  48. return true;
  49. }
  50. #else
  51. bool PixRacerLED::hw_init(void) { return true; }
  52. bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) { return true; }
  53. #endif