|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // omap3530/beagle_drivers/serialmouse/serialmouse.cpp |
|
15 // Serial mouse driver |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #include <e32keys.h> |
|
26 #include <arm.h> |
|
27 #include <comm.h> |
|
28 #include <assp.h> |
|
29 |
|
30 #include <assp/omap3530_assp/omap3530_uart.h> |
|
31 //#include <assp/omap3530_assp/omap3530_prm.h> |
|
32 #include <assp/omap3530_assp/omap3530_prcm.h> |
|
33 //#include <resourceman.h> |
|
34 |
|
35 #include "serialmouse.h" |
|
36 |
|
37 _LIT( KName, "SERMOUSE" ); |
|
38 |
|
39 #ifdef _FRAME_BUFFER_CURSOR_ |
|
40 # define CURSOR_SIZE 5 |
|
41 #endif |
|
42 |
|
43 |
|
44 LOCAL_C TInt halFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2) |
|
45 { |
|
46 TSerialMouse* pH=(TSerialMouse*)aPtr; |
|
47 return pH->HalFunction(aFunction,a1,a2); |
|
48 } |
|
49 |
|
50 TSerialMouse::TSerialMouse() |
|
51 : iKeyDfc( KeyDfcFn, this, Kern::DfcQue0(), 1 ), iState(ENormal), |
|
52 iUart( Omap3530Uart::EUart2 ) |
|
53 { |
|
54 Kern::Printf("+TSerialMouse::TSerialMouse"); |
|
55 |
|
56 # ifdef _FRAME_BUFFER_CURSOR_ |
|
57 iCursorBuffer = new TUint16[CURSOR_SIZE*CURSOR_SIZE]; |
|
58 # endif |
|
59 |
|
60 } |
|
61 |
|
62 TSerialMouse::~TSerialMouse() |
|
63 { |
|
64 # ifdef _FRAME_BUFFER_CURSOR_ |
|
65 delete[] iCursorBuffer; |
|
66 # endif |
|
67 } |
|
68 |
|
69 TInt TSerialMouse::Create() |
|
70 { |
|
71 |
|
72 GetScreenInfo(); |
|
73 |
|
74 TInt r=Kern::AddHalEntry(EHalGroupMouse, halFunction, this); |
|
75 if (r!=KErrNone) |
|
76 return r; |
|
77 |
|
78 |
|
79 __KTRACE_OPT(KBOOT,Kern::Printf("+TSerialMouse::Init")) ; |
|
80 |
|
81 iDebugPort = Kern::SuperPage().iDebugPort; // Get the debug port number |
|
82 if( Arm::EDebugPortJTAG == iDebugPort ) |
|
83 { |
|
84 __KTRACE_OPT(KBOOT,Kern::Printf("-TSerialMouse::Init: JTAG not supported")); |
|
85 // We don't want to return an error here, just don't bother to initialize |
|
86 return KErrNone; |
|
87 } |
|
88 else if( 2 != iDebugPort ) |
|
89 { |
|
90 __KTRACE_OPT(KBOOT,Kern::Printf("-TSerialMouse::Init: Only UART3 supported")); |
|
91 // We don't want to return an error here, just don't bother to initialize |
|
92 return KErrNone; |
|
93 } |
|
94 |
|
95 |
|
96 // Register with the power resource manager |
|
97 //r = PowerResourceManager::RegisterClient( iPrmClientId, KName ); |
|
98 //if( r != KErrNone ) |
|
99 // { |
|
100 // return r; |
|
101 // } |
|
102 |
|
103 //__KTRACE_OPT(KBOOT,Kern::Printf("+TSerialMouse::Init:PRM client ID=%x", iPrmClientId )) ; |
|
104 |
|
105 r =Interrupt::Bind( iUart.InterruptId(),Isr,this); |
|
106 if ( r < 0 ) |
|
107 { |
|
108 Kern::Printf("TSerialMouse::Create Cant Bind to Interrupt %d ret %d",iUart.InterruptId(), r ); |
|
109 return r; |
|
110 } |
|
111 |
|
112 // Ask power resource manager to turn on clocks to the UART |
|
113 // (this could take some time but we're not in any hurry) |
|
114 //r = PowerResourceManager::ChangeResourceState( iPrmClientId, iUart.PrmFunctionClk(), Prcm::EClkAuto ); |
|
115 //if( KErrNone != r ) |
|
116 // { |
|
117 // return r; |
|
118 // } |
|
119 |
|
120 //r = PowerResourceManager::ChangeResourceState( iPrmClientId, iUart.PrmInterfaceClk(), Prcm::EClkAuto ); |
|
121 //if( KErrNone != r ) |
|
122 // { |
|
123 // return r; |
|
124 // } |
|
125 |
|
126 iUart.Init(); |
|
127 iUart.DefineMode( Omap3530Uart::TUart::EUart ); |
|
128 iUart.SetBaud( Omap3530Uart::TUart::E1200 ); |
|
129 iUart.SetDataFormat( Omap3530Uart::TUart::E7Data, Omap3530Uart::TUart::E1Stop, Omap3530Uart::TUart::ENone ); |
|
130 iUart.EnableFifo( Omap3530Uart::TUart::EEnabled, Omap3530Uart::TUart::ETriggerUnchanged, Omap3530Uart::TUart::ETrigger8 ); |
|
131 iUart.EnableInterrupt( Omap3530Uart::TUart::EIntRhr ); |
|
132 iUart.Enable(); |
|
133 |
|
134 Interrupt::Enable(iUart.InterruptId()); |
|
135 |
|
136 return KErrNone; |
|
137 } |
|
138 |
|
139 |
|
140 void TSerialMouse::Isr( TAny* aPtr ) |
|
141 // |
|
142 // Interrupt service routine. Called when we receive an interrupt |
|
143 // on the IRQ line it is bound to. If it's a receive, queues DFC |
|
144 // to post the event into the event queue. |
|
145 // |
|
146 { |
|
147 TSerialMouse* self = (TSerialMouse*)aPtr; |
|
148 |
|
149 const TUint iir = Omap3530Uart::IIR::iMem.Read( self->iUart ); |
|
150 |
|
151 if ( 0 == (iir bitand Omap3530Uart::IIR::IT_PENDING::KMask) ) |
|
152 { |
|
153 const TUint pending = iir bitand Omap3530Uart::IIR::IT_TYPE::KFieldMask; |
|
154 |
|
155 // Although the TI datasheet descrivwed IT_TYPE as being an enumerated priority-decoded interrupt |
|
156 // it appears to actually be a bitmask of active interrupt sources |
|
157 if ( (pending bitand Omap3530Uart::IIR::IT_TYPE::ERHR) || (pending bitand Omap3530Uart::IIR::IT_TYPE::ERxLineStatus) ) |
|
158 { |
|
159 TUint byte = self->iUart.Read(); |
|
160 |
|
161 self->iKey = byte; |
|
162 self->iKeyDfc.Add(); |
|
163 Interrupt::Disable( self->iUart.InterruptId() ); |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 void TSerialMouse::KeyDfcFn( TAny* aPtr ) |
|
169 // |
|
170 // DFC function. Just calls inline function KeyDfc() |
|
171 // |
|
172 { |
|
173 ((TSerialMouse*)aPtr)->KeyDfc(); |
|
174 } |
|
175 |
|
176 inline void TSerialMouse::KeyDfc() |
|
177 // |
|
178 // Processes received characters |
|
179 // |
|
180 { |
|
181 |
|
182 const TUint8 b = iKey; |
|
183 |
|
184 if ( b & 1<<6 ) |
|
185 { |
|
186 // Beginning of a new frame |
|
187 iByteIndex = 0; |
|
188 iB0 = b; |
|
189 } |
|
190 else if ( iByteIndex == 0 ) |
|
191 { |
|
192 iByteIndex = 1; |
|
193 iB1 = b; |
|
194 } |
|
195 else if ( iByteIndex == 1 ) |
|
196 { |
|
197 iByteIndex = -1; |
|
198 iB2 = b; |
|
199 |
|
200 const TInt8 x_increment = (iB0 & 0x3)<<6 | (iB1 & 0x3f); |
|
201 const TInt8 y_increment = (iB0 & 0xC)<<4 | (iB2 & 0x3f); |
|
202 const TBool isLeftButtonDown = iB0& 1<<5; |
|
203 const TBool isRightButtonDown = iB0& 1<<4; |
|
204 |
|
205 # ifdef _FRAME_BUFFER_CURSOR_ |
|
206 iLastX = iX; |
|
207 iLastY = iY; |
|
208 # endif |
|
209 |
|
210 iX += x_increment; //Scale ( x_increment ); |
|
211 iY += y_increment; //Scale ( y_increment ); |
|
212 |
|
213 Clip( iX, iY ); |
|
214 |
|
215 //DBG_PRINT4(_L("\nx:%d y:%d (%d,%d)"), x_increment, y_increment, iX, iY ); |
|
216 |
|
217 TBool rightButtonEvent = (isRightButtonDown != iLastRightButtonDown); |
|
218 TBool leftButtonEvent = (isLeftButtonDown != iLastLeftButtonDown); |
|
219 iLastLeftButtonDown = isLeftButtonDown; |
|
220 iLastRightButtonDown = isRightButtonDown; |
|
221 |
|
222 TRawEvent e; |
|
223 |
|
224 if ( rightButtonEvent ) |
|
225 { |
|
226 e.Set( isRightButtonDown ? TRawEvent::EButton2Down : TRawEvent::EButton2Up, iX, iY ); |
|
227 Kern::AddEvent(e); |
|
228 //DBG_PRINT1(_L(" right:%S"), isRightButtonDown?&_L("down"):&_L("up") ); |
|
229 } |
|
230 |
|
231 if ( leftButtonEvent ) |
|
232 { |
|
233 e.Set( isLeftButtonDown ? TRawEvent::EButton1Down : TRawEvent::EButton1Up, iX, iY ); |
|
234 Kern::AddEvent(e); |
|
235 //DBG_PRINT1(_L(" left:%S"), isLeftButtonDown?&_L("down"):&_L("up") ); |
|
236 } |
|
237 |
|
238 if ( !rightButtonEvent && !leftButtonEvent ) |
|
239 { |
|
240 # ifdef _TRACK_COORDINATES_ |
|
241 // Reoprt the exact coordinate to the windowserver |
|
242 e.Set(TRawEvent::EPointerMove,iX,iY); |
|
243 # else |
|
244 // Report the change in coordinates to the windowserver |
|
245 e.Set(TRawEvent::EPointerMove,x_increment,y_increment); |
|
246 # endif |
|
247 Kern::AddEvent(e); |
|
248 } |
|
249 |
|
250 # ifdef _FRAME_BUFFER_CURSOR_ |
|
251 DrawCursor(iX,iY); |
|
252 # endif |
|
253 |
|
254 } |
|
255 |
|
256 Interrupt::Enable(iUart.InterruptId()); // Can handle new chars now |
|
257 } /* end of function - KeyDfc - */ |
|
258 |
|
259 |
|
260 /* |
|
261 Perform 2:1 scaling on a mosue movement. |
|
262 */ |
|
263 TInt TSerialMouse::Scale(const TInt& aVal) |
|
264 { |
|
265 switch (aVal) |
|
266 { |
|
267 case 0: return 0; |
|
268 case 1: |
|
269 case 2: return 1; |
|
270 case 3: return 3; |
|
271 case 4: return 6; |
|
272 case 5: return 9; |
|
273 case -1: |
|
274 case -2: return -1; |
|
275 case -3: return -3; |
|
276 case -4: return -6; |
|
277 case -5: return -9; |
|
278 default: return 2*aVal; |
|
279 } |
|
280 } |
|
281 |
|
282 /* |
|
283 Clip the mouse coordinates into the dimensions of the screen |
|
284 */ |
|
285 void TSerialMouse::Clip(TInt& aX, TInt& aY) |
|
286 { |
|
287 if ( aX < 0 ) aX = 0; |
|
288 if ( aX >= iScreenWidth ) aX = iScreenWidth - 1; |
|
289 if ( aY < 0 ) aY = 0; |
|
290 if ( aY >= iScreenHeight ) aY = iScreenHeight - 1; |
|
291 } |
|
292 |
|
293 void TSerialMouse::GetScreenInfo() |
|
294 { |
|
295 TScreenInfoV01 screenInfo; |
|
296 TPckg<TScreenInfoV01> sI(screenInfo); |
|
297 Kern::HalFunction(EHalGroupDisplay,EDisplayHalScreenInfo,(TAny*)&sI,NULL); |
|
298 iScreenWidth = screenInfo.iScreenSize.iWidth; |
|
299 iScreenHeight = screenInfo.iScreenSize.iHeight; |
|
300 # ifdef _FRAME_BUFFER_CURSOR_ |
|
301 iVideoAddress = (TUint8*)screenInfo.iScreenAddress; |
|
302 # endif |
|
303 } |
|
304 |
|
305 #ifdef _FRAME_BUFFER_CURSOR_ |
|
306 void TSerialMouse::Blit(TInt x, TInt y, TUint16 aColour) |
|
307 { |
|
308 |
|
309 TUint16* fb = (TUint16*)iVideoAddress; |
|
310 fb += (iLastY * iScreenWidth) + iLastX; |
|
311 for (TInt i = 0; i<CURSOR_SIZE; ++i) //row |
|
312 { |
|
313 |
|
314 if ( (iLastY + i) >= iScreenHeight) break; |
|
315 |
|
316 for (TInt j = 0; j<CURSOR_SIZE; ++j) //column |
|
317 { |
|
318 |
|
319 if ((iLastX+j) < iScreenWidth) |
|
320 { |
|
321 *fb = iCursorBuffer[i*CURSOR_SIZE + j]; |
|
322 } |
|
323 |
|
324 ++fb; |
|
325 } |
|
326 fb += iScreenWidth - CURSOR_SIZE; |
|
327 } |
|
328 |
|
329 |
|
330 fb = (TUint16*)iVideoAddress; |
|
331 fb += (y * iScreenWidth) + x; |
|
332 for (TInt i = 0; i<CURSOR_SIZE; ++i) //row |
|
333 { |
|
334 |
|
335 if ( (y + i) >= iScreenHeight) break; |
|
336 |
|
337 for (TInt j = 0; j<CURSOR_SIZE; ++j) //column |
|
338 { |
|
339 |
|
340 if ((x+j) < iScreenWidth) |
|
341 { |
|
342 iCursorBuffer[i*CURSOR_SIZE + j] = *fb; |
|
343 *fb = aColour; |
|
344 } |
|
345 |
|
346 ++fb; |
|
347 } |
|
348 fb += iScreenWidth - CURSOR_SIZE; |
|
349 } |
|
350 |
|
351 /*TUint8* fb = iVideoAddress; |
|
352 fb += ( (y * iScreenWidth) + x ) * 2; |
|
353 |
|
354 TBuf8<256> cur; |
|
355 cur.FillZ(); |
|
356 TUint8* cursor = &cur[0]; |
|
357 |
|
358 for (TInt i = 0; i<cursorSize; ++i) |
|
359 { |
|
360 |
|
361 if ( (y + i) >= iScreenHeight) break; |
|
362 |
|
363 TInt bytes_to_copy = Min( cursorSize, iScreenWidth*2 - x*2 ); |
|
364 |
|
365 Mem::Copy(fb, cursor, bytes_to_copy ); |
|
366 |
|
367 cursor += cursorSize; |
|
368 |
|
369 }*/ |
|
370 |
|
371 } |
|
372 |
|
373 void TSerialMouse::DrawCursor(TInt x, TInt y) |
|
374 { |
|
375 TUint16 cursorColour = iLastLeftButtonDown ? 0x1F : 0x00; |
|
376 Blit(x, y, cursorColour); |
|
377 } |
|
378 #endif |
|
379 |
|
380 |
|
381 TInt TSerialMouse::HalFunction(TInt aFunction, TAny* a1, TAny* /*a2*/) |
|
382 { |
|
383 TInt r=KErrNone; |
|
384 switch(aFunction) |
|
385 { |
|
386 case EMouseHalMouseInfo: |
|
387 { |
|
388 TPckgBuf<TMouseInfoV01> vPckg; |
|
389 TMouseInfoV01& xyinfo=vPckg(); |
|
390 xyinfo.iMouseButtons=2; |
|
391 xyinfo.iMouseAreaSize.iWidth=iScreenWidth; |
|
392 xyinfo.iMouseAreaSize.iHeight=iScreenHeight; |
|
393 xyinfo.iOffsetToDisplay.iX=0; |
|
394 xyinfo.iOffsetToDisplay.iY=0; |
|
395 Kern::InfoCopy(*(TDes8*)a1,vPckg); |
|
396 break; |
|
397 } |
|
398 default: |
|
399 r=KErrNotSupported; |
|
400 break; |
|
401 } |
|
402 return r; |
|
403 } |
|
404 |
|
405 void DoCreate( TAny* aParam ) |
|
406 { |
|
407 TInt r = reinterpret_cast< TSerialMouse* >( aParam )->Create(); |
|
408 __ASSERT_ALWAYS( r == KErrNone, Kern::Fault( "SERKEY-Cr", r ) ); |
|
409 } |
|
410 |
|
411 |
|
412 // |
|
413 // Kernel Extension entry point |
|
414 // |
|
415 DECLARE_STANDARD_EXTENSION() |
|
416 { |
|
417 __KTRACE_OPT(KBOOT,Kern::Printf("Starting mouse driver")); |
|
418 |
|
419 // create mouse driver |
|
420 TInt r=KErrNoMemory; |
|
421 TSerialMouse* mouse = new TSerialMouse; |
|
422 if ( mouse ) |
|
423 { |
|
424 // Because the Power Resource Manager doesn't finish initializing until after it |
|
425 // has run a DFC on SvMsgQue, we need to defer our initialization until after that |
|
426 // so we know that the PRM is ready for us to use it |
|
427 static TDfc createDfc( &DoCreate, NULL ); |
|
428 new( &createDfc ) TDfc( &DoCreate, mouse, Kern::SvMsgQue(), KMaxDfcPriority-2 ); |
|
429 createDfc.Enque(); |
|
430 r = KErrNone; |
|
431 } |
|
432 __KTRACE_OPT(KEXTENSION,Kern::Printf("Returns %d",r)); |
|
433 return r; |
|
434 } |