mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
Added fixes to the SPI implementation, removed debugging
This commit is contained in:
parent
4eb1053ffd
commit
3cf2173433
@ -15,14 +15,14 @@
|
|||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
|
enum class GpioMode {
|
||||||
|
GPIO_OUTPUT,
|
||||||
|
GPIO_INPUT
|
||||||
|
};
|
||||||
|
|
||||||
class RaspiGpioPin : public GpioPin
|
class RaspiGpioPin : public GpioPin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class GpioMode {
|
|
||||||
GPIO_OUTPUT,
|
|
||||||
GPIO_INPUT
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param pin Pin index
|
* @param pin Pin index
|
||||||
* @param mode The mode of the GPIO pin. Either INPUT or OUTPUT
|
* @param mode The mode of the GPIO pin. Either INPUT or OUTPUT
|
||||||
|
@ -68,8 +68,15 @@ namespace sta
|
|||||||
spi_message[0].tx_buf = (unsigned long)&value;
|
spi_message[0].tx_buf = (unsigned long)&value;
|
||||||
spi_message[0].len = 1;
|
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);
|
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);
|
STA_DEBUG_IOCTL_SEND(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +90,7 @@ namespace sta
|
|||||||
memset(spi_message, 0, sizeof(spi_message));
|
memset(spi_message, 0, sizeof(spi_message));
|
||||||
spi_message[0].tx_buf = (unsigned long)&value;
|
spi_message[0].tx_buf = (unsigned long)&value;
|
||||||
spi_message[0].len = 1;
|
spi_message[0].len = 1;
|
||||||
|
spi_message[0].cs_change = 1;
|
||||||
|
|
||||||
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
|
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].tx_buf = (unsigned long)buffer;
|
||||||
spi_message[0].len = size;
|
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);
|
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);
|
STA_DEBUG_IOCTL_SEND(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +137,7 @@ namespace sta
|
|||||||
|
|
||||||
int result = ioctl(spifd_, SPI_IOC_MESSAGE(1), spi_message);
|
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));
|
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);
|
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);
|
STA_DEBUG_IOCTL_SEND(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,18 +226,34 @@ namespace sta
|
|||||||
int result = ioctl(spifd_, SPI_IOC_WR_MODE, &mode_);
|
int result = ioctl(spifd_, SPI_IOC_WR_MODE, &mode_);
|
||||||
STA_DEBUG_IOCTL_WRITE(result);
|
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".
|
// Set the word size. According to the documentation "the value zero signifies eight bits".
|
||||||
result = ioctl(spifd_, SPI_IOC_WR_BITS_PER_WORD, &dataSize_);
|
result = ioctl(spifd_, SPI_IOC_WR_BITS_PER_WORD, &dataSize_);
|
||||||
STA_DEBUG_IOCTL_WRITE(result);
|
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.
|
// 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_);
|
result = ioctl(spifd_, SPI_IOC_WR_LSB_FIRST, &bitOrder_);
|
||||||
STA_DEBUG_IOCTL_WRITE(result);
|
STA_DEBUG_IOCTL_WRITE(result);
|
||||||
|
|
||||||
|
if (result < 0) {
|
||||||
|
printf("Update endianness failed with error '%s'! \n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
// Set the maximum clock speed.
|
// Set the maximum clock speed.
|
||||||
result = ioctl(spifd_, SPI_IOC_WR_MAX_SPEED_HZ, &clkSpeed_);
|
result = ioctl(spifd_, SPI_IOC_WR_MAX_SPEED_HZ, &clkSpeed_);
|
||||||
STA_DEBUG_IOCTL_WRITE(result);
|
STA_DEBUG_IOCTL_WRITE(result);
|
||||||
|
|
||||||
|
if (result < 0) {
|
||||||
|
printf("Update clock speed failed with error '%s'! \n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
uint8_t r_mode = 0;
|
uint8_t r_mode = 0;
|
||||||
get_setting(SPI_IOC_RD_MODE, &r_mode);
|
get_setting(SPI_IOC_RD_MODE, &r_mode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user