Did the same for the rest of busio
This commit is contained in:
parent
93d1e53c66
commit
deccdcc1d6
@ -36,33 +36,35 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
|
|
||||||
//|class I2C:
|
//| class I2C:
|
||||||
//|""".. currentmodule:: busio
|
//| """.. currentmodule:: busio
|
||||||
//|
|
//|
|
||||||
//|:class:`I2C` --- Two wire serial protocol
|
//| :class:`I2C` --- Two wire serial protocol
|
||||||
//|------------------------------------------"""
|
//| ------------------------------------------"""
|
||||||
//|def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 400000, timeout: int = 255):
|
|
||||||
//|"""I2C is a two-wire protocol for communicating between devices. At the
|
|
||||||
//|physical level it consists of 2 wires: SCL and SDA, the clock and data
|
|
||||||
//|lines respectively.
|
|
||||||
//|
|
//|
|
||||||
//|.. seealso:: Using this class directly requires careful lock management.
|
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 400000, timeout: int = 255):
|
||||||
//|Instead, use :class:`~adafruit_bus_device.i2c_device.I2CDevice` to
|
|
||||||
//|manage locks.
|
|
||||||
//|
|
//|
|
||||||
//|.. seealso:: Using this class to directly read registers requires manual
|
//| """I2C is a two-wire protocol for communicating between devices. At the
|
||||||
//|bit unpacking. Instead, use an existing driver or make one with
|
//| physical level it consists of 2 wires: SCL and SDA, the clock and data
|
||||||
//|:ref:`Register <register-module-reference>` data descriptors.
|
//| lines respectively.
|
||||||
//|
|
//|
|
||||||
//|:param ~microcontroller.Pin scl: The clock pin
|
//| .. seealso:: Using this class directly requires careful lock management.
|
||||||
//|:param ~microcontroller.Pin sda: The data pin
|
//| Instead, use :class:`~adafruit_bus_device.i2c_device.I2CDevice` to
|
||||||
//|:param int frequency: The clock frequency in Hertz
|
//| manage locks.
|
||||||
//|:param int timeout: The maximum clock stretching timeut - (used only for bitbangio.I2C; ignored for busio.I2C)
|
|
||||||
//|
|
//|
|
||||||
//|.. note:: On the nRF52840, only one I2C object may be created,
|
//| .. seealso:: Using this class to directly read registers requires manual
|
||||||
//|except on the Circuit Playground Bluefruit, which allows two,
|
//| bit unpacking. Instead, use an existing driver or make one with
|
||||||
//|one for the onboard accelerometer, and one for offboard use."""
|
//| :ref:`Register <register-module-reference>` data descriptors.
|
||||||
//|...
|
//|
|
||||||
|
//| :param ~microcontroller.Pin scl: The clock pin
|
||||||
|
//| :param ~microcontroller.Pin sda: The data pin
|
||||||
|
//| :param int frequency: The clock frequency in Hertz
|
||||||
|
//| :param int timeout: The maximum clock stretching timeut - (used only for bitbangio.I2C; ignored for busio.I2C)
|
||||||
|
//|
|
||||||
|
//| .. note:: On the nRF52840, only one I2C object may be created,
|
||||||
|
//| except on the Circuit Playground Bluefruit, which allows two,
|
||||||
|
//| one for the onboard accelerometer, and one for offboard use."""
|
||||||
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
|
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
|
||||||
self->base.type = &busio_i2c_type;
|
self->base.type = &busio_i2c_type;
|
||||||
@ -83,9 +85,9 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con
|
|||||||
return (mp_obj_t)self;
|
return (mp_obj_t)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def deinit(self, ) -> Any:
|
//| def deinit(self, ) -> Any:
|
||||||
//|"""Releases control of the underlying hardware so other classes can use it."""
|
//| """Releases control of the underlying hardware so other classes can use it."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_obj_deinit(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_i2c_obj_deinit(mp_obj_t self_in) {
|
||||||
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
common_hal_busio_i2c_deinit(self);
|
common_hal_busio_i2c_deinit(self);
|
||||||
@ -99,15 +101,15 @@ STATIC void check_for_deinit(busio_i2c_obj_t *self) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def __enter__(self, ) -> Any:
|
//| def __enter__(self, ) -> Any:
|
||||||
//|"""No-op used in Context Managers."""
|
//| """No-op used in Context Managers."""
|
||||||
//|...
|
//| ...
|
||||||
// Provided by context manager helper.
|
// Provided by context manager helper.
|
||||||
|
|
||||||
//|def __exit__(self, ) -> Any:
|
//| def __exit__(self, ) -> Any:
|
||||||
//|"""Automatically deinitializes the hardware on context exit. See
|
//| """Automatically deinitializes the hardware on context exit. See
|
||||||
//|:ref:`lifetime-and-contextmanagers` for more info."""
|
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||||
(void)n_args;
|
(void)n_args;
|
||||||
common_hal_busio_i2c_deinit(args[0]);
|
common_hal_busio_i2c_deinit(args[0]);
|
||||||
@ -122,13 +124,14 @@ static void check_lock(busio_i2c_obj_t *self) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def scan(self, ) -> Any:
|
//| def scan(self, ) -> Any:
|
||||||
//|"""Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
|
|
||||||
//|list of those that respond.
|
|
||||||
//|
|
//|
|
||||||
//|:return: List of device ids on the I2C bus
|
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
|
||||||
//|:rtype: list"""
|
//| list of those that respond.
|
||||||
//|...
|
//|
|
||||||
|
//| :return: List of device ids on the I2C bus
|
||||||
|
//| :rtype: list"""
|
||||||
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
|
||||||
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -145,11 +148,12 @@ STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan);
|
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan);
|
||||||
|
|
||||||
//|def try_lock(self, ) -> Any:
|
//| def try_lock(self, ) -> Any:
|
||||||
//|"""Attempts to grab the I2C lock. Returns True on success.
|
//| """Attempts to grab the I2C lock. Returns True on success.
|
||||||
//|:return: True when lock has been grabbed
|
//|
|
||||||
//|:rtype: bool"""
|
//| :return: True when lock has been grabbed
|
||||||
//|...
|
//| :rtype: bool"""
|
||||||
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
|
||||||
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -157,9 +161,9 @@ STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock);
|
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock);
|
||||||
|
|
||||||
//|def unlock(self, ) -> Any:
|
//| def unlock(self, ) -> Any:
|
||||||
//|"""Releases the I2C lock."""
|
//| """Releases the I2C lock."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
|
||||||
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -168,20 +172,20 @@ STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
|
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
|
||||||
|
|
||||||
//|def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> Any:
|
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> Any:
|
||||||
//|"""Read into ``buffer`` from the slave specified by ``address``.
|
//| """Read into ``buffer`` from the slave specified by ``address``.
|
||||||
//|The number of bytes read will be the length of ``buffer``.
|
//| The number of bytes read will be the length of ``buffer``.
|
||||||
//|At least one byte must be read.
|
//| At least one byte must be read.
|
||||||
//|
|
//|
|
||||||
//|If ``start`` or ``end`` is provided, then the buffer will be sliced
|
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||||
//|as if ``buffer[start:end]``. This will not cause an allocation like
|
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||||
//|``buf[start:end]`` will so it saves memory.
|
//| ``buf[start:end]`` will so it saves memory.
|
||||||
//|
|
//|
|
||||||
//|:param int address: 7-bit device address
|
//| :param int address: 7-bit device address
|
||||||
//|:param bytearray buffer: buffer to write into
|
//| :param bytearray buffer: buffer to write into
|
||||||
//|:param int start: Index to start writing at
|
//| :param int start: Index to start writing at
|
||||||
//|:param int end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
||||||
//|...
|
//| ...
|
||||||
// Shared arg parsing for readfrom_into and writeto_then_readfrom.
|
// Shared arg parsing for readfrom_into and writeto_then_readfrom.
|
||||||
STATIC void readfrom(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
STATIC void readfrom(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
@ -219,26 +223,26 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args,
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_into);
|
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_into);
|
||||||
|
|
||||||
//|def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> Any:
|
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> Any:
|
||||||
//|"""Write the bytes from ``buffer`` to the slave specified by ``address``.
|
//| """Write the bytes from ``buffer`` to the slave specified by ``address``.
|
||||||
//|Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be
|
//| Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be
|
||||||
//|removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and
|
//| removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and
|
||||||
//|repeated start before a read.
|
//| repeated start before a read.
|
||||||
//|
|
//|
|
||||||
//|If ``start`` or ``end`` is provided, then the buffer will be sliced
|
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||||
//|as if ``buffer[start:end]``. This will not cause an allocation like
|
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||||
//|``buffer[start:end]`` will so it saves memory.
|
//| ``buffer[start:end]`` will so it saves memory.
|
||||||
//|
|
//|
|
||||||
//|Writing a buffer or slice of length zero is permitted, as it can be used
|
//| Writing a buffer or slice of length zero is permitted, as it can be used
|
||||||
//|to poll for the existence of a device.
|
//| to poll for the existence of a device.
|
||||||
//|
|
//|
|
||||||
//|:param int address: 7-bit device address
|
//| :param int address: 7-bit device address
|
||||||
//|:param bytearray buffer: buffer containing the bytes to write
|
//| :param bytearray buffer: buffer containing the bytes to write
|
||||||
//|:param int start: Index to start writing from
|
//| :param int start: Index to start writing from
|
||||||
//|:param int end: Index to read up to but not include. Defaults to ``len(buffer)``
|
//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||||
//|:param bool stop: If true, output an I2C stop condition after the buffer is written.
|
//| :param bool stop: If true, output an I2C stop condition after the buffer is written.
|
||||||
//|Deprecated. Will be removed in 6.x and act as stop=True."""
|
//| Deprecated. Will be removed in 6.x and act as stop=True."""
|
||||||
//|...
|
//| ...
|
||||||
// Shared arg parsing for writeto and writeto_then_readfrom.
|
// Shared arg parsing for writeto and writeto_then_readfrom.
|
||||||
STATIC void writeto(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end, bool stop) {
|
STATIC void writeto(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end, bool stop) {
|
||||||
// get the buffer to write the data from
|
// get the buffer to write the data from
|
||||||
@ -277,23 +281,23 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
|
||||||
|
|
||||||
//|def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> Any:
|
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> Any:
|
||||||
//|"""Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
|
//| """Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
|
||||||
//|bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
|
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
|
||||||
//|``in_buffer`` can be the same buffer because they are used sequentially.
|
//| ``in_buffer`` can be the same buffer because they are used sequentially.
|
||||||
//|
|
//|
|
||||||
//|If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
|
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
|
||||||
//|as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
|
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
|
||||||
//|will so it saves memory.
|
//| will so it saves memory.
|
||||||
//|
|
//|
|
||||||
//|:param int address: 7-bit device address
|
//| :param int address: 7-bit device address
|
||||||
//|:param bytearray out_buffer: buffer containing the bytes to write
|
//| :param bytearray out_buffer: buffer containing the bytes to write
|
||||||
//|:param bytearray in_buffer: buffer to write into
|
//| :param bytearray in_buffer: buffer to write into
|
||||||
//|:param int out_start: Index to start writing from
|
//| :param int out_start: Index to start writing from
|
||||||
//|:param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
|
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||||
//|:param int in_start: Index to start writing at
|
//| :param int in_start: Index to start writing at
|
||||||
//|:param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
|
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
|
@ -34,36 +34,35 @@
|
|||||||
#include "shared-bindings/busio/OneWire.h"
|
#include "shared-bindings/busio/OneWire.h"
|
||||||
#include "shared-bindings/util.h"
|
#include "shared-bindings/util.h"
|
||||||
|
|
||||||
//|class OneWire:
|
//| class OneWire:
|
||||||
//|""".. currentmodule:: busio
|
//| """.. currentmodule:: busio
|
||||||
//|
|
//|
|
||||||
//|:class:`OneWire` -- Lowest-level of the Maxim OneWire protocol
|
//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol
|
||||||
//|================================================================="""
|
//| ================================================================="""
|
||||||
//|
|
//|
|
||||||
//|__init__(self, pin: microcontroller.Pin):
|
//| def __init__(self, pin: microcontroller.Pin):
|
||||||
//|""":class:`~busio.OneWire` implements the timing-sensitive foundation of the Maxim
|
//| """(formerly Dallas Semi) OneWire protocol.
|
||||||
//|(formerly Dallas Semi) OneWire protocol.
|
|
||||||
//|
|
//|
|
||||||
//|Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
|
//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
|
||||||
//|
|
//|
|
||||||
//|.. class:: OneWire(pin)
|
//| .. class:: OneWire(pin)
|
||||||
//|
|
//|
|
||||||
//|Create a OneWire object associated with the given pin. The object
|
//| Create a OneWire object associated with the given pin. The object
|
||||||
//|implements the lowest level timing-sensitive bits of the protocol.
|
//| implements the lowest level timing-sensitive bits of the protocol.
|
||||||
//|
|
//|
|
||||||
//|:param ~microcontroller.Pin pin: Pin connected to the OneWire bus
|
//| :param ~microcontroller.Pin pin: Pin connected to the OneWire bus
|
||||||
//|
|
//|
|
||||||
//|Read a short series of pulses::
|
//| Read a short series of pulses::
|
||||||
//|
|
//|
|
||||||
//|import busio
|
//| import busio
|
||||||
//|import board
|
//| import board
|
||||||
//|
|
//|
|
||||||
//|onewire = busio.OneWire(board.D7)
|
//| onewire = busio.OneWire(board.D7)
|
||||||
//|onewire.reset()
|
//| onewire.reset()
|
||||||
//|onewire.write_bit(True)
|
//| onewire.write_bit(True)
|
||||||
//|onewire.write_bit(False)
|
//| onewire.write_bit(False)
|
||||||
//|print(onewire.read_bit())"""
|
//| print(onewire.read_bit())"""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_pin };
|
enum { ARG_pin };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
@ -80,9 +79,9 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||||||
return MP_OBJ_FROM_PTR(self);
|
return MP_OBJ_FROM_PTR(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def deinit(self, ) -> Any:
|
//| def deinit(self, ) -> Any:
|
||||||
//|"""Deinitialize the OneWire bus and release any hardware resources for reuse."""
|
//| """Deinitialize the OneWire bus and release any hardware resources for reuse."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_onewire_deinit(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_onewire_deinit(mp_obj_t self_in) {
|
||||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
common_hal_busio_onewire_deinit(self);
|
common_hal_busio_onewire_deinit(self);
|
||||||
@ -96,15 +95,15 @@ STATIC void check_for_deinit(busio_onewire_obj_t *self) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def __enter__(self, ) -> Any:
|
//| def __enter__(self, ) -> Any:
|
||||||
//|"""No-op used by Context Managers."""
|
//| """No-op used by Context Managers."""
|
||||||
//|...
|
//| ...
|
||||||
// Provided by context manager helper.
|
// Provided by context manager helper.
|
||||||
|
|
||||||
//|def __exit__(self, ) -> Any:
|
//| def __exit__(self, ) -> Any:
|
||||||
//|"""Automatically deinitializes the hardware when exiting a context. See
|
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||||
//|:ref:`lifetime-and-contextmanagers` for more info."""
|
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||||
(void)n_args;
|
(void)n_args;
|
||||||
common_hal_busio_onewire_deinit(args[0]);
|
common_hal_busio_onewire_deinit(args[0]);
|
||||||
@ -112,12 +111,12 @@ STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args)
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, busio_onewire_obj___exit__);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, busio_onewire_obj___exit__);
|
||||||
|
|
||||||
//|def reset(self, ) -> Any:
|
//| def reset(self, ) -> Any:
|
||||||
//|"""Reset the OneWire bus and read presence
|
//| """Reset the OneWire bus and read presence
|
||||||
//|
|
//|
|
||||||
//|:returns: False when at least one device is present
|
//| :returns: False when at least one device is present
|
||||||
//|:rtype: bool"""
|
//| :rtype: bool"""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) {
|
||||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -126,12 +125,12 @@ STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset);
|
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset);
|
||||||
|
|
||||||
//|def read_bit(self, ) -> Any:
|
//| def read_bit(self, ) -> Any:
|
||||||
//|"""Read in a bit
|
//| """Read in a bit
|
||||||
//|
|
//|
|
||||||
//|:returns: bit state read
|
//| :returns: bit state read
|
||||||
//|:rtype: bool"""
|
//| :rtype: bool"""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) {
|
||||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -140,9 +139,9 @@ STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_read_bit_obj, busio_onewire_obj_read_bit);
|
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_read_bit_obj, busio_onewire_obj_read_bit);
|
||||||
|
|
||||||
//|def write_bit(self, value: Any) -> Any:
|
//| def write_bit(self, value: Any) -> Any:
|
||||||
//|"""Write out a bit based on value."""
|
//| """Write out a bit based on value."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) {
|
STATIC mp_obj_t busio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) {
|
||||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
|
@ -39,31 +39,31 @@
|
|||||||
#include "py/stream.h"
|
#include "py/stream.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
|
|
||||||
//|class UART:
|
//| class UART:
|
||||||
//|""".. currentmodule:: busio
|
//| """.. currentmodule:: busio
|
||||||
//|
|
//|
|
||||||
//|:class:`UART` -- a bidirectional serial protocol
|
//| :class:`UART` -- a bidirectional serial protocol
|
||||||
//|================================================="""
|
//| ================================================="""
|
||||||
//|def __init__(self, tx: microcontroller.Pin, rx: microcontroller.Pin, *, baudrate: int = 9600, bits: int = 8, parity: Parity = None, stop: int = 1, timeout: float = 1, receiver_buffer_size: int = 64):
|
//| def __init__(self, tx: microcontroller.Pin, rx: microcontroller.Pin, *, baudrate: int = 9600, bits: int = 8, parity: Parity = None, stop: int = 1, timeout: float = 1, receiver_buffer_size: int = 64):
|
||||||
//|"""A common bidirectional serial protocol that uses an an agreed upon speed
|
//| """A common bidirectional serial protocol that uses an an agreed upon speed
|
||||||
//|rather than a shared clock line.
|
//| rather than a shared clock line.
|
||||||
//|
|
//|
|
||||||
//|:param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
|
//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
|
||||||
//|:param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
|
//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
|
||||||
//|:param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
|
//| :param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
|
||||||
//|:param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
|
//| :param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
|
||||||
//|:param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
|
//| :param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
|
||||||
//|:param bool rs485_invert: set to invert the sense of the rs485_dir pin.
|
//| :param bool rs485_invert: set to invert the sense of the rs485_dir pin.
|
||||||
//|:param int baudrate: the transmit and receive speed.
|
//| :param int baudrate: the transmit and receive speed.
|
||||||
//|:param int bits: the number of bits per byte, 7, 8 or 9.
|
//| :param int bits: the number of bits per byte, 7, 8 or 9.
|
||||||
//|:param Parity parity: the parity used for error checking.
|
//| :param Parity parity: the parity used for error checking.
|
||||||
//|:param int stop: the number of stop bits, 1 or 2.
|
//| :param int stop: the number of stop bits, 1 or 2.
|
||||||
//|:param float timeout: the timeout in seconds to wait for the first character and between subsequent characters when reading. Raises ``ValueError`` if timeout >100 seconds.
|
//| :param float timeout: the timeout in seconds to wait for the first character and between subsequent characters when reading. Raises ``ValueError`` if timeout >100 seconds.
|
||||||
//|:param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
|
//| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
|
||||||
//|
|
//|
|
||||||
//|*New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds.
|
//| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds.
|
||||||
//|The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds."""
|
//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds."""
|
||||||
//|...
|
//| ...
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
} busio_uart_parity_obj_t;
|
} busio_uart_parity_obj_t;
|
||||||
@ -141,9 +141,9 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
|
|||||||
return (mp_obj_t)self;
|
return (mp_obj_t)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def deinit(self, ) -> Any:
|
//| def deinit(self, ) -> Any:
|
||||||
//|"""Deinitialises the UART and releases any hardware resources for reuse."""
|
//| """Deinitialises the UART and releases any hardware resources for reuse."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_uart_obj_deinit(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_uart_obj_deinit(mp_obj_t self_in) {
|
||||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
common_hal_busio_uart_deinit(self);
|
common_hal_busio_uart_deinit(self);
|
||||||
@ -157,15 +157,15 @@ STATIC void check_for_deinit(busio_uart_obj_t *self) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//|def __enter__(self, ) -> Any:
|
//| def __enter__(self, ) -> Any:
|
||||||
//|"""No-op used by Context Managers."""
|
//| """No-op used by Context Managers."""
|
||||||
//|...
|
//| ...
|
||||||
// Provided by context manager helper.
|
// Provided by context manager helper.
|
||||||
|
|
||||||
//|def __exit__(self, ) -> Any:
|
//| def __exit__(self, ) -> Any:
|
||||||
//|"""Automatically deinitializes the hardware when exiting a context. See
|
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||||
//|:ref:`lifetime-and-contextmanagers` for more info."""
|
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||||
//|...
|
//| ...
|
||||||
STATIC mp_obj_t busio_uart_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t busio_uart_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||||
(void)n_args;
|
(void)n_args;
|
||||||
common_hal_busio_uart_deinit(args[0]);
|
common_hal_busio_uart_deinit(args[0]);
|
||||||
@ -175,46 +175,40 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
|
|||||||
|
|
||||||
// These are standard stream methods. Code is in py/stream.c.
|
// These are standard stream methods. Code is in py/stream.c.
|
||||||
//
|
//
|
||||||
//|def read(self, nbytes: Any = None) -> Any:
|
//| def read(self, nbytes: Any = None) -> Any:
|
||||||
//|"""Read characters. If ``nbytes`` is specified then read at most that many
|
//| """Read characters. If ``nbytes`` is specified then read at most that many
|
||||||
//|bytes. Otherwise, read everything that arrives until the connection
|
//| bytes. Otherwise, read everything that arrives until the connection
|
||||||
//|times out. Providing the number of bytes expected is highly recommended
|
//| times out. Providing the number of bytes expected is highly recommended
|
||||||
//|because it will be faster.
|
//| because it will be faster.
|
||||||
//|
|
//|
|
||||||
//|:return: Data read
|
//| :return: Data read
|
||||||
//|:rtype: bytes or None"""
|
//| :rtype: bytes or None"""
|
||||||
//|...
|
//| ...
|
||||||
|
|
||||||
//|def readinto(self, buf: Any) -> Any:
|
//| def readinto(self, buf: Any) -> Any:
|
||||||
//|""".. method:: readinto(buf)
|
//| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
|
||||||
//|
|
//|
|
||||||
//|Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
|
//| :return: number of bytes read and stored into ``buf``
|
||||||
|
//| :rtype: int or None (on a non-blocking error)
|
||||||
//|
|
//|
|
||||||
//|:return: number of bytes read and stored into ``buf``
|
//| *New in CircuitPython 4.0:* No length parameter is permitted."""
|
||||||
//|:rtype: int or None (on a non-blocking error)
|
//| ...
|
||||||
//|
|
|
||||||
//|*New in CircuitPython 4.0:* No length parameter is permitted."""
|
|
||||||
//|...
|
|
||||||
|
|
||||||
//|def readline(self, ) -> Any:
|
//| def readline(self, ) -> Any:
|
||||||
//|""".. method:: readline()
|
//| """Read a line, ending in a newline character.
|
||||||
//|
|
//|
|
||||||
//|Read a line, ending in a newline character.
|
//| :return: the line read
|
||||||
//|
|
//| :rtype: int or None"""
|
||||||
//|:return: the line read
|
//| ...
|
||||||
//|:rtype: int or None"""
|
|
||||||
//|...
|
|
||||||
|
|
||||||
//|def write(self, buf: Any) -> Any:
|
//| def write(self, buf: Any) -> Any:
|
||||||
//|""".. method:: write(buf)
|
//| """Write the buffer of bytes to the bus.
|
||||||
//|
|
//|
|
||||||
//|Write the buffer of bytes to the bus.
|
//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
|
||||||
//|
|
//|
|
||||||
//|*New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
|
//| :return: the number of bytes written
|
||||||
//|
|
//| :rtype: int or None"""
|
||||||
//|:return: the number of bytes written
|
//| ...
|
||||||
//|:rtype: int or None"""
|
|
||||||
//|...
|
|
||||||
|
|
||||||
// These three methods are used by the shared stream methods.
|
// These three methods are used by the shared stream methods.
|
||||||
STATIC mp_uint_t busio_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
STATIC mp_uint_t busio_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||||
@ -258,9 +252,9 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//|baudrate: Any =
|
//| baudrate: Any = ...
|
||||||
//|"""The current baudrate."""
|
//| """The current baudrate."""
|
||||||
//|...
|
//|
|
||||||
STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) {
|
||||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -284,9 +278,9 @@ const mp_obj_property_t busio_uart_baudrate_obj = {
|
|||||||
(mp_obj_t)&mp_const_none_obj},
|
(mp_obj_t)&mp_const_none_obj},
|
||||||
};
|
};
|
||||||
|
|
||||||
//|in_waiting: Any =
|
//| in_waiting: Any = ...
|
||||||
//|"""The number of bytes in the input buffer, available to be read"""
|
//| """The number of bytes in the input buffer, available to be read"""
|
||||||
//|...
|
//|
|
||||||
STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) {
|
||||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -301,9 +295,9 @@ const mp_obj_property_t busio_uart_in_waiting_obj = {
|
|||||||
(mp_obj_t)&mp_const_none_obj},
|
(mp_obj_t)&mp_const_none_obj},
|
||||||
};
|
};
|
||||||
|
|
||||||
//|timeout: Any =
|
//| timeout: Any = ...
|
||||||
//|"""The current timeout, in seconds (float)."""
|
//| """The current timeout, in seconds (float)."""
|
||||||
//|...
|
//|
|
||||||
STATIC mp_obj_t busio_uart_obj_get_timeout(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_uart_obj_get_timeout(mp_obj_t self_in) {
|
||||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -329,9 +323,9 @@ const mp_obj_property_t busio_uart_timeout_obj = {
|
|||||||
(mp_obj_t)&mp_const_none_obj},
|
(mp_obj_t)&mp_const_none_obj},
|
||||||
};
|
};
|
||||||
|
|
||||||
//|def reset_input_buffer(self, ) -> Any:
|
//| def reset_input_buffer(self, ) -> Any: ...
|
||||||
//|"""Discard any unread characters in the input buffer."""
|
//| """Discard any unread characters in the input buffer."""
|
||||||
//|...
|
//|
|
||||||
STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
|
STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
|
||||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
check_for_deinit(self);
|
check_for_deinit(self);
|
||||||
@ -340,16 +334,16 @@ STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer);
|
||||||
|
|
||||||
//|class busio:
|
//| class busio:
|
||||||
//|def __init__(self, ):
|
//| """Enum-like class to define the parity used to verify correct data transfer."""
|
||||||
//|"""Enum-like class to define the parity used to verify correct data transfer."""
|
//|
|
||||||
//|ODD: Any =
|
//| def __init__(self, ):
|
||||||
//|"""Total number of ones should be odd."""
|
//| ODD: Any = ...
|
||||||
//|...
|
//| """Total number of ones should be odd."""
|
||||||
//|EVEN: Any =
|
//|
|
||||||
//|"""Total number of ones should be even."""
|
//| EVEN: Any = ...
|
||||||
//|...
|
//| """Total number of ones should be even."""
|
||||||
//|...
|
//| ...
|
||||||
const mp_obj_type_t busio_uart_parity_type;
|
const mp_obj_type_t busio_uart_parity_type;
|
||||||
|
|
||||||
const busio_uart_parity_obj_t busio_uart_parity_odd_obj = {
|
const busio_uart_parity_obj_t busio_uart_parity_odd_obj = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user