libpynq (release 5EWC0-2023 version 0.2.2 of 2023-09-24 22:22)
Loading...
Searching...
No Matches
audio.c
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2016, Xilinx, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 *****************************************************************************/
32
33/******************************************************************************
34 * @file audio_adau1761.c
35 *
36 * Functions to control audio controller.
37 *
38 * <pre>
39 * MODIFICATION HISTORY:
40 *
41 * Ver Who Date Changes
42 * ----- ------------ -------- -----------------------------------------------
43 * 1.00 Yun Rock Qu 12/04/17 Support for audio codec ADAU1761
44 * 1.01 Yun Rock Qu 01/02/18 Enable microphone for CTIA and OMTP standards
45 *
46 * </pre>
47 *
48 *****************************************************************************/
49#include "audio.h"
50#include <libpynq.h>
51#include <stdint.h>
52
53#include "i2cps.h"
54#include "uio.h"
55#include <fcntl.h>
56#include <linux/i2c-dev.h>
57#include <math.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <sys/ioctl.h>
62#include <sys/mman.h>
63#include <sys/stat.h>
64#include <time.h>
65#include <unistd.h>
66
67#define SAMPLE_RATE 44100
68
69#undef LOG_DOMAIN
70#define LOG_DOMAIN "audio"
71
72void audio_init(void) {
75}
76
77void audio_select_input(int input) {
78 if (input == MIC) {
79 select_mic();
80 } else if (input == LINE_IN) {
82 } else {
83 pynq_error("audio_select_input: invalid input %d, must be LINE_IN or MIC\n",
84 input);
85 }
86}
87
88// Original ADAU1761 code
89
90void write_audio_reg(unsigned char u8RegAddr, unsigned char u8Data,
91 int iic_fd) {
92 unsigned char u8TxData[3];
93 u8TxData[0] = 0x40;
94 u8TxData[1] = u8RegAddr;
95 u8TxData[2] = u8Data;
96 if (writeI2C_asFile(iic_fd, u8TxData, 3) < 0) {
97 pynq_error("write_audio_reg: unable to write audio register, ensure sudo "
98 "chmod 666 /dev/i2c-1 has been executed. \n");
99 }
100}
101
103 int iic_index = 1;
104 unsigned char u8TxData[8], u8RxData[6];
105 int iic_fd;
106 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
107 if (iic_fd < 0) {
108 pynq_error("config_audio_pll: unable to set I2C %d\n", iic_index);
109 }
110
111 // Disable Core Clock
112 write_audio_reg(R0_CLOCK_CONTROL, 0x0E, iic_fd);
113 /* MCLK = 10 MHz
114 * R = 0100 = 4, N = 0x064C = 1612, M = 0x0C35 = 3125
115 * PLL required output = 1024x44.1 KHz = 45.1584 MHz
116 * PLLout/MCLK = 45.1584 MHz/10 MHz = 4.51584 MHz
117 * = R + (N/M)
118 * = 4 + (1612/3125)
119 * Fs = PLL/1024 = 44.1 KHz
120 */
121
122 // Register write address [15:8]
123 u8TxData[0] = 0x40;
124 // Register write address [7:0]
125 u8TxData[1] = 0x02;
126 // byte 6 - M[15:8]
127 u8TxData[2] = 0x0C;
128 // byte 5 - M[7:0]
129 u8TxData[3] = 0x35;
130 // byte 4 - N[15:8]
131 u8TxData[4] = 0x06;
132 // byte 3 - N[7:0]
133 u8TxData[5] = 0x4C;
134 // byte 2 - bits 6:3 = R[3:0], 2:1 = X[1:0], 0 = PLL operation mode
135 u8TxData[6] = 0x21;
136 // byte 1 - 1 = PLL Lock, 0 = Core clock enable
137 u8TxData[7] = 0x03;
138 // Write bytes to PLL control register R1 at 0x4002
139 if (writeI2C_asFile(iic_fd, u8TxData, 8) < 0) {
140 pynq_error("config_audio_pll: unable to write audio register, ensure sudo "
141 "chmod 666 /dev/i2c-1 has been executed. \n");
142 }
143
144 // Poll PLL Lock bit
145 u8TxData[0] = 0x40;
146 u8TxData[1] = 0x02;
147 do {
148 if (writeI2C_asFile(iic_fd, u8TxData, 2) < 0) {
149 pynq_error("writeI2C_asFile: unable to write audio register, ensure sudo "
150 "chmod 666 /dev/i2c-1 has been executed. \n");
151 }
152 if (readI2C_asFile(iic_fd, u8RxData, 6) < 0) {
153 pynq_error("readI2C_asFile: unable to write audio register, ensure sudo "
154 "chmod 666 /dev/i2c-1 has been executed. \n");
155 }
156 } while ((u8RxData[5] & 0x02) == 0);
157
158 /* Clock control register: bit 3 CLKSRC = PLL Clock input
159 * bit 2:1 INFREQ = 1024 x fs
160 * bit 0 COREN = Core Clock enabled
161 */
162 write_audio_reg(R0_CLOCK_CONTROL, 0x0F, iic_fd);
163
164 if (unsetI2C(iic_fd) < 0) {
165 pynq_error("config_audio_pll: unable to set I2C %d\n", iic_fd);
166 }
167}
168
169/******************************************************************************
170 * Function to configure the audio codec.
171 * @param iic_index is the i2c index in /dev list.
172 * @return none.
173 *****************************************************************************/
175 int iic_index = 1;
176 int iic_fd;
177 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
178 if (iic_fd < 0) {
179 pynq_error("config_audio_codec: unable to set I2C %d\n", iic_index);
180 }
181
182 /*
183 * Input path control registers are configured
184 * in select_mic and select_line_in
185 */
186
187 // Mute Mixer1 and Mixer2 here, enable when MIC and Line In used
190 // Set LDVOL and RDVOL to 21 dB and Enable left and right differential
193 // Enable MIC bias
195 // Enable ALC control and noise gate
196 write_audio_reg(R14_ALC_CONTROL_3, 0x20, iic_fd);
197 // Put CODEC in Master mode
199 // Enable ADC on both channels, normal polarity and ADC high-pass filter
200 write_audio_reg(R19_ADC_CONTROL, 0x33, iic_fd);
201 // Mute play back Mixer3 and Mixer4 and enable when output is required
204 // Mute left input to mixer3 (R23) and right input to mixer4 (R25)
207 // Mute left and right channels output; enable them when output is needed
210 // Enable play back right and left channels
212 // Enable DAC for both channels
213 write_audio_reg(R36_DAC_CONTROL_0, 0x03, iic_fd);
214 // Set SDATA_In to DAC
216 // Set SDATA_Out to ADC
218 // Enable DSP and DSP Run
219 write_audio_reg(R61_DSP_ENABLE, 0x01, iic_fd);
220 write_audio_reg(R62_DSP_RUN, 0x01, iic_fd);
221 /*
222 * Enable Digital Clock Generator 0 and 1.
223 * Generator 0 generates sample rates for the ADCs, DACs, and DSP.
224 * Generator 1 generates BCLK and LRCLK for the serial port.
225 */
226 write_audio_reg(R65_CLOCK_ENABLE_0, 0x7F, iic_fd);
227 write_audio_reg(R66_CLOCK_ENABLE_1, 0x03, iic_fd);
228
229 if (unsetI2C(iic_fd) < 0) {
230 pynq_error("config_audio_codec: unable to unset I2C %d\n", iic_index);
231 }
232}
233
234void select_line_in(void) {
235 int iic_index = 1;
236 int iic_fd;
237 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
238 if (iic_fd < 0) {
239 pynq_error("select_line_in: unable to set I2C %d\n", iic_index);
240 }
241
242 // Mixer 1 (left channel)
244 // Enable LAUX (MX1AUXG)
246
247 // Mixer 2
249 // Enable RAUX (MX2AUXG)
251
252 if (unsetI2C(iic_fd) < 0) {
253 pynq_error("select_line_in: unable to unset I2C %d\n", iic_index);
254 }
255}
256
257void select_mic(void) {
258 int iic_index = 1;
259 int iic_fd;
260 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
261 if (iic_fd < 0) {
262 pynq_error("select_mic: unable to set I2C %d, ensure sudo chmod 666 "
263 "/dev/i2c-1 has been executed\n",
264 iic_index);
265 }
266
267 // Mixer 1 (left channel)
269 // LDBOOST, set to 20 dB
271 // LDVOL, set to 21 dB
273
274 // Mixer 2 (right channel)
276 // RDBOOST, set to 20 dB
278 // RDVOL, set to 21 dB
280
281 if (unsetI2C(iic_fd) < 0) {
282 pynq_error("select_mic: unable to unset I2C %d\n", iic_index);
283 }
284}
285
286void deselect(void) {
287 int iic_index = 1;
288 int iic_fd;
289 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
290 if (iic_fd < 0) {
291 pynq_error("deselect: unable to set I2C %d\n", iic_index);
292 }
293
294 // mute mixer 1 in left channel
296 // mute mixer 2 in right channel
298
299 if (unsetI2C(iic_fd) < 0) {
300 pynq_error("deselect: unable to unset I2C %d\n", iic_index);
301 }
302}
303
304void audio_bypass(unsigned int audio_mmap_size, unsigned int nsamples,
305 unsigned int volume, int uio_index) {
306 if (uio_index > 2) {
307 pynq_error("audio_bypass: uio_index outside of range. is %d, should be "
308 "below 3. \n",
309 uio_index);
310 }
311 if (volume > 100) {
312 pynq_error("audio_bypass: volume outside allowed range. Is %d, should be "
313 "below 100 \n",
314 volume);
315 }
316
317 int iic_index = 1;
318 int status;
319 void *uio_ptr;
320 int DataL, DataR;
321 int iic_fd;
322
323 uio_ptr = setUIO(uio_index, audio_mmap_size);
324 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
325 if (iic_fd < 0) {
326 pynq_error("audio_bypass: unable to set I2C %d, ensure sudo chmod 666 "
327 "/dev/i2c-1 has been executed\n",
328 iic_index);
329 }
330
331 // Mute mixer1 and mixer2 input
334 // Enable Mixer3 and Mixer4
337
338 unsigned char vol_register = (unsigned char)volume << 2 | 0x3;
339 // Enable Left/Right Headphone out
341 iic_fd);
343 iic_fd);
344
345 for (unsigned int i = 0; i < nsamples; i++) {
346 // wait for RX data to become available
347 do {
348 status = *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG));
349 } while (status == 0);
350 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG)) =
351 0x00000001;
352
353 // Read the sample from the input
354 DataL = *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_RX_L_REG));
355 DataR = *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_RX_R_REG));
356
357 // Write the sample to output
358 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_L_REG)) = DataL;
359 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_R_REG)) = DataR;
360 }
361
368
369 if (unsetUIO(uio_ptr, audio_mmap_size) < 0) {
370 pynq_error("audio_bypass: unable to free UIO %d, ensure sudo chmod 666 "
371 "/dev/i2c-1 has been executed\n",
372 uio_index);
373 }
374 if (unsetI2C(iic_fd) < 0) {
375 pynq_error("audio_bypass: unable to unset I2C %d, ensure sudo chmod 666 "
376 "/dev/i2c-1 has been executed\n",
377 iic_index);
378 }
379}
380
381void audio_record(unsigned int audio_mmap_size, unsigned int *BufAddr,
382 unsigned int nsamples, int uio_index) {
383 if (uio_index > 2) {
384 pynq_error("audio_record: uio_index outside of range. is %d, should be "
385 "below 3. \n",
386 uio_index);
387 }
388 int iic_index = 1;
389 unsigned int i, status;
390 void *uio_ptr;
391 int DataL, DataR;
392 int iic_fd;
393
394 uio_ptr = setUIO(uio_index, audio_mmap_size);
395 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
396 if (iic_fd < 0) {
397 pynq_error("audio_record: unable to set I2C %d, ensure sudo chmod 666 "
398 "/dev/i2c-1 has been executed\n",
399 iic_index);
400 }
401
402 for (i = 0; i < nsamples; i++) {
403 do {
404 status = *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG));
405 } while (status == 0);
406 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG)) =
407 0x00000001;
408
409 // Read the sample from the input
410 DataL = *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_RX_L_REG));
411 DataR = *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_RX_R_REG));
412
413 // Write the sample into memory
414 *(BufAddr + 2 * i) = DataL;
415 *(BufAddr + 2 * i + 1) = DataR;
416 }
417
418 if (unsetUIO(uio_ptr, audio_mmap_size) < 0) {
419 pynq_error("audio_record: unable to free UIO %d, ensure sudo chmod 666 "
420 "/dev/i2c-1 has been executed\n",
421 uio_index);
422 }
423 if (unsetI2C(iic_fd) < 0) {
424 pynq_error("audio_record: unable to unset I2C %d, ensure sudo chmod 666 "
425 "/dev/i2c-1 has been executed\n",
426 iic_index);
427 }
428}
429
430void audio_play(unsigned int audio_mmap_size, unsigned int *BufAddr,
431 unsigned int nsamples, unsigned int volume, int uio_index) {
432 if (uio_index > 2) {
434 "audio_play: uio_index outside of range. is %d, should be below 3. \n",
435 uio_index);
436 }
437 if (volume > 100) {
438 pynq_error("audio_play: volume outside allowed range. Is %d, should be "
439 "below 100 \n",
440 volume);
441 }
442 int iic_index = 1;
443 unsigned int i, status;
444 void *uio_ptr;
445 int DataL, DataR;
446 int iic_fd;
447
448 uio_ptr = setUIO(uio_index, audio_mmap_size);
449 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
450 if (iic_fd < 0) {
451 pynq_error("audio_play: unable to set I2C %d, ensure sudo chmod 666 "
452 "/dev/i2c-1 has been executed\n",
453 iic_index);
454 }
455
456 // Unmute left and right DAC, enable Mixer3 and Mixer4
459
460 unsigned char vol_register = (unsigned char)volume << 2 | 0x3;
461 // Enable Left/Right Headphone out
463 iic_fd);
465 iic_fd);
466
467 for (i = 0; i < nsamples; i++) {
468 do {
469 status = *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG));
470 } while (status == 0);
471 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG)) =
472 0x00000001;
473
474 // Read the sample from memory
475 DataL = *(BufAddr + 2 * i);
476 DataR = *(BufAddr + 2 * i + 1);
477
478 // Write the sample to output
479 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_L_REG)) = DataL;
480 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_R_REG)) = DataR;
481 }
482
483 // Mute left and right DAC
486 // Mute left input to mixer3 (R23) and right input to mixer4 (R25)
489
490 if (unsetUIO(uio_ptr, audio_mmap_size) < 0) {
491 pynq_error("audio_play: unable to free UIO %d, ensure sudo chmod 666 "
492 "/dev/i2c-1 has been executed\n",
493 uio_index);
494 }
495 if (unsetI2C(iic_fd) < 0) {
496 pynq_error("audio_play: unable to unset I2C %d, ensure sudo chmod 666 "
497 "/dev/i2c-1 has been executed\n",
498 iic_index);
499 }
500}
501
502void audio_repeat_play(unsigned int audio_mmap_size, unsigned int *BufAddr,
503 unsigned int nsamples, unsigned int volume,
504 unsigned int repetitions) {
505 if (volume > 100) {
506 pynq_error("audio_repeat_play: volume outside allowed range. Is %d, should "
507 "be below 100 \n",
508 volume);
509 }
510 int iic_index = 1;
511 unsigned int i, status;
512 void *uio_ptr;
513 int DataL, DataR;
514 int iic_fd;
515
516 uio_ptr = setUIO(0, audio_mmap_size);
517 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
518 if (iic_fd < 0) {
519 pynq_error("audio_repeat_play: unable to set I2C %d, ensure sudo chmod 666 "
520 "/dev/i2c-1 has been executed\n",
521 iic_index);
522 }
523
524 // Unmute left and right DAC, enable Mixer3 and Mixer4
527
528 unsigned char vol_register = (unsigned char)volume << 2 | 0x3;
529 // Enable Left/Right Headphone out
531 iic_fd);
533 iic_fd);
534
535 for (unsigned int repeat = 0; repeat < repetitions; repeat++) {
536 for (i = 0; i < nsamples; i++) {
537 do {
538 status =
539 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG));
540 } while (status == 0);
541 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG)) =
542 0x00000001;
543
544 // Read the sample from memory
545 DataL = *(BufAddr + 2 * i);
546 DataR = *(BufAddr + 2 * i + 1);
547
548 // Write the sample to output
549 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_L_REG)) = DataL;
550 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_R_REG)) = DataR;
551 }
552 }
553 // Mute left and right DAC
556 // Mute left input to mixer3 (R23) and right input to mixer4 (R25)
559
560 if (unsetUIO(uio_ptr, audio_mmap_size) < 0) {
561 pynq_error("audio_repeat_play: unable to free UIO %d\n", 0);
562 }
563 if (unsetI2C(iic_fd) < 0) {
564 pynq_error("audio_repeat_play: unable to unset I2C %d, ensure sudo chmod "
565 "666 /dev/i2c-1 has been executed\n",
566 iic_index);
567 }
568}
569
570void audio_generate_tone(unsigned int frequency, uint32_t time_ms,
571 unsigned int volume) {
572
573 if (frequency < 10) {
574 pynq_error("audio_generate_tone: frequency should be 10 or higher, "
575 "frequency is: %d\n",
576 frequency);
577 }
578 if (volume > 100) {
579 pynq_error("audio_generate_tone: volume outside allowed range. Is %d, "
580 "should be below 100 \n",
581 volume);
582 }
583 double period = 1 / ((double)(frequency));
584 unsigned int samplesPerPeriod = (int)(SAMPLE_RATE * period);
585 double time_s = ((double)(time_ms)) / 1000;
586 int totalPeriods = (int)(time_s / period); // Number of times one period must
587 // be played to play for time_ms
588
589 uint32_t audioBuffer[16 * 1024 + 1] = {0};
590 unsigned int i, status;
591
592 for (i = 0; i < samplesPerPeriod; i++) {
593 double t = (double)i / SAMPLE_RATE;
594 double value = sin(6.28318531 * frequency * t); // 6.28... = 2pi
595 value = value + 1;
596 value = value * 16000;
597 audioBuffer[2 * i] = (uint32_t)value;
598 audioBuffer[2 * i + 1] = (uint32_t)value;
599 }
600
601 unsigned int audio_mmap_size = 64 * 1024;
602 unsigned int *BufAddr = audioBuffer;
603 int iic_index = 1;
604 void *uio_ptr;
605 int DataL, DataR;
606 int iic_fd;
607
608 uio_ptr = setUIO(0, audio_mmap_size);
609 iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR);
610 if (iic_fd < 0) {
611 pynq_error("audio_generate_tone: unable to set I2C %d, ensure sudo chmod "
612 "666 /dev/i2c-1 has been executed\n",
613 iic_index);
614 }
615
616 // Unmute left and right DAC, enable Mixer3 and Mixer4
619
620 unsigned char vol_register = (unsigned char)volume << 2 | 0x3;
621 // Enable Left/Right Headphone out
623 iic_fd);
625 iic_fd);
626
627 for (int period = 0; period < totalPeriods; period++) {
628 for (i = 0; i < samplesPerPeriod; i++) {
629 do {
630 status =
631 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG));
632 } while (status == 0);
633 *((volatile unsigned *)(((uint8_t *)uio_ptr) + I2S_STATUS_REG)) =
634 0x00000001;
635
636 // Read the sample from memory
637 DataL = *(BufAddr + 2 * i);
638 DataR = *(BufAddr + 2 * i + 1);
639
640 // Write the sample to output
641 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_L_REG)) = DataL;
642 *((volatile int *)(((uint8_t *)uio_ptr) + I2S_DATA_TX_R_REG)) = DataR;
643 }
644 }
645 // Mute left and right DAC
648 // Mute left input to mixer3 (R23) and right input to mixer4 (R25)
651
652 if (unsetUIO(uio_ptr, audio_mmap_size) < 0) {
653 pynq_error("audio_generate_tone: unable to free UIO %d, ensure sudo chmod "
654 "666 /dev/i2c-1 has been executed\n",
655 0);
656 }
657 if (unsetI2C(iic_fd) < 0) {
658 pynq_error("audio_generate_tone: unable to unset I2C %d, ensure has been "
659 "executed\n",
660 iic_index);
661 }
662}
#define SAMPLE_RATE
Definition audio.c:67
void audio_generate_tone(unsigned int frequency, uint32_t time_ms, unsigned int volume)
Definition audio.c:570
void deselect(void)
Function to deselect input, either LINE_IN, or MIC.
Definition audio.c:286
void audio_record(unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, int uio_index)
Function to support audio recording without the audio codec controller.
Definition audio.c:381
void select_mic(void)
Function to select MIC as input.
Definition audio.c:257
void write_audio_reg(unsigned char u8RegAddr, unsigned char u8Data, int iic_fd)
Definition audio.c:90
void audio_repeat_play(unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, unsigned int volume, unsigned int repetitions)
Function to play one audio fragment for multiple repititions.
Definition audio.c:502
void config_audio_codec(void)
Definition audio.c:174
void audio_play(unsigned int audio_mmap_size, unsigned int *BufAddr, unsigned int nsamples, unsigned int volume, int uio_index)
Definition audio.c:430
#define I2S_STATUS_REG
Definition audio.h:46
void audio_bypass(unsigned int audio_mmap_size, unsigned int nsamples, unsigned int volume, int uio_index)
Record and play the audio without storing in DRAM.
Definition audio.c:304
void audio_select_input(int input)
selects the audio input channel.
Definition audio.c:77
#define I2S_DATA_RX_R_REG
Definition audio.h:43
#define MIC
Definition audio.h:33
#define IIC_SLAVE_ADDR
Definition audio.h:36
void audio_init(void)
Initializes the audio register. Sets the sampling frequency. defines several values such as audio rec...
Definition audio.c:72
#define I2S_DATA_TX_R_REG
Definition audio.h:45
#define LINE_IN
Definition audio.h:32
void config_audio_pll(void)
Definition audio.c:102
#define I2S_DATA_RX_L_REG
Definition audio.h:42
#define I2S_DATA_TX_L_REG
Definition audio.h:44
void select_line_in(void)
Function to select LINE_IN as input.
Definition audio.c:234
@ R8_LEFT_DIFFERENTIAL_INPUT_VOLUME_CONTROL
Definition audio.h:58
@ R9_RIGHT_DIFFERENTIAL_INPUT_VOLUME_CONTROL
Definition audio.h:59
@ R36_DAC_CONTROL_0
Definition audio.h:86
@ R29_PLAYBACK_HEADPHONE_LEFT_VOLUME_CONTROL
Definition audio.h:79
@ R5_RECORD_MIXER_LEFT_CONTROL_1
Definition audio.h:55
@ R22_PLAYBACK_MIXER_LEFT_CONTROL_0
Definition audio.h:72
@ R6_RECORD_MIXER_RIGHT_CONTROL_0
Definition audio.h:56
@ R35_PLAYBACK_POWER_MANAGEMENT
Definition audio.h:85
@ R30_PLAYBACK_HEADPHONE_RIGHT_VOLUME_CONTROL
Definition audio.h:80
@ R58_SERIAL_INPUT_ROUTE_CONTROL
Definition audio.h:94
@ R0_CLOCK_CONTROL
Definition audio.h:50
@ R59_SERIAL_OUTPUT_ROUTE_CONTROL
Definition audio.h:95
@ R66_CLOCK_ENABLE_1
Definition audio.h:101
@ R23_PLAYBACK_MIXER_LEFT_CONTROL_1
Definition audio.h:73
@ R7_RECORD_MIXER_RIGHT_CONTROL_1
Definition audio.h:57
@ R19_ADC_CONTROL
Definition audio.h:69
@ R4_RECORD_MIXER_LEFT_CONTROL_0
Definition audio.h:54
@ R65_CLOCK_ENABLE_0
Definition audio.h:100
@ R62_DSP_RUN
Definition audio.h:97
@ R24_PLAYBACK_MIXER_RIGHT_CONTROL_0
Definition audio.h:74
@ R61_DSP_ENABLE
Definition audio.h:96
@ R10_RECORD_MICROPHONE_BIAS_CONTROL
Definition audio.h:60
@ R14_ALC_CONTROL_3
Definition audio.h:64
@ R15_SERIAL_PORT_CONTROL_0
Definition audio.h:65
@ R25_PLAYBACK_MIXER_RIGHT_CONTROL_1
Definition audio.h:75
#define pynq_error(...)
Definition log.h:118
int setI2C(unsigned int index, long slave_addr)
Definition i2cps.c:60
int writeI2C_asFile(int i2c_fd, unsigned char writebuffer[], unsigned char bytes)
Definition i2cps.c:79
int unsetI2C(int i2c_fd)
Definition i2cps.c:74
int readI2C_asFile(int i2c_fd, unsigned char readbuffer[], unsigned char bytes)
Definition i2cps.c:88
void * setUIO(int uio_index, int length)
Definition uio.c:65
int unsetUIO(void *uio_ptr, int length)
Definition uio.c:86