1

Тема: TDA7449

http://rcl-radio.ru/?p=56015

TDA7449.h

#ifndef TDA7449_H
#define TDA7449_H
// address 7 bit
#define TDA7449_address 0x44 // адрес HEX 88 > 0b10001000 > 7 bit = 0b1000100 = 0x44

//Sub addresses
#define TDA7449_INP_SEL    0b00000000
#define TDA7449_INP_GAIN   0b00000001
#define TDA7449_VOLUME     0b00000010
#define TDA7449_BASS       0b00000100
#define TDA7449_TREBLE     0b00000101
#define TDA7449_ATT_RIGHT  0b00000110
#define TDA7449_ATT_LEFT   0b00000111

#include <Arduino.h>
class TDA7449
{
  public:
    TDA7449();
        void setInput(int input); //        int 1...2 //// номер входа
    void inputGain(int gain); //        int 0...15 (шаг 2дБ)    0...30 дБ  //// усиление
    void setVolume(int volume); //      int 0...47 (шаг 1 дБ)  -47...0 дБ  //// громкость
        void setBass(int bass); //          int -7...+7 (шаг 2 дБ) -14...14 дБ //// тембр НЧ
        void setTreble(int treble); //      int -7...+7 (шаг 2 дБ) -14...14 дБ //// тембр ВЧ
/////////////////////// для регулировки баланса до -79 дБ /////////////////////////////////
        void setAttL(int att_l); //         int 0...72 (шаг 1дБ)    -72...0 дБ 
        void setAttR(int att_r); //         int 0...72 (шаг 1дБ)    -72...0 дБ
/////////////////////////////////////////////////////////////////////////////////    
  private:
    void writeWire(char a, char b);
};
    
#endif //TDA7449_H

TDA7449.cpp

#include <Arduino.h>
#include <Wire.h>
#include "TDA7449.h"

TDA7449::TDA7449(){
    Wire.begin();
}

void TDA7449::setVolume(int volume){
  volume = 47 - volume;
  writeWire(TDA7449_VOLUME, volume);
}

void TDA7449::setBass(int bass){
  switch (bass){
        case -7:bass = 0;break;
    case -6:bass = 1;break;
    case -5:bass = 2;break;
    case -4:bass = 3;break;
    case -3:bass = 4;break;
    case -2:bass = 5;break;
    case -1:bass = 6;break;
    case 0 :bass = 15;break;
    case 1 :bass = 14;break;
    case 2 :bass = 13;break;
    case 3 :bass = 12;break;
    case 4 :bass = 11;break;
    case 5 :bass = 10;break;
    case 6 :bass = 9;break;
    case 7 :bass = 8;break;}
  writeWire(TDA7449_BASS, bass);
}

void TDA7449::setTreble(int treble){
  switch (treble){
        case -7:treble = 0;break;
    case -6:treble = 1;break;
    case -5:treble = 2;break;
    case -4:treble = 3;break;
    case -3:treble = 4;break;
    case -2:treble = 5;break;
    case -1:treble = 6;break;
    case 0 :treble = 15;break;
    case 1 :treble = 14;break;
    case 2 :treble = 13;break;
    case 3 :treble = 12;break;
    case 4 :treble = 11;break;
    case 5 :treble = 10;break;
    case 6 :treble = 9;break;
    case 7 :treble = 8;break;}
  writeWire(TDA7449_TREBLE, treble);
}

void TDA7449::setInput(int input){
  switch (input) {
        case 1: input = 0x02;break;
    case 2: input = 0x03;break;}
  writeWire(TDA7449_INP_SEL,input);    
  } 

void TDA7449::inputGain(int gain){
  writeWire(TDA7449_INP_GAIN, gain);
}

void TDA7449::setAttR(int att_r){
  writeWire(TDA7449_ATT_RIGHT, att_r);
}

void TDA7449::setAttL(int att_l){
  writeWire(TDA7449_ATT_LEFT, att_l);
}

void TDA7449::writeWire(char a, char b){
  Wire.beginTransmission(TDA7449_address);
  Wire.write (a);
  Wire.write (b);
  Wire.endTransmission();
}