dip_sw.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef _DIP_SW_H__
  2. #define _DIP_SW_H__
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "define.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define DIP_SW_INTERVAL 5
  10. #define DIP_SW_CHECK_COUNT 10
  11. #define DIP_SW_CHECK_FAST_COUNT 2
  12. #define DIP_SW_GPIO_RCC_ENABLE RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
  13. #define DIP_SW01_GPIO GPIOC
  14. #define DIP_SW01_PIN GPIO_Pin_9
  15. #define DIP_SW01_IN GPIO_ReadInputDataBit(DIP_SW01_GPIO, DIP_SW01_PIN)
  16. #define DIP_SW02_GPIO GPIOC
  17. #define DIP_SW02_PIN GPIO_Pin_8
  18. #define DIP_SW02_IN GPIO_ReadInputDataBit(DIP_SW02_GPIO, DIP_SW02_PIN)
  19. #define DIP_SW03_GPIO GPIOC
  20. #define DIP_SW03_PIN GPIO_Pin_7
  21. #define DIP_SW03_IN GPIO_ReadInputDataBit(DIP_SW03_GPIO, DIP_SW03_PIN)
  22. #define DIP_SW04_GPIO GPIOC
  23. #define DIP_SW04_PIN GPIO_Pin_6
  24. #define DIP_SW04_IN GPIO_ReadInputDataBit(DIP_SW04_GPIO, DIP_SW04_PIN)
  25. typedef struct{
  26. uint8_t dipsw01_level:1;
  27. uint8_t dipsw02_level:1;
  28. uint8_t dipsw03_level:1;
  29. uint8_t dipsw04_level:1;
  30. uint8_t :4;
  31. }dipsw_addr_s;
  32. typedef union{
  33. dipsw_addr_s dipsw_addr;
  34. uint8_t addr;
  35. }dipsw_addr_u;
  36. typedef bool (*get_level_func)(void);
  37. typedef struct{
  38. uint8_t idx;
  39. uint8_t dipsw_stat;
  40. bool dipsw_finish;
  41. uint8_t dipsw_on_count;
  42. uint8_t dipsw_off_count;
  43. get_level_func get_level;
  44. }dipsw_work_s;
  45. typedef void (*dipsw_upload_func)(uint8_t addr);
  46. void vDipsw_init(void);
  47. void dipsw_task_start(void);
  48. void vDipsw_set_upload_func(dipsw_upload_func func);
  49. uint16_t dipsw_task_process_event(uint8_t task_id, uint16_t events);
  50. #endif //_SWITCH_H__