Skip to content

Commit e26fcad

Browse files
committed
Get Accelerometer data from EC
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 90b67cf commit e26fcad

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

SensorsComboDriver/Device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
#include "Device.tmh"
2020

21-
#define ENABLE_ALS_SENSOR 1
21+
#define ENABLE_ALS_SENSOR 0
2222
#define ENABLE_ORIENTATION_SENSOR 0
23-
#define ENABLE_ACCEL_SENSOR 0
23+
#define ENABLE_ACCEL_SENSOR 1
2424

2525
//---------------------------------------
2626
// Declare and map devices below

SensorsComboDriver/EcCommunication.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ extern "C" {
2727

2828
/* Define the format of the accelerometer mapped memory status byte. */
2929
#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
30-
#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
31-
#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
30+
// BIT(4)
31+
#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
32+
// BIT(7)
33+
#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
3234

3335
#define FILE_DEVICE_CROS_EMBEDDED_CONTROLLER 0x80EC
3436

SensorsComboDriver/linearaccelerometerclient.cpp

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Windows User-Mode Driver Framework (UMDF)
1010

1111
#include "Clients.h"
12+
#include "EcCommunication.h"
1213

1314
#include "LinearAccelerometerClient.tmh"
1415

@@ -127,11 +128,11 @@ LinearAccelerometerDevice::Initialize(
127128
&(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value));
128129

129130
m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer;
130-
InitPropVariantFromString(L"Manufacturer name",
131+
InitPropVariantFromString(L"Framework Computer",
131132
&(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value));
132133

133134
m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model;
134-
InitPropVariantFromString(L"Linear Accelerometer",
135+
InitPropVariantFromString(L"Accelerometer",
135136
&(m_pEnumerationProperties->List[SENSOR_MODEL].Value));
136137

137138
m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType;
@@ -387,17 +388,50 @@ LinearAccelerometerDevice::Initialize(
387388
//------------------------------------------------------------------------------
388389
NTSTATUS
389390
LinearAccelerometerDevice::GetData(
390-
_In_ HANDLE Device
391+
_In_ HANDLE Handle
391392
)
392393
{
393394
BOOLEAN DataReady = FALSE;
394395
FILETIME TimeStamp = {0};
395396
NTSTATUS Status = STATUS_SUCCESS;
396397

397-
UNREFERENCED_PARAMETER(Device);
398-
399398
SENSOR_FunctionEnter();
400399

400+
UINT8 acc_status = 0;
401+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_STATUS, &acc_status);
402+
TraceInformation("Status: (%02x), Present: %d, Busy: %d\n",
403+
acc_status,
404+
(acc_status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT) > 0,
405+
(acc_status & EC_MEMMAP_ACC_STATUS_BUSY_BIT) > 0);
406+
407+
UINT8 lid_angle_bytes[2] = {0};
408+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 0, &lid_angle_bytes[0]);
409+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 1, &lid_angle_bytes[1]);
410+
UINT16 lid_angle = lid_angle_bytes[0] + (lid_angle_bytes[1] << 8);
411+
TraceInformation("Lid Angle Status: %dDeg%s", lid_angle, lid_angle == 500 ? "(Unreliable)" : "");
412+
413+
UINT16 Sensor1[6] = {0};
414+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 2, (UINT8*)&Sensor1[0]);
415+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 3, (UINT8*)&Sensor1[1]);
416+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 4, (UINT8*)&Sensor1[2]);
417+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 5, (UINT8*)&Sensor1[3]);
418+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 6, (UINT8*)&Sensor1[4]);
419+
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 7, (UINT8*)&Sensor1[5]);
420+
m_CachedData.Axis.X = (float) (Sensor1[0] + (Sensor1[1] << 8));
421+
m_CachedData.Axis.Y = (float) (Sensor1[2] + (Sensor1[3] << 8));
422+
m_CachedData.Axis.Z = (float) (Sensor1[4] + (Sensor1[5] << 8));
423+
#define quarter (0xFFFF/4)
424+
m_CachedData.Axis.X = -((float) (INT16) m_CachedData.Axis.X) / quarter;
425+
m_CachedData.Axis.Y = -((float) (INT16) m_CachedData.Axis.Y) / quarter;
426+
m_CachedData.Axis.Z = -((float) (INT16) m_CachedData.Axis.Z) / quarter;
427+
TraceInformation("Read Accel Value %02x %02x %02x %02x %02x %02x - x: %f, y: %f, z: %f\n",
428+
Sensor1[0], Sensor1[1],
429+
Sensor1[2], Sensor1[3],
430+
Sensor1[4], Sensor1[5],
431+
m_CachedData.Axis.X,
432+
m_CachedData.Axis.Y,
433+
m_CachedData.Axis.Z);
434+
401435
// new sample?
402436
if (m_FirstSample != FALSE)
403437
{

0 commit comments

Comments
 (0)