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.

104 lines
2.5 KiB

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