123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include "api_rt_gpio.h"
- #include "gd32f30x.h"
- Gpio_Handle const Gpios[GPIO_PIN_COUNT] = {
- [0] = {.GpioBase = GPIOB, .Index = 4},
- [1] = {.GpioBase = GPIOB, .Index = 5},
- [2] = {.GpioBase = GPIOB, .Index = 9},
- };
- void iRtGpio_Init()
- {
- }
- void iGpio_SetMode(uint16_t pin, ApiGpio_PinMode mode)
- {
- const Gpio_Handle *const gpio = &Gpios[pin];
- switch (mode)
- {
- case ApiGpio_Input:
- GPIO_CTL0(gpio->GpioBase) &= GPIO_MODE_SET(pin, mode);
- // gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
- break;
- case ApiGpio_Output:
- // gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
- // gpio->GpioBase->MODER |= (((uint32_t)0x00000001UL) << (2 * gpio->Index));
- break;
- case ApiGpio_AlternateFunction:
- // gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
- // gpio->GpioBase->MODER |= (((uint32_t)0x00000002UL) << (2 * gpio->Index));
- break;
- default:
- break;
- }
- }
- iGpio_Level iGpio_Read(uint16_t pin)
- {
- // ASSERT_LESS(pin, GPIO_PIN_COUNT);
- // const Gpio_Handle *const gpio = &Gpios[pin];
- //
- // iGpio_Level level = iGpio_LowLevel;
- //
- // if (gpio->GpioBase->IDR & (((uint32_t)0x00000001UL) << gpio->Index))
- // {
- // level = iGpio_HighLevel;
- // }
- // return level;
- }
- void iGpio_Write(uint16_t pin, iGpio_Level level)
- {
- // ASSERT_LESS(pin, GPIO_PIN_COUNT);
- // const Gpio_Handle *const gpio = &Gpios[pin];
- //
- // if (level == iGpio_HighLevel)
- // {
- // gpio->GpioBase->BSRR = (((uint32_t)0x00000001UL) << gpio->Index);
- // }
- // else
- // {
- // gpio->GpioBase->BSRR = (((uint32_t)0x00000001UL) << (gpio->Index + 16));
- // }
- }
|