Skip to content

Commit 5703e6e

Browse files
Add another function to SPI transcieve for slices (ptr + len)
1 parent e168580 commit 5703e6e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Inc/HALAL/Models/SPI/SPI2.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,30 @@ struct SPIDomain {
698698
return check_error_code(error_code);
699699
}
700700

701+
/**
702+
* @brief Sends and receives data over SPI in blocking mode.
703+
*/
704+
template <typename T>
705+
bool transceive(T *tx_data, T *rx_data, size_t count) {
706+
size_t size = count * sizeof(T);
707+
if (size % frame_size != 0) {
708+
ErrorHandler(
709+
"SPI transaction size (%d) not aligned to frame size (%d)",
710+
size,
711+
frame_size
712+
);
713+
return false;
714+
}
715+
auto error_code = HAL_SPI_TransmitReceive(
716+
&spi_instance.hspi,
717+
(uint8_t*)tx_data,
718+
(uint8_t*)rx_data,
719+
size / frame_size,
720+
10
721+
);
722+
return check_error_code(error_code);
723+
}
724+
701725
/**
702726
* @brief Sends and receives a trivially copyable data type over SPI in blocking mode.
703727
*/

0 commit comments

Comments
 (0)