Тема: TDA7718
Протестировано!!!
3 band car audio processor
Данный контент доступен только зарегистрированным пользователям.
https://github.com/liman324/TDA7718.git
TDA7718.h
#ifndef TDA7718_H
#define TDA7718_H
#define TDA7718_address 0b1000100 // 7 bit
#define MAIN 0b00000000
#define SOFT_MUTE 0b00000100
#define SOFT_STEP1 0b00000101
#define SOFT_STEP2 0b00000110
#define LOUNNESS 0b00000111
#define VOLUME_OUT 0b00001000
#define TERBLE 0b00001001
#define MIDDLE 0b00001010
#define BASS 0b00001011
#define SUB_MID_BASS 0b00001100
#define ATT_LF 0b00001101
#define ATT_RF 0b00001110
#define ATT_LR 0b00001111
#define ATT_RR 0b00010000
#define ATT_SL 0b00010001
#define ATT_SR 0b00010010
#include <Arduino.h>
class TDA7718
{
public:
TDA7718();
void setMain(byte main_sel, byte fd_qd, byte main_gain, byte sub_flat); // 0,0,0,0
// main_sel - 0 SE1 / 1 SE3 / 2 QD1 / 3 QD2_FD1 / 4 SE2 / 5 SE4 / 6 SE5 / 7 MUTE === TDA7718N
// main_sel - 0 SE1 / 1 SE3 / 2 QD1 / 3 QD2_FD1 / 4 SE2 / 5 MUTE / 6 MUTE / 7 MUTE === TDA7718B
// fd_qd - 0 FD / 1 QD2
// main_gain - 0 0dB / 1 3dB
// sub_flat - 0 off / 1 on
void setSoft_mute(byte soft_mute, byte pin_iic, byte soft_mute_time, byte sub_in, byte sub_eneble, byte fast_ch, byte anty_filter);// 0,0,1,0,0,0,0
// soft_mute - 0 off / 1 on
// pin_iic - 0 pin_and_iic / 1 iic
// soft_mute_time - 0 0.48ms / 1 0.96ms / 2 7.68ms / 3 15.63ms
// sub_in - 0 input_mux / 1 bass_output
// sub_eneble - 0 on / 1 off
// fast_ch - 0 on / 1 off
// anty_filter - 0 on / off(bypass)
void setSoft_step_1(byte loud_soft, byte vol_soft, byte treb_soft, byte mid_soft, byte bass_soft, byte lf_soft, byte rf_soft, byte lr_soft); // 0,0,0,0,0,0,0,0
// all - 0 on / 1 off
void setSoft_step_2(byte rr_soft, byte sub_l_soft, byte sub_r_soft, byte soft_time, byte zero, byte spike); // 0,0,0,0,1,1
// rr_soft - 0 on / 1 off
// sub_l_soft - 0 on / 1 off
// sub_r_soft - 0 on / 1 off
// soft_time - 0 5ms / 1 10ms
// zero - 0 100mV / 1 75mV / 2 50mV / 3 25mV
// spike - 0 11mkS / 1 22mkS / 2 33mkS / 3 44mkS
void setLoudness(byte lon_att, byte lon_cen_f, byte lon_h_boost, byte lon_soft_step); // 0,0,0,0
// lon_att - byte 0...15 = 0...-15dB
// lon_cen_f - 0 flat / 1 400Hz / 2 800Hz / 3 2400Hz
// lon_h_boost - 0 on / 1 off
// lon_soft_step - 0 act / 1 wait
void setVolume_gain(int vol_gain, byte vol_out_gain, byte vol_soft_step); // 0,0,0
// vol_gain - int -31...23 = -31...+23dB
// vol_out_gain - 0 1dB / 1 0dB
// vol_soft_step - 0 act / 1 wait
void setTreble(int treb, byte treb_cen_f, byte treb_soft_step); // 0,0,0
// treb - int -15...+15 = -15...+15dB
// treb_cen_f - 0 10.0kHz / 1 12.5kHz / 2 15.0kHz / 3 17.5 kHz
// treb_soft_step - 0 act / 1 wait
void setMiddle(int mid, byte mid_q, byte mid_soft_step); // 0,0,0
// mid - int -15...+15 = -15...+15dB
// mid_q - 0 0.75 / 1 1.0 / 2 1.25 / 3 reserved
// mid_soft_step - 0 act / 1 wait
void setBass(int bass, byte bass_q, byte bass_soft_step); // 0,0,0
// bass - int -15...+15 = -15...+15dB
// bass_q - 0 1.0 / 1 1.25 / 2 1.5 / 3 2.0
// bass_soft_step - 0 act / 1 wait
void setSub_Mid_Bass(byte sub_cen_f, byte sub_faza, byte mid_cen_f, byte bass_cen_f, byte bass_dc);
// sub_cen_f - 0 55Hz / 1 85Hz / 2 120Hz / 3 160Hz
// sub_faza - 0 180deg / 1 0deg
// mid_cen_f - 0 500Hz / 1 1000Hz / 2 1500Hz / 3 2500Hz
// bass_cen_f - 0 60Hz / 1 80Hz / 2 100Hz / 3 200Hz
// bass_dc - 0 on / 1 off
void setLF(int lf, byte lf_soft_step);
void setRF(int rf, byte rf_soft_step);
void setLR(int lr, byte lr_soft_step);
void setRR(int rr, byte rr_soft_step);
void setSL(int sl, byte sl_soft_step);
void setSR(int sr, byte sr_soft_step);
// all int -79...+15 = -79...+15dB
// all - 0 act / 1 wait
private:
void writeWire(char a, char b);
};
#endif //TDA7718_H
TDA7718.cpp
#include <Arduino.h>
#include <Wire.h>
#include "TDA7718.h"
TDA7718::TDA7718(){
Wire.begin();
}
void TDA7718::setMain(byte main_sel, byte fd_qd, byte main_gain, byte sub_flat){
switch(main_sel){
case 0: main_sel = 0b00000000;break;
case 1: main_sel = 0b00000001;break;
case 2: main_sel = 0b00000010;break;
case 3: main_sel = 0b00000011;break;
case 4: main_sel = 0b00000100;break;
case 5: main_sel = 0b00000101;break;
case 6: main_sel = 0b00000110;break;
case 7: main_sel = 0b00000111;break;
}
switch(fd_qd){
case 0: fd_qd = 0b00000000;break;
case 1: fd_qd = 0b00001000;break;
}
switch(main_gain){
case 0: main_gain = 0b00000000;break;
case 1: main_gain = 0b00010000;break;
}
switch(sub_flat){
case 0: sub_flat = 0b00000000;break;
case 1: sub_flat = 0b00100000;break;
}
writeWire(MAIN, main_sel + fd_qd + main_gain + sub_flat);
}
void TDA7718::setSoft_mute(byte soft_mute, byte pin_iic, byte soft_mute_time, byte sub_in, byte sub_eneble, byte fast_ch, byte anty_filter){
switch(soft_mute){
case 0: soft_mute = 0b00000000;break;
case 1: soft_mute = 0b00000001;break;
}
switch(pin_iic){
case 0: pin_iic = 0b00000000;break;
case 1: pin_iic = 0b00000010;break;
}
switch(soft_mute_time){
case 0: soft_mute_time = 0b00000000;break;
case 1: soft_mute_time = 0b00000100;break;
case 2: soft_mute_time = 0b00001000;break;
case 3: soft_mute_time = 0b00001100;break;
}
switch(sub_in){
case 0: sub_in = 0b00000000;break;
case 1: sub_in = 0b00010000;break;
}
switch(sub_eneble){
case 0: sub_eneble = 0b00000000;break;
case 1: sub_eneble = 0b00100000;break;
}
switch(fast_ch){
case 0: fast_ch = 0b00000000;break;
case 1: fast_ch = 0b01000000;break;
}
switch(anty_filter){
case 0: anty_filter = 0b00000000;break;
case 1: anty_filter = 0b10000000;break;
}
writeWire(SOFT_MUTE, soft_mute + pin_iic + soft_mute_time + sub_in + sub_eneble + fast_ch + anty_filter);
}
void TDA7718::setSoft_step_1(byte loud_soft, byte vol_soft, byte treb_soft, byte mid_soft, byte bass_soft, byte lf_soft, byte rf_soft, byte lr_soft){
switch(loud_soft){
case 0: loud_soft = 0b00000000;break;
case 1: loud_soft = 0b00000001;break;
}
switch(vol_soft){
case 0: vol_soft = 0b00000000;break;
case 1: vol_soft = 0b00000010;break;
}
switch(treb_soft){
case 0: treb_soft = 0b00000000;break;
case 1: treb_soft = 0b00000100;break;
}
switch(mid_soft){
case 0: mid_soft = 0b00000000;break;
case 1: mid_soft = 0b00001000;break;
}
switch(bass_soft){
case 0: bass_soft = 0b00000000;break;
case 1: bass_soft = 0b00010000;break;
}
switch(lf_soft){
case 0: lf_soft = 0b00000000;break;
case 1: lf_soft = 0b00100000;break;
}
switch(rf_soft){
case 0: rf_soft = 0b00000000;break;
case 1: rf_soft = 0b01000000;break;
}
switch(lr_soft){
case 0: lr_soft = 0b00000000;break;
case 1: lr_soft = 0b10000000;break;
}
writeWire(SOFT_STEP1, loud_soft + vol_soft + treb_soft + mid_soft + bass_soft + lf_soft + rf_soft + lr_soft);
}
void TDA7718::setSoft_step_2(byte rr_soft, byte sub_l_soft, byte sub_r_soft, byte soft_time, byte zero, byte spike){
switch(rr_soft){
case 0: rr_soft = 0b00000000;break;
case 1: rr_soft = 0b00000001;break;
}
switch(sub_l_soft){
case 0: sub_l_soft = 0b00000000;break;
case 1: sub_l_soft= 0b00000010;break;
}
switch(sub_r_soft){
case 0: sub_r_soft = 0b00000000;break;
case 1: sub_r_soft = 0b00000100;break;
}
switch(soft_time){
case 0: soft_time = 0b00000000;break;
case 1: soft_time = 0b00001000;break;
}
switch(zero){
case 0: zero = 0b00000000;break;
case 1: zero = 0b00010000;break;
case 2: zero = 0b00100000;break;
case 3: zero = 0b00110000;break;
}
switch(spike){
case 0: spike = 0b00000000;break;
case 1: spike = 0b01000000;break;
case 2: spike = 0b10000000;break;
case 3: spike = 0b11000000;break;
}
writeWire(SOFT_STEP2, rr_soft + sub_l_soft + sub_r_soft + soft_time + zero + spike);
}
void TDA7718::setLoudness(byte lon_att, byte lon_cen_f, byte lon_h_boost, byte lon_soft_step){
switch(lon_cen_f){
case 0: lon_cen_f = 0b00000000;break;
case 1: lon_cen_f = 0b00010000;break;
case 2: lon_cen_f = 0b00100000;break;
case 3: lon_cen_f = 0b00110000;break;
}
switch(lon_h_boost){
case 0: lon_h_boost = 0b00000000;break;
case 1: lon_h_boost = 0b01000000;break;
}
switch(lon_soft_step){
case 0: lon_soft_step = 0b00000000;break;
case 1: lon_soft_step = 0b10000000;break;
}
writeWire(LOUNNESS, lon_att + lon_cen_f + lon_h_boost + lon_soft_step);
}
void TDA7718::setVolume_gain(int vol_gain, byte vol_out_gain, byte vol_soft_step){
if(vol_gain<0){vol_gain = abs(vol_gain)+32;}
switch(vol_out_gain){
case 0: vol_out_gain = 0b00000000;break;
case 1: vol_out_gain = 0b01000000;break;
}
switch(vol_soft_step){
case 0: vol_soft_step = 0b00000000;break;
case 1: vol_soft_step = 0b10000000;break;
}
writeWire(VOLUME_OUT, vol_gain + vol_out_gain + vol_soft_step);
}
void TDA7718::setTreble(int treb, byte treb_cen_f, byte treb_soft_step){
if(treb >= 0){treb = 31 - treb;}
if(treb < 0){treb = treb + 15;}
switch(treb_cen_f){
case 0: treb_cen_f = 0b00000000;break;
case 1: treb_cen_f = 0b00100000;break;
case 2: treb_cen_f = 0b01000000;break;
case 3: treb_cen_f = 0b01100000;break;
}
switch(treb_soft_step){
case 0: treb_soft_step = 0b00000000;break;
case 1: treb_soft_step = 0b10000000;break;
}
writeWire(TERBLE, treb + treb_cen_f + treb_soft_step);
}
void TDA7718::setMiddle(int mid, byte mid_q, byte mid_soft_step){
if(mid >= 0){mid = 31 - mid;}
if(mid < 0){mid = mid + 15;}
switch(mid_q){
case 0: mid_q = 0b00000000;break;
case 1: mid_q = 0b00100000;break;
case 2: mid_q = 0b01000000;break;
case 3: mid_q = 0b01100000;break;
}
switch(mid_soft_step){
case 0: mid_soft_step = 0b00000000;break;
case 1: mid_soft_step = 0b10000000;break;
}
writeWire(MIDDLE, mid + mid_q + mid_soft_step);
}
void TDA7718::setBass(int bass, byte bass_q, byte bass_soft_step){
if(bass >= 0){bass = 31 - bass;}
if(bass < 0){bass = bass + 15;}
switch(bass_q){
case 0: bass_q = 0b00000000;break;
case 1: bass_q = 0b00100000;break;
case 2: bass_q = 0b01000000;break;
case 3: bass_q = 0b01100000;break;
}
switch(bass_soft_step){
case 0: bass_soft_step = 0b00000000;break;
case 1: bass_soft_step = 0b10000000;break;
}
writeWire(BASS, bass + bass_q + bass_soft_step);
}
void TDA7718::setSub_Mid_Bass(byte sub_cen_f, byte sub_faza, byte mid_cen_f, byte bass_cen_f, byte bass_dc){
switch(sub_cen_f){
case 0: sub_cen_f = 0b00000000;break;
case 1: sub_cen_f = 0b00000001;break;
case 2: sub_cen_f = 0b00000010;break;
case 3: sub_cen_f = 0b00000011;break;
}
switch(sub_faza){
case 0: sub_faza = 0b00000000;break;
case 1: sub_faza = 0b00000100;break;
}
switch(mid_cen_f){
case 0: mid_cen_f = 0b00000000;break;
case 1: mid_cen_f = 0b00001000;break;
case 2: mid_cen_f = 0b00010000;break;
case 3: mid_cen_f = 0b00011000;break;
}
switch(bass_cen_f){
case 0: bass_cen_f = 0b00000000;break;
case 1: bass_cen_f = 0b00100000;break;
case 2: bass_cen_f = 0b01000000;break;
case 3: bass_cen_f = 0b01100000;break;
}
switch(bass_dc){
case 0: bass_dc = 0b00000000;break;
case 1: bass_dc = 0b10000000;break;
}
writeWire(SUB_MID_BASS, sub_cen_f + sub_faza + mid_cen_f + bass_cen_f + bass_dc);
}
void TDA7718::setLF(int lf, byte lf_soft_step){
if(lf < 0){lf = abs(lf) + 16;}
writeWire(ATT_LF, lf + (lf_soft_step << 7));
}
void TDA7718::setRF(int rf, byte rf_soft_step){
if(rf < 0){rf = abs(rf) + 16;}
writeWire(ATT_RF, rf + (rf_soft_step << 7));
}
void TDA7718::setLR(int lr, byte lr_soft_step){
if(lr < 0){lr = abs(lr) + 16;}
writeWire(ATT_LR, lr + (lr_soft_step << 7));
}
void TDA7718::setRR(int rr, byte rr_soft_step){
if(rr < 0){rr = abs(rr) + 16;}
writeWire(ATT_RR, rr + (rr_soft_step << 7));
}
void TDA7718::setSL(int sl, byte sl_soft_step){
if(sl < 0){sl = abs(sl) + 16;}
writeWire(ATT_SL, sl + (sl_soft_step << 7));
}
void TDA7718::setSR(int sr, byte sr_soft_step){
if(sr < 0){sr = abs(sr) + 16;}
writeWire(ATT_SR, sr + (sr_soft_step << 7));
}
void TDA7718::writeWire(char a, char b){
Wire.beginTransmission(TDA7718_address);
Wire.write (a);
Wire.write (b);
Wire.endTransmission();
}
test.ino
#include <TDA7718.h>
TDA7718 tda;
void setup(){
delay(1000);
audio();
}
void loop(){}
void audio(){
tda.setMain(0,0,0,0); // 0,0,0,0
// main_sel - 0 SE1 / 1 SE3 / 2 QD1 / 3 QD2_FD1 / 4 SE2 / 5 SE4 / 6 SE5 / 7 MUTE === TDA7718N
// main_sel - 0 SE1 / 1 SE3 / 2 QD1 / 3 QD2_FD1 / 4 SE2 / 5 MUTE / 6 MUTE / 7 MUTE === TDA7718B
// fd_qd - 0 FD / 1 QD2
// main_gain - 0 0dB / 1 3dB
// sub_flat - 0 off / 1 on
tda.setSoft_mute(1,0,1,0,0,0,0);// 1,0,1,0,0,0,0
// soft_mute - 0 on / 1 off
// pin_iic - 0 pin_and_iic / 1 iic
// soft_mute_time - 0 0.48ms / 1 0.96ms / 2 7.68ms / 3 15.63ms
// sub_in - 0 input_mux / 1 bass_output
// sub_eneble - 0 on / 1 off
// fast_ch - 0 on / 1 off
// anty_filter - 0 on / off(bypass)
tda.setSoft_step_1(0,0,0,0,0,0,0,0); // 0,0,0,0,0,0,0,0
// all - 0 on / 1 off
tda.setSoft_step_2(0,0,0,0,1,1); // 0,0,0,0,1,1
// rr_soft - 0 on / 1 off
// sub_l_soft - 0 on / 1 off
// sub_r_soft - 0 on / 1 off
// soft_time - 0 5ms / 1 10ms
// zero - 0 100mV / 1 75mV / 2 50mV / 3 25mV
// spike - 0 11mkS / 1 22mkS / 2 33mkS / 3 44mkS
tda.setLoudness(0,0,0,0); // 0,0,0,0
// lon_att - byte 0...15 = 0...-15dB
// lon_cen_f - 0 flat / 1 400Hz / 2 800Hz / 3 2400Hz
// lon_h_boost - 0 on / 1 off
// lon_soft_step - 0 act / 1 wait
tda.setVolume_gain(-20,1,0); // 0,0,0
// vol_gain - int -31...23 = -31...+23dB
// vol_out_gain - 0 1dB / 1 0dB
// vol_soft_step - 0 act / 1 wait
tda.setTreble(12,0,0); // 0,0,0
// treb - int -15...+15 = -15...+15dB
// treb_cen_f - 0 10.0kHz / 1 12.5kHz / 2 15.0kHz / 3 17.5 kHz
// treb_soft_step - 0 act / 1 wait
tda.setMiddle(0,0,0); // 0,0,0
// mid - int -15...+15 = -15...+15dB
// mid_q - 0 0.75 / 1 1.0 / 2 1.25 / 3 reserved
// mid_soft_step - 0 act / 1 wait
tda.setBass(5,0,0); // 0,0,0
// bass - int -15...+15 = -15...+15dB
// bass_q - 0 1.0 / 1 1.25 / 2 1.5 / 3 2.0
// bass_soft_step - 0 act / 1 wait
tda.setSub_Mid_Bass(0,0,2,3,0); // 0,0,0,0,0
// sub_cen_f - 0 55Hz / 1 85Hz / 2 120Hz / 3 160Hz
// sub_faza - 0 180deg / 1 0deg
// mid_cen_f - 0 500Hz / 1 1000Hz / 2 1500Hz / 3 2500Hz
// bass_cen_f - 0 60Hz / 1 80Hz / 2 100Hz / 3 200Hz
// bass_dc - 0 on / 1 off
tda.setLF(0,0);
tda.setRF(0,0);
tda.setLR(0,0);
tda.setRR(0,0);
tda.setSL(0,0);
tda.setSR(0,0);
// all int -79...+15 = -79...+15dB
// all - 0 act / 1 wait
}