summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordherrada <dylan.herrada@gmail.com>2020-05-11 10:48:11 -0400
committerdherrada <dylan.herrada@gmail.com>2020-05-11 10:48:11 -0400
commit838b6c56858fa3888c558e5640031b8764c313d7 (patch)
tree346c6236f43ca4c641bef59edc6b9a8d403da1ed
parent09530e5dc34d6fbcbf5fa85a1f7df9d47d8c8329 (diff)
Did ps2io, pulseio, random
-rw-r--r--shared-bindings/ps2io/Ps2.c135
-rw-r--r--shared-bindings/ps2io/__init__.c4
-rw-r--r--shared-bindings/pulseio/PWMOut.c114
-rw-r--r--shared-bindings/pulseio/PulseIn.c161
-rw-r--r--shared-bindings/pulseio/PulseOut.c83
-rw-r--r--shared-bindings/pulseio/__init__.c4
-rw-r--r--shared-bindings/random/__init__.c55
7 files changed, 278 insertions, 278 deletions
diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c
index 89ed0a76c..d327d4180 100644
--- a/shared-bindings/ps2io/Ps2.c
+++ b/shared-bindings/ps2io/Ps2.c
@@ -36,38 +36,39 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
-//| .. currentmodule:: ps2io
+//| class Ps2:
+//| """.. currentmodule:: ps2io
//|
-//| :class:`Ps2` -- Communicate with a PS/2 keyboard or mouse
-//| =========================================================
+//| :class:`Ps2` -- Communicate with a PS/2 keyboard or mouse
+//| =========================================================
//|
-//| Ps2 implements the PS/2 keyboard/mouse serial protocol, used in
-//| legacy devices. It is similar to UART but there are only two
-//| lines (Data and Clock). PS/2 devices are 5V, so bidirectional
-//| level converters must be used to connect the I/O lines to pins
-//| of 3.3V boards.
+//| Ps2 implements the PS/2 keyboard/mouse serial protocol, used in
+//| legacy devices. It is similar to UART but there are only two
+//| lines (Data and Clock). PS/2 devices are 5V, so bidirectional
+//| level converters must be used to connect the I/O lines to pins
+//| of 3.3V boards."""
//|
-//| .. class:: Ps2(data_pin, clock_pin)
+//| def __init__(self, data_pin: microcontroller.Pin, clock_pin: microcontroller.Pin):
+//| """Create a Ps2 object associated with the given pins.
//|
-//| Create a Ps2 object associated with the given pins.
+//| :param ~microcontroller.Pin data_pin: Pin tied to data wire.
+//| :param ~microcontroller.Pin clock_pin: Pin tied to clock wire.
+//| This pin must support interrupts.
//|
-//| :param ~microcontroller.Pin data_pin: Pin tied to data wire.
-//| :param ~microcontroller.Pin clock_pin: Pin tied to clock wire.
-//| This pin must support interrupts.
+//| Read one byte from PS/2 keyboard and turn on Scroll Lock LED::
//|
-//| Read one byte from PS/2 keyboard and turn on Scroll Lock LED::
+//| import ps2io
+//| import board
//|
-//| import ps2io
-//| import board
+//| kbd = ps2io.Ps2(board.D10, board.D11)
//|
-//| kbd = ps2io.Ps2(board.D10, board.D11)
+//| while len(kbd) == 0:
+//| pass
//|
-//| while len(kbd) == 0:
-//| pass
-//|
-//| print(kbd.popleft())
-//| print(kbd.sendcmd(0xed))
-//| print(kbd.sendcmd(0x01))
+//| print(kbd.popleft())
+//| print(kbd.sendcmd(0xed))
+//| print(kbd.sendcmd(0x01))"""
+//| ...
//|
STATIC mp_obj_t ps2io_ps2_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_datapin, ARG_clkpin };
@@ -89,9 +90,9 @@ STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, con
return MP_OBJ_FROM_PTR(self);
}
-//| .. method:: deinit()
-//|
-//| Deinitialises the Ps2 and releases any hardware resources for reuse.
+//| def deinit(self, ) -> Any:
+//| """Deinitialises the Ps2 and releases any hardware resources for reuse."""
+//| ...
//|
STATIC mp_obj_t ps2io_ps2_deinit(mp_obj_t self_in) {
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -106,16 +107,16 @@ STATIC void check_for_deinit(ps2io_ps2_obj_t *self) {
}
}
-//| .. method:: __enter__()
-//|
-//| No-op used by Context Managers.
+//| def __enter__(self, ) -> Any:
+//| """No-op used by Context Managers."""
+//| ...
//|
// Provided by context manager helper.
-//| .. method:: __exit__()
-//|
-//| Automatically deinitializes the hardware when exiting a context. See
-//| :ref:`lifetime-and-contextmanagers` for more info.
+//| def __exit__(self, ) -> Any:
+//| """Automatically deinitializes the hardware when exiting a context. See
+//| :ref:`lifetime-and-contextmanagers` for more info."""
+//| ...
//|
STATIC mp_obj_t ps2io_ps2_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
@@ -124,10 +125,10 @@ STATIC mp_obj_t ps2io_ps2_obj___exit__(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ps2io_ps2___exit___obj, 4, 4, ps2io_ps2_obj___exit__);
-//| .. method:: popleft()
-//|
-//| Removes and returns the oldest received byte. When buffer
-//| is empty, raises an IndexError exception.
+//| def popleft(self, ) -> Any:
+//| """Removes and returns the oldest received byte. When buffer
+//| is empty, raises an IndexError exception."""
+//| ...
//|
STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) {
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -141,18 +142,18 @@ STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_popleft_obj, ps2io_ps2_obj_popleft);
-//| .. method:: sendcmd(byte)
-//|
-//| Sends a command byte to PS/2. Returns the response byte, typically
-//| the general ack value (0xFA). Some commands return additional data
-//| which is available through :py:func:`popleft()`.
+//| def sendcmd(self, byte: int) -> Any:
+//| """Sends a command byte to PS/2. Returns the response byte, typically
+//| the general ack value (0xFA). Some commands return additional data
+//| which is available through :py:func:`popleft()`.
//|
-//| Raises a RuntimeError in case of failure. The root cause can be found
-//| by calling :py:func:`clear_errors()`. It is advisable to call
-//| :py:func:`clear_errors()` before :py:func:`sendcmd()` to flush any
-//| previous errors.
+//| Raises a RuntimeError in case of failure. The root cause can be found
+//| by calling :py:func:`clear_errors()`. It is advisable to call
+//| :py:func:`clear_errors()` before :py:func:`sendcmd()` to flush any
+//| previous errors.
//|
-//| :param int byte: byte value of the command
+//| :param int byte: byte value of the command"""
+//| ...
//|
STATIC mp_obj_t ps2io_ps2_obj_sendcmd(mp_obj_t self_in, mp_obj_t ob) {
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -166,35 +167,35 @@ STATIC mp_obj_t ps2io_ps2_obj_sendcmd(mp_obj_t self_in, mp_obj_t ob) {
}
MP_DEFINE_CONST_FUN_OBJ_2(ps2io_ps2_sendcmd_obj, ps2io_ps2_obj_sendcmd);
-//| .. method:: clear_errors()
+//| def clear_errors(self, ) -> Any:
+//| """Returns and clears a bitmap with latest recorded communication errors.
//|
-//| Returns and clears a bitmap with latest recorded communication errors.
+//| Reception errors (arise asynchronously, as data is received):
//|
-//| Reception errors (arise asynchronously, as data is received):
+//| 0x01: start bit not 0
//|
-//| 0x01: start bit not 0
+//| 0x02: timeout
//|
-//| 0x02: timeout
+//| 0x04: parity bit error
//|
-//| 0x04: parity bit error
+//| 0x08: stop bit not 1
//|
-//| 0x08: stop bit not 1
+//| 0x10: buffer overflow, newest data discarded
//|
-//| 0x10: buffer overflow, newest data discarded
+//| Transmission errors (can only arise in the course of sendcmd()):
//|
-//| Transmission errors (can only arise in the course of sendcmd()):
+//| 0x100: clock pin didn't go to LO in time
//|
-//| 0x100: clock pin didn't go to LO in time
+//| 0x200: clock pin didn't go to HI in time
//|
-//| 0x200: clock pin didn't go to HI in time
+//| 0x400: data pin didn't ACK
//|
-//| 0x400: data pin didn't ACK
+//| 0x800: clock pin didn't ACK
//|
-//| 0x800: clock pin didn't ACK
+//| 0x1000: device didn't respond to RTS
//|
-//| 0x1000: device didn't respond to RTS
-//|
-//| 0x2000: device didn't send a response byte in time
+//| 0x2000: device didn't send a response byte in time"""
+//| ...
//|
STATIC mp_obj_t ps2io_ps2_obj_clear_errors(mp_obj_t self_in) {
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -204,10 +205,10 @@ STATIC mp_obj_t ps2io_ps2_obj_clear_errors(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_clear_errors_obj, ps2io_ps2_obj_clear_errors);
-//| .. method:: __len__()
-//|
-//| Returns the number of received bytes in buffer, available
-//| to :py:func:`popleft()`.
+//| def __len__(self, ) -> Any:
+//| """Returns the number of received bytes in buffer, available
+//| to :py:func:`popleft()`."""
+//| ...
//|
STATIC mp_obj_t ps2_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
diff --git a/shared-bindings/ps2io/__init__.c b/shared-bindings/ps2io/__init__.c
index ec7c43e51..081127bac 100644
--- a/shared-bindings/ps2io/__init__.c
+++ b/shared-bindings/ps2io/__init__.c
@@ -33,7 +33,7 @@
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/ps2io/Ps2.h"
-//| :mod:`ps2io` --- Support for PS/2 protocol
+//| """:mod:`ps2io` --- Support for PS/2 protocol
//| =====================================================
//|
//| .. module:: ps2io
@@ -57,7 +57,7 @@
//| All classes change hardware state and should be deinitialized when they
//| are no longer needed if the program continues after use. To do so, either
//| call :py:meth:`!deinit` or use a context manager. See
-//| :ref:`lifetime-and-contextmanagers` for more info.
+//| :ref:`lifetime-and-contextmanagers` for more info."""
//|
STATIC const mp_rom_map_elem_t ps2io_module_globals_table[] = {
diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c
index 2491a5c3f..3a25d6938 100644
--- a/shared-bindings/pulseio/PWMOut.c
+++ b/shared-bindings/pulseio/PWMOut.c
@@ -35,55 +35,56 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
-//| .. currentmodule:: pulseio
+//| class PWMOut:
+//| """.. currentmodule:: pulseio
//|
-//| :class:`PWMOut` -- Output a Pulse Width Modulated signal
-//| ========================================================
+//| :class:`PWMOut` -- Output a Pulse Width Modulated signal
+//| ========================================================
//|
-//| PWMOut can be used to output a PWM signal on a given pin.
+//| PWMOut can be used to output a PWM signal on a given pin."""
//|
-//| .. class:: PWMOut(pin, *, duty_cycle=0, frequency=500, variable_frequency=False)
+//| def __init__(self, pin: microcontroller.Pin, *, duty_cycle: int = 0, frequency: int = 500, variable_frequency: bool = False):
+//| """Create a PWM object associated with the given pin. This allows you to
+//| write PWM signals out on the given pin. Frequency is fixed after init
+//| unless ``variable_frequency`` is True.
//|
-//| Create a PWM object associated with the given pin. This allows you to
-//| write PWM signals out on the given pin. Frequency is fixed after init
-//| unless ``variable_frequency`` is True.
+//| .. note:: When ``variable_frequency`` is True, further PWM outputs may be
+//| limited because it may take more internal resources to be flexible. So,
+//| when outputting both fixed and flexible frequency signals construct the
+//| fixed outputs first.
//|
-//| .. note:: When ``variable_frequency`` is True, further PWM outputs may be
-//| limited because it may take more internal resources to be flexible. So,
-//| when outputting both fixed and flexible frequency signals construct the
-//| fixed outputs first.
+//| :param ~microcontroller.Pin pin: The pin to output to
+//| :param int duty_cycle: The fraction of each pulse which is high. 16-bit
+//| :param int frequency: The target frequency in Hertz (32-bit)
+//| :param bool variable_frequency: True if the frequency will change over time
//|
-//| :param ~microcontroller.Pin pin: The pin to output to
-//| :param int duty_cycle: The fraction of each pulse which is high. 16-bit
-//| :param int frequency: The target frequency in Hertz (32-bit)
-//| :param bool variable_frequency: True if the frequency will change over time
+//| Simple LED fade::
//|
-//| Simple LED fade::
+//| import pulseio
+//| import board
//|
-//| import pulseio
-//| import board
+//| pwm = pulseio.PWMOut(board.D13) # output on D13
+//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz
//|
-//| pwm = pulseio.PWMOut(board.D13) # output on D13
-//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz
+//| PWM at specific frequency (servos and motors)::
//|
-//| PWM at specific frequency (servos and motors)::
+//| import pulseio
+//| import board
//|
-//| import pulseio
-//| import board
+//| pwm = pulseio.PWMOut(board.D13, frequency=50)
+//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz
//|
-//| pwm = pulseio.PWMOut(board.D13, frequency=50)
-//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz
+//| Variable frequency (usually tones)::
//|
-//| Variable frequency (usually tones)::
+//| import pulseio
+//| import board
+//| import time
//|
-//| import pulseio
-//| import board
-//| import time
-//|
-//| pwm = pulseio.PWMOut(board.D13, duty_cycle=2 ** 15, frequency=440, variable_frequency=True)
-//| time.sleep(0.2)
-//| pwm.frequency = 880
-//| time.sleep(0.1)
+//| pwm = pulseio.PWMOut(board.D13, duty_cycle=2 ** 15, frequency=440, variable_frequency=True)
+//| time.sleep(0.2)
+//| pwm.frequency = 880
+//| time.sleep(0.1)"""
+//| ...
//|
STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
enum { ARG_pin, ARG_duty_cycle, ARG_frequency, ARG_variable_frequency };
@@ -119,9 +120,9 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args
return MP_OBJ_FROM_PTR(self);
}
-//| .. method:: deinit()
-//|
-//| Deinitialises the PWMOut and releases any hardware resources for reuse.
+//| def deinit(self, ) -> Any:
+//| """Deinitialises the PWMOut and releases any hardware resources for reuse."""
+//| ...
//|
STATIC mp_obj_t pulseio_pwmout_deinit(mp_obj_t self_in) {
pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -136,16 +137,16 @@ STATIC void check_for_deinit(pulseio_pwmout_obj_t *self) {
}
}
-//| .. method:: __enter__()
-//|
-//| No-op used by Context Managers.
+//| def __enter__(self, ) -> Any:
+//| """No-op used by Context Managers."""
+//| ...
//|
// Provided by context manager helper.
-//| .. method:: __exit__()
-//|
-//| Automatically deinitializes the hardware when exiting a context. See
-//| :ref:`lifetime-and-contextmanagers` for more info.
+//| def __exit__(self, ) -> Any:
+//| """Automatically deinitializes the hardware when exiting a context. See
+//| :ref:`lifetime-and-contextmanagers` for more info."""
+//| ...
//|
STATIC mp_obj_t pulseio_pwmout_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
@@ -154,16 +155,16 @@ STATIC mp_obj_t pulseio_pwmout_obj___exit__(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pwmout___exit___obj, 4, 4, pulseio_pwmout_obj___exit__);
-//| .. attribute:: duty_cycle
+//| duty_cycle: Any = ...
+//| """16 bit value that dictates how much of one cycle is high (1) versus low
+//| (0). 0xffff will always be high, 0 will always be low and 0x7fff will
+//| be half high and then half low.
//|
-//| 16 bit value that dictates how much of one cycle is high (1) versus low
-//| (0). 0xffff will always be high, 0 will always be low and 0x7fff will
-//| be half high and then half low.
+//| Depending on how PWM is implemented on a specific board, the internal
+//| representation for duty cycle might have less than 16 bits of resolution.
+//| Reading this property will return the value from the internal representation,
+//| so it may differ from the value set."""
//|
-//| Depending on how PWM is implemented on a specific board, the internal
-//| representation for duty cycle might have less than 16 bits of resolution.
-//| Reading this property will return the value from the internal representation,
-//| so it may differ from the value set.
STATIC mp_obj_t pulseio_pwmout_obj_get_duty_cycle(mp_obj_t self_in) {
pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@@ -190,16 +191,15 @@ const mp_obj_property_t pulseio_pwmout_duty_cycle_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//| .. attribute:: frequency
-//|
-//| 32 bit value that dictates the PWM frequency in Hertz (cycles per
+//| frequency: Any = ...
+//| """32 bit value that dictates the PWM frequency in Hertz (cycles per
//| second). Only writeable when constructed with ``variable_frequency=True``.
//|
//| Depending on how PWM is implemented on a specific board, the internal value
//| for the PWM's duty cycle may need to be recalculated when the frequency
//| changes. In these cases, the duty cycle is automatically recalculated
//| from the original duty cycle value. This should happen without any need
-//| to manually re-set the duty cycle.
+//| to manually re-set the duty cycle."""
//|
STATIC mp_obj_t pulseio_pwmout_obj_get_frequency(mp_obj_t self_in) {
pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in);
diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c
index 6c01a4c17..9024f53e3 100644
--- a/shared-bindings/pulseio/PulseIn.c
+++ b/shared-bindings/pulseio/PulseIn.c
@@ -35,51 +35,52 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
-//| .. currentmodule:: pulseio
+//| class PulseIn:
+//| """.. currentmodule:: pulseio
//|
-//| :class:`PulseIn` -- Read a series of pulse durations
-//| ========================================================
+//| :class:`PulseIn` -- Read a series of pulse durations
+//| ========================================================
//|
-//| PulseIn is used to measure a series of active and idle pulses. This is
-//| commonly used in infrared receivers and low cost temperature sensors (DHT).
-//| The pulsed signal consists of timed active and idle periods. Unlike PWM,
-//| there is no set duration for active and idle pairs.
+//| PulseIn is used to measure a series of active and idle pulses. This is
+//| commonly used in infrared receivers and low cost temperature sensors (DHT).
+//| The pulsed signal consists of timed active and idle periods. Unlike PWM,
+//| there is no set duration for active and idle pairs."""
//|
-//| .. class:: PulseIn(pin, maxlen=2, *, idle_state=False)
+//| def __init__(self, pin: microcontroller.Pin, maxlen: int = 2, *, idle_state: bool = False):
+//| """Create a PulseIn object associated with the given pin. The object acts as
+//| a read-only sequence of pulse lengths with a given max length. When it is
+//| active, new pulse lengths are added to the end of the list. When there is
+//| no more room (len() == `maxlen`) the oldest pulse length is removed to
+//| make room.
//|
-//| Create a PulseIn object associated with the given pin. The object acts as
-//| a read-only sequence of pulse lengths with a given max length. When it is
-//| active, new pulse lengths are added to the end of the list. When there is
-//| no more room (len() == `maxlen`) the oldest pulse length is removed to
-//| make room.
+//| :param ~microcontroller.Pin pin: Pin to read pulses from.
+//| :param int maxlen: Maximum number of pulse durations to store at once
+//| :param bool idle_state: Idle state of the pin. At start and after `resume`
+//| the first recorded pulse will the opposite state from idle.
//|
-//| :param ~microcontroller.Pin pin: Pin to read pulses from.
-//| :param int maxlen: Maximum number of pulse durations to store at once
-//| :param bool idle_state: Idle state of the pin. At start and after `resume`
-//| the first recorded pulse will the opposite state from idle.
+//| Read a short series of pulses::
//|
-//| Read a short series of pulses::
+//| import pulseio
+//| import board
//|
-//| import pulseio
-//| import board
+//| pulses = pulseio.PulseIn(board.D7)
//|
-//| pulses = pulseio.PulseIn(board.D7)
+//| # Wait for an active pulse
+//| while len(pulses) == 0:
+//| pass
+//| # Pause while we do something with the pulses
+//| pulses.pause()
//|
-//| # Wait for an active pulse
-//| while len(pulses) == 0:
-//| pass
-//| # Pause while we do something with the pulses
-//| pulses.pause()
+//| # Print the pulses. pulses[0] is an active pulse unless the length
+//| # reached max length and idle pulses are recorded.
+//| print(pulses)
//|
-//| # Print the pulses. pulses[0] is an active pulse unless the length
-//| # reached max length and idle pulses are recorded.
-//| print(pulses)
+//| # Clear the rest
+//| pulses.clear()
//|
-//| # Clear the rest
-//| pulses.clear()
-//|
-//| # Resume with an 80 microsecond active pulse
-//| pulses.resume(80)
+//| # Resume with an 80 microsecond active pulse
+//| pulses.resume(80)"""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_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, ARG_maxlen, ARG_idle_state };
@@ -101,9 +102,9 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg
return MP_OBJ_FROM_PTR(self);
}
-//| .. method:: deinit()
-//|
-//| Deinitialises the PulseIn and releases any hardware resources for reuse.
+//| def deinit(self, ) -> Any:
+//| """Deinitialises the PulseIn and releases any hardware resources for reuse."""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_deinit(mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -118,16 +119,16 @@ STATIC void check_for_deinit(pulseio_pulsein_obj_t *self) {
}
}
-//| .. method:: __enter__()
-//|
-//| No-op used by Context Managers.
+//| def __enter__(self, ) -> Any:
+//| """No-op used by Context Managers."""
+//| ...
//|
// Provided by context manager helper.
-//| .. method:: __exit__()
-//|
-//| Automatically deinitializes the hardware when exiting a context. See
-//| :ref:`lifetime-and-contextmanagers` for more info.
+//| def __exit__(self, ) -> Any:
+//| """Automatically deinitializes the hardware when exiting a context. See
+//| :ref:`lifetime-and-contextmanagers` for more info."""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
@@ -136,9 +137,9 @@ STATIC mp_obj_t pulseio_pulsein_obj___exit__(size_t n_args, const mp_obj_t *args
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pulsein___exit___obj, 4, 4, pulseio_pulsein_obj___exit__);
-//| .. method:: pause()
-//|
-//| Pause pulse capture
+//| def pause(self, ) -> Any:
+//| """Pause pulse capture"""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_obj_pause(mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -149,16 +150,16 @@ STATIC mp_obj_t pulseio_pulsein_obj_pause(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_pause_obj, pulseio_pulsein_obj_pause);
-//| .. method:: resume(trigger_duration=0)
-//|
-//| Resumes pulse capture after an optional trigger pulse.
+//| def resume(self, trigger_duration: int = 0) -> Any:
+//| """Resumes pulse capture after an optional trigger pulse.
//|
-//| .. warning:: Using trigger pulse with a device that drives both high and
-//| low signals risks a short. Make sure your device is open drain (only
-//| drives low) when using a trigger pulse. You most likely added a
-//| "pull-up" resistor to your circuit to do this.
+//| .. warning:: Using trigger pulse with a device that drives both high and
+//| low signals risks a short. Make sure your device is open drain (only
+//| drives low) when using a trigger pulse. You most likely added a
+//| "pull-up" resistor to your circuit to do this.
//|
-//| :param int trigger_duration: trigger pulse duration in microseconds
+//| :param int trigger_duration: trigger pulse duration in microseconds"""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_obj_resume(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_trigger_duration };
@@ -176,9 +177,9 @@ STATIC mp_obj_t pulseio_pulsein_obj_resume(size_t n_args, const mp_obj_t *pos_ar
}
MP_DEFINE_CONST_FUN_OBJ_KW(pulseio_pulsein_resume_obj, 1, pulseio_pulsein_obj_resume);
-//| .. method:: clear()
-//|
-//| Clears all captured pulses
+//| def clear(self, ) -> Any:
+//| """Clears all captured pulses"""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_obj_clear(mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -189,9 +190,9 @@ STATIC mp_obj_t pulseio_pulsein_obj_clear(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_clear_obj, pulseio_pulsein_obj_clear);
-//| .. method:: popleft()
-//|
-//| Removes and returns the oldest read pulse.
+//| def popleft(self, ) -> Any:
+//| """Removes and returns the oldest read pulse."""
+//| ...
//|
STATIC mp_obj_t pulseio_pulsein_obj_popleft(mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -201,10 +202,9 @@ STATIC mp_obj_t pulseio_pulsein_obj_popleft(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_popleft_obj, pulseio_pulsein_obj_popleft);
-//| .. attribute:: maxlen
-//|
-//| The maximum length of the PulseIn. When len() is equal to maxlen,
-//| it is unclear which pulses are active and which are idle.
+//| maxlen: Any = ...
+//| """The maximum length of the PulseIn. When len() is equal to maxlen,
+//| it is unclear which pulses are active and which are idle."""
//|
STATIC mp_obj_t pulseio_pulsein_obj_get_maxlen(mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -221,10 +221,9 @@ const mp_obj_property_t pulseio_pulsein_maxlen_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//| .. attribute:: paused
-//|
-//| True when pulse capture is paused as a result of :py:func:`pause` or an error during capture
-//| such as a signal that is too fast.
+//| paused: Any = ...
+//| """True when pulse capture is paused as a result of :py:func:`pause` or an error during capture
+//| such as a signal that is too fast."""
//|
STATIC mp_obj_t pulseio_pulsein_obj_get_paused(mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -241,14 +240,14 @@ const mp_obj_property_t pulseio_pulsein_paused_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//| .. method:: __len__()
-//|
-//| Returns the current pulse length
+//| def __len__(self, ) -> Any:
+//| """Returns the current pulse length
//|
-//| This allows you to::
+//| This allows you to::
//|
-//| pulses = pulseio.PulseIn(pin)
-//| print(len(pulses))
+//| pulses = pulseio.PulseIn(pin)
+//| print(len(pulses))"""
+//| ...
//|
STATIC mp_obj_t pulsein_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -261,14 +260,14 @@ STATIC mp_obj_t pulsein_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
}
}
-//| .. method:: __getitem__(index)
-//|
-//| Returns the value at the given index or values in slice.
+//| def __getitem__(self, index: Any) -> Any:
+//| """Returns the value at the given index or values in slice.
//|
-//| This allows you to::
+//| This allows you to::
//|
-//| pulses = pulseio.PulseIn(pin)
-//| print(pulses[0])
+//| pulses = pulseio.PulseIn(pin)
+//| print(pulses[0])"""
+//| ...
//|
STATIC mp_obj_t pulsein_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value) {
if (value == mp_const_none) {
diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c
index 172459e5d..9c650731b 100644
--- a/shared-bindings/pulseio/PulseOut.c
+++ b/shared-bindings/pulseio/PulseOut.c
@@ -36,37 +36,38 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
-//| .. currentmodule:: pulseio
+//| class PulseOut:
+//| """.. currentmodule:: pulseio
//|
-//| :class:`PulseOut` -- Output a pulse train
-//| ========================================================
+//| :class:`PulseOut` -- Output a pulse train
+//| ========================================================
//|
-//| PulseOut is used to pulse PWM "carrier" output on and off. This is commonly
-//| used in infrared remotes. The pulsed signal consists of timed on and off
-//| periods. Unlike PWM, there is no set duration for on and off pairs.
+//| PulseOut is used to pulse PWM "carrier" output on and off. This is commonly
+//| used in infrared remotes. The pulsed signal consists of timed on and off
+//| periods. Unlike PWM, there is no set duration for on and off pairs."""
//|
-//| .. class:: PulseOut(carrier)
+//| def __init__(self, carrier: pulseio.PWMOut):
+//| """Create a PulseOut object associated with the given PWMout object.
//|
-//| Create a PulseOut object associated with the given PWMout object.
+//| :param ~pulseio.PWMOut carrier: PWMOut that is set to output on the desired pin.
//|
-//| :param ~pulseio.PWMOut carrier: PWMOut that is set to output on the desired pin.
+//| Send a short series of pulses::
//|
-//| Send a short series of pulses::
+//| import array
+//| import pulseio
+//| import board
//|
-//| import array
-//| import pulseio
-//| import board
+//| # 50% duty cycle at 38kHz.
+//| pwm = pulseio.PWMOut(board.D13, frequency=38000, duty_cycle=32768)
+//| pulse = pulseio.PulseOut(pwm)
+//| # on off on off on
+//| pulses = array.array('H', [65000, 1000, 65000, 65000, 1000])
+//| pulse.send(pulses)
//|
-//| # 50% duty cycle at 38kHz.
-//| pwm = pulseio.PWMOut(board.D13, frequency=38000, duty_cycle=32768)
-//| pulse = pulseio.PulseOut(pwm)
-//| # on off on off on
-//| pulses = array.array('H', [65000, 1000, 65000, 65000, 1000])
-//| pulse.send(pulses)
-//|
-//| # Modify the array of pulses.
-//| pulses[0] = 200
-//| pulse.send(pulses)
+//| # Modify the array of pulses.
+//| pulses[0] = 200
+//| pulse.send(pulses)"""
+//| ...
//|
STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
mp_arg_check_num(n_args, kw_args, 1, 1, false);
@@ -85,9 +86,9 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar
return MP_OBJ_FROM_PTR(self);
}
-//| .. method:: deinit()
-//|
-//| Deinitialises the PulseOut and releases any hardware resources for reuse.
+//| def deinit(self, ) -> Any:
+//| """Deinitialises the PulseOut and releases any hardware resources for reuse."""
+//| ...
//|
STATIC mp_obj_t pulseio_pulseout_deinit(mp_obj_t self_in) {
pulseio_pulseout_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -96,16 +97,16 @@ STATIC mp_obj_t pulseio_pulseout_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulseout_deinit_obj, pulseio_pulseout_deinit);
-//| .. method:: __enter__()
-//|
-//| No-op used by Context Managers.
+//| def __enter__(self, ) -> Any:
+//| """No-op used by Context Managers."""
+//| ...
//|
// Provided by context manager helper.
-//| .. method:: __exit__()
-//|
-//| Automatically deinitializes the hardware when exiting a context. See
-//| :ref:`lifetime-and-contextmanagers` for more info.
+//| def __exit__(self, ) -> Any:
+//| """Automatically deinitializes the hardware when exiting a context. See
+//| :ref:`lifetime-and-contextmanagers` for more info."""
+//| ...
//|
STATIC mp_obj_t pulseio_pulseout_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
@@ -114,16 +115,16 @@ STATIC mp_obj_t pulseio_pulseout_obj___exit__(size_t n_args, const mp_obj_t *arg
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pulseout___exit___obj, 4, 4, pulseio_pulseout_obj___exit__);
-//| .. method:: send(pulses)
-//|
-//| Pulse alternating on and off durations in microseconds starting with on.
-//| ``pulses`` must be an `array.array` with data type 'H' for unsigned
-//| halfword (two bytes).
+//| def send(self, pulses: array.array) -> Any:
+//| """Pulse alternating on and off durations in microseconds starting with on.
+//| ``pulses`` must be an `array.array` with data type 'H' for unsigned
+//| halfword (two bytes).
//|
-//| This method waits until the whole array of pulses has been sent and
-//| ensures the signal is off afterwards.
+//| This method waits until the whole array of pulses has been sent and
+//| ensures the signal is off afterwards.
//|
-//| :param array.array pulses: pulse durations in microseconds
+//| :param array.array pulses: pulse durations in microseconds"""
+//| ...
//|
STATIC mp_obj_t pulseio_pulseout_obj_send(mp_obj_t self_in, mp_obj_t pulses) {
pulseio_pulseout_obj_t *self = MP_OBJ_TO_PTR(self_in);
diff --git a/shared-bindings/pulseio/__init__.c b/shared-bindings/pulseio/__init__.c
index a3cec3dca..70cb61fc3 100644
--- a/shared-bindings/pulseio/__init__.c
+++ b/shared-bindings/pulseio/__init__.c
@@ -35,7 +35,7 @@
#include "shared-bindings/pulseio/PulseOut.h"
#include "shared-bindings/pulseio/PWMOut.h"
-//| :mod:`pulseio` --- Support for pulse based protocols
+//| """:mod:`pulseio` --- Support for pulse based protocols
//| =====================================================
//|
//| .. module:: pulseio
@@ -73,7 +73,7 @@
//| :py:data:`~pulseio.PWMOut.duty_cycle`, and then sleep 0.1 seconds.
//| CircuitPython will automatically turn off the PWM when it resets all
//| hardware after program completion. Use ``deinit()`` or a ``with`` statement
-//| to do it yourself.
+//| to do it yourself."""
//|
STATIC const mp_rom_map_elem_t pulseio_module_globals_table[] = {
diff --git a/shared-bindings/random/__init__.c b/shared-bindings/random/__init__.c
index de4c90910..d8b266be0 100644
--- a/shared-bindings/random/__init__.c
+++ b/shared-bindings/random/__init__.c
@@ -33,7 +33,7 @@
#include "shared-bindings/random/__init__.h"
#include "supervisor/shared/translate.h"
-//| :mod:`random` --- pseudo-random numbers and choices
+//| """:mod:`random` --- pseudo-random numbers and choices
//| ========================================================
//|
//| .. module:: random
@@ -49,13 +49,13 @@
//| Once seeded, it will be deterministic, which is why its bad for cryptography.
//|
//| .. warning:: Numbers from this module are not cryptographically strong! Use
-//| bytes from `os.urandom` directly for true randomness.
+//| bytes from `os.urandom` directly for true randomness."""
//|
-//| .. function:: seed(seed)
-//|
-//| Sets the starting seed of the random number generation. Further calls to
-//| `random` will return deterministic results afterwards.
+//| def seed(seed: Any) -> Any:
+//| """Sets the starting seed of the random number generation. Further calls to
+//| `random` will return deterministic results afterwards."""
+//| ...
//|
STATIC mp_obj_t random_seed(mp_obj_t seed_in) {
mp_uint_t seed = mp_obj_get_int_truncated(seed_in);
@@ -64,9 +64,9 @@ STATIC mp_obj_t random_seed(mp_obj_t seed_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_seed_obj, random_seed);
-//| .. function:: getrandbits(k)
-//|
-//| Returns an integer with *k* random bits.
+//| def getrandbits(k: Any) -> Any:
+//| """Returns an integer with *k* random bits."""
+//| ...
//|
STATIC mp_obj_t random_getrandbits(mp_obj_t num_in) {
int n = mp_obj_get_int(num_in);
@@ -77,10 +77,9 @@ STATIC mp_obj_t random_getrandbits(mp_obj_t num_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_getrandbits_obj, random_getrandbits);
-//| .. function:: randrange(stop)
-//| randrange(start, stop, step=1)
-//|
-//| Returns a randomly selected integer from ``range(start, stop, step)``.
+//| def randrange(stop: Any) -> Any:
+//| """Returns a randomly selected integer from ``range(start, stop, step)``."""
+//| ...
//|
STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) {
mp_int_t start = 0;
@@ -120,10 +119,10 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(random_randrange_obj, 1, 3, random_randrange);
-//| .. function:: randint(a, b)
-//|
-//| Returns a randomly selected integer between a and b inclusive. Equivalent
-//| to ``randrange(a, b + 1, 1)``
+//| def randint(a: Any, b: Any) -> Any:
+//| """Returns a randomly selected integer between a and b inclusive. Equivalent
+//| to ``randrange(a, b + 1, 1)``"""
+//| ...
//|
STATIC mp_obj_t random_randint(mp_obj_t a_in, mp_obj_t b_in) {
mp_int_t a = mp_obj_get_int(a_in);
@@ -135,10 +134,10 @@ STATIC mp_obj_t random_randint(mp_obj_t a_in, mp_obj_t b_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(random_randint_obj, random_randint);
-//| .. function:: choice(seq)
-//|
-//| Returns a randomly selected element from the given sequence. Raises
-//| IndexError when the sequence is empty.
+//| def choice(seq: Any) -> Any:
+//| """Returns a randomly selected element from the given sequence. Raises
+//| IndexError when the sequence is empty."""
+//| ...
//|
STATIC mp_obj_t random_choice(mp_obj_t seq) {
mp_int_t len = mp_obj_get_int(mp_obj_len(seq));
@@ -149,19 +148,19 @@ STATIC mp_obj_t random_choice(mp_obj_t seq) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_choice_obj, random_choice);
-//| .. function:: random()
-//|
-//| Returns a random float between 0 and 1.0.
+//| def random() -> Any:
+//| """Returns a random float between 0 and 1.0."""
+//| ...
//|
STATIC mp_obj_t random_random(void) {
return mp_obj_new_float(shared_modules_random_random());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(random_random_obj, random_random);
-//| .. function:: uniform(a, b)
-//|
-//| Returns a random float between a and b. It may or may not be inclusive
-//| depending on float rounding.
+//| def uniform(a: Any, b: Any) -> Any:
+//| """Returns a random float between a and b. It may or may not be inclusive
+//| depending on float rounding."""
+//| ...
//|
STATIC mp_obj_t random_uniform(mp_obj_t a_in, mp_obj_t b_in) {
mp_float_t a = mp_obj_get_float(a_in);