You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "lwip/opt.h"
  6. #include "lwip/sys.h"
  7. #include "lwip/api.h"
  8. #include "main.h"
  9. #include "zport.h"
  10. #include "zboard.h"
  11. #include "encoder.h"
  12. #include "udpclient.h"
  13. #include "zflash.h"
  14. #include "config.h"
  15. #include "zkey.h"
  16. #define KEY_SCAN_PERIOD 20
  17. static uint16_t s_key_long_press_time_ms = 3000;
  18. static inline bool clear_key_get_status() { return HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_4); }
  19. static void onkey(zkey_t *key, zkey_state_t key_state);
  20. static zkey_t s_keys[] = {
  21. ZKEY_INIT("Clear_Key", clear_key_get_status), //
  22. // ZKEY_INIT("Signal_INT1", port_get_gpio_int1), //
  23. // ZKEY_INIT("Signal_INT2", port_get_gpio_int2), //
  24. // ZKEY_INIT("Signal_INT3", port_get_gpio_int3), //
  25. };
  26. static zkey_module_t s_key_module = ZMODULE_INIT(s_keys, onkey);
  27. static void zkey_schedule()
  28. {
  29. static uint32_t lastprocess_key_ticket;
  30. if (sys_haspassedms(lastprocess_key_ticket) >= KEY_SCAN_PERIOD)
  31. {
  32. zkey_do_loop_in_each_period(NULL);
  33. lastprocess_key_ticket = HAL_GetTick();
  34. }
  35. }
  36. static void onkey(zkey_t *key, zkey_state_t key_state)
  37. {
  38. if (key_state == zks_rising_edge)
  39. {
  40. encoder_all_clear_counter();
  41. printf("clear encoder count\r\n");
  42. }
  43. if (key_state == zks_keep)
  44. {
  45. if (key->keep_state_count == s_key_long_press_time_ms / KEY_SCAN_PERIOD)
  46. {
  47. // 触发长按事件
  48. key->hasProcessed = true;
  49. }
  50. }
  51. else if (key_state == zks_falling_edge)
  52. {
  53. /**
  54. * @brief
  55. */
  56. if (!key->hasProcessed)
  57. {
  58. }
  59. }
  60. }
  61. /**
  62. * @brief
  63. */
  64. void port_mock_on_uart_rx(uart_t *uart)
  65. {
  66. // 处理指令串口接收到的数据
  67. if (uart->uarthandler == &DEBUG_UART)
  68. {
  69. printf("%c", uart->rxbuf);
  70. }
  71. }
  72. void user_main()
  73. {
  74. printf("==============ethernet_sound_acquisition_card=============\r\n");
  75. printf("version %d.%d", VERSION_MAIN_ID, VERSION_SUB_ID);
  76. encoder_all_start();
  77. udp_client_init();
  78. config_init();
  79. zkey_init(&s_key_module);
  80. port_uart_start_all_uart_receive();
  81. while (1)
  82. {
  83. zkey_schedule();
  84. udp_client_recv();
  85. encoder_read_printf();
  86. port_do_debug_light_state();
  87. osDelay(1);
  88. }
  89. }