Compare commits

...

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

3 changed files with 18 additions and 19 deletions

View file

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

View file

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

View file

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