Added fixes to the SPI implementation, removed debugging

This commit is contained in:
Dario 2023-05-23 21:05:31 +01:00
parent 4eb1053ffd
commit 3cf2173433
2 changed files with 34 additions and 18 deletions

View File

@ -15,14 +15,14 @@
namespace sta
{
enum class GpioMode {
GPIO_OUTPUT,
GPIO_INPUT
};
class RaspiGpioPin : public GpioPin
{
public:
enum class GpioMode {
GPIO_OUTPUT,
GPIO_INPUT
};
/**
* @param pin Pin index
* @param mode The mode of the GPIO pin. Either INPUT or OUTPUT

View File

@ -68,8 +68,15 @@ namespace sta
spi_message[0].tx_buf = (unsigned long)&value;
spi_message[0].len = 1;
// For some reasons, this line makes the SPI interface work for the BMP388.
spi_message[0].cs_change = 1;
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
if (result < 0) {
printf("Sending failed with error '%s'! \n", strerror(errno));
}
STA_DEBUG_IOCTL_SEND(result);
}
@ -83,6 +90,7 @@ namespace sta
memset(spi_message, 0, sizeof(spi_message));
spi_message[0].tx_buf = (unsigned long)&value;
spi_message[0].len = 1;
spi_message[0].cs_change = 1;
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
@ -102,14 +110,12 @@ namespace sta
spi_message[0].tx_buf = (unsigned long)buffer;
spi_message[0].len = size;
printf("Sending ");
for (int i = 0; i < size; i++) {
printf("%x, ", buffer[i]);
}
printf("\n");
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
if (result < 0) {
printf("Sending failed with error '%s'! \n", strerror(errno));
}
STA_DEBUG_IOCTL_SEND(result);
}
@ -131,7 +137,7 @@ namespace sta
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
if (result == -1) {
if (result < 0) {
printf("Sending failed with error '%s'! \n", strerror(errno));
}
@ -154,12 +160,6 @@ namespace sta
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
printf("Receiving ");
for (int i = 0; i < size; i++) {
printf("%x, ", buffer[i]);
}
printf("\n");
STA_DEBUG_IOCTL_SEND(result);
}
@ -226,18 +226,34 @@ namespace sta
int result = ioctl(spifd_, SPI_IOC_WR_MODE, &mode_);
STA_DEBUG_IOCTL_WRITE(result);
if (result < 0) {
printf("Update mode failed with error '%s'! \n", strerror(errno));
}
// Set the word size. According to the documentation "the value zero signifies eight bits".
result = ioctl(spifd_, SPI_IOC_WR_BITS_PER_WORD, &dataSize_);
STA_DEBUG_IOCTL_WRITE(result);
if (result < 0) {
printf("Update dataSize failed with error '%s'! \n", strerror(errno));
}
// Set the bit order. According to the documentation zero means MSB first, everything else means LSB first.
result = ioctl(spifd_, SPI_IOC_WR_LSB_FIRST, &bitOrder_);
STA_DEBUG_IOCTL_WRITE(result);
if (result < 0) {
printf("Update endianness failed with error '%s'! \n", strerror(errno));
}
// Set the maximum clock speed.
result = ioctl(spifd_, SPI_IOC_WR_MAX_SPEED_HZ, &clkSpeed_);
STA_DEBUG_IOCTL_WRITE(result);
if (result < 0) {
printf("Update clock speed failed with error '%s'! \n", strerror(errno));
}
#if defined(DEBUG)
uint8_t r_mode = 0;
get_setting(SPI_IOC_RD_MODE, &r_mode);