Added type hints to bitbangio

This commit is contained in:
dherrada 2020-07-02 12:37:03 -04:00
parent ed476a417c
commit ffc5f0c338
3 changed files with 24 additions and 24 deletions

View File

@ -79,7 +79,7 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
return (mp_obj_t)self;
}
//| def deinit(self, ) -> Any:
//| def deinit(self, ) -> None:
//| """Releases control of the underlying hardware so other classes can use it."""
//| ...
//|
@ -96,13 +96,13 @@ STATIC void check_for_deinit(bitbangio_i2c_obj_t *self) {
}
}
//| def __enter__(self, ) -> Any:
//| def __enter__(self, ) -> I2C:
//| """No-op used in Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self, ) -> Any:
//| def __exit__(self, ) -> None:
//| """Automatically deinitializes the hardware on context exit. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
@ -120,7 +120,7 @@ static void check_lock(bitbangio_i2c_obj_t *self) {
}
}
//| def scan(self, ) -> Any:
//| def scan(self, ) -> list:
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of
//| those that respond. A device responds if it pulls the SDA line low after
//| its address (including a read bit) is sent on the bus."""
@ -142,7 +142,7 @@ STATIC mp_obj_t bitbangio_i2c_scan(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan);
//| def try_lock(self, ) -> Any:
//| def try_lock(self, ) -> bool:
//| """Attempts to grab the I2C lock. Returns True on success."""
//| ...
//|
@ -153,7 +153,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock);
//| def unlock(self, ) -> Any:
//| def unlock(self, ) -> None:
//| """Releases the I2C lock."""
//| ...
//|
@ -165,7 +165,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_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) -> None:
//| """Read into ``buffer`` from the device selected by ``address``.
//| The number of bytes read will be the length of ``buffer``.
//| At least one byte must be read.
@ -217,7 +217,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_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) -> None:
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and then transmits a
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
//| before a read.
@ -277,7 +277,7 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_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) -> None:
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
//| 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.

View File

@ -78,7 +78,7 @@ STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(self);
}
//| def deinit(self, ) -> Any:
//| def deinit(self, ) -> None:
//| """Deinitialize the OneWire bus and release any hardware resources for reuse."""
//| ...
//|
@ -95,13 +95,13 @@ STATIC void check_for_deinit(bitbangio_onewire_obj_t *self) {
}
}
//| def __enter__(self, ) -> Any:
//| def __enter__(self, ) -> OneWire:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self, ) -> Any:
//| def __exit__(self, ) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
@ -113,7 +113,7 @@ STATIC mp_obj_t bitbangio_onewire_obj___exit__(size_t n_args, const mp_obj_t *ar
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_onewire___exit___obj, 4, 4, bitbangio_onewire_obj___exit__);
//| def reset(self, ) -> Any:
//| def reset(self, ) -> bool:
//| """Reset the OneWire bus"""
//| ...
//|
@ -125,7 +125,7 @@ STATIC mp_obj_t bitbangio_onewire_obj_reset(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_reset_obj, bitbangio_onewire_obj_reset);
//| def read_bit(self, ) -> Any:
//| def read_bit(self, ) -> bool:
//| """Read in a bit
//|
//| :returns: bit state read
@ -140,7 +140,7 @@ STATIC mp_obj_t bitbangio_onewire_obj_read_bit(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_read_bit_obj, bitbangio_onewire_obj_read_bit);
//| def write_bit(self, value: Any) -> Any:
//| def write_bit(self, value: bool) -> None:
//| """Write out a bit based on value."""
//| ...
//|

View File

@ -90,7 +90,7 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
return (mp_obj_t)self;
}
//| def deinit(self, ) -> Any:
//| def deinit(self, ) -> None:
//| """Turn off the SPI bus."""
//| ...
//|
@ -107,13 +107,13 @@ STATIC void check_for_deinit(bitbangio_spi_obj_t *self) {
}
}
//| def __enter__(self, ) -> Any:
//| def __enter__(self, ) -> SPI:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self, ) -> Any:
//| def __exit__(self, ) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
@ -132,7 +132,7 @@ static void check_lock(bitbangio_spi_obj_t *self) {
}
}
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> None:
//| """Configures the SPI bus. Only valid when locked.
//|
//| :param int baudrate: the clock rate in Hertz
@ -174,7 +174,7 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args,
}
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_configure_obj, 1, bitbangio_spi_configure);
//| def try_lock(self, ) -> Any:
//| def try_lock(self, ) -> bool:
//| """Attempts to grab the SPI lock. Returns True on success.
//|
//| :return: True when lock has been grabbed
@ -188,7 +188,7 @@ STATIC mp_obj_t bitbangio_spi_obj_try_lock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock);
//| def unlock(self, ) -> Any:
//| def unlock(self, ) -> None:
//| """Releases the SPI lock."""
//| ...
//|
@ -200,7 +200,7 @@ STATIC mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock);
//| def write(self, buf: Any) -> Any:
//| def write(self, buf: bytes) -> None:
//| """Write the data contained in ``buf``. Requires the SPI being locked.
//| If the buffer is empty, nothing happens."""
//| ...
@ -224,7 +224,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write);
//| def readinto(self, buf: Any) -> Any:
//| def readinto(self, buf: bytearray) -> None:
//| """Read into the buffer specified by ``buf`` while writing zeroes.
//| Requires the SPI being locked.
//| If the number of bytes to read is 0, nothing happens."""
@ -248,7 +248,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_spi_readinto);
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
//| must be equal.