Skip to content

Commit

Permalink
Add optional parameter for using internal pull-up for int1
Browse files Browse the repository at this point in the history
This is useful in cases where there is no support for internal pull-up resistor on the board (for example Binho Nova host adapter). On such devices, one have to use an external pull-up resistor.
  • Loading branch information
perja12 committed Aug 13, 2023
1 parent 6791d3f commit 111bc2c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions adafruit_lis3dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,23 @@


class LIS3DH:
"""Driver base for the LIS3DH accelerometer.
"""Driver base for the LIS3DH accelerometer. Optional parameters:
:param digitalio.DigitalInOut int1: `digitalio.DigitalInOut` connected to
the LIS3DH INT interrupt pin
:param digitalio.DigitalInOut int2: `digitalio.DigitalInOut` connected to
the LIS3DH I2 interrupt pin (only on STEMMA QT model)
:param bool internal_pull_up_int1: use `internal_pull_up_int1` to control if
the internal pull-up of the board/MCU should be used or not for the LIS3DH
INT interrupt pin (int1). Use external pull-up resistor if set to false.
By default the internal pull-up resistor will be used.
"""

def __init__(
self,
int1: Optional[digitalio.DigitalInOut] = None,
int2: Optional[digitalio.DigitalInOut] = None,
internal_pull_up_int1: bool = True,
) -> None:
# Check device ID.
device_id = self._read_register_byte(_REG_WHOAMI)
Expand All @@ -129,7 +134,8 @@ def __init__(
self._int2 = int2
if self._int1:
self._int1.direction = digitalio.Direction.INPUT
self._int1.pull = digitalio.Pull.UP
if internal_pull_up_int1:
self._int1.pull = digitalio.Pull.UP

@property
def data_rate(
Expand Down Expand Up @@ -310,7 +316,7 @@ def set_tap(
time_limit: int = 10,
time_latency: int = 20,
time_window: int = 255,
click_cfg: Optional[int] = None
click_cfg: Optional[int] = None,
) -> None:
"""
The tap detection parameters.
Expand Down Expand Up @@ -413,15 +419,18 @@ def __init__(
*,
address: int = 0x18,
int1: Optional[digitalio.DigitalInOut] = None,
int2: Optional[digitalio.DigitalInOut] = None
int2: Optional[digitalio.DigitalInOut] = None,
internal_pull_up_int1: bool = True,
) -> None:
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
i2c_device,
)

self._i2c = i2c_device.I2CDevice(i2c, address)
self._buffer = bytearray(6)
super().__init__(int1=int1, int2=int2)
super().__init__(
int1=int1, int2=int2, internal_pull_up_int1=internal_pull_up_int1
)

def _read_register(self, register: int, length: int) -> bytearray:
self._buffer[0] = register & 0xFF
Expand Down Expand Up @@ -476,7 +485,7 @@ def __init__(
*,
baudrate: int = 100000,
int1: Optional[digitalio.DigitalInOut] = None,
int2: Optional[digitalio.DigitalInOut] = None
int2: Optional[digitalio.DigitalInOut] = None,
) -> None:
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
spi_device,
Expand Down

0 comments on commit 111bc2c

Please sign in to comment.