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

Revision 2802, 5.5 kB (checked in by jwoithe, 3 years ago)

Cosmetic: "Firewire" becomes "FireWire?".

Officially both the "F" and "W" were capitalised in the FireWire? name, so
reflect this throughout FFADO's source tree. This mostly affects comments.

This patch originated from pander on the ffado-devel mailing list. To
maintain consistency, the committed version has been expanded to include
files not originally included in the original patch.

Line 
1 /*
2  * Copyright (C) 2009 by Pieter Palmers
3  * Copyright (C) 2009 by Arnold Krille
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 "focusrite_eap.h"
26
27 namespace Dice {
28 namespace Focusrite {
29
30 FocusriteEAP::FocusriteEAP(Dice::Device& dev) : Dice::EAP(dev) {
31 }
32
33 /**
34  * Application space register read/write
35  */
36 bool FocusriteEAP::readApplicationReg(unsigned offset, quadlet_t* quadlet) {
37     bool ret = readReg(Dice::EAP::eRT_Application, offset, quadlet);
38     return ret;
39 }
40
41 bool FocusriteEAP::writeApplicationReg(unsigned offset, quadlet_t quadlet) {
42     // Do not write beyond the limit
43     if (offset > FOCUSRITE_EAP_REGISTER_APP_MONITORING_LIMIT)
44     {
45       debugWarning(" Writing beyond address 0x%02x prohibited\n",
46                    FOCUSRITE_EAP_REGISTER_APP_MONITORING_LIMIT);
47       return false;
48     }
49    
50     bool ret = writeReg(Dice::EAP::eRT_Application, offset, quadlet);
51     if (!ret) {
52         debugWarning("Couldn't write %i to register %x!\n", quadlet, offset);
53         return false;
54     }
55     return ret;
56 }
57
58 // Message set specific register
59 bool FocusriteEAP::messageSet(unsigned offset, quadlet_t quadlet) {
60     // Do not write beyond the limit
61     if (offset > FOCUSRITE_EAP_REGISTER_APP_MONITORING_LIMIT)
62     {
63       debugWarning(" Message set register can not be beyond address 0x%02x\n",
64                    FOCUSRITE_EAP_REGISTER_APP_MONITORING_LIMIT);
65       return false;
66     }
67
68     bool ret = writeApplicationReg(offset, quadlet);
69     // Send NO_MESSAGE after any non-zero messages (Focusrite recommandation)
70     writeApplicationReg(offset, (quadlet_t) FOCUSRITE_EAP_MESSAGE_SET_NO_MESSAGE);
71     return ret;
72 }
73
74 /**
75  *  Potentiometer Class
76  */
77 FocusriteEAP::Poti::Poti(Dice::Focusrite::FocusriteEAP* eap, std::string name,
78     size_t offset, size_t msgset_offset, int msgset_value) : Control::Discrete(eap, name)
79     , m_eap(eap)
80     , m_name(name)
81     , m_offset(offset)
82     , m_msgset_offset(msgset_offset)
83     , m_msgset_value(msgset_value)
84 {
85     debugOutput( DEBUG_LEVEL_VERBOSE, "Create Poti %s)\n", m_name.c_str());   
86 }
87
88 int FocusriteEAP::Poti::getValue() {
89     int m_value;
90     quadlet_t tmp;
91
92     m_eap->readApplicationReg(m_offset, &tmp);
93     m_value = -tmp;
94     return m_value;
95 }
96
97 bool FocusriteEAP::Poti::setValue(int n) {
98     // Might be the value has been modified via hardware; better to read the current value
99     int m_value = getValue();
100
101     if (n == m_value)
102         return true;
103     m_value = -n;
104     m_eap->writeApplicationReg(m_offset, (quadlet_t) m_value);
105     m_eap->messageSet(m_msgset_offset, (quadlet_t) m_msgset_value);
106     return true;
107 }
108
109 /**
110  * Switch class
111  */
112 FocusriteEAP::Switch::Switch(Dice::Focusrite::FocusriteEAP* eap, std::string name,
113     size_t offset, int activevalue, size_t msgset_offset, int msgset_value )
114     : Control::Boolean(eap, name)
115     , m_eap(eap)
116     , m_name(name)
117     , m_offset(offset)
118     , m_activevalue(activevalue)
119     , m_msgset_offset(msgset_offset)
120     , m_msgset_value(msgset_value)
121 {
122     debugOutput( DEBUG_LEVEL_VERBOSE, "Create Switch %s)\n", m_name.c_str());   
123 }
124
125 bool FocusriteEAP::Switch::selected() {
126     quadlet_t state_tmp;
127
128     m_eap->readApplicationReg(m_offset, &state_tmp);
129     bool is_selected = (state_tmp&m_activevalue)?true:false;
130     return is_selected;
131 }
132
133 bool FocusriteEAP::Switch::select(bool n) {
134     quadlet_t state_tmp;
135     m_eap->readApplicationReg(m_offset, &state_tmp);
136     bool is_selected = (state_tmp&m_activevalue)?true:false;
137
138     // Switch the corresponding bit(s)
139     if ( n != is_selected ) {
140         m_eap->writeApplicationReg(m_offset, state_tmp^m_activevalue);
141         m_eap->messageSet(m_msgset_offset, (quadlet_t) m_msgset_value);
142         is_selected = n;
143     }
144     return is_selected;
145 }
146
147 /**
148  * Volume Control Class
149  */
150 FocusriteEAP::VolumeControl::VolumeControl(Dice::Focusrite::FocusriteEAP* eap,
151     std::string name, size_t offset, int bitshift, size_t msgset_offset, int msgset_value)
152     : Control::Discrete(eap, name)
153     , m_eap(eap)
154     , m_name(name)
155     , m_offset(offset)
156     , m_bitshift(bitshift)
157     , m_msgset_offset(msgset_offset)
158     , m_msgset_value(msgset_value)
159 {
160     debugOutput( DEBUG_LEVEL_VERBOSE, "Create Volume Control %s)\n", m_name.c_str());   
161 }
162
163 int FocusriteEAP::VolumeControl::getValue() {
164     int m_value;
165     quadlet_t tmp;
166     m_eap->readApplicationReg(m_offset, &tmp);
167     m_value = - ((tmp>>m_bitshift)&0xff);
168     return m_value;
169 }
170
171 bool FocusriteEAP::VolumeControl::setValue(int n) {
172     int m_value;
173     quadlet_t tmp;
174     m_eap->readApplicationReg(m_offset, &tmp);
175     m_value = - ((tmp>>m_bitshift)&0xff);
176     if (n == m_value)
177         return true;
178
179     m_value = n;
180     tmp &= ~(0xff<<m_bitshift);
181     bool ret = m_eap->writeApplicationReg(m_offset, ((-n)<<m_bitshift)|tmp);
182     m_eap->messageSet(m_msgset_offset, (quadlet_t) m_msgset_value);
183     return ret;
184 }
185
186 }
187 }
188
189 // vim: et
Note: See TracBrowser for help on using the browser.