converted files to cpp

This commit is contained in:
2021-06-05 13:29:43 +02:00
parent be88bf1d50
commit 01d3bc2568
12 changed files with 245 additions and 133 deletions

View File

@ -27,18 +27,22 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf
spiHandle(spiHandle) {
transferMode = transferMode_;
if(transferMode == spi::TransferModes::DMA) {
set_dma_handles(&txDmaHandle, &rxDmaHandle);
set_spi_msp_functions(&hal_spi_msp_init_dma, spiHandle, &hal_spi_msp_deinit_dma, spiHandle);
spi::setDmaHandles(&txDmaHandle, &rxDmaHandle);
spi::setSpiMspFunctions(&spi::halMspInitDma, spiHandle,
&spi::halMspDeinitDma, spiHandle);
}
else if(transferMode == spi::TransferModes::INTERRUPT) {
set_spi_msp_functions(&hal_spi_msp_init_interrupt, spiHandle,
&hal_spi_msp_deinit_interrupt, spiHandle);
spi::setSpiMspFunctions(&spi::halMspInitInterrupt, spiHandle,
&spi::halMspDeinitInterrupt, spiHandle);
}
else if(transferMode == spi::TransferModes::POLLING) {
set_spi_msp_functions(&hal_spi_msp_init_polling, spiHandle,
&hal_spi_msp_deinit_polling, spiHandle);
spi::setSpiMspFunctions(&spi::halMspInitPolling, spiHandle,
&spi::halMspDeinitPolling, spiHandle);
}
spi::assignTransferRxTxCompleteCallback(&spiTransferCompleteCallback, nullptr);
spi::assignTransferErrorCallback(&spiTransferErrorCallback, nullptr);
GPIO_InitTypeDef chipSelect = {};
__HAL_RCC_GPIOD_CLK_ENABLE();
chipSelect.Pin = GPIO_PIN_14;
@ -502,14 +506,8 @@ void GyroL3GD20H::handleSensorReadout() {
sif::printInfo("Gyro Z: %f\n", gyroZ);
}
/**
* @brief TxRx Transfer completed callback.
* @param hspi: SPI handle
* @note This example shows a simple way to report end of DMA TxRx transfer, and
* you can add your own implementation.
* @retval None
*/
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args) {
transferState = TransferStates::SUCCESS;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
if(GyroL3GD20H::transferMode == spi::TransferModes::DMA) {
@ -526,6 +524,6 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
* add your own implementation.
* @retval None
*/
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
void GyroL3GD20H::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args) {
transferState = TransferStates::FAILURE;
}