motu: the 4pre channel layout within packets is now believed to be correct. Thanks...
[ffado.git] / libffado / src / fireworks / efc / efc_cmds_ioconfig.cpp
blob52b6c6510fb1511030c005111f01b03af1037db9
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) version 3 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "efc_cmd.h"
25 #include "efc_cmds_ioconfig.h"
27 #include "libutil/ByteSwap.h"
28 #include <iostream>
29 #include <cstring>
31 using namespace std;
33 namespace FireWorks {
35 EfcGenericIOConfigCmd::EfcGenericIOConfigCmd(enum eIOConfigRegister r)
36 : EfcCmd()
37 , m_value ( 0 )
38 , m_reg ( r )
40 m_category_id = EFC_CAT_IO_CONFIG;
41 m_type=eCT_Get;
42 setRegister(r);
45 bool
46 EfcGenericIOConfigCmd::serialize( Util::Cmd::IOSSerialize& se )
48 bool result=true;
50 if (m_type == eCT_Get) {
51 // the length should be specified before
52 // the header is serialized
53 m_length=EFC_HEADER_LENGTH_QUADLETS;
55 result &= EfcCmd::serialize ( se );
57 } else {
58 // the length should be specified before
59 // the header is serialized
60 m_length=EFC_HEADER_LENGTH_QUADLETS+1;
62 result &= EfcCmd::serialize ( se );
64 result &= se.write(CondSwapToBus32(m_value), "Value" );
66 return result;
69 bool
70 EfcGenericIOConfigCmd::deserialize( Util::Cmd::IISDeserialize& de )
72 bool result=true;
74 result &= EfcCmd::deserialize ( de );
76 if (m_type == eCT_Get) {
77 EFC_DESERIALIZE_AND_SWAP(de, &m_value, result);
80 return result;
83 bool
84 EfcGenericIOConfigCmd::setType( enum eCmdType type )
86 m_type=type;
87 if (m_type == eCT_Get) {
88 switch (m_reg) {
89 case eCR_Mirror:
90 m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR;
91 break;
92 case eCR_DigitalInterface:
93 m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE;
94 break;
95 case eCR_Phantom:
96 m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM;
97 break;
98 default:
99 debugError("Invalid IOConfig get command: %d\n", m_reg);
100 return false;
102 } else {
103 switch (m_reg) {
104 case eCR_Mirror:
105 m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR;
106 break;
107 case eCR_DigitalInterface:
108 m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE;
109 break;
110 case eCR_Phantom:
111 m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM;
112 break;
113 default:
114 debugError("Invalid IOConfig set command: %d\n", m_reg);
115 return false;
118 return true;
120 bool
121 EfcGenericIOConfigCmd::setRegister( enum eIOConfigRegister r )
123 m_reg=r;
124 if (m_type == eCT_Get) {
125 switch (m_reg) {
126 case eCR_Mirror:
127 m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR;
128 break;
129 case eCR_DigitalInterface:
130 m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE;
131 break;
132 case eCR_Phantom:
133 m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM;
134 break;
135 default:
136 debugError("Invalid IOConfig get command: %d\n", m_reg);
137 return false;
139 } else {
140 switch (m_reg) {
141 case eCR_Mirror:
142 m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR;
143 break;
144 case eCR_DigitalInterface:
145 m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE;
146 break;
147 case eCR_Phantom:
148 m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM;
149 break;
150 default:
151 debugError("Invalid IOConfig set command: %d\n", m_reg);
152 return false;
155 return true;
158 void
159 EfcGenericIOConfigCmd::showEfcCmd()
161 EfcCmd::showEfcCmd();
162 debugOutput(DEBUG_LEVEL_NORMAL, "EFC IOCONFIG %s %s:\n",
163 (m_type==eCT_Get?"GET":"SET"),
164 eIOConfigRegisterToString(m_reg));
165 debugOutput(DEBUG_LEVEL_NORMAL, " Value : %u\n", m_value);
168 // --- The specific commands
170 EfcIsocMapIOConfigCmd::EfcIsocMapIOConfigCmd(void)
171 : EfcCmd()
172 , m_samplerate (0)
173 , m_flags (0)
174 , m_num_playmap_entries (0)
175 , m_num_phys_out (0)
176 , m_num_recmap_entries (0)
177 , m_num_phys_in (0)
179 m_category_id = EFC_CAT_IO_CONFIG;
180 m_reg = eCR_IsocMap;
181 m_type = eCT_Get;
182 memset(m_playmap, EFC_MAX_ISOC_MAP_ENTRIES, 0);
183 memset(m_recmap, EFC_MAX_ISOC_MAP_ENTRIES, 0);
185 bool
186 EfcIsocMapIOConfigCmd::serialize( Util::Cmd::IOSSerialize& se )
188 bool result=true;
189 unsigned int i;
191 assert((m_num_playmap_entries <= EFC_MAX_ISOC_MAP_ENTRIES)
192 || (m_num_recmap_entries <= EFC_MAX_ISOC_MAP_ENTRIES));
194 if (m_type == eCT_Get) {
195 // the length should be specified before
196 // the header is serialized
197 m_length=EFC_HEADER_LENGTH_QUADLETS;
199 result &= EfcCmd::serialize ( se );
200 } else {
201 // the length should be specified before
202 // the header is serialized
203 m_length = EFC_HEADER_LENGTH_QUADLETS + sizeof(IsoChannelMap);
205 result &= EfcCmd::serialize ( se );
207 result &= se.write(CondSwapToBus32(m_samplerate), "Samplerate" );
208 result &= se.write(CondSwapToBus32(m_flags), "Flags" );
210 result &= se.write(CondSwapToBus32(m_num_playmap_entries), "Num. of Entries for Play Map" );
211 result &= se.write(CondSwapToBus32(m_num_phys_out), "Num. of Phys. Out" );
212 for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++)
213 result &= se.write(CondSwapToBus32(m_playmap[i]), "Play Map Entry" );
215 result &= se.write(CondSwapToBus32(m_num_recmap_entries), "Num. of Entries for Rec Map" );
216 result &= se.write(CondSwapToBus32(m_num_phys_in), "Num. of Phys. In" );
217 for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++)
218 result &= se.write(CondSwapToBus32(m_recmap[i]), "Rec Map Entry" );
221 return result;
224 bool
225 EfcIsocMapIOConfigCmd::deserialize( Util::Cmd::IISDeserialize& de )
227 bool result=true;
228 unsigned int i;
230 result &= EfcCmd::deserialize ( de );
232 if (m_type == eCT_Get) {
233 EFC_DESERIALIZE_AND_SWAP(de, &m_samplerate, result);
234 EFC_DESERIALIZE_AND_SWAP(de, &m_flags, result);
236 EFC_DESERIALIZE_AND_SWAP(de, &m_num_playmap_entries, result);
237 EFC_DESERIALIZE_AND_SWAP(de, &m_num_phys_out, result);
238 for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++)
239 EFC_DESERIALIZE_AND_SWAP(de, &m_playmap[i], result);
241 EFC_DESERIALIZE_AND_SWAP(de, &m_num_recmap_entries, result);
242 EFC_DESERIALIZE_AND_SWAP(de, &m_num_phys_in, result);
243 for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++)
244 EFC_DESERIALIZE_AND_SWAP(de, &m_recmap[i], result);
247 return result;
250 bool
251 EfcIsocMapIOConfigCmd::setType( enum eCmdType type )
253 m_type=type;
254 if (m_type == eCT_Get)
255 m_command_id = EFC_CMD_IO_CONFIG_GET_ISOC_MAP;
256 else
257 m_command_id = EFC_CMD_IO_CONFIG_SET_ISOC_MAP;
258 return true;
261 void
262 EfcIsocMapIOConfigCmd::showEfcCmd()
264 unsigned int i;
266 EfcCmd::showEfcCmd();
267 debugOutput(DEBUG_LEVEL_NORMAL, "EFC IOCONFIG %s %s:\n",
268 (m_type==eCT_Get?"GET":"SET"),
269 eIOConfigRegisterToString(m_reg));
270 debugOutput(DEBUG_LEVEL_NORMAL, " Samplerate : %u\n", m_samplerate);
271 debugOutput(DEBUG_LEVEL_NORMAL, " Flags : %u\n", m_flags);
272 debugOutput(DEBUG_LEVEL_NORMAL, " Playback:");
273 debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Entries : %u\n", m_num_playmap_entries);
274 debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Phys. Out: %u\n", m_num_phys_out);
275 for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++)
276 debugOutput(DEBUG_LEVEL_NORMAL, " Entriy %02d : %u\n", i, m_playmap[i]);
277 debugOutput(DEBUG_LEVEL_NORMAL, " Record:");
278 debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Entries : %u\n", m_num_recmap_entries);
279 debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Phys. In : %u\n", m_num_phys_in);
280 for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++)
281 debugOutput(DEBUG_LEVEL_NORMAL, " Entriy %02d : %u\n", i, m_recmap[i]);
285 } // namespace FireWorks