HAL.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. class AP_Param;
  3. #include "AP_HAL_Namespace.h"
  4. #include "AnalogIn.h"
  5. #include "GPIO.h"
  6. #include "RCInput.h"
  7. #include "RCOutput.h"
  8. #include "SPIDevice.h"
  9. #include "Storage.h"
  10. #include "UARTDriver.h"
  11. #include "system.h"
  12. #include "OpticalFlow.h"
  13. #if HAL_WITH_UAVCAN
  14. #include "CAN.h"
  15. #endif
  16. class AP_HAL::HAL {
  17. public:
  18. HAL(AP_HAL::UARTDriver* _uartA, // console
  19. AP_HAL::UARTDriver* _uartB, // 1st GPS
  20. AP_HAL::UARTDriver* _uartC, // telem1
  21. AP_HAL::UARTDriver* _uartD, // telem2
  22. AP_HAL::UARTDriver* _uartE, // 2nd GPS
  23. AP_HAL::UARTDriver* _uartF, // extra1
  24. AP_HAL::UARTDriver* _uartG, // extra2
  25. AP_HAL::UARTDriver* _uartH, // extra3
  26. AP_HAL::I2CDeviceManager* _i2c_mgr,
  27. AP_HAL::SPIDeviceManager* _spi,
  28. AP_HAL::AnalogIn* _analogin,
  29. AP_HAL::Storage* _storage,
  30. AP_HAL::UARTDriver* _console,
  31. AP_HAL::GPIO* _gpio,
  32. AP_HAL::RCInput* _rcin,
  33. AP_HAL::RCOutput* _rcout,
  34. AP_HAL::Scheduler* _scheduler,
  35. AP_HAL::Util* _util,
  36. AP_HAL::OpticalFlow *_opticalflow,
  37. AP_HAL::Flash *_flash,
  38. #if HAL_WITH_UAVCAN
  39. AP_HAL::CANManager* _can_mgr[MAX_NUMBER_OF_CAN_DRIVERS])
  40. #else
  41. AP_HAL::CANManager** _can_mgr)
  42. #endif
  43. :
  44. uartA(_uartA),
  45. uartB(_uartB),
  46. uartC(_uartC),
  47. uartD(_uartD),
  48. uartE(_uartE),
  49. uartF(_uartF),
  50. uartG(_uartG),
  51. uartH(_uartH),
  52. i2c_mgr(_i2c_mgr),
  53. spi(_spi),
  54. analogin(_analogin),
  55. storage(_storage),
  56. console(_console),
  57. gpio(_gpio),
  58. rcin(_rcin),
  59. rcout(_rcout),
  60. scheduler(_scheduler),
  61. util(_util),
  62. opticalflow(_opticalflow),
  63. flash(_flash)
  64. {
  65. #if HAL_WITH_UAVCAN
  66. if (_can_mgr == nullptr) {
  67. for (uint8_t i = 0; i < MAX_NUMBER_OF_CAN_DRIVERS; i++)
  68. can_mgr[i] = nullptr;
  69. } else {
  70. for (uint8_t i = 0; i < MAX_NUMBER_OF_CAN_DRIVERS; i++)
  71. can_mgr[i] = _can_mgr[i];
  72. }
  73. #endif
  74. AP_HAL::init();
  75. }
  76. struct Callbacks {
  77. virtual void setup() = 0;
  78. virtual void loop() = 0;
  79. };
  80. struct FunCallbacks : public Callbacks {
  81. FunCallbacks(void (*setup_fun)(void), void (*loop_fun)(void));
  82. void setup() override { _setup(); }
  83. void loop() override { _loop(); }
  84. private:
  85. void (*_setup)(void);
  86. void (*_loop)(void);
  87. };
  88. virtual void run(int argc, char * const argv[], Callbacks* callbacks) const = 0;
  89. AP_HAL::UARTDriver* uartA;
  90. AP_HAL::UARTDriver* uartB;
  91. AP_HAL::UARTDriver* uartC;
  92. AP_HAL::UARTDriver* uartD;
  93. AP_HAL::UARTDriver* uartE;
  94. AP_HAL::UARTDriver* uartF;
  95. AP_HAL::UARTDriver* uartG;
  96. AP_HAL::UARTDriver* uartH;
  97. AP_HAL::I2CDeviceManager* i2c_mgr;
  98. AP_HAL::SPIDeviceManager* spi;
  99. AP_HAL::AnalogIn* analogin;
  100. AP_HAL::Storage* storage;
  101. AP_HAL::UARTDriver* console;
  102. AP_HAL::GPIO* gpio;
  103. AP_HAL::RCInput* rcin;
  104. AP_HAL::RCOutput* rcout;
  105. AP_HAL::Scheduler* scheduler;
  106. AP_HAL::Util *util;
  107. AP_HAL::OpticalFlow *opticalflow;
  108. AP_HAL::Flash *flash;
  109. #if HAL_WITH_UAVCAN
  110. AP_HAL::CANManager* can_mgr[MAX_NUMBER_OF_CAN_DRIVERS];
  111. #else
  112. AP_HAL::CANManager** can_mgr;
  113. #endif
  114. };