diff --git a/include/sta/devices/stm32/can.hpp b/include/sta/devices/stm32/can.hpp index cd75304..598b2bd 100644 --- a/include/sta/devices/stm32/can.hpp +++ b/include/sta/devices/stm32/can.hpp @@ -80,7 +80,7 @@ namespace sta void disableFilter(uint8_t idx) override; void clearFilters() override; - // TODO + // Return pending RX FIFOs as iterable container CanPendingRxFifos getPendingRxFifos() override; // Const getters diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 66b07ac..7a5cd59 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -170,13 +170,22 @@ namespace sta } CanPendingRxFifos STM32CanController::getPendingRxFifos(){ - CanPendingRxFifos pendingFifos(42, 3); - // Example implementation: - //pendingFifos.fifo0Pending = HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0; - //pendingFifos.fifo1Pending = HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0; - return pendingFifos; + uint32_t rxFlags = 0; + + // Conditions to set the least significant bits + if (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0) { + // Set the first least significant bit + rxFlags |= 0x01; // 0x01 is 00000001 in binary (LSB set, others cleared) + } + + if (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0) { + // Set the second least significant bit + rxFlags |= 0x02; // 0x02 is 00000010 in binary (2nd LSB set, others cleared) + } + + return CanPendingRxFifos(rxFlags, MAX_FIFO_COUNT);; } uint8_t STM32CanController::maxFilterCount() const{