led.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * File : led.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard the first version
  13. */
  14. #include <rtthread.h>
  15. #include <stm32f10x.h>
  16. #define led1_rcc RCC_APB2Periph_GPIOF
  17. #define led1_gpio GPIOF
  18. #define led1_pin (GPIO_Pin_6 | GPIO_Pin_7)
  19. #define led2_rcc RCC_APB2Periph_GPIOF
  20. #define led2_gpio GPIOF
  21. #define led2_pin (GPIO_Pin_8)
  22. void rt_hw_led_init(void)
  23. {
  24. GPIO_InitTypeDef GPIO_InitStructure;
  25. RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
  26. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  27. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  28. GPIO_InitStructure.GPIO_Pin = led1_pin;
  29. GPIO_Init(led1_gpio, &GPIO_InitStructure);
  30. GPIO_InitStructure.GPIO_Pin = led2_pin;
  31. GPIO_Init(led2_gpio, &GPIO_InitStructure);
  32. }
  33. void rt_hw_led_on(rt_uint32_t n)
  34. {
  35. switch (n)
  36. {
  37. case 0:
  38. GPIO_SetBits(led1_gpio, led1_pin);
  39. break;
  40. case 1:
  41. GPIO_SetBits(led2_gpio, led2_pin);
  42. break;
  43. default:
  44. break;
  45. }
  46. }
  47. void rt_hw_led_off(rt_uint32_t n)
  48. {
  49. switch (n)
  50. {
  51. case 0:
  52. GPIO_ResetBits(led1_gpio, led1_pin);
  53. break;
  54. case 1:
  55. GPIO_ResetBits(led2_gpio, led2_pin);
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. #ifdef RT_USING_FINSH
  62. #include <finsh.h>
  63. static rt_uint8_t led_inited = 0;
  64. void led(rt_uint32_t led, rt_uint32_t value)
  65. {
  66. /* init led configuration if it's not inited. */
  67. if (!led_inited)
  68. {
  69. rt_hw_led_init();
  70. led_inited = 1;
  71. }
  72. if ( led == 0 )
  73. {
  74. /* set led status */
  75. switch (value)
  76. {
  77. case 0:
  78. rt_hw_led_off(0);
  79. break;
  80. case 1:
  81. rt_hw_led_on(0);
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. if ( led == 1 )
  88. {
  89. /* set led status */
  90. switch (value)
  91. {
  92. case 0:
  93. rt_hw_led_off(1);
  94. break;
  95. case 1:
  96. rt_hw_led_on(1);
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. }
  103. FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
  104. #endif