spi com if basic verification complete
This commit is contained in:
@ -40,6 +40,7 @@ void MGMHandlerLIS3MDL::doStartUp() {
|
||||
/* Set up cached registers which will be used to configure the MGM. */
|
||||
if(commandExecuted) {
|
||||
commandExecuted = false;
|
||||
/* Replace _MODE_TO_ON with MODE_NORMAL to jump to normal mode quickly */
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
break;
|
||||
@ -283,7 +284,8 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
if(debugDivider->check()) {
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue<< " <EFBFBD>C" << std::endl;
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " \xC2\xB0" << "C" <<
|
||||
std::endl;
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result = dataset.read();
|
||||
@ -442,77 +444,5 @@ ReturnValue_t MGMHandlerLIS3MDL::initializeLocalDataPool(
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
#include <devices/gpioIds.h>
|
||||
#include <linux/spi/spiDefinitions.h>
|
||||
#include <linux/utility/Utility.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <bitset>
|
||||
|
||||
void MGMHandlerLIS3MDL::performOperationHook() {
|
||||
|
||||
/* Adapt accordingly */
|
||||
// if(lis3Id != mgm0Lis3ChipSelect and lis3Id != mgm2Lis3mdlChipSelect) {
|
||||
// sif::warning << "SpiTestClass::performLis3MdlTest: Invalid MGM ID!" << std::endl;
|
||||
// }
|
||||
gpioId_t currentGpioId = gpioIds::MGM_0_LIS3_CS;
|
||||
uint8_t chipSelectPin = 0;
|
||||
uint8_t whoAmIReg = 0b0000'1111;
|
||||
uint8_t reg = whoAmIReg;
|
||||
|
||||
uint32_t spiSpeed = 3'900'000;
|
||||
spi::SpiMode spiMode = spi::SpiMode::MODE_3;
|
||||
#ifdef RASPBERRY_PI
|
||||
std::string deviceName = "/dev/spidev0.0";
|
||||
#else
|
||||
std::string deviceName = "placeholder";
|
||||
#endif
|
||||
int fileDescriptor = 0;
|
||||
uint8_t recvBuffer [16];
|
||||
uint8_t sendBuffer [16];
|
||||
|
||||
utility::UnixFileHelper fileHelper(deviceName, &fileDescriptor, O_RDWR,
|
||||
"SpiComIF::initializeInterface: ");
|
||||
if(fileHelper.getOpenResult()) {
|
||||
sif::error << "SpiTestClass::performLis3Mdl3100Test: File descriptor could not be opened!"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
int retval = ioctl(fileDescriptor, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&spiMode));
|
||||
if(retval != 0) {
|
||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!");
|
||||
}
|
||||
|
||||
retval = ioctl(fileDescriptor, SPI_IOC_WR_MAX_SPEED_HZ, &spiSpeed);
|
||||
if(retval != 0) {
|
||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI speed failed!");
|
||||
}
|
||||
GpioIF* gpioIF = objectManager->get<GpioIF>(objects::GPIO_IF);
|
||||
uint8_t STM_READ_MASK = 0b1000'0000;
|
||||
struct spi_ioc_transfer spiTransferStruct = {};
|
||||
reg |= STM_READ_MASK;
|
||||
spiTransferStruct.len = 2;
|
||||
sendBuffer[0] = reg;
|
||||
sendBuffer[1] = 0;
|
||||
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(recvBuffer);
|
||||
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(sendBuffer);
|
||||
//spiTransferStruct.bits_per_word = 8;
|
||||
//spiTransferStruct.speed_hz = 3'900'000;
|
||||
|
||||
if(gpioIF != nullptr and currentGpioId != gpio::NO_GPIO) {
|
||||
gpioIF->pullLow(currentGpioId);
|
||||
}
|
||||
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if(retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::readStmRegiste: Read failed");
|
||||
}
|
||||
if(gpioIF != nullptr and currentGpioId != gpio::NO_GPIO) {
|
||||
gpioIF->pullHigh(currentGpioId);
|
||||
}
|
||||
|
||||
sif::info << "SpiTestClass::performLis3MdlTest: WHO AM I Regiter 0b" <<
|
||||
std::bitset<8>(recvBuffer[1]) << std::endl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user