Тема: BD3473KS2
https://datasheet-pdf.com/PDF/BD3473KS2 … HM-1088560
BD34701KS2.h
// liman324@yandex.ru rcl-radio.ru
#ifndef BD3473KS2_H
#define BD3473KS2_H
#define ADDR_0 0b0000
#define ADDR_1 0b0001
#define ADDR_2 0b0010
#define ADDR_3 0b0011
#define ADDR_4 0b1000
#define ADDR_5 0b1001
#define ADDR_6 0b1010
#define ADDR_7 0b1011
#include <Arduino.h>
class BD3473KS2
{
public:
BD3473KS2(uint8_t cl, uint8_t da);
void set0(int in_main, int rec1, int rec2, int rec3, int rec4_0, int rec4_1, int rec5);
// int in_main 1...18 === IN1_MAIN...IN18_MAIN | in_main 0 === MUTE
// int rec1 0...1 === (REC1) ON OFF
// int rec2 0...1 === (REC2) ON OFF
// int rec3 0...1 === (REC3) ON OFF
// int rec4_0 0...1 === (REC4) ON OFF
// int rec4_1 0...1 === REC4 SUB2
// int rec5 0...1 === (REC4/SUB2) ON OFF
void set1(int in_sub1, int in_sub2);
// int in_sub1 0...18 === IN1_SUB1...IN18_SUB1 | 0b010011...0b111111 - prohibition
// int in_sub2 0...18 === IN1_SUB2...IN18_SUB2 | 0b010011...0b111111 - prohibition
void set2(int mode_sel_fl_fr, int mode_sel_c_sw, int mode_sel_sl_sr, int mode_sel_sbl_sbr, int adc_att);
// int mode_sel_fl_fr 0...3 === MUTE MAIN MULTI1 MULTI2
// int mode_sel_c_sw 0...3 === MUTE prohibition MULTI1 MULTI2
// int mode_sel_sl_sr 0...3 === MUTE prohibition MULTI1 MULTI2
// int mode_sel_sbl_sbr 0...7 === MUTE prohibition MULTI1 MULTI2 SUB1 SUB2 prohibition
// int adc_att 0...7 === MUTE 0dB -6dB -6.5dB -7.5dB -9dB -12dB prohibition
void set3(int sec_ch, int volume);
// int sec_ch 0...7 === FR FL SW C SR SL SBR SBL
// int volume -190...48 === -95.0dB...+24db , step 0.5dB
void set4(int tone, int bass_reg);
// int tone 0...1 === ON OFF
// int bass_reg -10...10 === -10dB...+10dB
void set5(int sw_ch_mix, int front_ph, int sb_front, int treb_reg);
// int sw_ch_mix 0...1 === ON OFF
// int front_ph 0...1 === 0'... 180'
// int sb_front 0...1 === sb...front
// int treb_reg -10...10 === -10dB...+10dB
void set7(int a_b, int b_a, int base_clk);
// int a_b 0...3 === 11 5 7 15 ms
// int b_a 0...3 === 11 5 7 15 ms
// int base_clk === x1 x1/2 x1/4 prohibition
private:
void write(char data);
uint8_t CL;
uint8_t DA;
};
#endif //BD3473KS2_H
BD3473KS2.cpp
#include <Arduino.h>
#include <BD3473KS2.h>
BD3473KS2::BD3473KS2(uint8_t cl, uint8_t da){
CL = cl;
DA = da;
pinMode(CL,OUTPUT);
pinMode(DA,OUTPUT);
digitalWrite(CL,LOW);digitalWrite(DA,LOW);
}
void BD3473KS2::set0(int in_main, int rec1, int rec2, int rec3, int rec4_0, int rec4_1, int rec5){
write((in_main<<10)|(rec1<<9)|(rec2<<8)|(rec3 << 7)|(rec4_0<<6)|(rec4_1<<5)|(rec5<<4)|ADDR_0);
}
void BD3473KS2::set1(int in_sub1, int in_sub2){
write((in_sub1<<10)|(in_sub2<<4)|ADDR_1);
}
void BD3473KS2::set2(int mode_sel_fl_fr, int mode_sel_c_sw, int mode_sel_sl_sr, int mode_sel_sbl_sbr, int adc_att){
write((mode_sel_fl_fr<<14)|(mode_sel_c_sw<<12)|(mode_sel_sl_sr<<10)|(mode_sel_sl_sr<<10)|(mode_sel_sbl_sbr<<7)|(adc_att<<4)|ADDR_2);
}
void BD3473KS2::set3(int sec_ch, int volume){
int vol_dig;
if(volume<=0){vol_dig=abs(volume);}
else{vol_dig=volume|1<<12;}
write((sec_ch<<13)|(vol_dig<<4)|ADDR_3);
}
void BD3473KS2::set4(int tone, int bass_reg){
int bass_dig;
if(bass_reg<=0){bass_dig=abs(bass_reg);}
else{bass_dig=bass_reg+0b10000;}
write((tone<<15)|(1<<13)|(bass_dig<<4)|ADDR_4);
}
void BD3473KS2::set5(int sw_ch_mix, int front_ph, int sb_front, int treb_reg){
int treb_dig;
if(treb_reg<=0){treb_dig=abs(treb_reg);}
else{treb_dig=treb_reg+0b10000;}
write((sw_ch_mix<<15)|(front_ph<<14)|(sb_front<<13)|(treb_dig<<4)|ADDR_5);
}
void BD3473KS2::set7(int a_b, int b_a, int base_clk){
write((a_b<<13)|(b_a<<10)|(base_clk<<8)|ADDR_7);
}
void BD3473KS2::write(char data){
for(int i = 0; i <= 15; i++){
digitalWrite(DA, (data << i) & 0x01);
digitalWrite(CL,HIGH);
if(i==15){digitalWrite(DA,HIGH);}else{digitalWrite(DA,LOW);}
digitalWrite(CL,LOW);
}
digitalWrite(CL,LOW);
digitalWrite(DA,LOW);
delay(10);
}
test.ino
#include <BD3473KS2.h>
BD3473KS2 bd(2,3); // cl,da
void setup(){
delay(500);
audio();
}
void loop(){
}
void audio(){
bd.set0(1, 0, 0, 0, 0, 0, 0);
// int in_main 1...18 === IN1_MAIN...IN18_MAIN | in_main 0 === MUTE
// int rec1 0...1 === (REC1) ON OFF
// int rec2 0...1 === (REC2) ON OFF
// int rec3 0...1 === (REC3) ON OFF
// int rec4_0 0...1 === (REC4) ON OFF
// int rec4_1 0...1 === REC4 SUB2
// int rec5 0...1 === (REC4/SUB2) ON OFF
bd.set1(0, 0);
// int in_sub1 0...18 === IN1_SUB1...IN18_SUB1 | 0b010011...0b111111 - prohibition
// int in_sub2 0...18 === IN1_SUB2...IN18_SUB2 | 0b010011...0b111111 - prohibition
bd.set2(1, 0, 0, 0, 1);
// int mode_sel_fl_fr 0...3 === MUTE MAIN MULTI1 MULTI2
// int mode_sel_c_sw 0...3 === MUTE prohibition MULTI1 MULTI2
// int mode_sel_sl_sr 0...3 === MUTE prohibition MULTI1 MULTI2
// int mode_sel_sbl_sbr 0...7 === MUTE prohibition MULTI1 MULTI2 SUB1 SUB2 prohibition
// int adc_att 0...7 === MUTE 0dB -6dB -6.5dB -7.5dB -9dB -12dB prohibition
bd.set3(0, 0);
bd.set3(1, 0);
bd.set3(2, 0);
bd.set3(3, 0);
bd.set3(4, 0);
bd.set3(5, 0);
bd.set3(6, 0);
bd.set3(7, 0);
// int sec_ch 0...7 === FR FL SW C SR SL SBR SBL
// int volume -190...48 === -95.0dB...+24db , step 0.5dB
bd.set4(0, 0);
// int tone 0...1 === ON OFF
// int bass_reg -10...10 === -10dB...+10dB
bd.set5(1, 0, 1, 0);
// int sw_ch_mix 0...1 === ON OFF
// int front_ph 0...1 === 0'... 180'
// int sb_front 0...1 === sb...front
// int treb_reg -10...10 === -10dB...+10dB
bd.set7(0, 0, 0);
// int a_b 0...3 === 11 5 7 15 ms
// int b_a 0...3 === 11 5 7 15 ms
// int base_clk === x1 x1/2 x1/4 prohibition
}