SPIDevice.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2015-2016 Intel Corporation. All rights reserved.
  3. *
  4. * This file is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This file is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * See the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include <inttypes.h>
  19. #include <AP_HAL/HAL.h>
  20. #include <AP_HAL/SPIDevice.h>
  21. #include "Semaphores.h"
  22. namespace Empty {
  23. class SPIDevice : public AP_HAL::SPIDevice {
  24. public:
  25. SPIDevice()
  26. {
  27. }
  28. virtual ~SPIDevice() { }
  29. /* AP_HAL::Device implementation */
  30. /* See AP_HAL::Device::set_speed() */
  31. bool set_speed(AP_HAL::Device::Speed speed) override
  32. {
  33. return true;
  34. }
  35. /* See AP_HAL::Device::transfer() */
  36. bool transfer(const uint8_t *send, uint32_t send_len,
  37. uint8_t *recv, uint32_t recv_len) override
  38. {
  39. return true;
  40. }
  41. /* See AP_HAL::SPIDevice::transfer_fullduplex() */
  42. bool transfer_fullduplex(const uint8_t *send, uint8_t *recv,
  43. uint32_t len) override
  44. {
  45. return true;
  46. }
  47. /* See AP_HAL::Device::get_semaphore() */
  48. AP_HAL::Semaphore *get_semaphore() override
  49. {
  50. return &_semaphore;
  51. }
  52. /* See AP_HAL::Device::register_periodic_callback() */
  53. AP_HAL::Device::PeriodicHandle register_periodic_callback(
  54. uint32_t period_usec, AP_HAL::Device::PeriodicCb) override
  55. {
  56. return nullptr;
  57. }
  58. private:
  59. Semaphore _semaphore;
  60. };
  61. class SPIDeviceManager : public AP_HAL::SPIDeviceManager {
  62. public:
  63. SPIDeviceManager() { }
  64. AP_HAL::OwnPtr<AP_HAL::SPIDevice> get_device(const char *name) override
  65. {
  66. return AP_HAL::OwnPtr<AP_HAL::SPIDevice>(new SPIDevice());
  67. }
  68. };
  69. }