Made the BSL Class now lets look for led.cpp implementation

interrupts
key 4 years ago
parent 681bd375cc
commit 9984ab9fe9

26
$

@ -0,0 +1,26 @@
#include "bsl_nucleo_f042k6.hpp"
Nucleo_f042k6::Nucleo_f042k6(){}
Nucleo_f042k6::~Nucleo_f042k6(){}
void Nucleo_f042k6::init()
{
ledPin.init();
ledPin.setMode(Pin::mode::output);
ledPin.setSpeed(Pin::speed::fast);
pin_a0.init();
pin_a0.setMode(Pin::mode::input);
pin_a0.setSpeed(Pin::speed::slow);
pin_a0.setPullUpDonw(Pin::pullUpDown::pullDown);
}
void Nucleo_f042k6::running()
{
ledPin.write(true);
delay.ms(200);
ledPin.write(false);
delay.ms(200);
}

@ -77,7 +77,7 @@ class Pin
virtual void config(mode mode, state state, pullUpDown resistance, speed speed) = 0;
virtual bool read() = 0;
virtual bool toggle() = 0;
virtual void toggle() = 0;
virtual void write(bool state) = 0;
virtual void init() = 0;

@ -66,7 +66,6 @@ enum Pin_no{
pin_15
};
template <Pin_no pin_no, GPIO_Port port_base_address>
class STM_Pin : Pin
{
@ -170,7 +169,7 @@ class STM_Pin : Pin
return (reinterpret_cast<GPIO_TypeDef*>(port_base_address)->IDR & (1<<pin_no)) >> pin_no;
}
bool toggle() override
void toggle() override
{
}

@ -1,42 +1,29 @@
#include "bsl_nucleo_f042k6.hpp"
int startBSL()
Nucleo_f042k6::Nucleo_f042k6()
{
stmStart();
Delay delay;
STM_Pin<Pin_no::pin_3, GPIO_Port::Port_B_base_address> led;
STM_Pin<Pin_no::pin_0, GPIO_Port::Port_A_base_address> pin_a0;
}
Nucleo_f042k6::~Nucleo_f042k6(){}
led.init();
led.setMode(Pin::mode::output);
led.setSpeed(Pin::speed::fast);
void Nucleo_f042k6::init()
{
ledPin.init();
ledPin.setMode(Pin::mode::output);
ledPin.setSpeed(Pin::speed::fast);
pin_a0.init();
pin_a0.setMode(Pin::mode::input);
pin_a0.setSpeed(Pin::speed::slow);
pin_a0.setPullUpDonw(Pin::pullUpDown::pullDown);
}
uint8_t i = 0;
for(i = 0 ; i < 10 ; i++)
{
delay.ms(100);
led.write(true);
delay.ms(100);
led.write(false);
}
while(1)
{
if(pin_a0.read())
{
led.write(true);
}
else
{
led.write(false);
}
}
return 1;
void Nucleo_f042k6::running()
{
ledPin.write(true);
delay.ms(200);
ledPin.write(false);
delay.ms(200);
}

@ -5,6 +5,23 @@
#include "../csl/interfaces/delay.hpp"
#include "../csl/stm32f042/Inc/stm_pin.hpp"
#include "stm32f0xx_csl.h"
int startBSL();
class Nucleo_f042k6
{
public:
Nucleo_f042k6();
~Nucleo_f042k6();
void init();
void running();
private :
Delay delay;
STM_Pin<Pin_no::pin_3, GPIO_Port::Port_B_base_address> ledPin;
STM_Pin<Pin_no::pin_0, GPIO_Port::Port_A_base_address> pin_a0;
};
#endif /* BSL_NUCLEO_F042K6_H */

@ -0,0 +1,18 @@
#include "led.hpp"
void Pin::on()
{
pin.write(true);
}
void Pin::off()
{
pin.write(false);
}
void Pin::toggle()
{
pin.toggle();
}

@ -0,0 +1,22 @@
#ifndef __LED_HPP
#define __LED_HPP
// TODO : Change Cmake to include "pin.hpp"
#include "../../bsl/csl/interfaces/pin.hpp"
class Led
{
public:
Led(Pin& pin);
~Led();
void on();
void off();
void toggle();
private:
Pin& pin;
};
#endif /* __LED_HPP */

@ -3,6 +3,15 @@
int main(int argc, char *argv[])
{
startBSL();
Nucleo_f042k6 bsl;
bsl.init();
while(1)
{
bsl.running();
}
return 1;
}

Loading…
Cancel
Save