main.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2021, Huada Semiconductor Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-09-07 PJQ first version
  9. */
  10. /*******************************************************************************
  11. * Include files
  12. ******************************************************************************/
  13. #include "board.h"
  14. #include <rtthread.h>
  15. #include <rtdevice.h>
  16. /*******************************************************************************
  17. * Local type definitions ('typedef')
  18. ******************************************************************************/
  19. /*******************************************************************************
  20. * Local pre-processor symbols/macros ('#define')
  21. ******************************************************************************/
  22. /* defined the LED pin: PC9 */
  23. #define LED_PIN GET_PIN(D, 5)
  24. #define KEY_PIN GET_PIN(B, 9)
  25. /*******************************************************************************
  26. * Global variable definitions (declared in header file with 'extern')
  27. ******************************************************************************/
  28. /*******************************************************************************
  29. * Local function prototypes ('static')
  30. ******************************************************************************/
  31. /*******************************************************************************
  32. * Local variable definitions ('static')
  33. ******************************************************************************/
  34. uint8_t flag;
  35. /*******************************************************************************
  36. * Function implementation - global ('extern') and local ('static')
  37. ******************************************************************************/
  38. void key_handler(void *param)
  39. {
  40. flag = ~flag;
  41. }
  42. /**
  43. *******************************************************************************
  44. ** \brief Main function of GPIO output
  45. **
  46. ** \param None
  47. **
  48. ** \retval int32_t Return value, if needed
  49. **
  50. ******************************************************************************/
  51. int32_t main(void)
  52. {
  53. rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
  54. rt_pin_attach_irq(KEY_PIN, PIN_IRQ_MODE_FALLING, key_handler, RT_NULL);
  55. rt_pin_irq_enable(KEY_PIN, PIN_IRQ_ENABLE);
  56. while(1)
  57. {
  58. if (flag == 0)
  59. {
  60. rt_pin_write(LED_PIN, PIN_HIGH);
  61. rt_thread_delay(500);
  62. rt_pin_write(LED_PIN, PIN_LOW);
  63. rt_thread_delay(500);
  64. }
  65. else
  66. {
  67. rt_pin_write(LED_PIN, PIN_HIGH);
  68. rt_thread_delay(2000);
  69. rt_pin_write(LED_PIN, PIN_LOW);
  70. rt_thread_delay(2000);
  71. }
  72. }
  73. }
  74. /*******************************************************************************
  75. * EOF (not truncated)
  76. ******************************************************************************/