RmtDriver4.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /********************************************************************************
  2. * https://github.com/RoboticsBrno/SmartLeds
  3. *
  4. * MIT License
  5. *
  6. * Copyright (c) 2017 RoboticsBrno (RobotikaBrno)
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all
  16. * copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. *******************************************************************************/
  26. #pragma once
  27. #include "RmtDriver.h"
  28. #if !SMARTLEDS_NEW_RMT_DRIVER
  29. #include "Color.h"
  30. #include <driver/rmt.h>
  31. #include <freertos/FreeRTOS.h>
  32. #include <freertos/semphr.h>
  33. namespace detail {
  34. constexpr const int CHANNEL_COUNT = RMT_CHANNEL_MAX;
  35. class RmtDriver {
  36. public:
  37. RmtDriver(const LedType& timing, int count, int pin, int channel_num, SemaphoreHandle_t finishedFlag);
  38. RmtDriver(const RmtDriver&) = delete;
  39. esp_err_t init();
  40. esp_err_t registerIsr(bool isFirstRegisteredChannel);
  41. esp_err_t unregisterIsr();
  42. esp_err_t transmit(const Rgb* buffer);
  43. private:
  44. static void IRAM_ATTR txEndCallback(rmt_channel_t channel, void* arg);
  45. static void IRAM_ATTR translateSample(const void* src, rmt_item32_t* dest, size_t src_size,
  46. size_t wanted_rmt_items_num, size_t* out_consumed_src_bytes, size_t* out_used_rmt_items);
  47. const LedType& _timing;
  48. int _count;
  49. gpio_num_t _pin;
  50. SemaphoreHandle_t _finishedFlag;
  51. rmt_channel_t _channel;
  52. rmt_item32_t _bitToRmt[2];
  53. size_t _translatorSourceOffset;
  54. };
  55. };
  56. #endif // !SMARTLEDS_NEW_RMT_DRIVER