added KED structure idea

interrupts
polymurph 4 years ago
parent 4cb7ec1772
commit fff29f491d

@ -0,0 +1,29 @@
cpp_src = $(wildcard *.cpp)
#cpp_src += $(wildcard ./utils/*.cpp)
#cpp_src += $(wildcard ./driver/*.cpp)
cpp_obj = $(cpp_src:.cpp=.o)
c_obj = $(c_src:.c=.o)
CC = g++
CFLAGS = -Wall -pedantic -li2c
LDFLAGS =
EXEC = runtest
all : $(EXEC)
$(EXEC): $(cpp_obj) $(c_obj)
$(CC) -o $@ $^ $(LDFLAGS)
debug : $(EXEC)
$(EXEC): $(cpp_obj) $(c_obj)
$(CC) -g -o $@ $^ $(LDFLAGS)
clean:
rm -rf $(c_obj) $(cpp_obj) $(EXEC)
clear
cleanall:
rm -rf $(c_obj) $(cpp_obj) $(EXEC)
clear

@ -0,0 +1,42 @@
#ifndef __HW_PLATTFORM_HPP__
#define __HW_PLATTFORM_HPP__
#include <iostream>
//
// csl ressources
//
#include "./../csl/implementations/dummy/dummy_pin.hpp"
//
// drivers
//
#include "./../drivers/LED.hpp"
struct HW_plattform
{
HW_plattform():
pin_0(),
pin_1(),
led_0(pin_0)
{}
void init()
{
std::cout << "bsl init..." << std::endl;
pin_0.set(false);
pin_1.set(false);
std::cout << "...done!" << std::endl;
};
private:
Dummy_Pin pin_0, pin_1;
public:
LED<Dummy_Pin> led_0;
};
#endif // __HW_PLATTFORM_HPP__

@ -0,0 +1,37 @@
#ifndef __AVR_PIN_HPP__
#define __AVR_PIN_HPP__
#include <iostream>
#include "./../../interfaces/pin.hpp"
struct AVR_Pin : Pin<AVR_Pin>
{
AVR_Pin()
{
std::cout << "created AVR_Pin" << std::endl;
}
void setImp(bool logic)
{
std::cout << "AVR pin set to " << logic << std::endl;
}
void toggleImp()
{
std::cout << "toggled AVR pin" << std::endl;
}
bool getImp()
{
return true;
}
void avr_stuff()
{
std::cout << "AVR specific stuff" << std::endl;
}
};
#endif // __AVR_PIN_HPP__

@ -0,0 +1,38 @@
#ifndef __DUMMY_PIN_HPP__
#define __DUMMY_PIN_HPP__
#include "./../../interfaces/pin.hpp"
#include <iostream>
struct Dummy_Pin : Pin<Dummy_Pin>
{
Dummy_Pin()
{
std::cout << "created Dummy_Pin" << std::endl;
}
void setImp(bool logic)
{
std::cout << "Dummy pin set to " << logic << std::endl;
}
void toggleImp()
{
std::cout << "toggled Dummy pin" << std::endl;
}
bool getImp()
{
return true;
}
void dummy_stuff()
{
std::cout << "dummy specific stuff" << std::endl;
}
};
#endif // __DUMMY_PIN_HPP__

@ -0,0 +1,37 @@
#ifndef __STM_PIN_HPP__
#define __STM_PIN_HPP__
#include "./../../interfaces/pin.hpp"
#include <iostream>
truct STM32_Pin : Pin<STM32_Pin>
{
STM32_Pin()
{
std::cout << "created STM32_Pin" << std::endl;
}
void setImp(bool logic)
{
std::cout << "stm32 pin set to " << logic << std::endl;
}
void toggleImp()
{
std::cout << "toggled stm32 pin" << std::endl;
}
bool getImp()
{
return true;
}
void STM32_stuff()
{
std::cout << "STM_32 specific stuff" << std::endl;
}
};
#endif // __STM_PIN_HPP__

@ -0,0 +1,23 @@
#ifndef __PIN_HPP__
#define __PIN_HPP__
template <typename Derived>
struct Pin
{
void set(bool logic)
{
static_cast<Derived*>(this)->setImp(logic);
}
void toggle()
{
static_cast<Derived*>(this)->toggleImp();
}
bool get(void)
{
return static_cast<Derived*>(this)->getImp();
}
};
#endif // __PIN_HPP__

@ -0,0 +1,35 @@
#ifndef __LED_HPP__
#define __LED_HPP__
#include "./../csl/interfaces/pin.hpp"
template <typename T>
class LED
{
public:
LED(Pin<T>& pin) :
pin(pin)
{}
void turnOn()
{
pin.set(true);
}
void turnOff()
{
pin.set(false);
}
void toggle()
{
pin.toggle();
}
private:
Pin<T>& pin;
};
#endif // __LED_HPP__

@ -0,0 +1,16 @@
#include <iostream>
#include "./bsl/hw_plattform.hpp"
int main()
{
HW_plattform hw;
hw.init();
//hw.pin_1.set(true);
hw.led_0.turnOn();
return 1;
}

Binary file not shown.
Loading…
Cancel
Save