diff options
| author | Benjamin Shockley <benjaminshockley@hotmail.com> | 2020-08-20 13:48:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-20 13:48:15 -0500 |
| commit | 0084f0af24e4e219bc040c52ee723959423de6e2 (patch) | |
| tree | 1aebdb362f08bf6417caa87836e3e4e739afc964 /shared-bindings/microcontroller/Processor.c | |
| parent | 9aebe2f1efc99871fcf283c304e3a8700050d736 (diff) | |
| parent | 4d7b9cde33934a44c4c905a49d2f831339fc8bd2 (diff) | |
Merge pull request #2 from adafruit/master
Master
Diffstat (limited to 'shared-bindings/microcontroller/Processor.c')
| -rw-r--r-- | shared-bindings/microcontroller/Processor.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index be685b0a8..c4b249124 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -34,29 +34,24 @@ #include "py/runtime.h" -//| .. currentmodule:: microcontroller +//| class Processor: +//| """Microcontroller CPU information and control //| -//| :class:`Processor` --- Microcontroller CPU information and control -//| ------------------------------------------------------------------ +//| Usage:: //| -//| Get information about the microcontroller CPU and control it. -//| -//| Usage:: -//| -//| import microcontroller -//| print(microcontroller.cpu.frequency) -//| print(microcontroller.cpu.temperature) +//| import microcontroller +//| print(microcontroller.cpu.frequency) +//| print(microcontroller.cpu.temperature)""" //| -//| .. class:: Processor() -//| -//| You cannot create an instance of `microcontroller.Processor`. -//| Use `microcontroller.cpu` to access the sole instance available. +//| def __init__(self, ): +//| """You cannot create an instance of `microcontroller.Processor`. +//| Use `microcontroller.cpu` to access the sole instance available.""" +//| ... //| -//| .. attribute:: frequency -//| -//| The CPU operating frequency as an `int`, in Hertz. (read-only) +//| frequency: int = ... +//| """The CPU operating frequency in Hertz. (read-only)""" //| STATIC mp_obj_t mcu_processor_get_frequency(mp_obj_t self) { return mp_obj_new_int_from_uint(common_hal_mcu_processor_get_frequency()); @@ -72,11 +67,10 @@ const mp_obj_property_t mcu_processor_frequency_obj = { }, }; -//| .. attribute:: temperature -//| -//| The on-chip temperature, in Celsius, as a float. (read-only) +//| temperature: Any = ... +//| """The on-chip temperature, in Celsius, as a float. (read-only) //| -//| Is `None` if the temperature is not available. +//| Is `None` if the temperature is not available.""" //| STATIC mp_obj_t mcu_processor_get_temperature(mp_obj_t self) { float temperature = common_hal_mcu_processor_get_temperature(); @@ -93,9 +87,8 @@ const mp_obj_property_t mcu_processor_temperature_obj = { }, }; -//| .. attribute:: uid -//| -//| The unique id (aka serial number) of the chip as a `bytearray`. (read-only) +//| uid: Any = ... +//| """The unique id (aka serial number) of the chip as a `bytearray`. (read-only)""" //| STATIC mp_obj_t mcu_processor_get_uid(mp_obj_t self) { uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; @@ -113,10 +106,31 @@ const mp_obj_property_t mcu_processor_uid_obj = { }, }; +//| voltage: Any = ... +//| """The input voltage to the microcontroller, as a float. (read-only) +//| +//| Is `None` if the voltage is not available.""" +//| +STATIC mp_obj_t mcu_processor_get_voltage(mp_obj_t self) { + float voltage = common_hal_mcu_processor_get_voltage(); + return isnan(voltage) ? mp_const_none : mp_obj_new_float(voltage); +} + +MP_DEFINE_CONST_FUN_OBJ_1(mcu_processor_get_voltage_obj, mcu_processor_get_voltage); + +const mp_obj_property_t mcu_processor_voltage_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&mcu_processor_get_voltage_obj, // getter + (mp_obj_t)&mp_const_none_obj, // no setter + (mp_obj_t)&mp_const_none_obj, // no deleter + }, +}; + STATIC const mp_rom_map_elem_t mcu_processor_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&mcu_processor_frequency_obj) }, { MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&mcu_processor_temperature_obj) }, { MP_ROM_QSTR(MP_QSTR_uid), MP_ROM_PTR(&mcu_processor_uid_obj) }, + { MP_ROM_QSTR(MP_QSTR_voltage), MP_ROM_PTR(&mcu_processor_voltage_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mcu_processor_locals_dict, mcu_processor_locals_dict_table); |
