led.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-05 Bernard the first version
  9. */
  10. #include <rtthread.h>
  11. #include <stm32f10x.h>
  12. // led define
  13. #ifdef STM32_SIMULATOR
  14. #define led1_rcc RCC_APB2Periph_GPIOA
  15. #define led1_gpio GPIOA
  16. #define led1_pin (GPIO_Pin_5)
  17. #define led2_rcc RCC_APB2Periph_GPIOA
  18. #define led2_gpio GPIOA
  19. #define led2_pin (GPIO_Pin_6)
  20. #else
  21. #define led1_rcc RCC_APB2Periph_GPIOE
  22. #define led1_gpio GPIOE
  23. #define led1_pin (GPIO_Pin_2)
  24. #define led2_rcc RCC_APB2Periph_GPIOE
  25. #define led2_gpio GPIOE
  26. #define led2_pin (GPIO_Pin_3)
  27. #endif // led define #ifdef STM32_SIMULATOR
  28. void rt_hw_led_init(void)
  29. {
  30. GPIO_InitTypeDef GPIO_InitStructure;
  31. RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
  32. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  33. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  34. GPIO_InitStructure.GPIO_Pin = led1_pin;
  35. GPIO_Init(led1_gpio, &GPIO_InitStructure);
  36. GPIO_InitStructure.GPIO_Pin = led2_pin;
  37. GPIO_Init(led2_gpio, &GPIO_InitStructure);
  38. }
  39. void rt_hw_led_on(rt_uint32_t n)
  40. {
  41. switch (n)
  42. {
  43. case 0:
  44. GPIO_SetBits(led1_gpio, led1_pin);
  45. break;
  46. case 1:
  47. GPIO_SetBits(led2_gpio, led2_pin);
  48. break;
  49. default:
  50. break;
  51. }
  52. }
  53. void rt_hw_led_off(rt_uint32_t n)
  54. {
  55. switch (n)
  56. {
  57. case 0:
  58. GPIO_ResetBits(led1_gpio, led1_pin);
  59. break;
  60. case 1:
  61. GPIO_ResetBits(led2_gpio, led2_pin);
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. #ifdef RT_USING_FINSH
  68. #include <finsh.h>
  69. static rt_uint8_t led_inited = 0;
  70. void led(rt_uint32_t led, rt_uint32_t value)
  71. {
  72. /* init led configuration if it's not inited. */
  73. if (!led_inited)
  74. {
  75. rt_hw_led_init();
  76. led_inited = 1;
  77. }
  78. if ( led == 0 )
  79. {
  80. /* set led status */
  81. switch (value)
  82. {
  83. case 0:
  84. rt_hw_led_off(0);
  85. break;
  86. case 1:
  87. rt_hw_led_on(0);
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. if ( led == 1 )
  94. {
  95. /* set led status */
  96. switch (value)
  97. {
  98. case 0:
  99. rt_hw_led_off(1);
  100. break;
  101. case 1:
  102. rt_hw_led_on(1);
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. }
  109. FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
  110. #endif