AP_RCProtocol_IBUS.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. */
  16. #pragma once
  17. #define IBUS_FRAME_SIZE 32
  18. #define IBUS_INPUT_CHANNELS 14
  19. #include "AP_RCProtocol.h"
  20. #include "SoftSerial.h"
  21. class AP_RCProtocol_IBUS : public AP_RCProtocol_Backend
  22. {
  23. public:
  24. AP_RCProtocol_IBUS(AP_RCProtocol &_frontend);
  25. void process_pulse(uint32_t width_s0, uint32_t width_s1) override;
  26. void process_byte(uint8_t byte, uint32_t baudrate) override;
  27. private:
  28. void _process_byte(uint32_t timestamp_us, uint8_t byte);
  29. bool ibus_decode(const uint8_t frame[IBUS_FRAME_SIZE], uint16_t *values, bool *ibus_failsafe);
  30. SoftSerial ss{115200, SoftSerial::SERIAL_CONFIG_8N1};
  31. struct {
  32. uint8_t buf[IBUS_FRAME_SIZE];
  33. uint8_t ofs;
  34. uint32_t last_byte_us;
  35. } byte_input;
  36. };