dip_sw.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_8
  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_9
  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_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_7
  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_6
  27. #define DIP_SW05_IN GPIO_ReadInputDataBit(DIP_SW05_GPIO, DIP_SW05_PIN)
  28. #define DIP_SW06_GPIO GPIOB
  29. #define DIP_SW06_PIN GPIO_Pin_15
  30. #define DIP_SW06_IN GPIO_ReadInputDataBit(DIP_SW06_GPIO, DIP_SW06_PIN)
  31. #define DIP_SW07_GPIO GPIOB
  32. #define DIP_SW07_PIN GPIO_Pin_14
  33. #define DIP_SW07_IN GPIO_ReadInputDataBit(DIP_SW07_GPIO, DIP_SW07_PIN)
  34. #define DIP_SW08_GPIO GPIOB
  35. #define DIP_SW08_PIN GPIO_Pin_13
  36. #define DIP_SW08_IN GPIO_ReadInputDataBit(DIP_SW08_GPIO, DIP_SW08_PIN)
  37. typedef struct{
  38. uint8_t dipsw01_level:1;
  39. uint8_t dipsw02_level:1;
  40. uint8_t dipsw03_level:1;
  41. uint8_t dipsw04_level:1;
  42. uint8_t dipsw05_level:1;
  43. uint8_t dipsw06_level:1;
  44. uint8_t dipsw07_level:1;
  45. uint8_t dipsw08_level:1;
  46. }dipsw_addr_s;
  47. typedef union{
  48. dipsw_addr_s dipsw_addr;
  49. uint8_t addr;
  50. }dipsw_addr_u;
  51. typedef bool (*get_level_func)(void);
  52. typedef struct{
  53. uint8_t idx;
  54. uint8_t dipsw_stat;
  55. bool dipsw_finish;
  56. uint8_t dipsw_on_count;
  57. uint8_t dipsw_off_count;
  58. get_level_func get_level;
  59. }dipsw_work_s;
  60. typedef void (*dipsw_upload_func)(uint8_t addr);
  61. void vDipsw_init(void);
  62. void dipsw_task_start(void);
  63. void vDipsw_set_upload_func(dipsw_upload_func func);
  64. uint16_t dipsw_task_process_event(uint8_t task_id, uint16_t events);
  65. #endif //_SWITCH_H__