bebob: improve support for PreSonus Inspire1394
[ffado.git] / libffado / src / bebob / presonus / inspire1394_avdevice.cpp
blobe2f50f7a90e98b7f810404f872a81ad15c3c1899
1 /*
2 * Copyright (C) 2014 by Takashi Sakamoto
3 * Copyright (C) 2005-2008 by Pieter Palmers
5 * This file is part of FFADO
6 * FFADO = Free Firewire (pro-)audio drivers for linux
8 * FFADO is based upon FreeBoB.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) version 3 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "./inspire1394_avdevice.h"
27 #include "libutil/ByteSwap.h"
28 #include "libutil/cmd_serialize.h"
30 namespace BeBoB {
31 namespace Presonus {
33 Inspire1394Cmd::Inspire1394Cmd(Ieee1394Service& ieee1394service)
34 : VendorDependentCmd( ieee1394service )
35 , m_subfunc( 0x00 )
36 , m_idx( 0x00 )
37 , m_arg( 0x00 )
39 m_companyId = 0x000a92;
40 setSubunitType( AVC::eST_Audio );
41 setSubunitId( 0x00 );
43 bool Inspire1394Cmd::serialize( Util::Cmd::IOSSerialize& se )
45 bool result = true;
46 result &= VendorDependentCmd::serialize( se );
47 result &= se.write(m_subfunc, "Inspire1394Cmd subfunc");
48 result &= se.write(m_idx, "Inspire1394Cmd idx");
49 result &= se.write(m_arg, "Inspire1394Cmd arg");
51 return result;
53 bool Inspire1394Cmd::deserialize( Util::Cmd::IISDeserialize& de )
55 bool result = true;
56 result &= VendorDependentCmd::deserialize( de );
57 result &= de.read( &m_subfunc);
58 result &= de.read( &m_idx );
59 result &= de.read( &m_arg );
61 return result;
64 BinaryControl::BinaryControl(Inspire1394Device& parent,
65 EInspire1394CmdSubfunc subfunc,
66 std::string name, std::string label, std::string desc)
67 : Control::Discrete(&parent)
68 , m_Parent(parent)
69 , m_subfunc( subfunc )
71 setName(name);
72 setLabel(label);
73 setDescription(desc);
75 bool BinaryControl::setValue(int idx, int v)
77 uint8_t val = v;
79 debugOutput(DEBUG_LEVEL_VERBOSE,
80 "setValue for type: %d, idx: %d, val: %d\n",
81 m_subfunc, idx, val);
83 if ( !m_Parent.setSpecificValue(m_subfunc, idx, val) ) {
84 debugError( "setSpecificValue failed\n" );
85 return false;
88 return true;
90 int BinaryControl::getValue(int idx)
92 uint8_t val;
94 if ( !m_Parent.getSpecificValue(m_subfunc, idx, &val) ) {
95 debugError( "getSpecificValue failed\n" );
96 return 0;
99 debugOutput(DEBUG_LEVEL_VERBOSE,
100 "getValue for type: %d, idx: %d, val: %d\n",
101 m_subfunc, idx, val);
103 return val;
106 Inspire1394Device::Inspire1394Device(DeviceManager& d,
107 std::auto_ptr<ConfigRom>(configRom))
108 : BeBoB::Device( d, configRom )
110 addSpecificControls();
112 Inspire1394Device::~Inspire1394Device(void)
115 void Inspire1394Device::showDevice()
117 debugOutput(DEBUG_LEVEL_NORMAL,
118 "This is a BeBoB::Presonus::Inspire1394Device\n");
119 BeBoB::Device::showDevice();
121 bool Inspire1394Device::addSpecificControls(void)
123 Control::Container *ctls;
124 BinaryControl *ctl;
125 bool result = true;
127 debugOutput(DEBUG_LEVEL_VERBOSE,
128 "Building a PreSonus Inspire1394 mixer...\n");
130 ctls = new Control::Container(this, "Preamp");
131 if ( !addElement(ctls) ) {
132 debugWarning("Could not register specific controls to device\n");
133 delete ctls;
134 return false;
137 // RIAA equalization curve for Analog In 3/4
138 ctl = new BinaryControl(*this, EInspire1394CmdSubfuncPhono,
139 "PhonoSwitch", "Phono Switch", "Phono Switch");
140 result &= ctls->addElement(ctl);
142 // 48V for Analog In 1/2
143 ctl = new BinaryControl(*this, EInspire1394CmdSubfuncPhantom,
144 "PhantomPower", "Phantom Power", "Phantom Power");
145 result &= ctls->addElement(ctl);
147 // +20dB for Analog In 1/2
148 ctl = new BinaryControl(*this, EInspire1394CmdSubfuncBoost,
149 "MicBoost", "Mic Boost", "Mic Boost");
150 result &= ctls->addElement(ctl);
152 // Limitter of preamp for Analog In 1/2
153 ctl = new BinaryControl(*this, EInspire1394CmdSubfuncLimit,
154 "MicLimit", "Mic Limit", "Mic Limit");
155 result &= ctls->addElement(ctl);
157 if ( !result ) {
158 debugWarning("Any controls could not be added\n");
159 destroyMixer();
160 return false;
163 return true;
165 bool Inspire1394Device::getSpecificValue(EInspire1394CmdSubfunc subfunc,
166 int idx, uint8_t *val)
168 Inspire1394Cmd cmd( get1394Service() );
169 cmd.setCommandType( AVC::AVCCommand::eCT_Status );
170 cmd.setNodeId( getConfigRom().getNodeId() );
171 cmd.setVerbose( getDebugLevel() );
173 cmd.setSubfunc(subfunc);
174 cmd.setIdx(idx);
175 cmd.setArg(0xff);
177 if ( !cmd.fire() ) {
178 debugError( "Inspire1394Cmd failed\n" );
179 return false;
180 } else if (cmd.getResponse() != AVC::AVCCommand::eR_Implemented ) {
181 debugError("Inspire1394Cmd received error response\n");
182 return false;
185 *val = cmd.getArg();
187 return true;
189 bool Inspire1394Device::setSpecificValue(EInspire1394CmdSubfunc subfunc,
190 int idx, uint8_t val)
192 Inspire1394Cmd cmd( get1394Service() );
193 cmd.setCommandType( AVC::AVCCommand::eCT_Control );
194 cmd.setNodeId( getConfigRom().getNodeId() );
195 cmd.setVerbose( getDebugLevel() );
197 cmd.setSubfunc(subfunc);
198 cmd.setIdx(idx);
199 cmd.setArg(val);
201 if ( !cmd.fire() ) {
202 debugError( "Inspire1394Cmd failed\n" );
203 return false;
204 } else if (cmd.getResponse() != AVC::AVCCommand::eR_Accepted) {
205 debugError("Inspire1394Cmd received error response\n");
206 return false;
209 return true;
212 } // namespace Presonus
213 } // namespace BeBoB