generated from Zengtudor/stm32F10xExp
update
This commit is contained in:
parent
bb18fbcae9
commit
7897577cca
11
Src/main.cpp
11
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);
|
||||
}
|
||||
}
|
29
Src/ztLed.hpp
Normal file
29
Src/ztLed.hpp
Normal file
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user