8 void DrvGpio::init(DrvTypes::PORT port, DrvTypes::PIN pin, DrvTypes::GPIO_FUNCTION func, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd) {
14 case DrvTypes::DRV_PORTA:
17 case DrvTypes::DRV_PORTB:
20 case DrvTypes::DRV_PORTC:
23 case DrvTypes::DRV_PORTD:
26 case DrvTypes::DRV_PORTE:
29 case DrvTypes::DRV_PORTF:
32 case DrvTypes::DRV_PORTG:
35 case DrvTypes::DRV_PORTH:
38 case DrvTypes::DRV_PORTI:
47 setPinFuncMode(mPort, mPin, func, mode, pupd);
50 void DrvGpio::setPinFuncMode(DrvTypes::GPIO_FUNCTION func, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd) {
51 setPinFuncMode(mPort, mPin, func, mode);
54 void DrvGpio::setPinFuncMode(DrvTypes::PORT port, DrvTypes::PIN pin, DrvTypes::GPIO_FUNCTION func, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd) {
58 case DrvTypes::DRV_PORTA:
61 case DrvTypes::DRV_PORTB:
64 case DrvTypes::DRV_PORTC:
67 case DrvTypes::DRV_PORTD:
70 case DrvTypes::DRV_PORTE:
73 case DrvTypes::DRV_PORTF:
76 case DrvTypes::DRV_PORTG:
79 case DrvTypes::DRV_PORTH:
82 case DrvTypes::DRV_PORTI:
89 int pinShift = 2 * pin;
91 gpio->OSPEEDR |= (0b11 << pinShift);
92 gpio->MODER &= ~(0b11 << pinShift);
93 gpio->PUPDR &= ~(0b11 << pinShift);
96 case DrvTypes::DRV_MODE_INPUT:
99 case DrvTypes::DRV_MODE_OUTPUT_PUSH_PULL:
102 case DrvTypes::DRV_MODE_OUTPUT_OPEN_DRAIN:
105 case DrvTypes::DRV_MODE_ALTERNATE_FUNCTION:
108 case DrvTypes::DRV_MODE_ANALOG:
116 case DrvTypes::PUPD_NONE:
118 case DrvTypes::PUPD_PULL_UP:
119 gpio->PUPDR |= 0x01 << pinShift;
121 case DrvTypes::PUPD_PULL_DOWN:
122 gpio->PUPDR |= 0x10 << pinShift;
126 gpio->MODER |= pinMode << pinShift;
128 pinShift = (4 * pin) % 32;
129 gpio->AFR[pin >> 3] &= ~(0xF << pinShift);
130 gpio->AFR[pin >> 3] |= func << pinShift;