Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
Spi_Codec.h
1/*
2 * Spi_Codec.h
3 *
4 * @brief Used for configuration of AD1938 codec for CTAG face2|4 Audio Card via spi-gpio
5 *
6 * Copyright (C) 2017 Henrik Langer henni19790@googlemail.com
7 */
8
9#ifndef SPI_CODEC_H_
10#define SPI_CODEC_H_
11
12#include "AudioCodec.h"
13#include <cstdlib>
14
15#define REG_PLL_CLK_CONTROL_0 0
16#define REG_PLL_CLK_CONTROL_1 1
17#define REG_DAC_CONTROL_0 2
18#define REG_DAC_CONTROL_1 3
19#define REG_DAC_CONTROL_2 4
20#define REG_DAC_CHANNEL_MUTES 5
21#define REG_DAC_VOLUME_L1 6
22#define REG_DAC_VOLUME_R1 7
23#define REG_DAC_VOLUME_L2 8
24#define REG_DAC_VOLUME_R2 9
25#define REG_DAC_VOLUME_L3 10
26#define REG_DAC_VOLUME_R3 11
27#define REG_DAC_VOLUME_L4 12
28#define REG_DAC_VOLUME_R4 13
29#define REG_ADC_CONTROL_0 14
30#define REG_ADC_CONTROL_1 15
31#define REG_ADC_CONTROL_2 16
32
33class Spi_Codec : public AudioCodec {
34
35public:
36 enum CODEC_TYPE {
37 MASTER_CODEC,
38 SLAVE_CODEC
39 };
40
41 Spi_Codec(const char* spidev_gpio_cs0, const char* spidev_gpio_cs1, bool isVerbose = false);
42 ~Spi_Codec();
43
44 int writeRegister(unsigned char reg, unsigned char value, CODEC_TYPE codec = MASTER_CODEC);
45 unsigned char readRegister(unsigned char reg, CODEC_TYPE codec = MASTER_CODEC);
46
47 int initCodec();
48 int startAudio(int shouldBeReady);
49 int stopAudio();
50 unsigned int getNumIns();
51 unsigned int getNumOuts();
52 float getSampleRate();
53 int dumpRegisters();
54 int reset(); // Hard reset of codec(s)
55 bool masterIsDetected(); // CTAG face2|4
56 bool slaveIsDetected(); // CTAG Beast
57 int setLineOutVolume(int channel, float gain);
58 int setHpVolume(int channel, float gain) { return 0; };
59 int setInputGain(int channel, float newGain) { return 0; };
60 int disable() {return 0;};
61 McaspConfig& getMcaspConfig();
62
63private:
64 int _fd_master, _fd_slave;
65 std::vector<int> _dacVolumethreeEighthsDbs;
66 int _writeDACVolumeRegisters(bool mute);
67 int _spiTransfer(unsigned char* tx_buf, unsigned char* rx_buf, size_t bytes, CODEC_TYPE codec = MASTER_CODEC);
68 McaspConfig mcaspConfig;
69 bool _isBeast = false;
70 bool _verbose;
71 bool _shouldPinmux;
72};
73
74#endif /* SPI_CODEC_H_ */
Definition AudioCodec.h:30
Definition Mcasp.h:33