diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d0fbac9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,47 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/bsl/csl/PC/peripherals/spiDummy.hpp b/bsl/csl/PC/peripherals/spiDummy.hpp new file mode 100644 index 0000000..e4f6be2 --- /dev/null +++ b/bsl/csl/PC/peripherals/spiDummy.hpp @@ -0,0 +1,28 @@ +#ifndef _SPIDUMMY_HPP_ +#define _SPIDUMMY_HPP_ + +#include +//#include "../../interfaces/spi.hpp" +#include + +struct SPI_dummy : SPI +{ + uint8_t trx_u8Impl(const uint8_t& data) + { + std::cout << "spi trx: tx " << data << " rx: " << +0 << std::endl; + return 0; + } + + void txImpl(const uint8_t& data) + { + std::cout << "spi tx: " << +data << std::endl; + } + + uint8_t rxImpl() + { + std::cout << "spi rx: " << +1 << std::endl; + return 1; + } +}; + +#endif // _SPIDUMMY_HPP_ diff --git a/interfaces/spich.hpp b/interfaces/spich.hpp index 49f3b7c..46e2daa 100644 --- a/interfaces/spich.hpp +++ b/interfaces/spich.hpp @@ -33,7 +33,7 @@ struct SPICH } void readArray(const uint8_t& address, - uint8_t[] buffer, + uint8_t* buffer, const uint8_t& len) { chipSelect.write(false); @@ -49,14 +49,14 @@ struct SPICH void writeArray(const uint8_t& address, - const uint8_t[] buffer, + const uint8_t* buffer, const uint8_t& len) { chipSelect.write(false); spiHwCH.tx(address); - for(uint8_t i = 0; i < len;i++) { + for(uint8_t i = 0; i < len; i++) { spiHwCH.tx(buffer[i]); }; @@ -66,8 +66,8 @@ struct SPICH private: // hardware resources - Pin chipSelect; - SPI spiHwCH; + Pin& chipSelect; + SPI& spiHwCH; }; #endif // _SPICH_HPP_ diff --git a/main.cpp b/main.cpp index 9e6e9bb..58bf127 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,12 @@ Pin_Raspberry rpin; Pin_PC pcpin; +SPI_dummy spi; + +Pin_PC chipSelectPin; + +SPICH spiCH(chipSelectPin, spi); + template void baa(Pin& p) { @@ -37,6 +43,10 @@ void foo() baa(rpin); baa(pcpin); + + std::cout << "SPI test:" << std::endl; + spiCH.read_write_u8(10); + } int main(int argc, char *argv[]) diff --git a/main.hpp b/main.hpp index 206957a..f35b1a2 100644 --- a/main.hpp +++ b/main.hpp @@ -6,7 +6,11 @@ #include #include "./utils/commandManager.h" #include "./interfaces/pin.hpp" +#include "./interfaces/spi.hpp" +#include "./interfaces/spich.hpp" #include "bsl/csl/raspberry/peripherals/pinRaspberry.hpp" #include "bsl/csl/PC/peripherals/pinPC.hpp" +#include "bsl/csl/PC/peripherals/spiDummy.hpp" + #endif // __MAIN_HPP__ diff --git a/runtest b/runtest new file mode 100755 index 0000000..cfbc972 Binary files /dev/null and b/runtest differ