diff --git a/Src/main.cpp b/Src/main.cpp index 5cbb89b..2798ab4 100644 --- a/Src/main.cpp +++ b/Src/main.cpp @@ -2,17 +2,16 @@ #include "stm32f10x_gpio.h" #include "stm32f10x_rcc.h" #include "stm32f10x.h" // Device header +#include "ztLed.hpp" int main(void){ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); - GPIO_InitTypeDef gpioInitStructure = {GPIO_Pin_13,GPIO_Speed_50MHz,GPIO_Mode_Out_PP}; - GPIO_Init(GPIOC, &gpioInitStructure); - u16 delayTime = 100; + zt::Led led(RCC_APB2Periph_GPIOA,GPIO_Pin_0,GPIOA); + u32 delayTime = 50; while(true){ delayTime+=1; - GPIO_ResetBits(GPIOC, GPIO_Pin_13); + led.setOn(); delay_ms(delayTime); - GPIO_SetBits(GPIOC, GPIO_Pin_13); + led.setOff(); delay_ms(delayTime); } } \ No newline at end of file diff --git a/Src/ztLed.hpp b/Src/ztLed.hpp new file mode 100644 index 0000000..a1a8e17 --- /dev/null +++ b/Src/ztLed.hpp @@ -0,0 +1,29 @@ +#include "stm32f10x.h" +#include "stm32f10x_gpio.h" +#include "stm32f10x_rcc.h" +namespace zt{ + class Led{ + private: + const u32 _RCC_APB2Periph; + const u16 _GPIO_Pin; + GPIO_TypeDef* const _GPIOx; + public: + Led(const u32 &RCC_APB2Periph,const u16 &GPIO_Pin,GPIO_TypeDef* const& GPIOx):_RCC_APB2Periph(RCC_APB2Periph),_GPIO_Pin(GPIO_Pin),_GPIOx(GPIOx){ + RCC_APB2PeriphClockCmd(_RCC_APB2Periph, ENABLE); + GPIO_InitTypeDef gpioInitStructure = {_GPIO_Pin,GPIO_Speed_50MHz,GPIO_Mode_Out_PP}; + GPIO_Init(_GPIOx, &gpioInitStructure); + } + ~Led(){ + GPIO_DeInit(_GPIOx); + RCC_APB2PeriphClockCmd(_RCC_APB2Periph, DISABLE); + } + Led& setOn(){ + GPIO_SetBits(_GPIOx, _GPIO_Pin); + return *this; + } + Led& setOff(){ + GPIO_ResetBits(_GPIOx, _GPIO_Pin); + return *this; + } + }; +} \ No newline at end of file