1 #ifndef _BFLB_AUDAC_H
2 #define _BFLB_AUDAC_H
3 
4 #include "bflb_core.h"
5 
6 /**
7  *  @defgroup AUDAC_SAMPLING_RATE audac sampling rate
8  */
9 #define AUDAC_SAMPLING_RATE_8K                      0
10 #define AUDAC_SAMPLING_RATE_16K                     1
11 #define AUDAC_SAMPLING_RATE_22P05K                  5
12 #define AUDAC_SAMPLING_RATE_24K                     3
13 #define AUDAC_SAMPLING_RATE_32K                     2
14 #define AUDAC_SAMPLING_RATE_44P1K                   6
15 #define AUDAC_SAMPLING_RATE_48K                     4
16 /**
17   * @}
18   */
19 
20 /**
21  *  @defgroup AUDAC_OUTPUT_MODE audac output mode
22  */
23 #define AUDAC_OUTPUT_MODE_PWM                       0
24 #define AUDAC_OUTPUT_MODE_GPDAC_CH_A                1
25 #define AUDAC_OUTPUT_MODE_GPDAC_CH_B                2
26 #define AUDAC_OUTPUT_MODE_GPDAC_CH_A_B              3
27 /**
28   * @}
29   */
30 
31 /**
32  *  @defgroup AUDAC_SOURCE_CHANNEL source channels num
33  */
34 #define AUDAC_SOURCE_CHANNEL_SINGLE                 0x01
35 #define AUDAC_SOURCE_CHANNEL_DUAL                   0x03
36 /**
37   * @}
38   */
39 
40 /**
41  *  @defgroup AUDAC_MIXER_MODE audac mixer mode, this parameter is valid only in AUDAC_SOURCE_CHANNEL_DUAL mode
42  */
43 #define AUDAC_MIXER_MODE_ONLY_L                     0
44 #define AUDAC_MIXER_MODE_ONLY_R                     1
45 #define AUDAC_MIXER_MODE_SUM                        2
46 #define AUDAC_MIXER_MODE_AVERAGE                    3
47 /**
48   * @}
49   */
50 
51 /**
52  *  @defgroup AUDAC_DATA_FORMAT audac data format
53  */
54 #define AUDAC_DATA_FORMAT_16BIT                     3
55 #define AUDAC_DATA_FORMAT_20BIT                     2
56 #define AUDAC_DATA_FORMAT_24BIT                     1
57 #define AUDAC_DATA_FORMAT_32BIT                     0
58 /**
59   * @}
60   */
61 
62 /**
63  *  @defgroup AUDAC_RAMP_RATE audac volume ramp rate
64  */
65 #define AUDAC_RAMP_RATE_FS_2                        0
66 #define AUDAC_RAMP_RATE_FS_4                        1
67 #define AUDAC_RAMP_RATE_FS_8                        2
68 #define AUDAC_RAMP_RATE_FS_16                       3
69 #define AUDAC_RAMP_RATE_FS_32                       4
70 #define AUDAC_RAMP_RATE_FS_64                       5
71 #define AUDAC_RAMP_RATE_FS_128                      6
72 #define AUDAC_RAMP_RATE_FS_256                      7
73 #define AUDAC_RAMP_RATE_FS_512                      8
74 #define AUDAC_RAMP_RATE_FS_1024                     9
75 #define AUDAC_RAMP_RATE_FS_2048                     10
76 /**
77   * @}
78   */
79 
80 /**
81  *  @defgroup AUDAC_VOLUME_UPDATE_MODE audac volume ramp rate
82  */
83 #define AUDAC_VOLUME_UPDATE_MODE_FORCE              0
84 #define AUDAC_VOLUME_UPDATE_MODE_RAMP               1
85 #define AUDAC_VOLUME_UPDATE_MODE_RAMP_ZERO_CROSSING 2
86 /**
87   * @}
88   */
89 
90 /** @defgroup AUDAC_INTSTS audac interrupt status definition
91   * @{
92   */
93 #define AUDAC_INTSTS_VOLUME_RAMP                    (1 << 0)
94 #define AUDAC_INTSTS_FIFO_OVER                      (1 << 1)
95 #define AUDAC_INTSTS_FIFO_UNDER                     (1 << 2)
96 #define AUDAC_INTSTS_FIFO_AVAILABLE                 (1 << 3)
97 
98 /** @defgroup AUDAC_CMD audac feature control cmd definition
99   * @{
100   */
101 #define AUDAC_CMD_PLAY_START                        (0x01)
102 #define AUDAC_CMD_PLAY_STOP                         (0x02)
103 #define AUDAC_CMD_SET_MUTE                          (0x03)
104 #define AUDAC_CMD_SET_VOLUME_VAL                    (0x04)
105 #define AUDAC_CMD_CLEAR_TX_FIFO                     (0x05)
106 #define AUDAC_CMD_GET_TX_FIFO_CNT                   (0x06)
107 
108 /**
109   * @}
110   */
111 
112 /**
113  * @brief AUDAC initialization configuration structure
114  *
115  * @param sampling_rate         AUDAC sampling rate, use @ref AUDAC_SAMPLING_RATE
116  * @param output_mode           AUDAC mode, use @ref AUDAC_OUTPUT_MODE
117  * @param source_channels_num   AUDAC source channels num, use @ref AUDAC_SOURCE_CHANNEL
118  * @param mixer_mode            AUDAC mixer mode, valid only in AUDAC_SOURCE_CHANNEL_DUAL mode, use @ref AUDAC_MIXER_MODE
119  * @param data_format           AUDAC audac data format, use @ref AUDAC_DATA_FORMAT
120  * @param fifo_threshold        AUDAC tx fifo threshold, 0 ~ 7
121  * @param dma_enable            AUDAC dma mode enable, use true or false
122  */
123 struct bflb_audac_init_config_s {
124     uint8_t sampling_rate;
125     uint8_t output_mode;
126     uint8_t source_channels_num;
127     uint8_t mixer_mode;
128     uint8_t data_format;
129     uint8_t fifo_threshold;
130 };
131 
132 /**
133  * @brief AUDAC volume configuration structure
134  *
135  * @param mute_ramp_en              AUDAC mute mode en, use true or false
136  * @param mute_up_ramp_rate         AUDAC mute up ramp rate, valid when mute_ramp_en is true, use @ref AUDAC_RAMP_RATE
137  * @param mute_down_ramp_rate       AUDAC mute down ramp rate, valid when mute_ramp_en is true, use @ref AUDAC_RAMP_RATE
138  * @param volume_update_mode        AUDAC volume update mode, use @ref AUDAC_VOLUME_UPDATE_MODE
139  * @param volume_ramp_rate          AUDAC volume ramp rate, valid when volume_update_mode is not AUDAC_VOLUME_UPDATE_MODE_FORCE, use @ref AUDAC_RAMP_RATE
140  * @param volume_zero_cross_timeout AUDAC volume update zero cross timeout period, valid only in AUDAC_VOLUME_UPDATE_MODE_RAMP_ZERO_CROSSING mode
141  */
142 struct bflb_audac_volume_config_s {
143     bool mute_ramp_en;
144     uint8_t mute_up_ramp_rate;
145     uint8_t mute_down_ramp_rate;
146     uint8_t volume_update_mode;
147     uint8_t volume_ramp_rate;
148     uint8_t volume_zero_cross_timeout;
149 };
150 
151 int bflb_audac_init(struct bflb_device_s *dev, const struct bflb_audac_init_config_s *config);
152 
153 int bflb_audac_volume_init(struct bflb_device_s *dev, const struct bflb_audac_volume_config_s *vol_cfg);
154 
155 int bflb_audac_link_rxdma(struct bflb_device_s *dev, bool enable);
156 
157 int bflb_audac_int_mask(struct bflb_device_s *dev, uint32_t mask);
158 
159 int bflb_audac_get_intstatus(struct bflb_device_s *dev);
160 
161 int bflb_audac_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
162 
163 int bflb_audac_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
164 
165 #endif