@@ -61,6 +61,63 @@ UINT8 CrosEcGetMotionSensorCount(HANDLE Handle)
6161 return res.SensorCount ;
6262}
6363
64+ // Returns STATUS_NOT_FOUND if either base or lid accelerometer sensors are not found.
65+ NTSTATUS
66+ CrosEcGetAccelIndeces (HANDLE Handle, UINT8 *BaseSensor, UINT8 *LidSensor)
67+ {
68+ EC_REQUEST_MOTION_SENSE_INFO req{};
69+ EC_RESPONSE_MOTION_SENSE_INFO res{};
70+ UINT8 SensorCount = CrosEcGetMotionSensorCount (Handle);
71+ BOOLEAN FoundBase = FALSE ;
72+ BOOLEAN FoundLid = FALSE ;
73+
74+ if (BaseSensor == nullptr || LidSensor == nullptr )
75+ {
76+ TraceError (" %!FUNC! Invalid BaseSensor or LidSensor pointer" );
77+ return STATUS_INVALID_PARAMETER;
78+ }
79+
80+ for (UINT8 i = 0 ; i < SensorCount; i++)
81+ {
82+ req.Cmd = 1 ;
83+ req.SensorNum = i;
84+ if (0 == CrosEcSendCommand (
85+ Handle,
86+ EC_CMD_MOTION_SENSE,
87+ 0 ,
88+ &req,
89+ sizeof (req),
90+ &res,
91+ sizeof (res)
92+ )) {
93+ TraceError (" %!FUNC! EC_CMD_MOTION_SENSE_INFO failed for sensor %d" , i);
94+ continue ;
95+ }
96+ if (res.SensorType != MOTION_SENSE_TYPE_ACCEL) {
97+ continue ;
98+ }
99+
100+ switch (res.Location ) {
101+ case MOTION_SENSE_LOCATION_BASE:
102+ FoundBase = TRUE ;
103+ *BaseSensor = i;
104+ break ;
105+ case MOTION_SENSE_LOCATION_LID:
106+ FoundLid = TRUE ;
107+ *LidSensor = i;
108+ break ;
109+ }
110+ }
111+
112+ if (!FoundBase || !FoundLid)
113+ {
114+ TraceError (" %!FUNC! Base or Lid accelerometer sensor not found" );
115+ return STATUS_NOT_FOUND;
116+ }
117+
118+ return STATUS_SUCCESS;
119+ }
120+
64121
65122// ------------------------------------------------------------------------------
66123// Function: Initialize
@@ -102,6 +159,13 @@ AccelerometerDevice::Initialize(
102159 goto Exit;
103160 }
104161
162+ Status = CrosEcGetAccelIndeces (Context->m_CrosEcHandle , &m_LidSensorIndex, &m_LidBaseSensor);
163+ if (!NT_SUCCESS (Status))
164+ {
165+ TraceError (" %!FUNC! Failed to get accelerometer indeces: %!STATUS!" , Status);
166+ goto Exit;
167+ }
168+
105169 //
106170 // Create Lock
107171 //
@@ -446,13 +510,17 @@ AccelerometerDevice::GetData(
446510 UINT16 lid_angle = lid_angle_bytes[0 ] + (lid_angle_bytes[1 ] << 8 );
447511 TraceInformation (" Lid Angle Status: %dDeg%s" , lid_angle, lid_angle == 500 ? " (Unreliable)" : " " );
448512
513+ // Lid accelerometer is relevant for screen rotation
514+ // Base accelerometer is not used in this driver
515+ // It's only used for lid angle in the EC firmware
516+ UINT SensorOffset = 6 * m_LidSensorIndex + EC_MEMMAP_ACC_DATA + 2 ;
449517 UINT16 Sensor1[6 ] = {0 };
450- CrosEcReadMemU8 (Handle, EC_MEMMAP_ACC_DATA + 2 , (UINT8*)&Sensor1[0 ]);
451- CrosEcReadMemU8 (Handle, EC_MEMMAP_ACC_DATA + 3 , (UINT8*)&Sensor1[1 ]);
452- CrosEcReadMemU8 (Handle, EC_MEMMAP_ACC_DATA + 4 , (UINT8*)&Sensor1[2 ]);
453- CrosEcReadMemU8 (Handle, EC_MEMMAP_ACC_DATA + 5 , (UINT8*)&Sensor1[3 ]);
454- CrosEcReadMemU8 (Handle, EC_MEMMAP_ACC_DATA + 6 , (UINT8*)&Sensor1[4 ]);
455- CrosEcReadMemU8 (Handle, EC_MEMMAP_ACC_DATA + 7 , (UINT8*)&Sensor1[5 ]);
518+ CrosEcReadMemU8 (Handle, SensorOffset , (UINT8*)&Sensor1[0 ]);
519+ CrosEcReadMemU8 (Handle, SensorOffset + 1 , (UINT8*)&Sensor1[1 ]);
520+ CrosEcReadMemU8 (Handle, SensorOffset + 2 , (UINT8*)&Sensor1[2 ]);
521+ CrosEcReadMemU8 (Handle, SensorOffset + 3 , (UINT8*)&Sensor1[3 ]);
522+ CrosEcReadMemU8 (Handle, SensorOffset + 4 , (UINT8*)&Sensor1[4 ]);
523+ CrosEcReadMemU8 (Handle, SensorOffset + 5 , (UINT8*)&Sensor1[5 ]);
456524 m_CachedData.Axis .X = (float ) (Sensor1[0 ] + (Sensor1[1 ] << 8 ));
457525 m_CachedData.Axis .Y = (float ) (Sensor1[2 ] + (Sensor1[3 ] << 8 ));
458526 m_CachedData.Axis .Z = (float ) (Sensor1[4 ] + (Sensor1[5 ] << 8 ));
0 commit comments