fsfw-example-stm32h7-freertos/bsp_stm32h7_freertos/boardtest/SpiTest.cpp

22 lines
822 B
C++
Raw Normal View History

2021-10-27 17:09:41 +02:00
#include "SpiTest.h"
2021-10-27 18:38:31 +02:00
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
2021-10-27 17:09:41 +02:00
2021-10-27 18:38:31 +02:00
SpiTest::SpiTest(SpiComIF &spiComIF):
spiComIF(spiComIF), spiCookie(TEST_ADDRESS, spi::SpiBus::SPI_1,
2021-10-27 17:35:42 +02:00
spi::TransferModes::POLLING, &mspCfg, 1000000, spi::SpiModes::MODE_0, 32) {
2021-10-27 18:38:31 +02:00
stm32h7::h743zi::standardPollingCfg(mspCfg);
2021-10-27 17:35:42 +02:00
spiComIF.initializeInterface(&spiCookie);
2021-10-27 17:09:41 +02:00
}
2021-10-27 18:38:31 +02:00
ReturnValue_t SpiTest::performOperation(uint8_t opCode) {
std::array<uint8_t, 3> dummyData = {0x01, 0x02, 0x03};
ReturnValue_t result = spiComIF.sendMessage(&spiCookie, dummyData.data(), dummyData.size());
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
std::array<uint8_t, 3> recBuf;
uint8_t* recPtr = recBuf.data();
size_t readLen = 0;
return spiComIF.readReceivedMessage(&spiCookie, &recPtr, &readLen);
}