added spi example in foo function

interrupts
polymurph 4 years ago
parent adfb08bc3d
commit e8c353bc59

@ -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"
}
}

@ -0,0 +1,28 @@
#ifndef _SPIDUMMY_HPP_
#define _SPIDUMMY_HPP_
#include <iostream>
//#include "../../interfaces/spi.hpp"
#include <stdint.h>
struct SPI_dummy : SPI<SPI_dummy>
{
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_

@ -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<DerivedPin> chipSelect;
SPI<DerivedSPI> spiHwCH;
Pin<DerivedPin>& chipSelect;
SPI<DerivedSPI>& spiHwCH;
};
#endif // _SPICH_HPP_

@ -18,6 +18,12 @@ Pin_Raspberry rpin;
Pin_PC pcpin;
SPI_dummy spi;
Pin_PC chipSelectPin;
SPICH<Pin_PC, SPI_dummy> spiCH(chipSelectPin, spi);
template<typename derivation>
void baa(Pin<derivation>& 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[])

@ -6,7 +6,11 @@
#include <unistd.h>
#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__

Binary file not shown.
Loading…
Cancel
Save