From 4b644b22bf4ced4406eb6427a7e437604fc26357 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 21 Feb 2020 17:29:45 +0100 Subject: [PATCH] Completely separted driver from interface --- hardware.hpp | 13 +++++++++++++ spi.hpp | 11 ++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hardware.hpp b/hardware.hpp index c0fc2af..4defd34 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -33,6 +33,19 @@ class Hardware { SPCR |= (1 << SPE); } + static uint8_t transfer(uint8_t data) + { + SPDR = data; + while (!(SPSR & (1 << SPIF))) + ; + return SPDR; + } + + static void select(bool selectState) + { + sm_ss = !selectState; + } + private: static io::Pin sm_sck; static io::Pin sm_miso; diff --git a/spi.hpp b/spi.hpp index 822f0ca..3d535a6 100644 --- a/spi.hpp +++ b/spi.hpp @@ -17,22 +17,15 @@ class Spi { static uint8_t transfer(uint8_t ui8Data) { - SPDR = ui8Data; - while (!(SPSR & (1 << SPIF))) - ; - return SPDR; + return Driver::transfer(ui8Data); } static void select(bool bSelect) { - sm_cSS.write(!bSelect); + Driver::select(bSelect); } private: - static io::Pin sm_cSCK; - static io::Pin sm_cMISO; - static io::Pin sm_cMOSI; - static io::Pin sm_cSS; }; } // namespace spi