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.

68 lines
1.8KB

  1. #ifndef FreqMeasureMultiIMXRT_h
  2. #define FreqMeasureMultiIMXRT_h
  3. #if defined(__IMXRT1062__)
  4. struct freq_pwm_pin_info_struct {
  5. IMXRT_FLEXPWM_t *pflexpwm;
  6. uint8_t module; // 0-3, 0-3
  7. uint8_t channel; // 0=X, 1=A, 2=B
  8. uint8_t muxval; //
  9. uint8_t irq; // which IRQ to use
  10. void (*isr)(); // interrupt handler.
  11. volatile uint32_t *select_input_register; // Which register controls the selection
  12. const uint32_t select_val; // Value for that selection
  13. };
  14. class FreqMeasureMulti
  15. {
  16. public:
  17. bool begin(uint32_t pin);
  18. bool begin(uint32_t pin, uint8_t mode);
  19. uint32_t available(void);
  20. uint32_t read(void);
  21. uint8_t readLevel(void);
  22. static float countToFrequency(uint32_t count);
  23. static float countToNanoseconds(uint32_t count);
  24. void end(void);
  25. private:
  26. static const struct freq_pwm_pin_info_struct freq_pwm_pin_info[];
  27. static FreqMeasureMulti *list[16];
  28. fmultiRecord buffer_value[FREQMEASUREMULTI_BUFFER_LEN];
  29. uint8_t buffer_head;
  30. uint8_t buffer_tail;
  31. IMXRT_FLEXPWM_t *_pflexpwm;
  32. void processChannelISR(uint8_t channel, uint32_t capture, uint8_t edge);
  33. void isr();
  34. uint8_t last_read_level;
  35. uint8_t _pin; // remember the pin number;
  36. uint8_t _mode; // remember the mode we are using.
  37. uint8_t _channel;
  38. FreqMeasureMulti *_next = nullptr; // in case we have multiple ones who are on the same module.
  39. uint32_t _capture_previous[2]; // Not sure yet
  40. uint16_t capture_msw = 0;
  41. static void flexpwm1_0_isr();
  42. static void flexpwm1_1_isr();
  43. static void flexpwm1_2_isr();
  44. static void flexpwm1_3_isr();
  45. static void flexpwm2_0_isr();
  46. static void flexpwm2_1_isr();
  47. static void flexpwm2_2_isr();
  48. static void flexpwm2_3_isr();
  49. static void flexpwm3_0_isr();
  50. static void flexpwm3_1_isr();
  51. static void flexpwm3_3_isr();
  52. static void flexpwm4_0_isr();
  53. static void flexpwm4_1_isr();
  54. static void flexpwm4_2_isr();
  55. };
  56. #endif // IMXRT
  57. #endif