Skip to content

Commit f2a0060

Browse files
committed
drivers: Standardize device identification to device_id().
1 parent dd5e082 commit f2a0060

10 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/apds9960/apds9960/device.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def __init__(self, i2c, address=APDS9960_I2C_ADDR, valid_id=APDS9960_DEV_ID):
7979
self._write_reg(APDS9960_REG_GCONF3, APDS9960_DEFAULT_GCONF3)
8080
self.set_gesture_int_enable(APDS9960_DEFAULT_GIEN)
8181

82+
def device_id(self):
83+
return self._read_reg(APDS9960_REG_ID)
84+
8285
def get_mode(self):
8386
return self._read_reg(APDS9960_REG_ENABLE)
8487

lib/hts221/hts221/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _read_reg16(self, reg):
5757
return (hi << 8) + lo
5858

5959
# Device identification
60-
def who_am_i(self):
60+
def device_id(self):
6161
return self._read_reg(HTS221_WHO_AM_I)
6262

6363
# get STATUS register

lib/ism330dl/ism330dl/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ def _read_vector(self, reg):
7777
# Device check
7878
# --------------------------------------------------
7979

80-
def who_am_i(self):
80+
def device_id(self):
8181
return self._read_u8(REG_WHO_AM_I)
8282

8383
def check_device(self):
84-
if self.who_am_i() != ISM330DL_WHO_AM_I_VALUE:
84+
if self.device_id() != ISM330DL_WHO_AM_I_VALUE:
8585
raise ISM330DLNotFound("ISM330DL not detected")
8686

8787
# --------------------------------------------------

lib/lis2mdl/examples/magnet_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def test_reads(dev):
234234
print("\n=== TEST READS ===")
235235

236236
# WHO_AM_I
237-
who = dev.read_who_am_i()
237+
who = dev.device_id()
238238
print(f"WHO_AM_I=0x{who:02X} expected 0x40 =>", "OK" if who == 0x40 else "FAIL")
239239
ok &= who == 0x40
240240

@@ -652,7 +652,7 @@ def test_reboot(dev):
652652
ok &= reboot_cleared
653653

654654
# WHO_AM_I still correct
655-
who = dev.read_who_am_i()
655+
who = dev.device_id()
656656
print(f"WHO_AM_I=0x{who:02X} expected 0x40 =>", "OK" if who == 0x40 else "FAIL")
657657
ok &= who == 0x40
658658

lib/lis2mdl/lis2mdl/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def calibrate_temperature(self, ref_low, measured_low, ref_high, measured_high):
290290

291291
# --- IDENTITY & HARDWARE OFFSETS ---
292292

293-
def read_who_am_i(self) -> int:
293+
def device_id(self) -> int:
294294
"""Reads WHO_AM_I (should be 0x40)."""
295295
return self._read_reg(LIS2MDL_WHO_AM_I)
296296

lib/vl53l1x/vl53l1x/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(self, i2c, address=0x29):
103103
self.address = address
104104
self.reset()
105105
machine.lightsleep(1)
106-
if self.read_model_id() != 0xEACC:
106+
if self.device_id() != 0xEACC:
107107
raise RuntimeError("Failed to find expected ID register values. Check wiring!")
108108
# write default configuration
109109
self.i2c.writeto_mem(self.address, 0x2D, VL53L1X_DEFAULT_CONFIGURATION, addrsize=16)
@@ -126,7 +126,7 @@ def _read_reg16(self, reg):
126126
data = self.i2c.readfrom_mem(self.address, reg, 2, addrsize=16)
127127
return (data[0] << 8) + data[1]
128128

129-
def read_model_id(self):
129+
def device_id(self):
130130
return self._read_reg16(0x010F)
131131

132132
def reset(self):

tests/scenarios/hts221.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ tests:
5151

5252
- name: "Read WHO_AM_I via method"
5353
action: call
54-
method: who_am_i
54+
method: device_id
5555
expect: 0xBC
5656
mode: [mock, hardware]
5757

tests/scenarios/ism330dl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tests:
3636

3737
- name: "Read WHO_AM_I via method"
3838
action: call
39-
method: who_am_i
39+
method: device_id
4040
expect: 0x6A
4141
mode: [mock, hardware]
4242

tests/scenarios/lis2mdl.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tests:
4242

4343
- name: "Read WHO_AM_I via method"
4444
action: call
45-
method: read_who_am_i
45+
method: device_id
4646
expect: 0x40
4747
mode: [mock, hardware]
4848

@@ -165,15 +165,15 @@ tests:
165165
action: hardware_script
166166
script: |
167167
dev.soft_reset()
168-
result = dev.read_who_am_i()
168+
result = dev.device_id()
169169
expect: 0x40
170170
mode: [hardware]
171171

172172
- name: "Reboot then WHO_AM_I"
173173
action: hardware_script
174174
script: |
175175
dev.reboot()
176-
result = dev.read_who_am_i()
176+
result = dev.device_id()
177177
expect: 0x40
178178
mode: [hardware]
179179

tests/scenarios/vl53l1x.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mock_registers:
3737
tests:
3838
- name: "Verify model ID register"
3939
action: call
40-
method: read_model_id
40+
method: device_id
4141
expect: 0xEACC
4242
mode: [mock, hardware]
4343

0 commit comments

Comments
 (0)