Skip to content

Commit e31e9ee

Browse files
committed
Did math, microcontroller, and multiterminal
1 parent 4f33a20 commit e31e9ee

File tree

6 files changed

+184
-195
lines changed

6 files changed

+184
-195
lines changed

shared-bindings/math/__init__.c

Lines changed: 80 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846)
3939

4040

41-
//| :mod:`math` --- mathematical functions
41+
//| """:mod:`math` --- mathematical functions
4242
//| ========================================================
4343
//|
4444
//| .. module:: math
4545
//| :synopsis: mathematical functions
4646
//| :platform: SAMD21/SAMD51
4747
//|
4848
//| The `math` module provides some basic mathematical functions for
49-
//| working with floating-point numbers.
49+
//| working with floating-point numbers."""
5050
//|
5151

5252
STATIC NORETURN void math_error(void) {
@@ -86,117 +86,113 @@ STATIC NORETURN void math_error(void) {
8686
//| Constants
8787
//| ---------
8888
//|
89-
//| .. data:: e
89+
//| e: Any = ...
90+
//| """base of the natural logarithm"""
9091
//|
91-
//| base of the natural logarithm
92-
//|
93-
//| .. data:: pi
94-
//|
95-
//| the ratio of a circle's circumference to its diameter
92+
//| pi: Any = ...
93+
//| """the ratio of a circle's circumference to its diameter"""
9694
//|
9795

9896
//| Functions
9997
//| ---------
10098
//|
101-
//| .. function:: acos(x)
102-
//|
103-
//| Return the inverse cosine of ``x``.
104-
//|
105-
//| .. function:: asin(x)
106-
//|
107-
//| Return the inverse sine of ``x``.
108-
//|
109-
//| .. function:: atan(x)
110-
//|
111-
//| Return the inverse tangent of ``x``.
112-
//|
113-
//| .. function:: atan2(y,x)
114-
//|
115-
//| Return the principal value of the inverse tangent of ``y/x``.
116-
//|
117-
//| .. function:: ceil(x)
118-
//|
119-
//| Return an integer, being ``x`` rounded towards positive infinity.
120-
//|
121-
//| .. function:: copysign(x,y)
122-
//|
123-
//| Return ``x`` with the sign of ``y``.
124-
//|
125-
//| .. function:: cos(x)
126-
//|
127-
//| Return the cosine of ``x``.
128-
//|
129-
//| .. function:: degrees(x)
130-
//|
131-
//| Return radians ``x`` converted to degrees.
132-
//|
133-
//| .. function:: exp(x)
134-
//|
135-
//| Return the exponential of ``x``.
136-
//|
137-
//| .. function:: fabs(x)
138-
//|
139-
//| Return the absolute value of ``x``.
140-
//|
141-
//| .. function:: floor(x)
142-
//|
143-
//| Return an integer, being ``x`` rounded towards negative infinity.
144-
//|
145-
//| .. function:: fmod(x,y)
146-
//|
147-
//| Return the remainder of ``x/y``.
148-
//|
149-
//| .. function:: frexp(x)
99+
//| def acos(x: Any) -> Any:
100+
//| """Return the inverse cosine of ``x``."""
101+
//| ...
150102
//|
151-
//| Decomposes a floating-point number into its mantissa and exponent.
152-
//| The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e``
153-
//| exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise
154-
//| the relation ``0.5 <= abs(m) < 1`` holds.
103+
//| def asin(x: Any) -> Any:
104+
//| """Return the inverse sine of ``x``."""
105+
//| ...
155106
//|
156-
//| .. function:: isfinite(x)
107+
//| def atan(x: Any) -> Any:
108+
//| """Return the inverse tangent of ``x``."""
109+
//| ...
157110
//|
158-
//| Return ``True`` if ``x`` is finite.
111+
//| def atan2(y: Any, x: Any) -> Any:
112+
//| """Return the principal value of the inverse tangent of ``y/x``."""
113+
//| ...
159114
//|
160-
//| .. function:: isinf(x)
115+
//| def ceil(x: Any) -> Any:
116+
//| """Return an integer, being ``x`` rounded towards positive infinity."""
117+
//| ...
161118
//|
162-
//| Return ``True`` if ``x`` is infinite.
119+
//| def copysign(x: Any, y: Any) -> Any:
120+
//| """Return ``x`` with the sign of ``y``."""
121+
//| ...
163122
//|
164-
//| .. function:: isnan(x)
123+
//| def cos(x: Any) -> Any:
124+
//| """Return the cosine of ``x``."""
125+
//| ...
165126
//|
166-
//| Return ``True`` if ``x`` is not-a-number
127+
//| def degrees(x: Any) -> Any:
128+
//| """Return radians ``x`` converted to degrees."""
129+
//| ...
167130
//|
168-
//| .. function:: ldexp(x, exp)
131+
//| def exp(x: Any) -> Any:
132+
//| """Return the exponential of ``x``."""
133+
//| ...
169134
//|
170-
//| Return ``x * (2**exp)``.
135+
//| def fabs(x: Any) -> Any:
136+
//| """Return the absolute value of ``x``."""
137+
//| ...
171138
//|
172-
//| .. function:: modf(x)
139+
//| def floor(x: Any) -> Any:
140+
//| """Return an integer, being ``x`` rounded towards negative infinity."""
141+
//| ...
173142
//|
174-
//| Return a tuple of two floats, being the fractional and integral parts of
175-
//| ``x``. Both return values have the same sign as ``x``.
143+
//| def fmod(x: Any, y: Any) -> Any:
144+
//| """Return the remainder of ``x/y``."""
145+
//| ...
176146
//|
177-
//| .. function:: pow(x, y)
147+
//| def frexp(x: Any) -> Any:
148+
//| """Decomposes a floating-point number into its mantissa and exponent.
149+
//| The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e``
150+
//| exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise
151+
//| the relation ``0.5 <= abs(m) < 1`` holds."""
152+
//| ...
178153
//|
179-
//| Returns ``x`` to the power of ``y``.
154+
//| def isfinite(x: Any) -> Any:
155+
//| """Return ``True`` if ``x`` is finite."""
156+
//| ...
180157
//|
181-
//| .. function:: radians(x)
158+
//| def isinf(x: Any) -> Any:
159+
//| """Return ``True`` if ``x`` is infinite."""
160+
//| ...
182161
//|
183-
//| Return degrees ``x`` converted to radians.
162+
//| def isnan(x: Any) -> Any:
163+
//| """Return ``True`` if ``x`` is not-a-number"""
164+
//| ...
184165
//|
185-
//| .. function:: sin(x)
166+
//| def ldexp(x: Any, exp: Any) -> Any:
167+
//| """Return ``x * (2**exp)``."""
168+
//| ...
186169
//|
187-
//| Return the sine of ``x``.
170+
//| def modf(x: Any) -> Any:
171+
//| """Return a tuple of two floats, being the fractional and integral parts of
172+
//| ``x``. Both return values have the same sign as ``x``."""
173+
//| ...
188174
//|
189-
//| .. function:: sqrt(x)
175+
//| def pow(x: Any, y: Any) -> Any:
176+
//| """Returns ``x`` to the power of ``y``."""
190177
//|
191-
//| Returns the square root of ``x``.
178+
//| def radians(x: Any) -> Any:
179+
//| """Return degrees ``x`` converted to radians."""
192180
//|
193-
//| .. function:: tan(x)
181+
//| def sin(x: Any) -> Any:
182+
//| """Return the sine of ``x``."""
183+
//| ...
194184
//|
195-
//| Return the tangent of ``x``.
185+
//| def sqrt(x: Any) -> Any:
186+
//| """Returns the square root of ``x``."""
187+
//| ...
196188
//|
197-
//| .. function:: trunc(x)
189+
//| def tan(x: Any) -> Any: ...
190+
//| """Return the tangent of ``x``."""
191+
//| ...
198192
//|
199-
//| Return an integer, being ``x`` rounded towards 0.
193+
//| def trunc(x: Any) -> Any:
194+
//| """Return an integer, being ``x`` rounded towards 0."""
195+
//| ...
200196
//|
201197
MATH_FUN_1_ERRCOND(sqrt, sqrt, (x < (mp_float_t)0.0))
202198

shared-bindings/microcontroller/Pin.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@
3333
#include "py/runtime.h"
3434
#include "supervisor/shared/translate.h"
3535

36-
//| .. currentmodule:: microcontroller
36+
//| class Pin:
37+
//| """.. currentmodule:: microcontroller
3738
//|
38-
//| :class:`Pin` --- Pin reference
39-
//| ------------------------------------------
39+
//| :class:`Pin` --- Pin reference
40+
//| ------------------------------------------
4041
//|
41-
//| Identifies an IO pin on the microcontroller.
42+
//| Identifies an IO pin on the microcontroller."""
4243
//|
43-
//| .. class:: Pin()
44-
//|
45-
//| Identifies an IO pin on the microcontroller. They are fixed by the
46-
//| hardware so they cannot be constructed on demand. Instead, use
47-
//| `board` or `microcontroller.pin` to reference the desired pin.
44+
//| def __init__(self, ):
45+
//| """Identifies an IO pin on the microcontroller. They are fixed by the
46+
//| hardware so they cannot be constructed on demand. Instead, use
47+
//| `board` or `microcontroller.pin` to reference the desired pin."""
48+
//| ...
4849
//|
4950

5051
static void get_pin_name(const mcu_pin_obj_t *self, qstr* package, qstr* module, qstr* name) {

shared-bindings/microcontroller/Processor.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@
3434

3535
#include "py/runtime.h"
3636

37-
//| .. currentmodule:: microcontroller
37+
//| class Processor:
38+
//| """.. currentmodule:: microcontroller
3839
//|
39-
//| :class:`Processor` --- Microcontroller CPU information and control
40-
//| ------------------------------------------------------------------
40+
//| :class:`Processor` --- Microcontroller CPU information and control
41+
//| ------------------------------------------------------------------
4142
//|
42-
//| Get information about the microcontroller CPU and control it.
43+
//| Get information about the microcontroller CPU and control it.
4344
//|
44-
//| Usage::
45+
//| Usage::
4546
//|
46-
//| import microcontroller
47-
//| print(microcontroller.cpu.frequency)
48-
//| print(microcontroller.cpu.temperature)
47+
//| import microcontroller
48+
//| print(microcontroller.cpu.frequency)
49+
//| print(microcontroller.cpu.temperature)"""
4950
//|
5051

51-
//| .. class:: Processor()
52-
//|
53-
//| You cannot create an instance of `microcontroller.Processor`.
54-
//| Use `microcontroller.cpu` to access the sole instance available.
52+
//| def __init__(self, ):
53+
//| """You cannot create an instance of `microcontroller.Processor`.
54+
//| Use `microcontroller.cpu` to access the sole instance available."""
55+
//| ...
5556
//|
5657

57-
//| .. attribute:: frequency
58-
//|
59-
//| The CPU operating frequency as an `int`, in Hertz. (read-only)
58+
//| frequency: Any = ...
59+
//| """The CPU operating frequency as an `int`, in Hertz. (read-only)"""
6060
//|
6161
STATIC mp_obj_t mcu_processor_get_frequency(mp_obj_t self) {
6262
return mp_obj_new_int_from_uint(common_hal_mcu_processor_get_frequency());
@@ -72,11 +72,10 @@ const mp_obj_property_t mcu_processor_frequency_obj = {
7272
},
7373
};
7474

75-
//| .. attribute:: temperature
76-
//|
77-
//| The on-chip temperature, in Celsius, as a float. (read-only)
75+
//| temperature: Any = ...
76+
//| """The on-chip temperature, in Celsius, as a float. (read-only)
7877
//|
79-
//| Is `None` if the temperature is not available.
78+
//| Is `None` if the temperature is not available."""
8079
//|
8180
STATIC mp_obj_t mcu_processor_get_temperature(mp_obj_t self) {
8281
float temperature = common_hal_mcu_processor_get_temperature();
@@ -93,9 +92,8 @@ const mp_obj_property_t mcu_processor_temperature_obj = {
9392
},
9493
};
9594

96-
//| .. attribute:: uid
97-
//|
98-
//| The unique id (aka serial number) of the chip as a `bytearray`. (read-only)
95+
//| uid: Any = ...
96+
//| """The unique id (aka serial number) of the chip as a `bytearray`. (read-only)"""
9997
//|
10098
STATIC mp_obj_t mcu_processor_get_uid(mp_obj_t self) {
10199
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
@@ -113,11 +111,10 @@ const mp_obj_property_t mcu_processor_uid_obj = {
113111
},
114112
};
115113

116-
//| .. attribute:: voltage
117-
//|
118-
//| The input voltage to the microcontroller, as a float. (read-only)
114+
//| voltage: Any = ...
115+
//| """The input voltage to the microcontroller, as a float. (read-only)
119116
//|
120-
//| Is `None` if the voltage is not available.
117+
//| Is `None` if the voltage is not available."""
121118
//|
122119
STATIC mp_obj_t mcu_processor_get_voltage(mp_obj_t self) {
123120
float voltage = common_hal_mcu_processor_get_voltage();

shared-bindings/microcontroller/RunMode.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,31 @@
2626

2727
#include "shared-bindings/microcontroller/RunMode.h"
2828

29-
//| .. currentmodule:: microcontroller
29+
//| class RunMode:
30+
//| """.. currentmodule:: microcontroller
3031
//|
31-
//| :class:`RunMode` -- run state of the microcontroller
32-
//| =============================================================
32+
//| :class:`RunMode` -- run state of the microcontroller
33+
//| ============================================================="""
3334
//|
34-
//| .. class:: RunMode()
35+
//| def __init__(self, ):
36+
//| """Enum-like class to define the run mode of the microcontroller and
37+
//| CircuitPython."""
3538
//|
36-
//| Enum-like class to define the run mode of the microcontroller and
37-
//| CircuitPython.
39+
//| NORMAL: Any = ...
40+
//| """Run CircuitPython as normal.
3841
//|
39-
//| .. attribute:: NORMAL
42+
//| :type microcontroller.RunMode:"""
4043
//|
41-
//| Run CircuitPython as normal.
44+
//| SAFE_MODE: Any = ...
45+
//| """Run CircuitPython in safe mode. User code will not be run and the
46+
//| file system will be writeable over USB.
4247
//|
43-
//| :type microcontroller.RunMode:
48+
//| :type microcontroller.RunMode:"""
4449
//|
45-
//| .. attribute:: SAFE_MODE
50+
//| BOOTLOADER: Any = ...
51+
//| """Run the bootloader.
4652
//|
47-
//| Run CircuitPython in safe mode. User code will not be run and the
48-
//| file system will be writeable over USB.
49-
//|
50-
//| :type microcontroller.RunMode:
51-
//|
52-
//| .. attribute:: BOOTLOADER
53-
//|
54-
//| Run the bootloader.
55-
//|
56-
//| :type microcontroller.RunMode:
53+
//| :type microcontroller.RunMode:"""
5754
//|
5855
const mp_obj_type_t mcu_runmode_type;
5956

0 commit comments

Comments
 (0)