1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __AOS_PCM_H__
6 #define __AOS_PCM_H__
7 
8 #define AOS_PCM_DIR_OUT 0
9 #define AOS_PCM_DIR_IN  1
10 
11 typedef enum {
12     AOS_PCM_FORMAT_INVALID = -1,
13     AOS_PCM_FORMAT_S16_LE = 0,  /* 16-bit signed */
14     AOS_PCM_FORMAT_S32_LE,      /* 32-bit signed */
15     AOS_PCM_FORMAT_S8,          /* 8-bit signed */
16     AOS_PCM_FORMAT_S24_LE,      /* 24-bits in 4-bytes */
17     AOS_PCM_FORMAT_S24_3LE,     /* 24-bits in 3-bytes */
18     AOS_PCM_FORMAT_MAX,
19 } aos_pcm_format_t;
20 
21 typedef struct {
22     int rate;
23     int channels;
24     int period_size;
25     int period_count;
26     aos_pcm_format_t format;
27 } aos_pcm_config_t;
28 
29 typedef struct {
30     aos_pcm_config_t config;
31     unsigned char   dir:1;
32     unsigned char   card:2;
33     unsigned char   state:3;
34     void *private_data;
35 } aos_pcm_device_t;
36 
37 typedef enum {
38     AOS_SND_DEVICE_OUT_SPEAKER = 1,
39     AOS_SND_DEVICE_OUT_HEADPHONE,
40     AOS_SND_DEVICE_OUT_HEADSET,
41     AOS_SND_DEVICE_OUT_RECEIVER,
42     AOS_SND_DEVICE_OUT_SPEAKER_AND_HEADPHONE,
43     AOS_SND_DEVICE_OUT_SPEAKER_AND_HEADSET,
44     AOS_SND_DEVICE_IN_MAIN_MIC,
45     AOS_SND_DEVICE_IN_HEADSET_MIC,
46     AOS_SND_DEVICE_MAX,
47 } aos_snd_device_t;
48 
49 typedef struct {
50     aos_snd_device_t out_device;
51     int external_pa;
52     int external_pa_pin;
53     int external_pa_delay_ms;
54     int external_pa_active_high;
55     void *priv;
56 } aos_audio_dev_t;
57 
58 /*
59  * Configure external pa control gpio.
60  *
61  * Return:
62  *   0 -- success or unsupport
63  *  -1 -- failed
64  */
65 int aos_ext_pa_config(int gpio, int active_high, int delay_ms);
66 
67 /*
68  * Set output volume.
69  *
70  * Return:
71  *   0 -- success or unsupport
72  *  -1 -- failed
73  */
74 int aos_set_volume(aos_snd_device_t device, int volume);
75 
76 
77 /*
78  * Select audio output/input device
79  *
80  * Return:
81  *   0 -- success or unsupport
82  *  -1 -- failed
83  */
84 int aos_set_path(aos_pcm_device_t *pcm, aos_snd_device_t device);
85 
86 
87 /*
88  * Mute audio output/input.
89  *
90  * Return:
91  *   0 -- success or unsupport
92  *  -1 -- failed
93  */
94 int aos_dev_mute(aos_pcm_device_t *pcm, aos_snd_device_t device, int mute);
95 
96 
97 /**
98  * Configure pcm parameters
99  *
100  * Return:
101  *   0 -- success
102  *  -1 -- failed
103  */
104 int aos_pcm_setup(aos_pcm_device_t *pcm);
105 
106 /**
107  * Open pcm device
108  *
109  * Return:
110  *   0 -- success
111  *  -1 -- failed
112  */
113 int aos_pcm_open(aos_pcm_device_t *pcm);
114 
115 /**
116  * Read data in. Block reading if input data not ready.
117  *
118  * Return read length, or negative if failed.
119  */
120 int aos_pcm_read(aos_pcm_device_t *pcm, unsigned char *buffer, int nbytes);
121 
122 /*
123  * Block write if free dma buffer not ready, otherwise,
124  * please return after copied.
125  *
126  * Return writen length, or negative if failed.
127  *
128  */
129 int aos_pcm_write(aos_pcm_device_t *pcm, unsigned char *buffer, int nbytes);
130 
131 /*
132  * Flush remaining data in dma buffer
133  *
134  * Return:
135  *   0 -- success or unsupport
136  *  -1 -- failed
137  */
138 int aos_pcm_flush(aos_pcm_device_t *pcm);
139 
140 /*
141  * close pcm device
142  *
143  * Return:
144  *   0 -- success
145  *  -1 -- failed
146  *
147  */
148 int aos_pcm_close(aos_pcm_device_t *pcm);
149 
150 /*
151  * pcm adapter init
152  *
153  * Return:
154  *   0 -- success
155  *  -1 -- failed
156  *
157  */
158 int amp_pcm_init(void);
159 
160 #endif
161