led.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "led.h"
  2. static uint32_t GPIO_PORT[LEDn] = {LED1_GPIO_PORT};
  3. static uint32_t GPIO_PIN[LEDn] = {LED1_PIN};
  4. static rcu_periph_enum GPIO_CLK[LEDn] = {LED1_GPIO_CLK};
  5. /*!
  6. \brief configure led GPIO
  7. \param[in] lednum: specify the led to be configured
  8. \arg LED1
  9. \param[out] none
  10. \retval none
  11. */
  12. void gd_eval_led_init(led_typedef_enum lednum)
  13. {
  14. /* enable the led clock */
  15. rcu_periph_clock_enable(GPIO_CLK[lednum]);
  16. /* configure led GPIO port */
  17. gpio_init(GPIO_PORT[lednum], GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN[lednum]);
  18. GPIO_BC(GPIO_PORT[lednum]) = GPIO_PIN[lednum];
  19. gpio_bit_set(GPIOB,GPIO_PIN_11);
  20. }
  21. /*!
  22. \brief turn on selected led
  23. \param[in] lednum: specify the led to be turned on
  24. \arg LED2
  25. \arg LED3
  26. \arg LED4
  27. \arg LED5
  28. \param[out] none
  29. \retval none
  30. */
  31. void gd_eval_led_on(led_typedef_enum lednum)
  32. {
  33. GPIO_BOP(GPIO_PORT[lednum]) = GPIO_PIN[lednum];
  34. }
  35. /*!
  36. \brief turn off selected led
  37. \param[in] lednum: specify the led to be turned off
  38. \arg LED2
  39. \arg LED3
  40. \arg LED4
  41. \arg LED5
  42. \param[out] none
  43. \retval none
  44. */
  45. void gd_eval_led_off(led_typedef_enum lednum)
  46. {
  47. GPIO_BC(GPIO_PORT[lednum]) = GPIO_PIN[lednum];
  48. }
  49. /*!
  50. \brief toggle selected led
  51. \param[in] lednum: specify the led to be toggled
  52. \arg LED2
  53. \arg LED3
  54. \arg LED4
  55. \arg LED5
  56. \param[out] none
  57. \retval none
  58. */
  59. void gd_eval_led_toggle(led_typedef_enum lednum)
  60. {
  61. gpio_bit_write(GPIO_PORT[lednum], GPIO_PIN[lednum],
  62. (bit_status)(1-gpio_input_bit_get(GPIO_PORT[lednum], GPIO_PIN[lednum])));
  63. }