Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
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 
33 class Spi_Codec : public AudioCodec {
34 
35 public:
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 dummy_parameter = 0);
49  int stopAudio();
50  int setDACVolume(int halfDbSteps);
51  int dumpRegisters();
52  int reset(); // Hard reset of codec(s)
53  bool masterIsDetected(); // CTAG face2|4
54  bool slaveIsDetected(); // CTAG Beast
55  int setADCVolume(int halfDbSteps) {return 0;};
56  int setHPVolume(int halfDbSteps) {return 0;};
57  int setPga(float newGain, unsigned short int channel) {return 0;};
58  int disable() {return 0;};
59 
60 private:
61  int _fd_master, _fd_slave;
62  int _dacVolumethreeEighthsDbs;
63  int _writeDACVolumeRegisters(bool mute);
64  int _spiTransfer(unsigned char* tx_buf, unsigned char* rx_buf, size_t bytes, CODEC_TYPE codec = MASTER_CODEC);
65  bool _isBeast = false;
66  bool _verbose;
67 };
68 
69 #endif /* SPI_CODEC_H_ */
Definition: Spi_Codec.h:33
Definition: AudioCodec.h:4