Тема: BD3702
Данный контент доступен только зарегистрированным пользователям.
BD3702.h
// Александр Лиман
// liman324@yandex.ru
// rcl-radio.ru
// BD3702FV
// http://forum.rcl-radio.ru/viewtopic.php?id=121
#ifndef BD3702_H
#define BD3702_H
#define BD3702_address 0b1000000
#define INITIAL_SETUP_1 0x01
#define INITIAL_SETUP_2 0x02
#define INITIAL_SETUP_3 0x03
#define INPUT_SELECT 0x05
#define INPUT_GAIN 0x06
#define VOLUME_GAIN 0x20
#define FADER_1_FRONT 0x28
#define FADER_2_FRONT 0x29
#define FADER_1_REAR 0x2A
#define FADER_2_REAR 0x2B
#define FADER_SUB 0x2C
#define MIXING 0x30
#define BASS_SETUP 0x41
#define MIDDLE_SETUP 0x44
#define TREBLE_SETUP 0x47
#define BASS_GAIN 0x51
#define MIDDLE_GAIN 0x54
#define TREBLE_GAIN 0x57
#define LOUDNESS_GAIN 0x75
#define INITIAL_SETUP_4 0x90
#include <Arduino.h>
class BD3702
{
public:
BD3702();
// Advanced switch time of Mute === 0.6 1.0 1.4 3.2 ms = int 0...3
// Advanced switch time of Input gain/Volume/Tone/Fader/Loudness === 4.7 7.1 11.2 14.4 ms = int 0...3
// Advanced switch ON/OFF === OFF ON = int 0...1
void setInitial_1(int sw1, int sw2, int sw3); // 0x01
// Subwoofer LPF fc === OFF 55Hz 85 Hz 120Hz = int 0...3
// Subwoofer Output Select === LPF Front Rear Prohibition = int 0...3
// Level Meter RESET === HOLD RESET = int 0...1
void setInitial_2(int sub_f, int sub_out, int l_metr); // 0x02
// Loudness fo === 250Hz 400Hz 800Hz Prohibition = int 0...3
void setInitial_3(int loud_f); // 0x03
// Input Selector === A B C D_single E1_single E2_single D_diff E_full_diff Input_SHORT = int 0...8
void setIn(int in, int in_type); // 0x05
// Input Gain === 0...20 dB = int 0...20
// MUTE ON/OFF === OFF ON = int 0...1
void setIn_gain(int in_gain, int mute); // 0x06
// VOL === -79...+15 dB = int -79...15
void setVol(int vol); // 0x20
// FADER FRONT 1CH === -79...+15 dB = int -79...15
void setFront_1(int front_1); // 0x28
// FADER FRONT 2CH === -79...+15 dB = int -79...15
void setFront_2(int front_2); // 0x29
// FADER REAR 1CH === -79...+15 dB = int -79...15
void setRear_1(int rear_1); // 0x2A
// FADER REAR 2CH === -79...+15 dB = int -79...15
void setRear_2(int rear_2); // 0x2B
// FADER SUB === -79...+15 dB = int -79...15
void setSub(int sub); // 0x2C
// Mixing Gain === -79...+7 dB = int -79...7
void setMix_gain(int mix_g); // 0x30
// Bass Q factor === 0.5 1.0 1.5 2.0 = int 0...3
// Bass fo === 60Hz 80Hz 100Hz 120Hz = int 0...3
void setBass_setup(int bass_q, int bass_f); // 0x41
// Middle Q factor === 0.75 1.0 1.25 1.5 = int 0...3
// Middle fo === 500Hz 1kHz 1.5kHz 2.5kHz = int 0...3
void setMiddle_setup(int mid_q, int mid_f); // 0x44
// Treble Q factor === 0.75 1.25 = int 0...1
// Treble fo === 7.5kHz 10kHz 12.5kHz 15kHz = int 0...3
void setTreble_setup(int treb_q, int treb_f); // 0x47
// Bass Gain === -20...+20 dB = int -20...20
void setBass_gain(int bass_gain); // 0x51
// Middle Gain === -20...+20 dB = int -20...20
void setMiddle_gain(int mid_gain); // 0x54
// Treble Gain === -20...+20 dB = int -20...20
void setTreble_gain(int treb_gain); // 0x57
// Loudness Gain === 0...20 dB = int 0...20
void setLoudness_gain(int loud_gain); // 0x75
// Setup 4 = not param
void setInitial_4();
private:
void writeWire(char a, char b);
};
#endif //BD3702_H
BD3702.cpp
#include <Arduino.h>
#include <Wire.h>
#include "BD3702.h"
BD3702::BD3702(){
Wire.begin();
}
void BD3702::setInitial_1(int sw1, int sw2, int sw3){
switch(sw1){
case 0: sw1 = 0b00000000;break;
case 1: sw1 = 0b00000001;break;
case 2: sw1 = 0b00000010;break;
case 3: sw1 = 0b00000011;break;
}
switch(sw2){
case 0: sw2 = 0b00000000;break;
case 1: sw2 = 0b00010000;break;
case 2: sw2 = 0b00100000;break;
case 3: sw2 = 0b00110000;break;
}
switch(sw3){
case 0: sw3 = 0b00000000;break;
case 1: sw3 = 0b10000000;break;
}
writeWire(INITIAL_SETUP_1, 0b01000100 + sw1 + sw2 + sw3);
}
void BD3702::setInitial_2(int sub_f, int sub_out, int l_metr){
switch(sub_f){
case 0: sub_f = 0b00000000;break;
case 1: sub_f = 0b00000001;break;
case 2: sub_f = 0b00000010;break;
case 3: sub_f = 0b00000011;break;
}
switch(sub_out){
case 0: sub_out = 0b00000000;break;
case 1: sub_out = 0b00010000;break;
case 2: sub_out = 0b00100000;break;
case 3: sub_out = 0b00110000;break;
}
switch(l_metr){
case 0: l_metr = 0b00000000;break;
case 1: l_metr = 0b01000000;break;
}
writeWire(INITIAL_SETUP_2, sub_f + sub_out + l_metr);
}
void BD3702::setInitial_3(int loud_f){
switch(loud_f){
case 0: loud_f = 0b00000001;break;
case 1: loud_f = 0b00001001;break;
case 2: loud_f = 0b00010001;break;
case 3: loud_f = 0b00011001;break;
}
writeWire(INITIAL_SETUP_3, loud_f);
}
void BD3702::setIn(int in, int in_type){
switch(in){
case 0: in = 0b00000000;break;
case 1: in = 0b00000001;break;
case 2: in = 0b00000010;break;
case 3: in = 0b00000011;break;
case 4: in = 0b00001010;break;
case 5: in = 0b00001011;break;
case 6: in = 0b00000110;break;
case 7: in = 0b00001000;break;
case 8: in = 0b00001001;break;
}
switch(in_type){
case 0: in_type = 0b00000000;break;
case 1: in_type = 0b10000000;break;
}
writeWire(INPUT_SELECT, in + in_type);
}
void BD3702::setIn_gain(int in_gain, int mute){
switch(mute){
case 0: mute = 0b00000000;break;
case 1: mute = 0b10000000;break;
}
writeWire(INPUT_GAIN, in_gain + mute);
}
void BD3702::setVol(int vol){
if(vol > 0){vol = 128 - vol;}
if(vol <= 0){vol = abs(vol) + 128;}
writeWire(VOLUME_GAIN, vol);
}
void BD3702::setFront_1(int front_1){
if(front_1 > 0){front_1 = 128 - front_1;}
if(front_1 <= 0){front_1 = abs(front_1) + 128;}
writeWire(FADER_1_FRONT, front_1);
}
void BD3702::setFront_2(int front_2){
if(front_2 > 0){front_2 = 128 - front_2;}
if(front_2 <= 0){front_2 = abs(front_2) + 128;}
writeWire(FADER_2_FRONT, front_2);
}
void BD3702::setRear_1(int rear_1){
if(rear_1 > 0){rear_1 = 128 - rear_1;}
if(rear_1 <= 0){rear_1 = abs(rear_1) + 128;}
writeWire(FADER_1_REAR, rear_1);
}
void BD3702::setRear_2(int rear_2){
if(rear_2 > 0){rear_2 = 128 - rear_2;}
if(rear_2 <= 0){rear_2 = abs(rear_2) + 128;}
writeWire(FADER_2_REAR, rear_2);
}
void BD3702::setSub(int sub){
if(sub > 0){sub = 128 - sub;}
if(sub <= 0){sub = abs(sub) + 128;}
writeWire(FADER_SUB, sub);
}
void BD3702::setMix_gain(int mix_g){
if(mix_g > 0){mix_g = 128 - mix_g;}
if(mix_g <= 0){mix_g = abs(mix_g) + 128;}
writeWire(MIXING, mix_g);
}
void BD3702::setBass_setup(int bass_q, int bass_f){
switch(bass_q){
case 0: bass_q = 0b00000000;break;
case 1: bass_q = 0b00000001;break;
case 2: bass_q = 0b00000010;break;
case 3: bass_q = 0b00000011;break;
}
switch(bass_f){
case 0: bass_f = 0b00000000;break;
case 1: bass_f = 0b00010000;break;
case 2: bass_f = 0b00100000;break;
case 3: bass_f = 0b00110000;break;
}
writeWire(BASS_SETUP, bass_q + bass_f);
}
void BD3702::setMiddle_setup(int mid_q, int mid_f){
switch(mid_q){
case 0: mid_q = 0b00000000;break;
case 1: mid_q = 0b00000001;break;
case 2: mid_q = 0b00000010;break;
case 3: mid_q = 0b00000011;break;
}
switch(mid_f){
case 0: mid_f = 0b00000000;break;
case 1: mid_f = 0b00010000;break;
case 2: mid_f = 0b00100000;break;
case 3: mid_f = 0b00110000;break;
}
writeWire(MIDDLE_SETUP, mid_q + mid_f);
}
void BD3702::setTreble_setup(int treb_q, int treb_f){
switch(treb_q){
case 0: treb_q = 0b00000000;break;
case 1: treb_q = 0b00000001;break;
}
switch(treb_f){
case 0: treb_f = 0b00000000;break;
case 1: treb_f = 0b00010000;break;
case 2: treb_f = 0b00100000;break;
case 3: treb_f = 0b00110000;break;
}
writeWire(TREBLE_SETUP, treb_q + treb_f);
}
void BD3702::setBass_gain(int bass_gain){
if(bass_gain>0){bass_gain = bass_gain + 0b00000000;}
if(bass_gain<=0){bass_gain = abs(bass_gain) + 0b10000000;}
writeWire(BASS_GAIN, bass_gain);
}
void BD3702::setMiddle_gain(int mid_gain){
if(mid_gain>0){mid_gain = mid_gain + 0b00000000;}
if(mid_gain<=0){mid_gain = abs(mid_gain) + 0b10000000;}
writeWire(MIDDLE_GAIN, mid_gain);
}
void BD3702::setTreble_gain(int treb_gain){
if(treb_gain>0){treb_gain = treb_gain + 0b00000000;}
if(treb_gain<=0){treb_gain = abs(treb_gain) + 0b10000000;}
writeWire(TREBLE_GAIN, treb_gain);
}
void BD3702::setLoudness_gain(int loud_gain){
writeWire(LOUDNESS_GAIN, loud_gain);
}
void BD3702::setInitial_4(){
writeWire(INITIAL_SETUP_4, 0b00110000);
}
void BD3702::writeWire(char a, char b){
Wire.beginTransmission(BD3702_address);
Wire.write (a);
Wire.write (b);
Wire.endTransmission();
}
test.ino
#include <BD3702.h>
BD3702 bd;
void setup() {
audio();
}
void loop() {}
void audio(){
// Advanced switch time of Mute === 0.6 1.0 1.4 3.2 ms = int 0...3
// Advanced switch time of Input gain/Volume/Tone/Fader/Loudness === 4.7 7.1 11.2 14.4 ms = int 0...3
// Advanced switch ON/OFF === OFF ON = int 0...1
bd.setInitial_1(0, 0, 0); // 0x01
// Subwoofer LPF fc === OFF 55Hz 85 Hz 120Hz = int 0...3
// Subwoofer Output Select === LPF Front Rear Prohibition = int 0...3
// Level Meter RESET === HOLD RESET = int 0...1
bd.setInitial_2(0, 0, 0); // 0x02
// Loudness fo === 250Hz 400Hz 800Hz Prohibition = int 0...3
bd.setInitial_3(0); // 0x03
// Input Selector === A B C D_single E1_single E2_single D_diff E_full_diff Input_SHORT = int 0...8
bd.setIn(0, 0); // 0x05
// Input Gain === 0...20 dB = int 0...20
// MUTE ON/OFF === OFF ON = int 0...1
bd.setIn_gain(0, 0); // 0x06
// VOL === -79...+15 dB = int -79...15
bd.setVol(0); // 0x20
// FADER FRONT 1CH === -79...+15 dB = int -79...15
bd.setFront_1(0); // 0x28
// FADER FRONT 2CH === -79...+15 dB = int -79...15
bd.setFront_2(0); // 0x29
// FADER REAR 1CH === -79...+15 dB = int -79...15
bd.setRear_1(0); // 0x2A
// FADER REAR 2CH === -79...+15 dB = int -79...15
bd.setRear_2(0); // 0x2B
// FADER SUB === -79...+15 dB = int -79...15
bd.setSub(0); // 0x2C
// Mixing Gain === -79...+7 dB = int -79...7
bd.setMix_gain(0); // 0x30
// Bass Q factor === 0.5 1.0 1.5 2.0 = int 0...3
// Bass fo === 60Hz 80Hz 100Hz 120Hz = int 0...3
bd.setBass_setup(0, 0); // 0x41
// Middle Q factor === 0.75 1.0 1.25 1.5 = int 0...3
// Middle fo === 500Hz 1kHz 1.5kHz 2.5kHz = int 0...3
bd.setMiddle_setup(0, 0); // 0x44
// Treble Q factor === 0.75 1.25 = int 0...1
// Treble fo === 7.5kHz 10kHz 12.5kHz 15kHz = int 0...3
bd.setTreble_setup(0, 0); // 0x47
// Bass Gain === -20...+20 dB = int -20...20
bd.setBass_gain(0); // 0x51
// Middle Gain === -20...+20 dB = int -20...20
bd.setMiddle_gain(0); // 0x54
// Treble Gain === -20...+20 dB = int -20...20
bd.setTreble_gain(0); // 0x57
// Loudness Gain === 0...20 dB = int 0...20
bd.setLoudness_gain(0); // 0x75
// Setup 4 = not param
bd.setInitial_4();
}