PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

FreqMeasureMulti.h 1.3KB

3 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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