mux.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "at32f403a_407.h"
  2. #include "mux.h"
  3. //
  4. void mux_gpio_init(void)
  5. {
  6. gpio_init_type gpio_initstructure;
  7. crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
  8. crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
  9. crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
  10. // LED_COL
  11. // COL_1 - PD6
  12. // COL_2 - PD7
  13. // COL_3 - PB6
  14. // COL_4 - PB7
  15. gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
  16. gpio_initstructure.gpio_pull = GPIO_PULL_NONE;
  17. gpio_initstructure.gpio_mode = GPIO_MODE_OUTPUT;
  18. gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  19. gpio_initstructure.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
  20. gpio_init(GPIOB, &gpio_initstructure);
  21. gpio_initstructure.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
  22. gpio_init(GPIOD, &gpio_initstructure);
  23. gpio_bits_reset(GPIOB, GPIO_PINS_6 | GPIO_PINS_7);
  24. gpio_bits_reset(GPIOD, GPIO_PINS_6 | GPIO_PINS_7);
  25. // LED_LINE
  26. // LINE_0 - PE3
  27. // LINE_1 - PE2
  28. // LINE_2 - PB9
  29. gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
  30. gpio_initstructure.gpio_pull = GPIO_PULL_NONE;
  31. gpio_initstructure.gpio_mode = GPIO_MODE_OUTPUT;
  32. gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  33. gpio_initstructure.gpio_pins = GPIO_PINS_2 | GPIO_PINS_3;
  34. gpio_init(GPIOE, &gpio_initstructure);
  35. gpio_initstructure.gpio_pins = GPIO_PINS_9;
  36. gpio_init(GPIOB, &gpio_initstructure);
  37. gpio_bits_reset(GPIOE, GPIO_PINS_2 | GPIO_PINS_3);
  38. gpio_bits_reset(GPIOB, GPIO_PINS_9);
  39. }
  40. //
  41. void mux_test(void)
  42. {
  43. // INP_1
  44. gpio_bits_set(GPIOE, GPIO_PINS_2 | GPIO_PINS_3);
  45. gpio_bits_set(GPIOB, GPIO_PINS_9);
  46. gpio_bits_set(GPIOD, GPIO_PINS_6);
  47. vTaskDelay(1);
  48. // INP_2
  49. gpio_bits_set(GPIOE, GPIO_PINS_2);
  50. gpio_bits_reset(GPIOE, GPIO_PINS_3);
  51. gpio_bits_set(GPIOB, GPIO_PINS_9);
  52. gpio_bits_set(GPIOD, GPIO_PINS_7);
  53. vTaskDelay(1);
  54. }