Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ lib/<component>/
- **Constructor signature**: `def __init__(self, i2c, ..., address=DEFAULT_ADDR)` — first parameter is always `i2c` (not `bus`), address uses keyword argument with a default from `const.py`.
- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`).
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access.
- **Device identification**: `device_id()` — returns the device/WHO_AM_I register value. All I2C drivers with an ID register must implement this method.

### Linting

Expand Down
3 changes: 3 additions & 0 deletions lib/apds9960/apds9960/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def __init__(self, i2c, address=APDS9960_I2C_ADDR, valid_id=APDS9960_DEV_ID):
self._write_reg(APDS9960_REG_GCONF3, APDS9960_DEFAULT_GCONF3)
self.set_gesture_int_enable(APDS9960_DEFAULT_GIEN)

def device_id(self):
return self.dev_id

def get_mode(self):
return self._read_reg(APDS9960_REG_ENABLE)

Expand Down
7 changes: 3 additions & 4 deletions lib/bq27441/bq27441/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def disable_shutdown_mode(self):

def is_valid_device(self):
"""Checks if device id returned matches bq27441"""
device_id = self.device_type() # Read device_type from BQ27441
return device_id == BQ27441_DEVICE_ID
return self.device_id() == BQ27441_DEVICE_ID

# Configures the design capacity of the connected battery.
def set_capacity(self, capacity):
Expand Down Expand Up @@ -353,8 +352,8 @@ def set_soci_delta(self, delta):
def pulse_gpout(self):
return self.execute_control_word(BQ27441_CONTROL_PULSE_SOC_INT)

# Read the device type - should be 0x0421
def device_type(self):
# Read the device ID - should be 0x0421
def device_id(self):
return self.read_control_word(BQ27441_CONTROL_DEVICE_TYPE)

Comment thread
nedseb marked this conversation as resolved.
def get_time_ms(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/hts221/hts221/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _read_reg16(self, reg):
return (hi << 8) + lo

# Device identification
def who_am_i(self):
def device_id(self):
return self._read_reg(HTS221_WHO_AM_I)

Comment thread
nedseb marked this conversation as resolved.
# get STATUS register
Expand Down
4 changes: 2 additions & 2 deletions lib/ism330dl/ism330dl/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def _read_vector(self, reg):
# Device check
# --------------------------------------------------

def who_am_i(self):
def device_id(self):
return self._read_u8(REG_WHO_AM_I)

Comment thread
nedseb marked this conversation as resolved.
def check_device(self):
if self.who_am_i() != ISM330DL_WHO_AM_I_VALUE:
if self.device_id() != ISM330DL_WHO_AM_I_VALUE:
raise ISM330DLNotFound("ISM330DL not detected")

# --------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/lis2mdl/examples/magnet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_reads(dev):
print("\n=== TEST READS ===")

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

Expand Down Expand Up @@ -652,7 +652,7 @@ def test_reboot(dev):
ok &= reboot_cleared

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

Expand Down
2 changes: 1 addition & 1 deletion lib/lis2mdl/lis2mdl/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def calibrate_temperature(self, ref_low, measured_low, ref_high, measured_high):

# --- IDENTITY & HARDWARE OFFSETS ---

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

Comment thread
nedseb marked this conversation as resolved.
Expand Down
4 changes: 2 additions & 2 deletions lib/vl53l1x/vl53l1x/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, i2c, address=0x29):
self.address = address
self.reset()
machine.lightsleep(1)
if self.read_model_id() != 0xEACC:
if self.device_id() != 0xEACC:
raise RuntimeError("Failed to find expected ID register values. Check wiring!")
# write default configuration
self.i2c.writeto_mem(self.address, 0x2D, VL53L1X_DEFAULT_CONFIGURATION, addrsize=16)
Expand All @@ -126,7 +126,7 @@ def _read_reg16(self, reg):
data = self.i2c.readfrom_mem(self.address, reg, 2, addrsize=16)
return (data[0] << 8) + data[1]

def read_model_id(self):
def device_id(self):
return self._read_reg16(0x010F)

Comment thread
nedseb marked this conversation as resolved.
def reset(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/scenarios/apds9960.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ tests:
expect: 0xAB
mode: [mock]

- name: "Read device ID via method"
action: call
method: device_id
expect: 0xAB
mode: [mock]

- name: "Verify device ID register (hardware)"
action: read_register
register: 0x92
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/hts221.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tests:

- name: "Read WHO_AM_I via method"
action: call
method: who_am_i
method: device_id
expect: 0xBC
mode: [mock, hardware]

Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/ism330dl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tests:

- name: "Read WHO_AM_I via method"
action: call
method: who_am_i
method: device_id
expect: 0x6A
mode: [mock, hardware]

Expand Down
6 changes: 3 additions & 3 deletions tests/scenarios/lis2mdl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tests:

- name: "Read WHO_AM_I via method"
action: call
method: read_who_am_i
method: device_id
expect: 0x40
mode: [mock, hardware]

Expand Down Expand Up @@ -165,15 +165,15 @@ tests:
action: hardware_script
script: |
dev.soft_reset()
result = dev.read_who_am_i()
result = dev.device_id()
expect: 0x40
mode: [hardware]

- name: "Reboot then WHO_AM_I"
action: hardware_script
script: |
dev.reboot()
result = dev.read_who_am_i()
result = dev.device_id()
expect: 0x40
mode: [hardware]

Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/vl53l1x.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mock_registers:
tests:
- name: "Verify model ID register"
action: call
method: read_model_id
method: device_id
expect: 0xEACC
mode: [mock, hardware]

Expand Down
Loading