SoftSigReaderInt.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <AP_HAL/utility/RingBuffer.h>
  18. #include <AP_HAL/AP_HAL_Boards.h>
  19. #include "AP_HAL_ChibiOS.h"
  20. #if HAL_USE_EICU == TRUE
  21. #define INPUT_CAPTURE_FREQUENCY 1000000 //capture unit in microseconds
  22. #ifndef SOFTSIG_MAX_SIGNAL_TRANSITIONS
  23. #define SOFTSIG_MAX_SIGNAL_TRANSITIONS 128
  24. #endif
  25. class ChibiOS::SoftSigReaderInt {
  26. public:
  27. SoftSigReaderInt();
  28. /* Do not allow copies */
  29. SoftSigReaderInt(const SoftSigReaderInt &other) = delete;
  30. SoftSigReaderInt &operator=(const SoftSigReaderInt&) = delete;
  31. // get singleton
  32. static SoftSigReaderInt *get_singleton(void)
  33. {
  34. return _singleton;
  35. }
  36. void init(EICUDriver* icu_drv, eicuchannel_t chan);
  37. bool read(uint32_t &widths0, uint32_t &widths1);
  38. private:
  39. // singleton
  40. static SoftSigReaderInt *_singleton;
  41. static void _irq_handler(EICUDriver *eicup, eicuchannel_t channel);
  42. static eicuchannel_t get_pair_channel(eicuchannel_t channel);
  43. typedef struct PACKED {
  44. uint16_t w0;
  45. uint16_t w1;
  46. } pulse_t;
  47. ObjectBuffer<pulse_t> sigbuf{SOFTSIG_MAX_SIGNAL_TRANSITIONS};
  48. EICUConfig icucfg;
  49. EICUChannelConfig channel_config;
  50. EICUChannelConfig aux_channel_config;
  51. EICUDriver* _icu_drv = nullptr;
  52. uint16_t last_value;
  53. };
  54. #endif // HAL_USE_EICU