dac.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <string.h>
  15. #include "esp_log.h"
  16. #include "esp_err.h"
  17. #include "freertos/FreeRTOS.h"
  18. #include "freertos/semphr.h"
  19. #include "freertos/timers.h"
  20. #include "driver/rtc_io.h"
  21. #include "driver/dac.h"
  22. #include "soc/dac_periph.h"
  23. #include "hal/dac_hal.h"
  24. extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
  25. #define DAC_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock)
  26. #define DAC_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock)
  27. /*---------------------------------------------------------------
  28. Digital controller setting
  29. ---------------------------------------------------------------*/
  30. esp_err_t dac_i2s_enable(void)
  31. {
  32. DAC_ENTER_CRITICAL();
  33. dac_hal_digi_enable_dma(true);
  34. DAC_EXIT_CRITICAL();
  35. return ESP_OK;
  36. }
  37. esp_err_t dac_i2s_disable(void)
  38. {
  39. DAC_ENTER_CRITICAL();
  40. dac_hal_digi_enable_dma(false);
  41. DAC_EXIT_CRITICAL();
  42. return ESP_OK;
  43. }