-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2f1dde6
Showing
19 changed files
with
26,688 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2021, Soberia | ||
Copyright (c) 2007-2010, OpenLibSys.org | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# **📋 How to use** | ||
You can either copy the source code directly to your project or using compiled [Dynamic-Link Library (DLL)](https://github.com/Soberia/EmbeddedController/releases) version. | ||
You need to compile your app with `c++17` flag or newer versions. | ||
This app uses `WinRing0` driver to access the hardware, make sure you place `WinRing0x64.sys` or `WinRing0.sys` beside your binary files. | ||
Your program has to run with administrator privileges to work properly. | ||
|
||
Include `ec.hpp` header file and initialize an object from `EmbeddedController` class. | ||
```cpp | ||
#include <iostream> | ||
#include <windows.h> | ||
|
||
#include "ec.hpp" | ||
|
||
int main() | ||
{ | ||
EmbeddedController ec = EmbeddedController(); | ||
|
||
// Making sure driver file loaded successfully | ||
if (ec.driverFileExist && ec.driverLoaded) | ||
{ | ||
// Your rest of code palces in here | ||
// ... | ||
|
||
// Free up the resources at the end | ||
ec.close(); | ||
} | ||
|
||
} | ||
``` | ||
|
||
### **Public Methods** | ||
* `EmbeddedController(BYTE scPort = EC_SC, BYTE dataPort = EC_DATA, BYTE endianness = LITTLE_ENDIAN, UINT16 retry = 5, UINT16 timeout = 100)` | ||
</br> | ||
If read or write operations often fails, you should increase the `retry` and `timeout` values. | ||
* `scPort`: Embedded Controller Status/Command port, default value is `0x66` | ||
* `dataPort`: Embedded Controller Data port, default value is `0x62` | ||
* `endianness`: Byte order of read and write operations, could be `LITTLE_ENDIAN` or `BIG_ENDIAN`, default value is `LITTLE_ENDIAN` | ||
* `retry`: Number of retires for failed read or write operations, default value is `5` | ||
* `timeout`: Waiting threshold for reading EC's OBF and IBF flags, default value is `100` | ||
|
||
* `VOID close()` | ||
</br> | ||
Close the driver resources | ||
|
||
* `EC_DUMP dump()` | ||
</br> | ||
Generate a `map` object of all registers | ||
</br> | ||
`return`: `map` object of register's address and value | ||
```cpp | ||
EC_DUMP dump = ec.dump(); | ||
BYTE value = dump.find(0x20)->second; // Accessing value of 0x20 register | ||
``` | ||
|
||
* `VOID printDump()` | ||
</br> | ||
Print generated dump of all registers | ||
|
||
* `VOID saveDump(std::string output = "dump.bin")` | ||
</br> | ||
Store generated dump of all registers to the disk | ||
</br> | ||
`output`: Path of output file, default is in the current directory | ||
|
||
* `BYTE readByte(BYTE bRegister)` | ||
</br> | ||
Read EC register as `BYTE` | ||
</br> | ||
`bRegister`: Address of register | ||
</br> | ||
`return`: Value of register | ||
```cpp | ||
BYTE value = ec.readByte(0x20); | ||
std::cout << std::hex << (INT)value; // Print value of register 0x20 | ||
``` | ||
|
||
* `WORD readWord(BYTE bRegister)` | ||
</br> | ||
Read EC register as `WORD` | ||
</br> | ||
`bRegister`: Address of register | ||
</br> | ||
`return`: Value of register | ||
```cpp | ||
WORD value = ec.readWord(0x20); | ||
std::cout << std::hex << (INT)value; // Print value of register 0x20 and 0x21 in Little Endian byte order | ||
``` | ||
|
||
* `DWORD readDword(BYTE bRegister)` | ||
</br> | ||
Read EC register as `DWORD` | ||
</br> | ||
`bRegister`: Address of register | ||
</br> | ||
`return`: Value of register | ||
```cpp | ||
ec.endianness = BIG_ENDIAN; | ||
DWORD value = ec.readDword(0x20); | ||
std::cout << std::hex << (INT)value; // Print value of register 0x20, 0x21, 0x22 and 0x23 in Big Endian byte order | ||
``` | ||
|
||
* `BOOL writeByte(BYTE bRegister, BYTE value)` | ||
</br> | ||
Write EC register as `BYTE` | ||
</br> | ||
`bRegister`: Address of register | ||
</br> | ||
`value`: Value of register | ||
</br> | ||
`return`: `TRUE` if the opreation was successful, `FALSE` otherwise | ||
```cpp | ||
ec.writeByte(0x20, 0xAA); // Write 0xAA to register 0x20 | ||
``` | ||
|
||
* `BOOL writeWord(BYTE bRegister, WORD value)` | ||
</br> | ||
Write EC register as `WORD` | ||
</br> | ||
`bRegister`: Address of register | ||
</br> | ||
`value`: Value of register | ||
</br> | ||
`return`: `TRUE` if the opreation was successful, `FALSE` otherwise | ||
```cpp | ||
// Write 0xBB to register 0x20 and 0xAA to register 0x21 in Little Endian byte order | ||
ec.writeWord(0x20, 0xAABB); | ||
``` | ||
|
||
* `BOOL writeDword(BYTE bRegister, DWORD value)` | ||
</br> | ||
Write EC register as `DWORD` | ||
</br> | ||
`bRegister`: Address of register | ||
</br> | ||
`value`: Value of register | ||
</br> | ||
`return`: `TRUE` if the opreation was successful, `FALSE` otherwise | ||
```cpp | ||
// Write 0xAA to register 0x20, 0xBB to register 0x21, 0xCC to register 0x22 | ||
// and 0xDD to register 0x23 in Big Endian byte order | ||
ec.endianness = BIG_ENDIAN; | ||
ec.writeDword(0x20, 0xAABBCCDD); | ||
``` | ||
|
||
# **⚠️ Disclaimer** | ||
**Author of this software is not responsible for damage of any kind, use it at your own risk!** |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.