#pragma once #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); } virtual ~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; } }; }