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

View File

@ -36,28 +36,27 @@
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
#include "supervisor/shared/translate.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 //| import analogio
//| from microcontroller import pin //| from microcontroller import pin
//| //|
//| dac = analogio.AnalogOut(pin.PA02) # output on pin PA02 //| dac = analogio.AnalogOut(pin.PA02) # output on pin PA02
//| dac.value = 32768 # makes PA02 1.65V //| dac.value = 32768 # makes PA02 1.65V"""
//| def __init__(self, pin: microcontroller.Pin):
//| //|
//| """Use the AnalogOut on the given pin.
//| .. class:: AnalogOut(pin)
//|
//| Use the AnalogOut on the given pin.
//|
//| :param ~microcontroller.Pin pin: the pin to output to
//| //|
//| :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) { 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 // check arguments
mp_arg_check_num(n_args, kw_args, 1, 1, false); 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); return MP_OBJ_FROM_PTR(self);
} }
//| .. method:: deinit() //| def deinit(self, ) -> Any:
//| //| """Turn off the AnalogOut and release the pin for other use."""
//| Turn off the AnalogOut and release the pin for other use. //| ...
//|
STATIC mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) { STATIC mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) {
analogio_analogout_obj_t *self = 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); STATIC MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogout_deinit_obj, analogio_analogout_deinit);
//| .. method:: __enter__() //| 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.
//| .. method:: __exit__() //| 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 analogio_analogout___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t analogio_analogout___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args; (void)n_args;
common_hal_analogio_analogout_deinit(args[0]); 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__); 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) { 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); analogio_analogout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_analogio_analogout_deinited(self)) { if (common_hal_analogio_analogout_deinited(self)) {