#include #include void MyGPIO_Init(GPIO_TypeDef *GPIO, char pin, char conf){ if (GPIO == GPIOA) {RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN);} else if (GPIO == GPIOB) {RCC->APB2ENR |= (RCC_APB2ENR_IOPBEN);} else if (GPIO == GPIOC) {RCC->APB2ENR |= (RCC_APB2ENR_IOPCEN);} else if (GPIO == GPIOD) {RCC->APB2ENR |= (RCC_APB2ENR_IOPDEN);} if (pin < 8) { if (conf == 0xF) { GPIO->CRL&=~(0xF<<4*pin); GPIO->CRL|=(0x8<<4*pin); GPIO->ODR|=(1<CRL&=~(0xF<<4*pin); GPIO->CRL|=(conf<<4*pin); GPIO->ODR&=~(1<CRL&=~(0xF<<4*pin); GPIO->CRL|=(conf<<4*pin); } } else { if (conf == 0xF) { GPIO->CRH&=~(0xF<<4*(pin-8)); GPIO->CRH|=(0x8<<4*(pin-8)); GPIO->ODR|=(1<CRH&=~(0xF<<4*(pin-8)); GPIO->CRH|=(conf<<4*(pin-8)); GPIO->ODR&=~(1<CRH&=~(0xF<<4*(pin-8)); GPIO->CRH|=(conf<<4*(pin-8)); } } } int MyGPIO_Read(GPIO_TypeDef *GPIO, char GPIO_Pin){ return (GPIO->IDR&(1<BSRR=(1<BSRR=(1<<(GPIO_Pin+16)); } void MyGPIO_Toggle(GPIO_TypeDef *GPIO, char GPIO_Pin){ if (((GPIO->ODR>>GPIO_Pin)&1) == 1) MyGPIO_Reset(GPIO, GPIO_Pin); else MyGPIO_Set(GPIO, GPIO_Pin);