api_rt_gpio.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "api_rt_gpio.h"
  2. #include "gd32f30x.h"
  3. Gpio_Handle const Gpios[GPIO_PIN_COUNT] = {
  4. [0] = {.GpioBase = GPIOB, .Index = 4},
  5. [1] = {.GpioBase = GPIOB, .Index = 5},
  6. [2] = {.GpioBase = GPIOB, .Index = 9},
  7. };
  8. void iRtGpio_Init()
  9. {
  10. }
  11. void iGpio_SetMode(uint16_t pin, ApiGpio_PinMode mode)
  12. {
  13. const Gpio_Handle *const gpio = &Gpios[pin];
  14. switch (mode)
  15. {
  16. case ApiGpio_Input:
  17. GPIO_CTL0(gpio->GpioBase) &= GPIO_MODE_SET(pin, mode);
  18. // gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
  19. break;
  20. case ApiGpio_Output:
  21. // gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
  22. // gpio->GpioBase->MODER |= (((uint32_t)0x00000001UL) << (2 * gpio->Index));
  23. break;
  24. case ApiGpio_AlternateFunction:
  25. // gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
  26. // gpio->GpioBase->MODER |= (((uint32_t)0x00000002UL) << (2 * gpio->Index));
  27. break;
  28. default:
  29. break;
  30. }
  31. }
  32. iGpio_Level iGpio_Read(uint16_t pin)
  33. {
  34. // ASSERT_LESS(pin, GPIO_PIN_COUNT);
  35. // const Gpio_Handle *const gpio = &Gpios[pin];
  36. //
  37. // iGpio_Level level = iGpio_LowLevel;
  38. //
  39. // if (gpio->GpioBase->IDR & (((uint32_t)0x00000001UL) << gpio->Index))
  40. // {
  41. // level = iGpio_HighLevel;
  42. // }
  43. // return level;
  44. }
  45. void iGpio_Write(uint16_t pin, iGpio_Level level)
  46. {
  47. // ASSERT_LESS(pin, GPIO_PIN_COUNT);
  48. // const Gpio_Handle *const gpio = &Gpios[pin];
  49. //
  50. // if (level == iGpio_HighLevel)
  51. // {
  52. // gpio->GpioBase->BSRR = (((uint32_t)0x00000001UL) << gpio->Index);
  53. // }
  54. // else
  55. // {
  56. // gpio->GpioBase->BSRR = (((uint32_t)0x00000001UL) << (gpio->Index + 16));
  57. // }
  58. }