root/trunk/libffado/src/dice/focusrite/saffire_pro14.cpp

Revision 2239, 7.1 kB (checked in by jwoithe, 10 years ago)

DICE EAP: Saffire Pro 14: Fixes get/set nickname issues for Saffire Pro 14 as per r2238. Patch from Philippe Carriere (as was r2238).

Line 
1 /*
2  * Copyright (C) 2009 by Pieter Palmers
3  * Copyright (C) 2012 by Philippe Carriere
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  */
24
25 #include "saffire_pro14.h"
26
27 #include "focusrite_eap.h"
28
29 namespace Dice {
30 namespace Focusrite {
31
32 int SaffirePro14::SaffirePro14EAP::commandToFix(unsigned offset) {
33     if (offset<0x14) return 2;
34     if (offset<0x3C && offset>=0x14) return 1;
35     if (offset<0x5C && offset>=0x54) return 1;
36     if (offset<0x44 && offset>=0x3C) return 3;
37     if (offset == 0x5C) return 4;
38     return 0;
39 }
40 FocusriteEAP::Poti* SaffirePro14::SaffirePro14EAP::getMonitorPoti(std::string name) {
41     return new FocusriteEAP::Poti(this, name, 0x54);
42 }
43 FocusriteEAP::Poti* SaffirePro14::SaffirePro14EAP::getDimPoti(std::string name) {
44     return new FocusriteEAP::Poti(this, name, 0x58);
45 }
46
47 //
48 // From Focusrite doc, whatever is the samplerate, Pro 14 has
49 //  - 4 analogic inputs (mic/line)
50 //  - 2 SPDIF inputs
51 //  - 8 ieee1394 inputs
52 //  - 18 mixer inputs (this is the standart for all Dice Jr)
53 //
54 //  - 4 analogic outputs
55 //  - 2 SPDIF outputs
56 //  - 12 ieee1394 outputs
57 //  - 16 mixer outputs
58 //
59 void SaffirePro14::SaffirePro14EAP::setupSources_low() {
60     addSource("SPDIF/In",  6,  2, eRS_AES, 1);
61     addSource("Mic/Lin", 0,  4, eRS_InS0, 1);
62     addSource("Mixer/Out",  0, 16, eRS_Mixer, 1);
63     addSource("1394",   0, 12, eRS_ARX0, 1);
64     addSource("Mute",   0,  1, eRS_Muted);
65 }
66
67 void SaffirePro14::SaffirePro14EAP::setupDestinations_low() {
68     addDestination("SPDIF/Out",  6,  2, eRD_AES, 1);
69     addDestination("Line", 0,  4, eRD_InS0, 1);
70     addDestination("Mixer/In",  0, 16, eRD_Mixer0, 1);
71     addDestination("Mixer/In",  0,  2, eRD_Mixer1, 17);
72     addDestination("1394",   0, 6, eRD_ATX0, 1);
73     addDestination("Loop",   6,  2, eRD_ATX0, 1);
74 // Is a Mute destination useful ?
75 //    addDestination("Mute",   0,  1, eRD_Muted);
76 }
77
78 // 88.2/96 kHz
79 //
80 void SaffirePro14::SaffirePro14EAP::setupSources_mid() {
81     setupSources_low();
82 }
83
84 void SaffirePro14::SaffirePro14EAP::setupDestinations_mid() {
85     setupDestinations_low();
86 }
87
88 //
89 // 192 kHz is not supported
90 //
91 void SaffirePro14::SaffirePro14EAP::setupSources_high() {
92     printMessage("High (192 kHz) sample rate not supported by Saffire Pro 14\n");
93 }
94
95 void SaffirePro14::SaffirePro14EAP::setupDestinations_high() {
96     printMessage("High (192 kHz) sample rate not supported by Saffire Pro 14\n");
97 }
98
99 SaffirePro14::SaffirePro14( DeviceManager& d,
100                                         std::auto_ptr<ConfigRom>( configRom ))
101     : Dice::Device( d , configRom)
102 {
103     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Dice::Focusrite::SaffirePro14 (NodeID %d)\n",
104                  getConfigRom().getNodeId() );
105 }
106
107 /**
108  * The default configurations for the Saffire Pro 14 router.
109  *  For coherence with hardware, destinations must follow a specific ordering
110  */
111 void
112 SaffirePro14::SaffirePro14EAP::setupDefaultRouterConfig_low() {
113     unsigned int i;
114     // the 1394 stream receivers except the two "loops" one
115     for (i=0; i<4; i++) {
116         addRoute(eRS_InS1, i, eRD_ATX0, i);
117     }
118     for (i=0; i<2; i++) {
119         addRoute(eRS_AES, i, eRD_ATX0, i+4);
120     }
121     // The audio ports
122     // Ensure that audio port are not muted
123     for (i=0; i<4; i++) {
124         addRoute(eRS_ARX0, i, eRD_InS0, i);
125     }
126     // the SPDIF receiver
127     for (i=0; i<2; i++) {
128         addRoute(eRS_Muted, 0, eRD_AES, i);
129     }
130     // the "loops" 1394 stream receivers
131     for (i=0; i<2; i++) {
132         addRoute(eRS_Muted, 0, eRD_ATX0, i+6);
133     }
134     // the Mixer inputs
135     for (i=0; i<4; i++) {
136         addRoute(eRS_InS1, i, eRD_Mixer0, i);
137     }
138     for (i=0; i<2; i++) {
139         addRoute(eRS_AES, i, eRD_Mixer0, i+4);
140     }
141     for (i=0; i<10; i++) {
142         addRoute(eRS_Muted, 0, eRD_Mixer0, i+6);
143     }
144     for (i=0; i<2; i++) {
145         addRoute(eRS_ARX0, i, eRD_Mixer1, i);
146     }
147     // The two mute destinations
148     for (i=0; i<2; i++) {
149         addRoute(eRS_Mixer, i, eRD_Muted, 0);
150     }
151 }
152
153 /**
154  *  Assume to be identical to low rate
155  */
156 void
157 SaffirePro14::SaffirePro14EAP::setupDefaultRouterConfig_mid() {
158     setupDefaultRouterConfig_low();
159 }
160
161 /**
162  *  High rate not supported
163  */
164 void
165 SaffirePro14::SaffirePro14EAP::setupDefaultRouterConfig_high() {
166     printMessage("High (192 kHz) sample rate not supported by Saffire Pro 14\n");
167 }
168
169 SaffirePro14::~SaffirePro14()
170 {
171     getEAP()->storeFlashConfig();
172 }
173
174 bool SaffirePro14::discover() {
175     if (Dice::Device::discover()) {
176         m_monitor = new FocusriteEAP::MonitorSection(dynamic_cast<FocusriteEAP*>(getEAP()), "Monitoring");
177         getEAP()->addElement(m_monitor);
178         return true;
179     }
180     return false;
181 }
182
183 void
184 SaffirePro14::showDevice()
185 {
186     debugOutput(DEBUG_LEVEL_VERBOSE, "This is a Dice::Focusrite::SaffirePro14\n");
187     Dice::Device::showDevice();
188 }
189
190 Dice::EAP* SaffirePro14::createEAP() {
191     return new SaffirePro14EAP(*this);
192 }
193
194 bool SaffirePro14::setNickname(std::string name) {
195     char nickname[SAFFIRE_PRO14_APP_NICK_NAME_SIZE+1];
196
197     // The device has room for SAFFIRE_PRO14_APP_NICK_NAME_SIZE characters.
198     // Erase supplementary characters or fill-in with NULL character if necessary
199     strncpy(nickname, name.c_str(), SAFFIRE_PRO14_APP_NICK_NAME_SIZE);
200
201     // Strings from the device are always little-endian,
202     // so byteswap for big-endian machines
203     #if __BYTE_ORDER == __BIG_ENDIAN
204     byteSwapBlock((quadlet_t *)nickname, SAFFIRE_PRO14_APP_NICK_NAME_SIZE/4);
205     #endif
206
207     if (!getEAP()->writeRegBlock(Dice::EAP::eRT_Application, SAFFIRE_PRO14_REGISTER_APP_NICK_NAME,
208                                  (quadlet_t*)nickname, SAFFIRE_PRO14_APP_NICK_NAME_SIZE)) {
209         debugError("Could not write nickname string \n");
210         return false;
211     }
212     return true;
213 }
214 std::string SaffirePro14::getNickname() {
215     char nickname[SAFFIRE_PRO14_APP_NICK_NAME_SIZE+1];
216     if (!getEAP()->readRegBlock(Dice::EAP::eRT_Application, SAFFIRE_PRO14_REGISTER_APP_NICK_NAME,
217                                 (quadlet_t*)nickname, SAFFIRE_PRO14_APP_NICK_NAME_SIZE)){
218         debugError("Could not read nickname string \n");
219         return std::string("(unknown)");
220     }
221
222     // Strings from the device are always little-endian,
223     // so byteswap for big-endian machines
224     #if __BYTE_ORDER == __BIG_ENDIAN
225     byteSwapBlock((quadlet_t *)nickname, SAFFIRE_PRO14_APP_NICK_NAME_SIZE/4);
226     #endif
227
228     // The device supplies at most SAFFIRE_PRO14_APP_NICK_NAME_SIZE characters.  Ensure the string is
229     // NULL terminated.
230     nickname[SAFFIRE_PRO14_APP_NICK_NAME_SIZE] = 0;
231     return std::string(nickname);
232 }
233
234 }
235 }
236 // vim: et
Note: See TracBrowser for help on using the browser.