PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3KB

  1. #ifndef FreqMeasureMulti_h
  2. #define FreqMeasureMulti_h
  3. #include <Arduino.h>
  4. #define FREQMEASUREMULTI_BUFFER_LEN 24
  5. // capture modes
  6. #define FREQMEASUREMULTI_RAISING 1
  7. #define FREQMEASUREMULTI_FALLING 2
  8. #define FREQMEASUREMULTI_INTERLEAVE 3
  9. #define FREQMEASUREMULTI_SPACE_ONLY 5
  10. #define FREQMEASUREMULTI_MARK_ONLY 6
  11. #define FREQMEASUREMULTI_ALTERNATE 7
  12. // result constants for fmultiRecord.level
  13. #define LEVEL_SPACE_ONLY 0
  14. #define LEVEL_SPACE_MARK 1
  15. #define LEVEL_MARK_SPACE 2
  16. #define LEVEL_MARK_ONLY 3
  17. #define LEVEL_UNDEFINED 255
  18. typedef struct {
  19. uint8_t level;
  20. uint32_t count;
  21. } fmultiRecord;
  22. #if defined(__IMXRT1062__)
  23. #include "FreqMeasureMultiIMXRT.h"
  24. #else
  25. // Teensy 3.x and LC
  26. class FreqMeasureMulti
  27. {
  28. public:
  29. bool begin(uint32_t pin);
  30. bool begin(uint32_t pin, uint8_t mode);
  31. uint32_t available(void);
  32. uint32_t read(void);
  33. uint8_t readLevel(void);
  34. static float countToFrequency(uint32_t count);
  35. static float countToNanoseconds(uint32_t count);
  36. void end(void);
  37. private:
  38. fmultiRecord buffer_value[FREQMEASUREMULTI_BUFFER_LEN];
  39. uint8_t buffer_head;
  40. uint8_t buffer_tail;
  41. friend void ftm0_isr(void);
  42. void isr(bool inc);
  43. uint8_t channel;
  44. uint8_t last_read_level;
  45. uint32_t raiscap_previous;
  46. uint32_t fallcap_previous;
  47. bool act_on_fall, act_on_raise, read_diff;
  48. bool next_is_falling;
  49. };
  50. #endif //defined(__IMXRT1062__)
  51. #endif