-
-
Save MayaPosch/2272560bbd38f4f882e3d80cfbd21c20 to your computer and use it in GitHub Desktop.
STM32 GPIO output F1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input/output registers are spread over two combined registers (CRL, CRH). | |
if (pin < 8) { | |
// Set CRL register (CNF & MODE). | |
uint8_t pinmode = pin * 4; | |
uint8_t pincnf = pinmode + 2; | |
if (speed == GPIO_LOW) { instance.regs->CRL |= (0x2 << pinmode); } | |
else if (speed == GPIO_MID) { instance.regs->CRL |= (0x1 << pinmode); } | |
else if (speed == GPIO_HIGH) { instance.regs->CRL |= (0x3 << pinmode); } | |
if (type == GPIO_PUSH_PULL) { instance.regs->CRL &= ~(0x1 << pincnf); } | |
else if (type == GPIO_OPEN_DRAIN) { instance.regs->CRL |= (0x1 << pincnf); } | |
} | |
else { | |
// Set CRH register. | |
uint8_t pinmode = (pin - 8) * 4; | |
uint8_t pincnf = pinmode + 2; | |
if (speed == GPIO_LOW) { instance.regs->CRH |= (0x2 << pinmode); } | |
else if (speed == GPIO_MID) { instance.regs->CRH |= (0x1 << pinmode); } | |
else if (speed == GPIO_HIGH) { instance.regs->CRH |= (0x3 << pinmode); } | |
if (type == GPIO_PUSH_PULL) { instance.regs->CRH &= ~(0x1 << pincnf); } | |
else if (type == GPIO_OPEN_DRAIN) { instance.regs->CRH |= (0x1 << pincnf); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment