Skip to content

Commit ff06556

Browse files
committed
added support for activity interrupts
1 parent 0b31285 commit ff06556

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

adafruit_lsm303_accel.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
import ustruct as struct
5353
from micropython import const
5454
from adafruit_bus_device.i2c_device import I2CDevice
55+
from adafruit_register.i2c_struct import UnaryStruct
56+
from adafruit_register.i2c_bit import RWBit
57+
from adafruit_register.i2c_bits import RWBits
58+
5559

5660
__version__ = "0.0.0-auto.0"
5761
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM303_Accel.git"
@@ -92,7 +96,9 @@
9296
_REG_ACCEL_TIME_LIMIT_A = const(0x3B)
9397
_REG_ACCEL_TIME_LATENCY_A = const(0x3C)
9498
_REG_ACCEL_TIME_WINDOW_A = const(0x3D)
95-
99+
_REG_ACCEL_ACT_THS_A = const(0x3E)
100+
_REG_ACCEL_ACT_DUR_A = const(0x3F)
101+
_REG_ACCEL_WHO_AM_I = const(0x0F)
96102

97103
# Conversion constants
98104
_LSM303ACCEL_MG_LSB = 16704.0
@@ -105,10 +111,23 @@ class LSM303_Accel:
105111
# Class-level buffer for reading and writing data with the sensor.
106112
# This reduces memory allocations but means the code is not re-entrant or
107113
# thread safe!
114+
_chip_id = UnaryStruct(_REG_ACCEL_WHO_AM_I, "B")
115+
_int2_int1_enable = RWBit(_REG_ACCEL_CTRL_REG6_A, 6, 1)
116+
_int2_int2_enable = RWBit(_REG_ACCEL_CTRL_REG6_A, 5, 1)
117+
118+
_int2_activity_enable = RWBit(_REG_ACCEL_CTRL_REG6_A, 3, 1)
119+
_int_pin_active_low = RWBit(_REG_ACCEL_CTRL_REG6_A, 1, 1)
120+
121+
_act_threshold = UnaryStruct(_REG_ACCEL_ACT_THS_A, "B")
122+
_act_duration = UnaryStruct(_REG_ACCEL_ACT_DUR_A, "B")
123+
124+
_data_rate = RWBits(4, _REG_ACCEL_CTRL_REG1_A, 4, 1)
125+
108126
_BUFFER = bytearray(6)
109127

110128
def __init__(self, i2c):
111129
self._accel_device = I2CDevice(i2c, _ADDRESS_ACCEL)
130+
self.i2c_device = self._accel_device
112131
self._write_u8(self._accel_device, _REG_ACCEL_CTRL_REG1_A, 0x27) # Enable the accelerometer
113132

114133
@property

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Uncomment the below if you use native CircuitPython modules such as
1919
# digitalio, micropython and busio. List the modules you use. Without it, the
2020
# autodoc module docs will fail to generate with a warning.
21-
autodoc_mock_imports = ["adafruit_bus_device", "micropython"]
21+
autodoc_mock_imports = ["adafruit_bus_device", "micropython", "adafruit_register"]
2222

2323
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
2424

0 commit comments

Comments
 (0)