|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Minimalistic pointer driver |
|
15 * |
|
16 */ |
|
17 |
|
18 //#define DEBUG |
|
19 |
|
20 #include <syborg_priv.h> |
|
21 #include "syborg_pointer.h" |
|
22 |
|
23 TPointerRv::TPointerRv(): |
|
24 iRxDfc(RxDfc,this,Kern::DfcQue0(),1) |
|
25 { |
|
26 __DEBUG_PRINT("TPointerRv::TPointerRv()"); |
|
27 TInt r = Interrupt::Bind(EIntPointer,Isr,this); |
|
28 if(r != KErrNone) |
|
29 __KTRACE_OPT(KPANIC, Kern::Printf("TPointerRv::TPointerRv() Interrupt::Bind(%d)=%d", |
|
30 EIntPointer, r)); |
|
31 iPointerOn = ETrue; |
|
32 iLastBut = 0; |
|
33 |
|
34 Interrupt::Enable(EIntPointer); |
|
35 } |
|
36 |
|
37 TPointerRv::~TPointerRv() |
|
38 { |
|
39 } |
|
40 |
|
41 struct TPointerRv::PData* TPointerRv::FifoPop(void) |
|
42 { |
|
43 struct TPointerRv::PData* val = &iPDataFifo[iFifoPos]; |
|
44 iFifoPos++; |
|
45 iFifoCount--; |
|
46 |
|
47 if (iFifoPos == FIFO_SIZE) |
|
48 iFifoPos = 0; |
|
49 |
|
50 return val; |
|
51 } |
|
52 |
|
53 void TPointerRv::FifoPush(struct TPointerRv::PData* val) |
|
54 { |
|
55 TInt slot; |
|
56 |
|
57 if (iFifoCount == FIFO_SIZE) |
|
58 return; |
|
59 |
|
60 slot = iFifoPos + iFifoCount; |
|
61 if (slot >= FIFO_SIZE) |
|
62 slot -= FIFO_SIZE; |
|
63 iPDataFifo[slot] = *val; |
|
64 iFifoCount++; |
|
65 |
|
66 // __DEBUG_PRINT("TPointerRv::FifoPush %d %d %d %d",val->x, val->y, val->z, val->but); |
|
67 // __DEBUG_PRINT("TPointerRv::FifoPush %d %d %d %d",iPDataFifo[slot].x, iPDataFifo[slot].y, iPDataFifo[slot].z, iPDataFifo[slot].but); |
|
68 |
|
69 } |
|
70 |
|
71 void TPointerRv::Init3() |
|
72 { |
|
73 __DEBUG_PRINT("TPointerRv::Init3"); |
|
74 |
|
75 TInt reg = ReadReg(KHwBaseKmiPointer,POINTER_ID); |
|
76 WriteReg(KHwBaseKmiPointer,POINTER_INT_ENABLE,1); |
|
77 |
|
78 TInt r = Kern::AddHalEntry(EHalGroupMouse,DoPointerHalFunction,this); |
|
79 if(r != KErrNone) |
|
80 __KTRACE_OPT(KPANIC, Kern::Printf("TPointerRv::Init3(): Kern::AddHalEntry()=%d", r)); |
|
81 |
|
82 // Get information about the screen display mode |
|
83 TPckgBuf<TVideoInfoV01> buf; |
|
84 TVideoInfoV01& videoInfo = buf(); |
|
85 |
|
86 r = Kern::HalFunction(EHalGroupDisplay, EDisplayHalCurrentModeInfo, (TAny*)&buf, NULL); |
|
87 if(r != KErrNone) |
|
88 __KTRACE_OPT(KPANIC, Kern::Printf("TPointerRv::Init3(): Kern::HalFunction(EDisplayHalCurrentModeInfo)=%d", r)); |
|
89 |
|
90 iScreenWidth = videoInfo.iSizeInPixels.iWidth; |
|
91 iScreenHeight = videoInfo.iSizeInPixels.iHeight; |
|
92 iDisplayMode = videoInfo.iDisplayMode; |
|
93 ix = iy = 0; |
|
94 |
|
95 iXFactor = Fixed(iScreenWidth) / Fixed(0x8000); |
|
96 iYFactor = Fixed(iScreenHeight) / Fixed(0x8000); |
|
97 |
|
98 iFifoPos = iFifoCount = 0; |
|
99 } |
|
100 |
|
101 |
|
102 void TPointerRv::Process(TPointerRv *i, struct TPointerRv::PData *pd) |
|
103 { |
|
104 TRawEvent e; |
|
105 |
|
106 // __DEBUG_PRINT("Event: X=%d Y=%d Point %d", pd->x, pd->y, pd->but); |
|
107 // __DEBUG_PRINT(" Last X=%d Y=%d Point %d", i->ix, i->iy, i->iLastBut); |
|
108 |
|
109 // i->ix += pd->x; |
|
110 // i->iy += pd->y; |
|
111 |
|
112 i->ix = int(Fixed(pd->x) * i->iXFactor); |
|
113 i->iy = int(Fixed(pd->y) * i->iYFactor); |
|
114 |
|
115 switch(pd->but) |
|
116 { |
|
117 case 0: // Button released |
|
118 switch(i->iLastBut) |
|
119 { |
|
120 case 0: |
|
121 if( (pd->x!=0) || (pd->y!=0) ) { |
|
122 e.Set(TRawEvent::EPointerMove, i->ix, i->iy); |
|
123 __DEBUG_PRINT("1 EPointerMove (x:%d y:%d)", i->ix, i->iy); |
|
124 } |
|
125 goto fin; |
|
126 case 1: // Left |
|
127 e.Set(TRawEvent::EButton1Up, i->ix, i->iy); |
|
128 __DEBUG_PRINT("2 EButton1UP (x:%d y:%d)", i->ix, i->iy); |
|
129 goto fin; |
|
130 case 2: // Right |
|
131 e.Set(TRawEvent::EButton2Up, i->ix, i->iy); |
|
132 __DEBUG_PRINT("3 EButton2UP (x:%d y:%d)", i->ix, i->iy); |
|
133 goto fin; |
|
134 } |
|
135 case 1: // Left |
|
136 if (i->iLastBut == 0) { |
|
137 e.Set(TRawEvent::EButton1Down, i->ix, i->iy); |
|
138 __DEBUG_PRINT("4 EButton1Down (x:%d y:%d)", i->ix, i->iy); |
|
139 } |
|
140 else if( (pd->x!=0) || (pd->y!=0) ) { |
|
141 e.Set(TRawEvent::EPointerMove, i->ix, i->iy); |
|
142 __DEBUG_PRINT("5 EPointerMove (x:%d y:%d)", i->ix, i->iy); |
|
143 } |
|
144 break; |
|
145 case 2: // Right |
|
146 if (i->iLastBut == 0) { |
|
147 e.Set(TRawEvent::EButton2Down, i->ix, i->iy); |
|
148 __DEBUG_PRINT("6 EButton2Down (x:%d y:%d)", i->ix, i->iy); |
|
149 } |
|
150 else if( (pd->x!=0) || (pd->y!=0) ) { |
|
151 e.Set(TRawEvent::EPointerMove, i->ix, i->iy); |
|
152 __DEBUG_PRINT("7 EPointerMove (x:%d y:%d)", i->ix, i->iy); |
|
153 } |
|
154 break; |
|
155 |
|
156 } |
|
157 fin: |
|
158 Kern::AddEvent(e); |
|
159 i->iLastBut = pd->but; |
|
160 } |
|
161 |
|
162 void TPointerRv::RxDfc(TAny* aPtr) |
|
163 { |
|
164 __DEBUG_PRINT("TPointerRv::RxDfc"); |
|
165 |
|
166 TPointerRv* i = static_cast<TPointerRv*>(aPtr); |
|
167 |
|
168 while(i->iFifoCount>0) { |
|
169 struct TPointerRv::PData *pd= i->FifoPop(); |
|
170 Process(i,pd); |
|
171 } |
|
172 } |
|
173 |
|
174 void TPointerRv::Isr(TAny* aPtr) |
|
175 { |
|
176 __DEBUG_PRINT("TPointerRv::Isr"); |
|
177 |
|
178 TPointerRv& k = *(TPointerRv*)aPtr; |
|
179 // interrupts are now auto clear |
|
180 |
|
181 while(ReadReg(KHwBaseKmiPointer, POINTER_FIFO_COUNT)!=0) { |
|
182 struct TPointerRv::PData pd; |
|
183 pd.x = ReadReg(KHwBaseKmiPointer,POINTER_X); |
|
184 pd.y = ReadReg(KHwBaseKmiPointer,POINTER_Y); |
|
185 pd.z = ReadReg(KHwBaseKmiPointer,POINTER_Z); |
|
186 pd.but = ReadReg(KHwBaseKmiPointer,POINTER_BUTTONS); |
|
187 k.FifoPush(&pd); |
|
188 WriteReg(KHwBaseKmiPointer,POINTER_LATCH,0); |
|
189 } |
|
190 |
|
191 // WriteReg(KHwBaseKmiPointer,POINTER_CLEAR_INT,0); |
|
192 Interrupt::Clear(EIntPointer); |
|
193 k.iRxDfc.Add(); |
|
194 } |
|
195 |
|
196 TInt TPointerRv::DoPointerHalFunction(TAny* aThis, TInt aFunction, TAny* a1, TAny* a2) |
|
197 { |
|
198 return static_cast<TPointerRv*>(aThis)->PointerHalFunction(aFunction,a1,a2); |
|
199 } |
|
200 |
|
201 TInt TPointerRv::PointerHalFunction(TInt aFunction, TAny* a1, TAny* /*a2*/) |
|
202 { |
|
203 __DEBUG_PRINT("TPointerRv::PointerHalFunction"); |
|
204 |
|
205 TInt r=KErrNone; |
|
206 |
|
207 switch(aFunction) |
|
208 { |
|
209 case EMouseHalMouseState: |
|
210 { |
|
211 kumemput32(a1, (TBool*)&iPointerOn, sizeof(TBool)); |
|
212 break; |
|
213 } |
|
214 case EMouseHalSetMouseState: |
|
215 { |
|
216 __SECURE_KERNEL( |
|
217 if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD, |
|
218 __PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EMouseHalSetMouseState"))) |
|
219 return KErrPermissionDenied; |
|
220 ); |
|
221 if(((TBool)a1 == HAL::EMouseState_Visible) && (iPointerOn == (TBool)EFalse)) |
|
222 { |
|
223 iPointerOn=(TBool)ETrue; |
|
224 } |
|
225 else if(((TBool)a1 == HAL::EMouseState_Invisible) && (iPointerOn==(TBool)ETrue)) |
|
226 { |
|
227 iPointerOn=(TBool)EFalse; |
|
228 } |
|
229 break; |
|
230 } |
|
231 case EMouseHalMouseInfo: |
|
232 { |
|
233 TPckgBuf<TMouseInfoV01> vPckg; |
|
234 TMouseInfoV01& xyinfo = vPckg(); |
|
235 xyinfo.iMouseButtons = 2; |
|
236 xyinfo.iMouseAreaSize.iWidth = iScreenWidth; |
|
237 xyinfo.iMouseAreaSize.iHeight = iScreenHeight; |
|
238 xyinfo.iOffsetToDisplay.iX = 0; |
|
239 xyinfo.iOffsetToDisplay.iY = 0; |
|
240 Kern::InfoCopy(*(TDes8*)a1,vPckg); |
|
241 break; |
|
242 } |
|
243 case EMouseHalSetMouseSpeed: |
|
244 { |
|
245 __SECURE_KERNEL( |
|
246 if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD, |
|
247 __PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EMouseHalSetMouseSpeed"))) |
|
248 return KErrPermissionDenied; |
|
249 ); |
|
250 // fall thru to NotSupported |
|
251 } |
|
252 case EMouseHalSetMouseAcceleration: |
|
253 { |
|
254 __SECURE_KERNEL( |
|
255 if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD, |
|
256 __PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EMouseHalSetMouseAcceleration"))) |
|
257 return KErrPermissionDenied; |
|
258 ); |
|
259 // fall thru to NotSupported |
|
260 } |
|
261 default: |
|
262 { |
|
263 r = KErrNotSupported; |
|
264 break; |
|
265 } |
|
266 } |
|
267 return r; |
|
268 } |
|
269 |
|
270 DECLARE_STANDARD_EXTENSION() |
|
271 { |
|
272 __DEBUG_PRINT("DECLARE_STANDARD_EXTENSION"); |
|
273 TPointerRv *d = new TPointerRv; |
|
274 d->Init3(); |
|
275 return KErrNone; |
|
276 } |