dip_sw.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
  13. #define DIP_SW01_GPIO GPIOA
  14. #define DIP_SW01_PIN GPIO_Pin_10
  15. #define DIP_SW01_IN GPIO_ReadInputDataBit(DIP_SW01_GPIO, DIP_SW01_PIN)
  16. #define DIP_SW02_GPIO GPIOA
  17. #define DIP_SW02_PIN GPIO_Pin_9
  18. #define DIP_SW02_IN GPIO_ReadInputDataBit(DIP_SW02_GPIO, DIP_SW02_PIN)
  19. #define DIP_SW03_GPIO GPIOA
  20. #define DIP_SW03_PIN GPIO_Pin_8
  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_9
  24. #define DIP_SW04_IN GPIO_ReadInputDataBit(DIP_SW04_GPIO, DIP_SW04_PIN)
  25. #define DIP_SW05_GPIO GPIOC
  26. #define DIP_SW05_PIN GPIO_Pin_8
  27. #define DIP_SW05_IN GPIO_ReadInputDataBit(DIP_SW05_GPIO, DIP_SW05_PIN)
  28. #define DIP_SW06_GPIO GPIOC
  29. #define DIP_SW06_PIN GPIO_Pin_7
  30. #define DIP_SW06_IN GPIO_ReadInputDataBit(DIP_SW06_GPIO, DIP_SW06_PIN)
  31. #define DIP_SW07_GPIO GPIOC
  32. #define DIP_SW07_PIN GPIO_Pin_6
  33. #define DIP_SW07_IN GPIO_ReadInputDataBit(DIP_SW07_GPIO, DIP_SW07_PIN)
  34. typedef struct{
  35. uint8_t dipsw01_level:1;
  36. uint8_t dipsw02_level:1;
  37. uint8_t dipsw03_level:1;
  38. uint8_t dipsw04_level:1;
  39. uint8_t dipsw05_level:1;
  40. uint8_t dipsw06_level:1;
  41. uint8_t dipsw07_level:1;
  42. uint8_t dipsw08_level:1;
  43. }dipsw_addr_s;
  44. typedef union{
  45. dipsw_addr_s dipsw_addr;
  46. uint8_t addr;
  47. }dipsw_addr_u;
  48. typedef bool (*get_level_func)(void);
  49. typedef struct{
  50. uint8_t idx;
  51. uint8_t dipsw_stat;
  52. bool dipsw_finish;
  53. uint8_t dipsw_on_count;
  54. uint8_t dipsw_off_count;
  55. get_level_func get_level;
  56. }dipsw_work_s;
  57. typedef void (*dipsw_upload_func)(uint8_t addr);
  58. void vDipsw_init(void);
  59. void dipsw_task_start(void);
  60. void vDipsw_set_upload_func(dipsw_upload_func func);
  61. uint16_t dipsw_task_process_event(uint8_t task_id, uint16_t events);
  62. #endif //_SWITCH_H__