RCOutput_Disco.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include "AP_HAL_Linux.h"
  3. #include "RCOutput_Sysfs.h"
  4. #include "RCOutput_Bebop.h"
  5. namespace Linux {
  6. class RCOutput_Disco : public AP_HAL::RCOutput {
  7. public:
  8. RCOutput_Disco(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
  9. ~RCOutput_Disco() {}
  10. static RCOutput_Bebop *from(AP_HAL::RCOutput *rcoutput)
  11. {
  12. // this is used by AP_BattMonitor_Bebop to get obs data. We
  13. // need to return the Bebop output, not ourselves
  14. RCOutput_Disco *d = static_cast<RCOutput_Disco *>(rcoutput);
  15. return static_cast<RCOutput_Bebop *>(&d->bebop_out);
  16. }
  17. void init() override;
  18. void set_freq(uint32_t chmask, uint16_t freq_hz) override;
  19. uint16_t get_freq(uint8_t ch) override;
  20. void enable_ch(uint8_t ch) override;
  21. void disable_ch(uint8_t ch) override;
  22. void write(uint8_t ch, uint16_t period_us) override;
  23. uint16_t read(uint8_t ch) override;
  24. void read(uint16_t *period_us, uint8_t len) override;
  25. void cork() override;
  26. void push() override;
  27. void set_esc_scaling(uint16_t min_pwm, uint16_t max_pwm) override;
  28. private:
  29. // Disco RC output combines methods from Sysfs and Bebop
  30. RCOutput_Bebop bebop_out;
  31. RCOutput_Sysfs sysfs_out{0, 1, 6};
  32. /*
  33. use a table to provide the mapping to channel numbers in each
  34. backend
  35. */
  36. typedef struct {
  37. RCOutput &output;
  38. uint8_t channel;
  39. } output_table_t;
  40. const output_table_t output_table[7] = {
  41. /*
  42. servo rail pin numbers are from left to right when looking
  43. at the CHUCK from the back, so pin1 on the servo rail is
  44. closest to the first 'C' in 'C.H.U.C.K' on the case
  45. */
  46. { sysfs_out, 3 }, // chan1, servo rail pin 1
  47. { sysfs_out, 2 }, // chan2, servo rail pin 6
  48. { bebop_out, 0 }, // I2C motor output
  49. { sysfs_out, 4 }, // chan4, servo rail pin 2
  50. { sysfs_out, 1 }, // chan5, servo rail pin 5
  51. { sysfs_out, 5 }, // chan6, servo rail pin 3
  52. { sysfs_out, 0 }, // chan7, servo rail pin 4
  53. };
  54. };
  55. }