From 05ea46acd07da41705ba59824df91b9e2ad73fa9 Mon Sep 17 00:00:00 2001 From: Erki Date: Mon, 29 Mar 2021 23:32:35 +0300 Subject: [PATCH] RGB peripheral --- Peripherals/Inc/peripherals_rgb.hpp | 101 ++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Peripherals/Inc/peripherals_rgb.hpp diff --git a/Peripherals/Inc/peripherals_rgb.hpp b/Peripherals/Inc/peripherals_rgb.hpp new file mode 100644 index 0000000..3546d4c --- /dev/null +++ b/Peripherals/Inc/peripherals_rgb.hpp @@ -0,0 +1,101 @@ +/* + * peripherals_rgb.hpp + * + * Created on: Mar 29, 2021 + * Author: erki + */ + +#ifndef PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ +#define PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ + +#include "peripherals_io.hpp" + +namespace Peripherals +{ + +enum class RgbColor : std::uint32_t +{ + OFF, + RED, + GREEN, + BLUE, + CYAN, + PINK, + YELLOW, + WHITE +}; + +template +struct Rgb +{ + using IOType = T; + + IOType red; + IOType green; + IOType blue; + + RgbColor color = RgbColor::OFF; + + Rgb() = delete; + Rgb(const IOType& r, const IOType& g, const IOType& b) + : red(r) + , green(g) + , blue(b) + { + Set(RgbColor::OFF); + } + + void Set(const RgbColor& new_color) + { + color = new_color; + + switch (color) + { + case RgbColor::OFF: + red.Set(false); + green.Set(false); + blue.Set(false); + break; + case RgbColor::RED: + red.Set(true); + green.Set(false); + blue.Set(false); + break; + case RgbColor::GREEN: + red.Set(false); + green.Set(true); + blue.Set(false); + break; + case RgbColor::BLUE: + red.Set(false); + green.Set(false); + blue.Set(true); + break; + case RgbColor::CYAN: + red.Set(false); + green.Set(true); + blue.Set(true); + break; + case RgbColor::PINK: + red.Set(true); + green.Set(false); + blue.Set(true); + break; + case RgbColor::YELLOW: + red.Set(true); + green.Set(true); + blue.Set(false); + break; + case RgbColor::WHITE: + red.Set(true); + green.Set(true); + blue.Set(true); + break; + } + } +}; + +} + + +#endif /* PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ */