Skip to content

Commit 5ea09fe

Browse files
committed
Fixed stubs
1 parent 78477a3 commit 5ea09fe

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

shared-bindings/busdevice/I2CDevice.c

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,30 @@
3939

4040

4141
//| class I2CDevice:
42-
//| """
43-
//| Represents a single I2C device and manages locking the bus and the device
44-
//| address.
45-
//| :param ~busio.I2C i2c: The I2C bus the device is on
46-
//| :param int device_address: The 7 bit device address
47-
//| :param bool probe: Probe for the device upon object creation, default is true
48-
//| .. note:: This class is **NOT** built into CircuitPython. See
49-
//| :ref:`here for install instructions <bus_device_installation>`.
50-
//| Example:
51-
//| .. code-block:: python
52-
//| import busio
53-
//| from board import *
54-
//| from adafruit_bus_device.i2c_device import I2CDevice
55-
//| with busio.I2C(SCL, SDA) as i2c:
56-
//| device = I2CDevice(i2c, 0x70)
57-
//| bytes_read = bytearray(4)
58-
//| with device:
59-
//| device.readinto(bytes_read)
60-
//| # A second transaction
61-
//| with device:
62-
//| device.write(bytes_read)"""
42+
//| """I2C Device Manager"""
43+
//|
44+
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 100000, timeout: int = 255) -> None:
45+
//|
46+
//| """Represents a single I2C device and manages locking the bus and the device
47+
//| address.
48+
//| :param ~busio.I2C i2c: The I2C bus the device is on
49+
//| :param int device_address: The 7 bit device address
50+
//| :param bool probe: Probe for the device upon object creation, default is true
51+
//| .. note:: This class is **NOT** built into CircuitPython. See
52+
//| :ref:`here for install instructions <bus_device_installation>`.
53+
//| Example:
54+
//| .. code-block:: python
55+
//| import busio
56+
//| from board import *
57+
//| from adafruit_bus_device.i2c_device import I2CDevice
58+
//| with busio.I2C(SCL, SDA) as i2c:
59+
//| device = I2CDevice(i2c, 0x70)
60+
//| bytes_read = bytearray(4)
61+
//| with device:
62+
//| device.readinto(bytes_read)
63+
//| # A second transaction
64+
//| with device:
65+
//| device.write(bytes_read)"""
6366
//| ...
6467
//|
6568
STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -84,20 +87,28 @@ STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n
8487
return (mp_obj_t)self;
8588
}
8689

90+
//| def __enter__(self) -> I2C:
91+
//| """Context manager entry to lock bus."""
92+
//| ...
93+
//|
8794
STATIC mp_obj_t busdevice_i2cdevice_obj___enter__(mp_obj_t self_in) {
8895
busdevice_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
8996
common_hal_busdevice_i2cdevice_lock(self);
9097
return self;
9198
}
9299
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busdevice_i2cdevice___enter___obj, busdevice_i2cdevice_obj___enter__);
93100

101+
//| def __exit__(self) -> None:
102+
//| """Automatically unlocks the bus on exit."""
103+
//| ...
104+
//|
94105
STATIC mp_obj_t busdevice_i2cdevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
95106
common_hal_busdevice_i2cdevice_unlock(MP_OBJ_TO_PTR(args[0]));
96107
return mp_const_none;
97108
}
98109
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busdevice_i2cdevice___exit___obj, 4, 4, busdevice_i2cdevice_obj___exit__);
99110

100-
//| def readinto(self, buf, *, start=0, end=None):
111+
//| def readinto(self, buf, *, start=0, end=None) -> None:
101112
//| """
102113
//| Read into ``buf`` from the device. The number of bytes read will be the
103114
//| length of ``buf``.
@@ -143,18 +154,17 @@ STATIC mp_obj_t busdevice_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_
143154
}
144155
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_readinto_obj, 2, busdevice_i2cdevice_readinto);
145156

146-
//| def write(self, buf, *, start=0, end=None):
147-
//| """
148-
//| Write the bytes from ``buffer`` to the device, then transmit a stop
149-
//| bit.
150-
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
151-
//| as if ``buffer[start:end]``. This will not cause an allocation like
152-
//| ``buffer[start:end]`` will so it saves memory.
153-
//| :param bytearray buffer: buffer containing the bytes to write
154-
//| :param int start: Index to start writing from
155-
//| :param int end: Index to read up to but not include; if None, use ``len(buf)``
156-
//| """
157-
//| ...
157+
//| def write(self, buf, *, start=0, end=None) -> None:
158+
//| """
159+
//| Write the bytes from ``buffer`` to the device, then transmit a stop bit.
160+
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
161+
//| as if ``buffer[start:end]``. This will not cause an allocation like
162+
//| ``buffer[start:end]`` will so it saves memory.
163+
//| :param bytearray buffer: buffer containing the bytes to write
164+
//| :param int start: Index to start writing from
165+
//| :param int end: Index to read up to but not include; if None, use ``len(buf)``
166+
//| """
167+
//| ...
158168
//|
159169
STATIC void write(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
160170
mp_buffer_info_t bufinfo;
@@ -190,7 +200,7 @@ STATIC mp_obj_t busdevice_i2cdevice_write(size_t n_args, const mp_obj_t *pos_arg
190200
MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_write_obj, 2, busdevice_i2cdevice_write);
191201

192202

193-
//| def write_then_readinto(self, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None):
203+
//| def write_then_readinto(self, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None) -> None:
194204
//| """
195205
//| Write the bytes from ``out_buffer`` to the device, then immediately
196206
//| reads into ``in_buffer`` from the device. The number of bytes read

shared-bindings/busdevice/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
//| The I2CDevice and SPIDevice helper classes make managing transaction state on a bus easy.
4141
//| For example, they manage locking the bus to prevent other concurrent access. For SPI
4242
//| devices, it manages the chip select and protocol changes such as mode. For I2C, it
43-
//| manages the device address.
43+
//| manages the device address."""
4444
//|
4545

4646
STATIC const mp_rom_map_elem_t busdevice_module_globals_table[] = {

0 commit comments

Comments
 (0)