led.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifdef STM32_SIMULATOR
  17. #define led1_rcc RCC_APB2Periph_GPIOA
  18. #define led1_gpio GPIOA
  19. #define led1_pin (GPIO_Pin_5)
  20. #define led2_rcc RCC_APB2Periph_GPIOA
  21. #define led2_gpio GPIOA
  22. #define led2_pin (GPIO_Pin_6)
  23. #else
  24. #define led1_rcc RCC_APB2Periph_GPIOF
  25. #define led1_gpio GPIOF
  26. #define led1_pin (GPIO_Pin_6 | GPIO_Pin_7)
  27. #define led2_rcc RCC_APB2Periph_GPIOF
  28. #define led2_gpio GPIOF
  29. #define led2_pin (GPIO_Pin_8)
  30. #endif
  31. void rt_hw_led_init(void)
  32. {
  33. GPIO_InitTypeDef GPIO_InitStructure;
  34. RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
  35. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  36. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  37. GPIO_InitStructure.GPIO_Pin = led1_pin;
  38. GPIO_Init(led1_gpio, &GPIO_InitStructure);
  39. GPIO_InitStructure.GPIO_Pin = led2_pin;
  40. GPIO_Init(led2_gpio, &GPIO_InitStructure);
  41. }
  42. void rt_hw_led_on(rt_uint32_t n)
  43. {
  44. switch (n)
  45. {
  46. case 0:
  47. GPIO_SetBits(led1_gpio, led1_pin);
  48. break;
  49. case 1:
  50. GPIO_SetBits(led2_gpio, led2_pin);
  51. break;
  52. default:
  53. break;
  54. }
  55. }
  56. void rt_hw_led_off(rt_uint32_t n)
  57. {
  58. switch (n)
  59. {
  60. case 0:
  61. GPIO_ResetBits(led1_gpio, led1_pin);
  62. break;
  63. case 1:
  64. GPIO_ResetBits(led2_gpio, led2_pin);
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. #ifdef RT_USING_FINSH
  71. #include <finsh.h>
  72. static rt_uint8_t led_inited = 0;
  73. void led(rt_uint32_t led, rt_uint32_t value)
  74. {
  75. /* init led configuration if it's not inited. */
  76. if (!led_inited)
  77. {
  78. rt_hw_led_init();
  79. led_inited = 1;
  80. }
  81. if ( led == 0 )
  82. {
  83. /* set led status */
  84. switch (value)
  85. {
  86. case 0:
  87. rt_hw_led_off(0);
  88. break;
  89. case 1:
  90. rt_hw_led_on(0);
  91. break;
  92. default:
  93. break;
  94. }
  95. }
  96. if ( led == 1 )
  97. {
  98. /* set led status */
  99. switch (value)
  100. {
  101. case 0:
  102. rt_hw_led_off(1);
  103. break;
  104. case 1:
  105. rt_hw_led_on(1);
  106. break;
  107. default:
  108. break;
  109. }
  110. }
  111. }
  112. FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
  113. #endif