From c8bb5e6469c1f3b6f319299d2534108f0a6539f5 Mon Sep 17 00:00:00 2001 From: Luiz Ywata Date: Tue, 26 Apr 2016 15:33:22 -0300 Subject: [PATCH] AP_HAL_Linux: RCInput_Raspilot use SPIDevice interface --- libraries/AP_HAL_Linux/RCInput_Raspilot.cpp | 19 +++++++------------ libraries/AP_HAL_Linux/RCInput_Raspilot.h | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/libraries/AP_HAL_Linux/RCInput_Raspilot.cpp b/libraries/AP_HAL_Linux/RCInput_Raspilot.cpp index 3fa6163436..5d2a7a04fb 100644 --- a/libraries/AP_HAL_Linux/RCInput_Raspilot.cpp +++ b/libraries/AP_HAL_Linux/RCInput_Raspilot.cpp @@ -21,14 +21,7 @@ using namespace Linux; void RCInput_Raspilot::init() { - _spi = hal.spi->device(AP_HAL::SPIDevice_RASPIO); - _spi_sem = _spi->get_semaphore(); - - if (_spi_sem == NULL) { - AP_HAL::panic("PANIC: RCIutput_Raspilot did not get " - "valid SPI semaphore!"); - return; // never reached - } + _dev = hal.spi->get_device("raspio"); // start the timer process to read samples hal.scheduler->register_timer_process(FUNCTOR_BIND_MEMBER(&RCInput_Raspilot::_poll_data, void)); @@ -43,7 +36,7 @@ void RCInput_Raspilot::_poll_data(void) _last_timer = AP_HAL::micros(); - if (!_spi_sem->take_nonblocking()) { + if (!_dev->get_semaphore()->take_nonblocking()) { return; } @@ -55,9 +48,11 @@ void RCInput_Raspilot::_poll_data(void) _dma_packet_tx.crc = 0; _dma_packet_tx.crc = crc_packet(&_dma_packet_tx); /* set raspilotio to read reg4 */ - _spi->transaction((uint8_t *)&_dma_packet_tx, (uint8_t *)&_dma_packet_rx, sizeof(_dma_packet_tx)); + _dev->transfer((uint8_t *)&_dma_packet_tx, sizeof(_dma_packet_tx), + (uint8_t *)&_dma_packet_rx, sizeof(_dma_packet_rx)); /* get reg4 data from raspilotio */ - _spi->transaction((uint8_t *)&_dma_packet_tx, (uint8_t *)&_dma_packet_rx, sizeof(_dma_packet_tx)); + _dev->transfer((uint8_t *)&_dma_packet_tx, sizeof(_dma_packet_tx), + (uint8_t *)&_dma_packet_rx, sizeof(_dma_packet_rx)); uint16_t num_values = _dma_packet_rx.regs[0]; uint16_t rc_ok = _dma_packet_rx.regs[1] & (1 << 4); @@ -69,7 +64,7 @@ void RCInput_Raspilot::_poll_data(void) _update_periods(&_dma_packet_rx.regs[6], (uint8_t)num_values); } - _spi_sem->give(); + _dev->get_semaphore()->give(); } #endif // CONFIG_HAL_BOARD_SUBTYPE diff --git a/libraries/AP_HAL_Linux/RCInput_Raspilot.h b/libraries/AP_HAL_Linux/RCInput_Raspilot.h index 2a1c32b193..f967ab3b4a 100644 --- a/libraries/AP_HAL_Linux/RCInput_Raspilot.h +++ b/libraries/AP_HAL_Linux/RCInput_Raspilot.h @@ -2,6 +2,7 @@ #include "AP_HAL_Linux.h" #include "RCInput.h" +#include class Linux::RCInput_Raspilot : public Linux::RCInput { @@ -11,8 +12,7 @@ public: private: uint32_t _last_timer; - AP_HAL::SPIDeviceDriver *_spi; - AP_HAL::Semaphore *_spi_sem; + AP_HAL::OwnPtr _dev; void _poll_data(void); };