-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcCommunication.h
More file actions
128 lines (104 loc) · 2.69 KB
/
EcCommunication.h
File metadata and controls
128 lines (104 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//SPDX-License-Identifier: MS-PL
//
//Copyright (C) Framework Computer Inc
//
//Abstract:
//
// Definitions for accessing EC
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <handleapi.h>
#include <windows.h>
#include <wdf.h>
#include "Trace.h"
#include "ec_compat_win.h"
#pragma pack(push, 1)
#include "ec_commands.h"
#pragma pack(pop)
#pragma warning(pop) /* matches push in ec_compat_win.h */
#define FILE_DEVICE_CROS_EMBEDDED_CONTROLLER 0x80EC
#define IOCTL_CROSEC_XCMD \
CTL_CODE(FILE_DEVICE_CROS_EMBEDDED_CONTROLLER, 0x801, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
#define IOCTL_CROSEC_RDMEM CTL_CODE(FILE_DEVICE_CROS_EMBEDDED_CONTROLLER, 0x802, METHOD_BUFFERED, FILE_READ_DATA)
#define CROSEC_CMD_MAX_REQUEST 0x100
#define CROSEC_CMD_MAX_RESPONSE 0x100
#define CROSEC_MEMMAP_SIZE 0xFF
NTSTATUS ConnectToEc(
_Inout_ HANDLE* Handle
);
#define EC_RES_SUCCESS 0
#define EC_INVALID_COMMAND 1
#define EC_ERROR 2
#define EC_INVALID_PARAMETER 3
#define EC_ACCESS_DENIED 4
#define EC_INVALID_RESPONSE 5
#define EC_INVALID_VERSION 6
#define EC_INVALID_CHECKSUM 7
#define CROS_EC_CMD_MAX_REQUEST (0x100-8)
typedef struct _CROSEC_COMMAND {
UINT32 version;
UINT32 command;
UINT32 outlen;
UINT32 inlen;
UINT32 result;
UINT8 data[CROS_EC_CMD_MAX_REQUEST];
} * PCROSEC_COMMAND, CROSEC_COMMAND;
typedef struct _CROSEC_READMEM {
ULONG offset;
ULONG bytes;
UCHAR buffer[CROSEC_MEMMAP_SIZE];
} * PCROSEC_READMEM, CROSEC_READMEM;
#include <pshpack1.h>
#define CROS_EC_CMD_MAX_KEY_COUNT 64
typedef struct {
UINT8 r;
UINT8 g;
UINT8 b;
} Rgb;
typedef struct {
UINT8 StartKey;
UINT8 Length;
Rgb Colors[CROS_EC_CMD_MAX_KEY_COUNT];
} EC_REQUEST_RGB_KBD_SET_COLOR;
typedef struct {
// Dump = 0
UINT8 Cmd;
UINT8 MaxSensorCount;
} EC_REQUEST_MOTION_SENSE_DUMP;
typedef struct {
UINT8 MaxSensorCount;
UINT8 SensorCount;
// Need to allocate extra data if you care about this field.
// Right now I only care about the count.
// If this field is not there, the EC just truncates the response.
// UINT8 Sensors[];
} EC_RESPONSE_MOTION_SENSE_DUMP;
typedef struct {
// Info = 1
UINT8 Cmd;
UINT8 SensorNum;
} EC_REQUEST_MOTION_SENSE_INFO;
typedef struct {
UINT8 SensorType;
UINT8 Location;
UINT8 Chip;
} EC_RESPONSE_MOTION_SENSE_INFO;
#include <poppack.h>
int CrosEcSendCommand(
HANDLE Handle,
UINT16 command,
UINT8 version,
LPVOID outdata,
unsigned int outlen,
LPVOID indata,
unsigned int inlen
);
int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest);
#ifdef __cplusplus
}
// Motion sensor helpers (defined in AccelerometerClient.cpp)
UINT8 CrosEcGetMotionSensorCount(HANDLE Handle);
NTSTATUS CrosEcGetAccelIndeces(HANDLE Handle, UINT8 *BaseSensor, UINT8 *LidSensor);
#endif