本项止转自github官方arduino-esp32 传在这里仅为阅读源码方便
projectuser
2019-07-05 50148ccffe21ff54262064ec9f2245900eaf18aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
 
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
#ifndef _DRIVER_DAC_H_
#define _DRIVER_DAC_H_
 
#ifdef __cplusplus
extern "C" {
#endif
 
#include <stdint.h>
#include "esp_err.h"
#include "soc/dac_channel.h"
 
typedef enum {
    DAC_CHANNEL_1 = 1,  /*!< DAC channel 1 is GPIO25 */
    DAC_CHANNEL_2,      /*!< DAC channel 2 is GPIO26 */
    DAC_CHANNEL_MAX,
} dac_channel_t;
 
/**
 * @brief Get the gpio number of a specific DAC channel.
 * 
 * @param channel Channel to get the gpio number
 * 
 * @param gpio_num output buffer to hold the gpio number
 * 
 * @return 
 *   - ESP_OK if success
 *   - ESP_ERR_INVALID_ARG if channal not valid 
 */
esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num);
 
/** @cond */
/**
  * @brief  Set DAC output voltage.
  *
  * @note Function has been deprecated, please use dac_output_voltage instead.
  *       This name will be removed in a future release.
  *       The difference is that before calling dac_output_voltage, we need to initialize the dac pad by dac_output_enable
  *
  *
  * @param channel DAC channel
  * @param dac_value DAC output value
  *
  * @return
  *     - ESP_OK success
  *     - ESP_ERR_INVALID_ARG Parameter error
  */
esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value) __attribute__ ((deprecated));
/** @endcond */
 
/**
 * @brief Set DAC output voltage.
 *
 * DAC output is 8-bit. Maximum (255) corresponds to VDD.
 *
 * @note Need to configure DAC pad before calling this function.
 *       DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
 *
 * @param channel DAC channel
 * @param dac_value DAC output value
 *
 * @return
 *     - ESP_OK success
 *     - ESP_ERR_INVALID_ARG Parameter error
 */
esp_err_t dac_output_voltage(dac_channel_t channel, uint8_t dac_value);
 
/**
 * @brief DAC pad output enable
 *
 * @param channel DAC channel
 * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
 *       I2S left channel will be mapped to DAC channel 2
 *       I2S right channel will be mapped to DAC channel 1
 */
esp_err_t dac_output_enable(dac_channel_t channel);
 
/**
 * @brief DAC pad output disable
 *
 * @param channel DAC channel
 * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
 */
esp_err_t dac_output_disable(dac_channel_t channel);
 
/**
 * @brief Enable DAC output data from I2S
 */
esp_err_t dac_i2s_enable();
 
/**
 * @brief Disable DAC output data from I2S
 */
esp_err_t dac_i2s_disable();
#ifdef __cplusplus
}
#endif
 
#endif  /*_DRIVER_DAC_H_*/