PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AnalogBufferDMA.h 3.1KB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Teensy 3.x, LC, 4.0 ADC library
  2. * https://github.com/pedvide/ADC
  3. * Copyright (c) 2020 Pedro Villanueva
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. #ifdef ADC_USE_DMA
  26. #ifndef ANALOGBUFFERDMA_H
  27. #define ANALOGBUFFERDMA_H
  28. #include "DMAChannel.h"
  29. #include "ADC.h"
  30. // lets wrap some of our Dmasettings stuff into helper class
  31. class AnalogBufferDMA
  32. {
  33. // keep our settings and the like:
  34. public: // At least temporary to play with dma settings.
  35. #ifndef KINETISL
  36. DMASetting _dmasettings_adc[2];
  37. #endif
  38. DMAChannel _dmachannel_adc;
  39. static AnalogBufferDMA *_activeObjectPerADC[2];
  40. static void adc_0_dmaISR();
  41. static void adc_1_dmaISR();
  42. void processADC_DMAISR();
  43. public:
  44. AnalogBufferDMA(volatile uint16_t *buffer1, uint16_t buffer1_count,
  45. volatile uint16_t *buffer2 = nullptr, uint16_t buffer2_count = 0) : _buffer1(buffer1), _buffer1_count(buffer1_count), _buffer2(buffer2), _buffer2_count(buffer2_count){};
  46. void init(ADC *adc, int8_t adc_num = -1);
  47. void stopOnCompletion(bool stop_on_complete);
  48. inline bool stopOnCompletion(void) { return _stop_on_completion; }
  49. bool clearCompletion();
  50. inline volatile uint16_t *bufferLastISRFilled() { return (!_buffer2 || (_interrupt_count & 1)) ? _buffer1 : _buffer2; }
  51. inline uint16_t bufferCountLastISRFilled() { return (!_buffer2 || (_interrupt_count & 1)) ? _buffer1_count : _buffer2_count; }
  52. inline uint32_t interruptCount() { return _interrupt_count; }
  53. inline uint32_t interruptDeltaTime() { return _interrupt_delta_time; }
  54. inline bool interrupted() { return _interrupt_delta_time != 0; }
  55. inline void clearInterrupt() { _interrupt_delta_time = 0; }
  56. inline void userData(uint32_t new_data) { _user_data = new_data; }
  57. inline uint32_t userData(void) { return _user_data; }
  58. protected:
  59. volatile uint32_t _interrupt_count = 0;
  60. volatile uint32_t _interrupt_delta_time;
  61. volatile uint32_t _last_isr_time;
  62. volatile uint16_t *_buffer1;
  63. uint16_t _buffer1_count;
  64. volatile uint16_t *_buffer2;
  65. uint16_t _buffer2_count;
  66. uint32_t _user_data = 0;
  67. bool _stop_on_completion = false;
  68. };
  69. #endif
  70. #endif // ADC_USE_DMA