detection.c 537 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "detection.h"
  2. #include "gd32e230x_conf.h"
  3. void detection_Init()
  4. {
  5. rcu_periph_clock_enable(RCU_GPIOB);
  6. rcu_periph_clock_enable(RCU_GPIOA);
  7. gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP,GPIO_PIN_3);
  8. gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP,GPIO_PIN_11);
  9. }
  10. uint8_t get_detection()
  11. {
  12. uint8_t value = 0;
  13. if(gpio_input_bit_get(GPIOB,GPIO_PIN_3)==0)
  14. value |= 1;
  15. if(gpio_input_bit_get(GPIOA,GPIO_PIN_11)==0)
  16. value |= 2;
  17. return value;
  18. }