• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2019 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 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #pragma once
15 
16 #include <esp_types.h>
17 #include "soc/soc_caps.h"
18 #include "soc/sigmadelta_periph.h"
19 #include "driver/gpio.h"
20 #include "hal/sigmadelta_types.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @brief Configure Sigma-delta channel
28  *
29  * @param  config Pointer of Sigma-delta channel configuration struct
30  *
31  * @return
32  *     - ESP_OK Success
33  *     - ESP_ERR_INVALID_STATE sigmadelta driver already initialized
34  *     - ESP_ERR_INVALID_ARG Parameter error
35  */
36 esp_err_t sigmadelta_config(const sigmadelta_config_t *config);
37 
38 /**
39  * @brief Set Sigma-delta channel duty.
40  *
41  *        This function is used to set Sigma-delta channel duty,
42  *        If you add a capacitor between the output pin and ground,
43  *        the average output voltage will be Vdc = VDDIO / 256 * duty + VDDIO/2,
44  *        where VDDIO is the power supply voltage.
45  *
46  * @param channel Sigma-delta channel number
47  * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90.
48  *             The waveform is more like a random one in this range.
49  *
50  * @return
51  *     - ESP_OK Success
52  *     - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized
53  *     - ESP_ERR_INVALID_ARG Parameter error
54  */
55 esp_err_t sigmadelta_set_duty(sigmadelta_channel_t channel, int8_t duty);
56 
57 /**
58  * @brief Set Sigma-delta channel's clock pre-scale value.
59  *        The source clock is APP_CLK, 80MHz. The clock frequency of the sigma-delta channel is APP_CLK / pre_scale
60  *
61  * @param channel Sigma-delta channel number
62  * @param prescale The divider of source clock, ranges from 0 to 255
63  *
64  * @return
65  *     - ESP_OK Success
66  *     - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized
67  *     - ESP_ERR_INVALID_ARG Parameter error
68  */
69 esp_err_t sigmadelta_set_prescale(sigmadelta_channel_t channel, uint8_t prescale);
70 
71 /**
72  * @brief Set Sigma-delta signal output pin
73  *
74  * @param channel Sigma-delta channel number
75  * @param gpio_num GPIO number of output pin.
76  *
77  * @return
78  *     - ESP_OK Success
79  *     - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized
80  *     - ESP_ERR_INVALID_ARG Parameter error
81  */
82 esp_err_t sigmadelta_set_pin(sigmadelta_channel_t channel, gpio_num_t gpio_num);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87