Skip to content

Commit 90ebd1e

Browse files
committed
Implement PawnIO detection and fix ioperm permissions
1 parent a13dffb commit 90ebd1e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cros_ec_python/devices/lpc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def ec_init(self) -> None:
116116

117117
# Request I/O permissions
118118
if (
119-
(res := self.portio.ioperm(EC_LPC_ADDR_HOST_DATA, EC_MEMMAP_SIZE, True))
120-
or (res := self.portio.ioperm(EC_LPC_ADDR_HOST_CMD, EC_MEMMAP_SIZE, True))
119+
(res := self.portio.ioperm(EC_LPC_ADDR_HOST_DATA, 1, True))
120+
or (res := self.portio.ioperm(EC_LPC_ADDR_HOST_CMD, 1, True))
121121
or (
122122
res := self.portio.ioperm(
123123
EC_LPC_ADDR_HOST_PACKET, EC_LPC_HOST_PACKET_SIZE, True
@@ -283,6 +283,7 @@ def ec_command_v3(
283283
for i in range(len(request)):
284284
csum += request[i]
285285

286+
# Write checksum field so the entire packet sums to 0
286287
request[1] = (-csum) & 0xFF
287288

288289
# Copy header
@@ -301,7 +302,7 @@ def ec_command_v3(
301302

302303
# Read back response and start checksum
303304
csum = 0
304-
data_out = bytearray(1 + 1 + 2 + 2 + 2)
305+
data_out = bytearray(struct.calcsize("BBHHH"))
305306
for i in range(len(data_out)):
306307
data_out[i] = self.portio.inb(EC_LPC_ADDR_HOST_PACKET + i)
307308
csum += data_out[i]

cros_ec_python/devices/pawnio.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import struct
22
import warnings
33
import ctypes
4+
import os
45
from ctypes import wintypes
56
from ctypes import util as ctypes_util
67

@@ -103,8 +104,12 @@ def _pawnio_close(self):
103104

104105
@staticmethod
105106
def detect() -> bool:
106-
# TODO
107-
return True
107+
"""
108+
Detect if the PawnIO driver is installed.
109+
"""
110+
return bool(ctypes_util.find_library("PawnIOLib.dll")) or os.path.exists(
111+
"C:\\Program Files\\PawnIO\\PawnIOLib.dll"
112+
)
108113

109114
def ec_init(self) -> None:
110115
self._pawnio_open()

0 commit comments

Comments
 (0)