led.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <rtthread.h>
  2. #include <stm32f10x.h>
  3. #define led1_rcc RCC_APB2Periph_GPIOF
  4. #define led1_gpio GPIOF
  5. #define led1_pin (GPIO_Pin_6 | GPIO_Pin_7)
  6. #define led2_rcc RCC_APB2Periph_GPIOF
  7. #define led2_gpio GPIOF
  8. #define led2_pin (GPIO_Pin_8)
  9. void rt_hw_led_init(void)
  10. {
  11. GPIO_InitTypeDef GPIO_InitStructure;
  12. RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
  13. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  14. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  15. GPIO_InitStructure.GPIO_Pin = led1_pin;
  16. GPIO_Init(led1_gpio, &GPIO_InitStructure);
  17. GPIO_InitStructure.GPIO_Pin = led2_pin;
  18. GPIO_Init(led2_gpio, &GPIO_InitStructure);
  19. }
  20. void rt_hw_led_on(rt_uint32_t n)
  21. {
  22. switch (n)
  23. {
  24. case 0:
  25. GPIO_SetBits(led1_gpio, led1_pin);
  26. break;
  27. case 1:
  28. GPIO_SetBits(led2_gpio, led2_pin);
  29. break;
  30. default:
  31. break;
  32. }
  33. }
  34. void rt_hw_led_off(rt_uint32_t n)
  35. {
  36. switch (n)
  37. {
  38. case 0:
  39. GPIO_ResetBits(led1_gpio, led1_pin);
  40. break;
  41. case 1:
  42. GPIO_ResetBits(led2_gpio, led2_pin);
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. #ifdef RT_USING_FINSH
  49. #include <finsh.h>
  50. static rt_uint8_t led_inited = 0;
  51. void led(rt_uint32_t led, rt_uint32_t value)
  52. {
  53. /* init led configuration if it's not inited. */
  54. if (!led_inited)
  55. {
  56. rt_hw_led_init();
  57. led_inited = 1;
  58. }
  59. if ( led == 0 )
  60. {
  61. /* set led status */
  62. switch (value)
  63. {
  64. case 0:
  65. rt_hw_led_off(0);
  66. break;
  67. case 1:
  68. rt_hw_led_on(0);
  69. break;
  70. default:
  71. break;
  72. }
  73. }
  74. if ( led == 1 )
  75. {
  76. /* set led status */
  77. switch (value)
  78. {
  79. case 0:
  80. rt_hw_led_off(1);
  81. break;
  82. case 1:
  83. rt_hw_led_on(1);
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. }
  90. FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
  91. #endif