RCOutput_Tap.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2016 PX4 Development Team. All rights reserved.
  3. * Copyright (C) 2017 Intel Corporation. All rights reserved.
  4. *
  5. * This file is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This file is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. * Implementation of TAP UART ESCs. Used the implementation from PX4 as a base
  20. * which is BSD-licensed:
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * 1. Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * 3. Neither the name PX4 nor the names of its contributors may be
  33. * used to endorse or promote products derived from this software
  34. * without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  40. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  41. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  42. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  43. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  44. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  46. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  47. * POSSIBILITY OF SUCH DAMAGE.
  48. */
  49. #pragma once
  50. #include <AP_HAL/Util.h>
  51. namespace ap {
  52. struct EscPacket;
  53. class RCOutput_Tap : public AP_HAL::RCOutput {
  54. public:
  55. void init() override;
  56. void set_freq(uint32_t chmask, uint16_t freq_hz) override;
  57. uint16_t get_freq(uint8_t ch) override;
  58. void enable_ch(uint8_t ch) override;
  59. void disable_ch(uint8_t ch) override;
  60. void write(uint8_t ch, uint16_t period_us) override;
  61. uint16_t read(uint8_t ch) override;
  62. void read(uint16_t *period_us, uint8_t len) override;
  63. void set_esc_scaling(uint16_t min_pwm, uint16_t max_pwm) override {
  64. _esc_pwm_min = min_pwm;
  65. _esc_pwm_max = max_pwm;
  66. }
  67. void cork() override;
  68. void push() override;
  69. private:
  70. static uint8_t _crc8_esc(uint8_t *p, uint8_t len);
  71. static uint8_t _crc_packet(EscPacket &p);
  72. static const uint8_t MAX_MOTORS = 4;
  73. int _send_packet(EscPacket &p);
  74. bool _uart_open();
  75. bool _uart_set_speed(int speed);
  76. void _uart_close();
  77. AP_HAL::Util::perf_counter_t _perf_rcout;
  78. uint8_t _enabled_channels;
  79. bool _corking;
  80. bool _led_on;
  81. uint8_t _channels_count = MAX_MOTORS;
  82. uint16_t _period[MAX_MOTORS];
  83. uint16_t _esc_pwm_min;
  84. uint16_t _esc_pwm_max;
  85. uint32_t _last_led_update_msec;
  86. int _uart_fd = -1;
  87. };
  88. }