author | zecke <zecke> | 2004-09-15 00:03:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-15 00:03:10 (UTC) |
commit | edc1f329044600c15cdccdacce2b2d6a776ca4ce (patch) (unidiff) | |
tree | 20cd9eebfd75e5c163f128adb7724c61adef1e27 /libopie2 | |
parent | d46a01de16c8ad65b00c76beda547970f7972b62 (diff) | |
download | opie-edc1f329044600c15cdccdacce2b2d6a776ca4ce.zip opie-edc1f329044600c15cdccdacce2b2d6a776ca4ce.tar.gz opie-edc1f329044600c15cdccdacce2b2d6a776ca4ce.tar.bz2 |
Patch by Till Harbum for SIMpad to more properly use the ChipSelect3
proc filesystem interface.
Method introduced:
setCS3Bit
This method reads the current CS3 Bits before setting the new bit. Using
this function allows to toggle the display without overwriting other
CS3 bits for example the DECT_ON bit
-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.cpp | 83 |
1 files changed, 66 insertions, 17 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index 2d0160d..fd46b95 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp | |||
@@ -198,2 +198,63 @@ void SIMpad::initButtons() | |||
198 | 198 | ||
199 | |||
200 | /* | ||
201 | * The SIMpad exposes ChipSelect3 to userspace | ||
202 | * via a proc filesystem file. Using this register | ||
203 | * one can toggle power of serial, irda, dect circuits | ||
204 | * change the video driver and display status and | ||
205 | * many more things. | ||
206 | * To not lose the current setting we read the current | ||
207 | * cs3 setting and toggle the necessary bits and then | ||
208 | * write it. | ||
209 | */ | ||
210 | static bool setCS3Bit( bool bitset, int bit ) { | ||
211 | int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_RDONLY ); | ||
212 | |||
213 | if ( cs3_fd < 0 ) | ||
214 | return false; | ||
215 | |||
216 | static char line[32]; | ||
217 | int val = 0; | ||
218 | bool ok = false; | ||
219 | |||
220 | /* | ||
221 | * try to read and parse the Chipselect3 status | ||
222 | * be paranoid and make sure line[31] is null | ||
223 | * terminated | ||
224 | */ | ||
225 | while( !ok && ::read(cs3_fd, &line, sizeof(line)) > 0 ) { | ||
226 | line[31] = '\0'; | ||
227 | if (::sscanf(line, "Chipselect3 : %x", &val )) | ||
228 | ok = true; | ||
229 | } | ||
230 | |||
231 | ::close(cs3_fd); | ||
232 | |||
233 | /* | ||
234 | * we were not able to find the current value | ||
235 | * and as a result we won't set it | ||
236 | */ | ||
237 | if ( !ok ) | ||
238 | return false; | ||
239 | |||
240 | /* | ||
241 | * change the value | ||
242 | */ | ||
243 | val = bitset ? (val | bit) : (val & ~bit); | ||
244 | |||
245 | /* | ||
246 | * write it back | ||
247 | */ | ||
248 | cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY ); | ||
249 | if ( cs3_fd < 0 ) | ||
250 | return false; | ||
251 | |||
252 | ::snprintf(line, sizeof(line), "0x%04x\n", val); | ||
253 | ::write(cs3_fd, line, strlen(line)); | ||
254 | ::close(cs3_fd); | ||
255 | |||
256 | return true; | ||
257 | } | ||
258 | |||
259 | |||
199 | QValueList <OLed> SIMpad::ledList() const | 260 | QValueList <OLed> SIMpad::ledList() const |
@@ -231,17 +292,8 @@ bool SIMpad::setLedState ( OLed l, OLedState st ) | |||
231 | { | 292 | { |
232 | #if 0 | 293 | if ( l == Led_Power ) { |
233 | static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); | ||
234 | |||
235 | /*TODO Implement this like that: | ||
236 | read from cs3 | ||
237 | && with SIMPAD_LED2_ON | ||
238 | write to cs3 */ | ||
239 | m_leds [0] = st; | 294 | m_leds [0] = st; |
295 | setCS3Bit(st == Led_On, SIMPAD_LED2_ON); | ||
240 | return true; | 296 | return true; |
241 | // } | 297 | } |
242 | // } | 298 | |
243 | #else | ||
244 | Q_UNUSED( l ) | ||
245 | Q_UNUSED( st ) | ||
246 | #endif | ||
247 | return false; | 299 | return false; |
@@ -312,6 +364,3 @@ bool SIMpad::setDisplayStatus ( bool on ) | |||
312 | 364 | ||
313 | 365 | return setCS3Bit(on, SIMPAD_DISPLAY_ON); | |
314 | QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) | ||
315 | |||
316 | return ( ::system( (const char*) cmdline ) == 0 ); | ||
317 | } | 366 | } |