-
Notifications
You must be signed in to change notification settings - Fork 4
/
DFRobot_GP8403.h
121 lines (111 loc) · 3.61 KB
/
DFRobot_GP8403.h
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
113
114
115
116
117
118
119
120
121
/*!
* @file DFRobot_GP8403.h
* @brief This is a method description file for the DAC module
* @copyright Copyright (c) 2021 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [TangJie]([email protected])
* @version V1.0
* @date 2022-03-07
* @url https://github.com/DFRobot/DFRobot_Microphone
*/
#ifndef _DFROBOT_GP8403_H_
#define _DFROBOT_GP8403_H
#include "Arduino.h"
#include "Wire.h"
//#define ENABLE_DBG //!< Open the macro and you can see the detailed procedure of the program
#ifdef ENABLE_DBG
#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);}
#else
#define DBG(...)
#endif
#define GP8302_CONFIG_CURRENT_REG 0x02
#define OUTPUT_RANGE 0X01
class DFRobot_GP8403
{
public:
/**
* @enum eOutPutRange_t
* @brief Analog voltage output range select
*/
typedef enum{
eOutputRange5V = 0X00,
eOutputRange10V = 0X11,
}eOutPutRange_t;
/**
* @brief DFRobot_GP8403 constructor
* @param pWire I2C object
* @param addr I2C address
*/
DFRobot_GP8403(TwoWire *pWire = &Wire,uint8_t addr = 0x58);
/**
* @fn begin
* @brief Initialize the module
*/
uint8_t begin(void);
/**
* @fn setDACOutRange
* @brief Set DAC output range
* @param range DAC output range
* @return NONE
*/
void setDACOutRange(eOutPutRange_t range);
/**
* @fn setDACOutVoltage
* @brief Set output DAC voltage of different channels
* @param data The voltage value to be output
* @param channel Output channel. 0: channel 0; 1: channel 1; 2: all the channels
* @return NONE
*/
void setDACOutVoltage(uint16_t data,uint8_t channel);
/**
* @brief Save the set voltage in the chip
*/
void store(void);
/**
* @brief Call the function to output sine wave
* @param amp Set sine wave amplitude Vp
* @param freq Set sine wave frequency f
* @param offset Set sine wave DC offset Voffset
* @param channel Output channel. 0: channel 0; 1: channel 1; 2: all the channels
*/
void outputSin(uint16_t amp, uint16_t freq, uint16_t offset,uint8_t channel);
/**
* @brief Call the function to output triangle wave
* @param amp Set triangle wave amplitude Vp
* @param freq Set triangle wave frequency f
* @param offset Set triangle wave DC offset Voffset
* @param dutyCycle Set triangle (sawtooth) wave duty cycle
* @param channel Output channel. 0: channel 0; 1: channel 1; 2: all the channels
*/
void outputTriangle(uint16_t amp, uint16_t freq, uint16_t offset, int8_t dutyCycle, uint8_t channel);
/**
* @brief Call the function to output square wave
* @param amp Set square wave amplitude Vp
* @param freq Set square wave frequency f
* @param offset Set square wave DC offset Voffset
* @param dutyCycle Set square wave duty cycle
* @param channel Output channel. 0: channel 0; 1: channel 1; 2: all the channels
*/
void outputSquare(uint16_t amp, uint16_t freq, uint16_t offset, int8_t dutyCycle, uint8_t channel);
protected:
void startSignal(void);
void stopSignal(void);
uint8_t recvAck(uint8_t ack);
uint8_t sendByte(uint8_t data, uint8_t ack = 0, uint8_t bits = 8, bool flag = true);
private:
/**
* @fn writeReg
* @brief Write register value through IIC bus
* @param reg Register address 8bits
* @param pBuf Storage cache to write data in
* @param size The length of data to be written
*/
void writeReg(uint8_t reg, void *pBuf, size_t size);
TwoWire *_pWire;
uint8_t _addr;
uint16_t voltage = 0;
int _scl= SCL;
int _sda = SDA;
void sendData(uint16_t data, uint8_t channel);
};
#endif