You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-22Lines changed: 33 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,11 @@ SPI register based device. Data descriptors act like basic attributes from the
5
5
outside which makes using them really easy.
6
6
7
7
## Creating a driver
8
-
Creating a driver with the register library is really easy. First, import the register modules you need from the [available modules](adafruit_register/index.html):
8
+
Creating a driver with the register library is really easy. First, import the
9
+
register modules you need from the [available modules](adafruit_register/index.html):
9
10
10
11
from adafruit_register import i2c_bit
12
+
from adafruit_bus_device import i2c_device
11
13
12
14
Next, define where the bit is located in the device's memory map:
13
15
@@ -20,14 +22,13 @@ Next, define where the bit is located in the device's memory map:
20
22
world = i2c_bit.RWBit(0x1, 0x0)
21
23
"""Bit to indicate if world is lit."""
22
24
23
-
Lastly, we need to add two instance members `i2c` and `device_address` so that
24
-
the register classes know how to talk to the device. Make sure their names are
25
-
exact, otherwise the registers will not be able to find them. Also, make sure
26
-
that the i2c device implements the `nativeio.I2C`interface.
25
+
Lastly, we need to add an `i2c_device` member that manages sharing the I2C bus
26
+
for us. Make sure the name is exact, otherwise the registers will not be able to
27
+
find it. Also, make sure that the i2c device implements the `nativeio.I2C`
Thats it! Now we have a class we can use to talk to those registers:
33
34
@@ -40,9 +41,14 @@ Thats it! Now we have a class we can use to talk to those registers:
40
41
device.world = True
41
42
42
43
## Adding register types
43
-
Adding a new register type is a little more complicated because you need to be careful and minimize the amount of memory the class will take. If you don't, then a driver with five registers of your type could take up five times more extra memory.
44
+
Adding a new register type is a little more complicated because you need to be
45
+
careful and minimize the amount of memory the class will take. If you don't,
46
+
then a driver with five registers of your type could take up five times more
47
+
extra memory.
44
48
45
-
First, determine whether the new register class should go in an existing module or not. When in doubt choose a new module. The more finer grained the modules are, the fewer extra classes a driver needs to load in.
49
+
First, determine whether the new register class should go in an existing module
50
+
or not. When in doubt choose a new module. The more finer grained the modules
51
+
are, the fewer extra classes a driver needs to load in.
46
52
47
53
Here is the start of the `RWBit` class:
48
54
@@ -70,7 +76,7 @@ register classes will be shared.
70
76
71
77
In `__init__` we only use two member variable because each costs 8 bytes of
72
78
memory plus the memory for the value. And remember this gets multiplied by the
73
-
number of registers of this type in a device! Thats why we pack both the
79
+
number of registers of this type in a driver! Thats why we pack both the
74
80
register address and data byte into one bytearray. We could use two byte arrays
75
81
of size one but each MicroPython object is 16 bytes minimum due to the garbage
76
82
collector. So, by sharing a byte array we keep it to the 16 byte minimum instead
@@ -85,24 +91,29 @@ Ok, onward. To make a [data descriptor](https://docs.python.org/3/howto/descript
0 commit comments