Compare commits

..

No commits in common. "ba6ec8e022c3ef4824ad44c9d8edd443f0b0fa93" and "56875f8dcb676d074c86577265e36763af33e4ef" have entirely different histories.

3 changed files with 19 additions and 18 deletions

View file

@ -17,6 +17,7 @@ typedef struct {
#define AltOut_Ppull 0xA
#define AltOut_OD 0xE
void MyGPIO_InitClock(void);
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr);
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin);
void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin);

View file

@ -1,5 +1,9 @@
#include "gpio.h"
void MyGPIO_InitClock(void) {
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4);
}
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) {
if (GPIOStructPtr->GPIO_Pin >= 8) {
switch (GPIOStructPtr->GPIO_Conf) {
@ -29,8 +33,8 @@ void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) {
else {
switch (GPIOStructPtr->GPIO_Conf) {
case In_PullDown:
GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin % 8)));
GPIOStructPtr->GPIO->CRH |= (0x8 << (4 * (GPIOStructPtr->GPIO_Pin % 8)));
GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin)));
GPIOStructPtr->GPIO->CRH |= (0x8 << (4 * (GPIOStructPtr->GPIO_Pin)));
GPIOStructPtr->GPIO->ODR &= (0x0 << GPIOStructPtr->GPIO_Pin);
break;

View file

@ -2,24 +2,20 @@
#include "gpio.h"
int main(void) {
MyGPIO_Struct_TypeDef * led2;
MyGPIO_Struct_TypeDef * b1;
MyGPIO_Struct_TypeDef led2;
MyGPIO_Struct_TypeDef b1;
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4);
MyGPIO_InitClock();
/*GPIOA->CRL &= ~(0xF << (4 * 5));
GPIOA->CRL |= (0x3 << (4 * 5));
GPIOA->ODR &= (0x0 << 5);
led2.GPIO = GPIOA;
led2.GPIO_Pin = 5;
led2.GPIO_Conf = Out_Ppull;
b1.GPIO = GPIOC;
b1.GPIO_Pin = 13;
b1.GPIO_Conf = In_PullUp;
GPIOC->CRH &= ~(0xF << (4 * (13%8)));
GPIOC->CRH |= (0x8 << (4 * (13%8)));*/
led2->GPIO = GPIOA;
led2->GPIO_Pin = 5;
led2->GPIO_Conf = Out_Ppull;
b1->GPIO = GPIOC;
b1->GPIO_Pin = 13;
b1->GPIO_Conf = In_PullUp;
MyGPIO_Init(&led2);
MyGPIO_Init(&b1);
do
{
@ -30,4 +26,4 @@ int main(void) {
MyGPIO_Set(GPIOA, 5);
}
} while (1);
}
}