Added inline pyi to analogio

This commit is contained in:
dherrada 2020-04-27 13:06:47 -04:00
parent 27e085ec36
commit 8344fce994
No known key found for this signature in database
GPG Key ID: CE2ADBAB8775CE81
2 changed files with 61 additions and 72 deletions

View File

@ -36,27 +36,25 @@
#include "shared-bindings/analogio/AnalogIn.h"
#include "shared-bindings/util.h"
//| .. currentmodule:: analogio
//|class AnalogIn:
//| """:class:`AnalogIn` -- read analog voltage
//| ============================================
//|
//| :class:`AnalogIn` -- read analog voltage
//| ============================================
//| Usage::
//|
//| Usage::
//| import analogio
//| from board import *
//|
//| import analogio
//| from board import *
//| adc = analogio.AnalogIn(A1)
//| val = adc.value"""
//|
//| adc = analogio.AnalogIn(A1)
//| val = adc.value
//| def __init__(self, pin: microcontroller.Pin):
//|
//| .. class:: AnalogIn(pin)
//|
//| Use the AnalogIn on the given pin. The reference voltage varies by
//| platform so use ``reference_voltage`` to read the configured setting.
//|
//| :param ~microcontroller.Pin pin: the pin to read from
//| """Use the AnalogIn on the given pin. The reference voltage varies by
//| platform so use ``reference_voltage`` to read the configured setting.
//|
//| :param ~microcontroller.Pin pin: the pin to read from"""
//| ...
STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// check number of arguments
@ -72,10 +70,9 @@ STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
//|
//| Turn off the AnalogIn and release the pin for other use.
//|
//| def deinit(self, ) -> Any:
//| """Turn off the AnalogIn and release the pin for other use."""
//| ...
STATIC mp_obj_t analogio_analogin_deinit(mp_obj_t self_in) {
analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_analogio_analogin_deinit(self);
@ -88,17 +85,15 @@ STATIC void check_for_deinit(analogio_analogin_obj_t *self) {
raise_deinited_error();
}
}
//| .. 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 analogio_analogin___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_analogio_analogin_deinit(args[0]);
@ -106,13 +101,12 @@ STATIC mp_obj_t analogio_analogin___exit__(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogin___exit___obj, 4, 4, analogio_analogin___exit__);
//| .. attribute:: value
//|
//| The value on the analog pin between 0 and 65535 inclusive (16-bit). (read-only)
//|
//| Even if the underlying analog to digital converter (ADC) is lower
//| resolution, the value is 16-bit.
//| value: Any =
//| """The value on the analog pin between 0 and 65535 inclusive (16-bit). (read-only)
//|
//| Even if the underlying analog to digital converter (ADC) is lower
//| resolution, the value is 16-bit."""
//| ...
STATIC mp_obj_t analogio_analogin_obj_get_value(mp_obj_t self_in) {
analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -127,11 +121,10 @@ const mp_obj_property_t analogio_analogin_value_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: reference_voltage
//|
//| The maximum voltage measurable (also known as the reference voltage) as a
//| `float` in Volts.
//|
//| reference_voltage: Any =
//| """The maximum voltage measurable (also known as the reference voltage) as a
//| `float` in Volts."""
//| ...
STATIC mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) {
analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View File

@ -36,28 +36,27 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
//| .. currentmodule:: analogio
//|class AnalogOut:
//| """.. currentmodule:: analogio
//|
//| :class:`AnalogOut` -- output analog voltage
//| ============================================
//| :class:`AnalogOut` -- output analog voltage
//| ============================================
//|
//| The AnalogOut is used to output analog values (a specific voltage).
//| The AnalogOut is used to output analog values (a specific voltage).
//|
//| Example usage::
//| Example usage::
//|
//| import analogio
//| from microcontroller import pin
//| import analogio
//| from microcontroller import pin
//|
//| dac = analogio.AnalogOut(pin.PA02) # output on pin PA02
//| dac.value = 32768 # makes PA02 1.65V
//| dac = analogio.AnalogOut(pin.PA02) # output on pin PA02
//| dac.value = 32768 # makes PA02 1.65V"""
//| def __init__(self, pin: microcontroller.Pin):
//|
//| .. class:: AnalogOut(pin)
//|
//| Use the AnalogOut on the given pin.
//|
//| :param ~microcontroller.Pin pin: the pin to output to
//| """Use the AnalogOut on the given pin.
//|
//| :param ~microcontroller.Pin pin: the pin to output to"""
//| ...
STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// check arguments
mp_arg_check_num(n_args, kw_args, 1, 1, false);
@ -71,10 +70,9 @@ STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t
return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
//|
//| Turn off the AnalogOut and release the pin for other use.
//|
//| def deinit(self, ) -> Any:
//| """Turn off the AnalogOut and release the pin for other use."""
//| ...
STATIC mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) {
analogio_analogout_obj_t *self = self_in;
@ -84,17 +82,15 @@ STATIC mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogout_deinit_obj, analogio_analogout_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 analogio_analogout___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_analogio_analogout_deinit(args[0]);
@ -102,12 +98,12 @@ STATIC mp_obj_t analogio_analogout___exit__(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogout___exit___obj, 4, 4, analogio_analogout___exit__);
//| .. attribute:: value
//| value: Any =
//| """The value on the analog pin between 0 and 65535 inclusive (16-bit). (write-only)
//|
//| The value on the analog pin between 0 and 65535 inclusive (16-bit). (write-only)
//|
//| Even if the underlying digital to analog converter (DAC) is lower
//| resolution, the value is 16-bit.
//| Even if the underlying digital to analog converter (DAC) is lower
//| resolution, the value is 16-bit."""
//| ...
STATIC mp_obj_t analogio_analogout_obj_set_value(mp_obj_t self_in, mp_obj_t value) {
analogio_analogout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_analogio_analogout_deinited(self)) {