1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include <esp_types.h> 10 #include "soc/soc_caps.h" 11 #include "soc/sigmadelta_periph.h" 12 #include "driver/gpio.h" 13 #include "hal/sigmadelta_types.h" 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * @brief Configure Sigma-delta channel 21 * 22 * @param config Pointer of Sigma-delta channel configuration struct 23 * 24 * @return 25 * - ESP_OK Success 26 * - ESP_ERR_INVALID_STATE sigmadelta driver already initialized 27 * - ESP_ERR_INVALID_ARG Parameter error 28 */ 29 esp_err_t sigmadelta_config(const sigmadelta_config_t *config); 30 31 /** 32 * @brief Set Sigma-delta channel duty. 33 * 34 * This function is used to set Sigma-delta channel duty, 35 * If you add a capacitor between the output pin and ground, 36 * the average output voltage will be Vdc = VDDIO / 256 * duty + VDDIO/2, 37 * where VDDIO is the power supply voltage. 38 * 39 * @param channel Sigma-delta channel number 40 * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90. 41 * The waveform is more like a random one in this range. 42 * 43 * @return 44 * - ESP_OK Success 45 * - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized 46 * - ESP_ERR_INVALID_ARG Parameter error 47 */ 48 esp_err_t sigmadelta_set_duty(sigmadelta_channel_t channel, int8_t duty); 49 50 /** 51 * @brief Set Sigma-delta channel's clock pre-scale value. 52 * The source clock is APP_CLK, 80MHz. The clock frequency of the sigma-delta channel is APP_CLK / pre_scale 53 * 54 * @param channel Sigma-delta channel number 55 * @param prescale The divider of source clock, ranges from 0 to 255 56 * 57 * @return 58 * - ESP_OK Success 59 * - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized 60 * - ESP_ERR_INVALID_ARG Parameter error 61 */ 62 esp_err_t sigmadelta_set_prescale(sigmadelta_channel_t channel, uint8_t prescale); 63 64 /** 65 * @brief Set Sigma-delta signal output pin 66 * 67 * @param channel Sigma-delta channel number 68 * @param gpio_num GPIO number of output pin. 69 * 70 * @return 71 * - ESP_OK Success 72 * - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized 73 * - ESP_ERR_INVALID_ARG Parameter error 74 */ 75 esp_err_t sigmadelta_set_pin(sigmadelta_channel_t channel, gpio_num_t gpio_num); 76 77 #ifdef __cplusplus 78 } 79 #endif 80