From cfe24b85322a029758c3376eed2726657397bf33 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 30 May 2019 19:01:27 -0700 Subject: Improve rST consistency for rst2pyi use --- shared-bindings/microcontroller/Pin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings/microcontroller/Pin.c') diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index e79663107..3635f0afb 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -40,7 +40,7 @@ //| //| Identifies an IO pin on the microcontroller. //| -//| .. class:: Pin +//| .. class:: Pin() //| //| Identifies an IO pin on the microcontroller. They are fixed by the //| hardware so they cannot be constructed on demand. Instead, use -- cgit v1.2.3 From b6206406de2a232299ebdd1d187c7656ae79f8f2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 28 Feb 2020 23:32:24 -0500 Subject: new pin validation routines; don't use mp_const_none if NULL will do --- .../atmel-samd/boards/hallowing_m4_express/board.c | 2 +- ports/atmel-samd/boards/monster_m4sk/board.c | 2 +- ports/atmel-samd/boards/openbook_m4/board.c | 2 +- ports/atmel-samd/boards/pewpew_m4/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pybadge_airlift/board.c | 2 +- ports/atmel-samd/boards/pygamer/board.c | 2 +- ports/atmel-samd/boards/pygamer_advance/board.c | 2 +- ports/atmel-samd/common-hal/analogio/AnalogIn.c | 4 +- ports/atmel-samd/common-hal/audiobusio/I2SOut.c | 8 ++-- ports/atmel-samd/common-hal/audiobusio/PDMIn.c | 6 +-- ports/atmel-samd/common-hal/audioio/AudioOut.c | 6 +-- ports/atmel-samd/common-hal/busio/SPI.c | 4 +- ports/atmel-samd/common-hal/busio/UART.c | 8 ++-- .../atmel-samd/common-hal/digitalio/DigitalInOut.c | 4 +- ports/atmel-samd/common-hal/pulseio/PWMOut.c | 4 +- ports/cxd56/common-hal/analogio/AnalogIn.c | 4 +- ports/cxd56/common-hal/busio/UART.c | 4 +- ports/cxd56/common-hal/digitalio/DigitalInOut.c | 4 +- ports/cxd56/common-hal/pulseio/PWMOut.c | 8 ++-- ports/cxd56/common-hal/pulseio/PulseIn.c | 25 ++++++------ ports/mimxrt10xx/common-hal/analogio/AnalogIn.c | 4 +- ports/mimxrt10xx/common-hal/busio/UART.c | 18 ++++----- .../mimxrt10xx/common-hal/digitalio/DigitalInOut.c | 4 +- ports/nrf/boards/clue_nrf52840_express/board.c | 2 +- ports/nrf/boards/ohs2020_badge/board.c | 2 +- ports/nrf/common-hal/analogio/AnalogIn.c | 4 +- ports/nrf/common-hal/busio/SPI.c | 4 +- ports/nrf/common-hal/busio/UART.c | 14 +++---- ports/nrf/common-hal/digitalio/DigitalInOut.c | 4 +- ports/stm32f4/common-hal/analogio/AnalogIn.c | 14 +++---- ports/stm32f4/common-hal/analogio/AnalogOut.c | 4 +- ports/stm32f4/common-hal/busio/I2C.c | 18 ++++----- ports/stm32f4/common-hal/busio/SPI.c | 44 +++++++++++----------- ports/stm32f4/common-hal/busio/UART.c | 16 ++++---- ports/stm32f4/common-hal/digitalio/DigitalInOut.c | 12 +++--- ports/stm32f4/common-hal/pulseio/PWMOut.c | 16 ++++---- shared-bindings/analogio/AnalogIn.c | 9 ++--- shared-bindings/analogio/AnalogOut.c | 6 +-- shared-bindings/audiobusio/I2SOut.c | 14 ++----- shared-bindings/audiobusio/PDMIn.c | 11 +----- shared-bindings/audioio/AudioOut.c | 12 +----- shared-bindings/audiopwmio/PWMAudioOut.c | 12 +----- shared-bindings/bitbangio/I2C.c | 7 ++-- shared-bindings/bitbangio/OneWire.c | 5 +-- shared-bindings/bitbangio/SPI.c | 10 ++--- shared-bindings/busio/I2C.c | 10 ++--- shared-bindings/busio/OneWire.c | 4 +- shared-bindings/busio/SPI.c | 16 +++----- shared-bindings/busio/UART.c | 20 +++++----- shared-bindings/digitalio/DigitalInOut.c | 6 +-- shared-bindings/displayio/Display.c | 8 +--- shared-bindings/displayio/EPaperDisplay.c | 8 +--- shared-bindings/frequencyio/FrequencyIn.c | 4 +- shared-bindings/i2cslave/I2CSlave.c | 8 +--- shared-bindings/microcontroller/Pin.c | 29 +++++++++++++- shared-bindings/microcontroller/Pin.h | 6 ++- shared-bindings/ps2io/Ps2.c | 9 ++--- shared-bindings/pulseio/PWMOut.c | 5 +-- shared-bindings/pulseio/PulseIn.c | 4 +- shared-bindings/rotaryio/IncrementalEncoder.c | 9 +---- shared-bindings/touchio/TouchIn.c | 5 +-- shared-bindings/wiznet/wiznet5k.c | 6 +-- shared-module/bitbangio/SPI.c | 6 +-- shared-module/board/__init__.c | 6 +-- 65 files changed, 241 insertions(+), 299 deletions(-) (limited to 'shared-bindings/microcontroller/Pin.c') diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index 5d1ef6d9b..6bb2a591f 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index 40141ca15..2377f4a9d 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index 85a588879..2d9b31647 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -55,7 +55,7 @@ uint8_t stop_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index 1872d1876..5f5a01e48 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -97,7 +97,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 28e1aec13..bead06f3c 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index fbb4441f0..061f3d777 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index c052614db..70d4a05dc 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index a138c7e50..ff2da34a2 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/common-hal/analogio/AnalogIn.c b/ports/atmel-samd/common-hal/analogio/AnalogIn.c index fc11d5d19..2bd218cdd 100644 --- a/ports/atmel-samd/common-hal/analogio/AnalogIn.c +++ b/ports/atmel-samd/common-hal/analogio/AnalogIn.c @@ -73,7 +73,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self, } bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { @@ -81,7 +81,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { return; } reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } void analogin_reset() { diff --git a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c index 05a6aaf7b..99d3762cb 100644 --- a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c +++ b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c @@ -204,7 +204,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self, } bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t* self) { - return self->bit_clock == mp_const_none; + return self->bit_clock == NULL; } void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) { @@ -213,11 +213,11 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) { } reset_pin_number(self->bit_clock->number); - self->bit_clock = mp_const_none; + self->bit_clock = NULL; reset_pin_number(self->word_select->number); - self->word_select = mp_const_none; + self->word_select = NULL; reset_pin_number(self->data->number); - self->data = mp_const_none; + self->data = NULL; } void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self, diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c index 3a51cce8f..f70f1fec0 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -219,7 +219,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, } bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t* self) { - return self->clock_pin == mp_const_none; + return self->clock_pin == NULL; } void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) { @@ -237,8 +237,8 @@ void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) { reset_pin_number(self->clock_pin->number); reset_pin_number(self->data_pin->number); - self->clock_pin = mp_const_none; - self->data_pin = mp_const_none; + self->clock_pin = NULL; + self->data_pin = NULL; } uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t* self) { diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index b75c2b335..1d9b4cbe8 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -304,7 +304,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, } bool common_hal_audioio_audioout_deinited(audioio_audioout_obj_t* self) { - return self->left_channel == mp_const_none; + return self->left_channel == NULL; } void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) { @@ -332,10 +332,10 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) { tc_set_enable(tc_insts[self->tc_index], false); reset_pin_number(self->left_channel->number); - self->left_channel = mp_const_none; + self->left_channel = NULL; #ifdef SAMD51 reset_pin_number(self->right_channel->number); - self->right_channel = mp_const_none; + self->right_channel = NULL; #endif } diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 7a1426bed..1dc389027 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -89,8 +89,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, Sercom* sercom = NULL; uint8_t sercom_index; uint32_t clock_pinmux = 0; - bool mosi_none = mosi == mp_const_none || mosi == NULL; - bool miso_none = miso == mp_const_none || miso == NULL; + bool mosi_none = mosi == NULL; + bool miso_none = miso == NULL; uint32_t mosi_pinmux = 0; uint32_t miso_pinmux = 0; uint8_t clock_pad = 0; diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index fb9968605..1f6b75f97 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -65,7 +65,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, uint32_t tx_pinmux = 0; uint8_t tx_pad = 255; // Unset pad - if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) { + if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) { mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device")); } @@ -73,8 +73,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, mp_raise_NotImplementedError(translate("bytes > 8 bits not supported")); } - bool have_tx = tx != mp_const_none; - bool have_rx = rx != mp_const_none; + bool have_tx = tx != NULL; + bool have_rx = rx != NULL; if (!have_tx && !have_rx) { mp_raise_ValueError(translate("tx and rx cannot both be None")); } @@ -109,7 +109,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, #endif tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D); tx_pad = tx->sercom[i].pad; - if (rx == mp_const_none) { + if (rx == NULL) { sercom = potential_sercom; break; } diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c index e167cbb69..68d3da806 100644 --- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c +++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c @@ -55,7 +55,7 @@ void common_hal_digitalio_digitalinout_never_reset( } bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) { @@ -63,7 +63,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self return; } reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } void common_hal_digitalio_digitalinout_switch_to_input( diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c index 0adb23fc5..fef581584 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c @@ -292,7 +292,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, } bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { @@ -319,7 +319,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { } } reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) { diff --git a/ports/cxd56/common-hal/analogio/AnalogIn.c b/ports/cxd56/common-hal/analogio/AnalogIn.c index e2ca5e4a4..cdf37c06a 100644 --- a/ports/cxd56/common-hal/analogio/AnalogIn.c +++ b/ports/cxd56/common-hal/analogio/AnalogIn.c @@ -83,7 +83,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const // start ADC ioctl(analogin_dev[self->number].fd, ANIOC_CXD56_START, 0); - + self->pin = pin; } @@ -97,7 +97,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { close(analogin_dev[self->number].fd); analogin_dev[self->number].fd = -1; - self->pin = mp_const_none; + self->pin = NULL; } bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { diff --git a/ports/cxd56/common-hal/busio/UART.c b/ports/cxd56/common-hal/busio/UART.c index 3ed980952..3bca240e0 100644 --- a/ports/cxd56/common-hal/busio/UART.c +++ b/ports/cxd56/common-hal/busio/UART.c @@ -60,10 +60,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, mp_float_t timeout, uint16_t receiver_buffer_size) { struct termios tio; - if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) { + if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) { mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device")); } - + if (bits != 8) { mp_raise_ValueError(translate("Could not initialize UART")); } diff --git a/ports/cxd56/common-hal/digitalio/DigitalInOut.c b/ports/cxd56/common-hal/digitalio/DigitalInOut.c index 7b1f6cc03..c9af12e44 100644 --- a/ports/cxd56/common-hal/digitalio/DigitalInOut.c +++ b/ports/cxd56/common-hal/digitalio/DigitalInOut.c @@ -56,11 +56,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.c b/ports/cxd56/common-hal/pulseio/PWMOut.c index a0b4e79c6..7e0be566b 100644 --- a/ports/cxd56/common-hal/pulseio/PWMOut.c +++ b/ports/cxd56/common-hal/pulseio/PWMOut.c @@ -50,7 +50,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, const mcu_pin_obj_t *pin, uint16_t duty, uint32_t frequency, bool variable_frequency) { self->number = -1; - + for (int i = 0; i < MP_ARRAY_SIZE(pwmout_dev); i++) { if (pin->number == pwmout_dev[i].pin->number) { self->number = i; @@ -95,7 +95,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) { pwmout_dev[self->number].fd = -1; reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) { @@ -131,11 +131,11 @@ bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { never_reset_pin_number(self->pin->number); - pwmout_dev[self->number].reset = false; + pwmout_dev[self->number].reset = false; } void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { - pwmout_dev[self->number].reset = true; + pwmout_dev[self->number].reset = true; } void pwmout_reset(void) { diff --git a/ports/cxd56/common-hal/pulseio/PulseIn.c b/ports/cxd56/common-hal/pulseio/PulseIn.c index dd2773d1d..65ca1d97e 100644 --- a/ports/cxd56/common-hal/pulseio/PulseIn.c +++ b/ports/cxd56/common-hal/pulseio/PulseIn.c @@ -106,7 +106,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, board_gpio_int(self->pin->number, true); } - + void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { if (common_hal_pulseio_pulsein_deinited(self)) { return; @@ -116,18 +116,18 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { board_gpio_intconfig(self->pin->number, 0, false, NULL); reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } - + bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } - + void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) { board_gpio_int(self->pin->number, false); self->paused = true; } - + void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t trigger_duration) { // Make sure we're paused. common_hal_pulseio_pulsein_pause(self); @@ -147,14 +147,14 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t tri pulsein_set_config(self, true); board_gpio_int(self->pin->number, true); } - + void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) { common_hal_mcu_disable_interrupts(); self->start = 0; self->len = 0; common_hal_mcu_enable_interrupts(); } - + uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) { if (self->len == 0) { mp_raise_IndexError(translate("pop from an empty PulseIn")); @@ -167,19 +167,19 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) { return value; } - + uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t *self) { return self->maxlen; } - + bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t *self) { return self->paused; } - + uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t *self) { return self->len; } - + uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_t index) { common_hal_mcu_disable_interrupts(); if (index < 0) { @@ -193,4 +193,3 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_ common_hal_mcu_enable_interrupts(); return value; } - \ No newline at end of file diff --git a/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c b/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c index d714001f3..2cc2681b4 100644 --- a/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c +++ b/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c @@ -58,7 +58,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self, } bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { @@ -66,7 +66,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { return; } reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index 4fd7afecb..b34b948b2 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -80,8 +80,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, // TODO: Allow none rx or tx - bool have_tx = tx != mp_const_none; - bool have_rx = rx != mp_const_none; + bool have_tx = tx != NULL; + bool have_rx = rx != NULL; if (!have_tx && !have_rx) { mp_raise_ValueError(translate("tx and rx cannot both be None")); } @@ -116,8 +116,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, } // Filter for sane settings for RS485 - if (rs485_dir != mp_const_none) { - if ((rts != mp_const_none) || (cts != mp_const_none)) { + if (rs485_dir != NULL) { + if ((rts != NULL) || (cts != NULL)) { mp_raise_ValueError(translate("Cannot specify RTS or CTS in RS485 mode")); } // For IMXRT the RTS pin is used for RS485 direction @@ -133,7 +133,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, const uint32_t rts_count = sizeof(mcu_uart_rts_list) / sizeof(mcu_periph_obj_t); const uint32_t cts_count = sizeof(mcu_uart_cts_list) / sizeof(mcu_periph_obj_t); - if (rts != mp_const_none) { + if (rts != NULL) { for (uint32_t i=0; i < rts_count; ++i) { if (mcu_uart_rts_list[i].bank_idx == self->rx_pin->bank_idx) { if (mcu_uart_rts_list[i].pin == rts) { @@ -146,7 +146,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, mp_raise_ValueError(translate("Selected RTS pin not valid")); } - if (cts != mp_const_none) { + if (cts != NULL) { for (uint32_t i=0; i < cts_count; ++i) { if (mcu_uart_cts_list[i].bank_idx == self->rx_pin->bank_idx) { if (mcu_uart_cts_list[i].pin == cts) { @@ -158,7 +158,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, if (self->cts_pin == NULL) mp_raise_ValueError(translate("Selected CTS pin not valid")); } - + self->uart = mcu_uart_banks[self->tx_pin->bank_idx - 1]; config_periph_pin(self->rx_pin); @@ -166,7 +166,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, if (self->rts_pin) config_periph_pin(self->rts_pin); if (self->cts_pin) - config_periph_pin(self->cts_pin); + config_periph_pin(self->cts_pin); lpuart_config_t config = { 0 }; LPUART_GetDefaultConfig(&config); @@ -187,7 +187,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, // Before we init, setup RS485 direction pin // ..unfortunately this isn't done by the driver library uint32_t modir = (self->uart->MODIR) & ~(LPUART_MODIR_TXRTSPOL_MASK | LPUART_MODIR_TXRTSE_MASK); - if (rs485_dir != mp_const_none) { + if (rs485_dir != NULL) { modir |= LPUART_MODIR_TXRTSE_MASK; if (rs485_invert) modir |= LPUART_MODIR_TXRTSPOL_MASK; diff --git a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c index d69a18d96..603515764 100644 --- a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c +++ b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c @@ -78,7 +78,7 @@ void common_hal_digitalio_digitalinout_never_reset( } bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) { @@ -86,7 +86,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self return; } reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } void common_hal_digitalio_digitalinout_switch_to_input( diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index 5f5337a3d..e342c6d93 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 7e3e05814..9e881d763 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, mp_const_none); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/nrf/common-hal/analogio/AnalogIn.c b/ports/nrf/common-hal/analogio/AnalogIn.c index 3bc097019..dbcc5281c 100644 --- a/ports/nrf/common-hal/analogio/AnalogIn.c +++ b/ports/nrf/common-hal/analogio/AnalogIn.c @@ -55,7 +55,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const } bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { @@ -65,7 +65,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { nrf_gpio_cfg_default(self->pin->number); reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index b4ebddde1..3f205e778 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -155,7 +155,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * self->clock_pin_number = clock->number; claim_pin(clock); - if (mosi != mp_const_none) { + if (mosi != NULL) { config.mosi_pin = mosi->number; self->MOSI_pin_number = mosi->number; claim_pin(mosi); @@ -163,7 +163,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * self->MOSI_pin_number = NO_PIN; } - if (miso != mp_const_none) { + if (miso != NULL) { config.miso_pin = miso->number; self->MISO_pin_number = mosi->number; claim_pin(miso); diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 933faf17b..14fa36374 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -135,10 +135,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, uint16_t receiver_buffer_size) { - if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) { + if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) { mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device")); } - + // Find a free UART peripheral. self->uarte = NULL; for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) { @@ -152,7 +152,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, mp_raise_ValueError(translate("All UART peripherals are in use")); } - if ( (tx == mp_const_none) && (rx == mp_const_none) ) { + if ( (tx == NULL) && (rx == NULL) ) { mp_raise_ValueError(translate("tx and rx cannot both be None")); } @@ -165,8 +165,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, } nrfx_uarte_config_t config = { - .pseltxd = (tx == mp_const_none) ? NRF_UARTE_PSEL_DISCONNECTED : tx->number, - .pselrxd = (rx == mp_const_none) ? NRF_UARTE_PSEL_DISCONNECTED : rx->number, + .pseltxd = (tx == NULL) ? NRF_UARTE_PSEL_DISCONNECTED : tx->number, + .pselrxd = (rx == NULL) ? NRF_UARTE_PSEL_DISCONNECTED : rx->number, .pselcts = NRF_UARTE_PSEL_DISCONNECTED, .pselrts = NRF_UARTE_PSEL_DISCONNECTED, .p_context = self, @@ -181,7 +181,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, _VERIFY_ERR(nrfx_uarte_init(self->uarte, &config, uart_callback_irq)); // Init buffer for rx - if ( rx != mp_const_none ) { + if ( rx != NULL ) { // Initially allocate the UART's buffer in the long-lived part of the // heap. UARTs are generally long-lived objects, but the "make long- // lived" machinery is incapable of moving internal pointers like @@ -200,7 +200,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, claim_pin(rx); } - if ( tx != mp_const_none ) { + if ( tx != NULL ) { self->tx_pin_number = tx->number; claim_pin(tx); } else { diff --git a/ports/nrf/common-hal/digitalio/DigitalInOut.c b/ports/nrf/common-hal/digitalio/DigitalInOut.c index 0836962c6..c5a7a7dfb 100644 --- a/ports/nrf/common-hal/digitalio/DigitalInOut.c +++ b/ports/nrf/common-hal/digitalio/DigitalInOut.c @@ -46,7 +46,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct( } bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) { @@ -56,7 +56,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self nrf_gpio_cfg_default(self->pin->number); reset_pin_number(self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } void common_hal_digitalio_digitalinout_switch_to_input( diff --git a/ports/stm32f4/common-hal/analogio/AnalogIn.c b/ports/stm32f4/common-hal/analogio/AnalogIn.c index 3ee3c4dbb..1d1b308b6 100644 --- a/ports/stm32f4/common-hal/analogio/AnalogIn.c +++ b/ports/stm32f4/common-hal/analogio/AnalogIn.c @@ -45,11 +45,11 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self, } // TODO: add ADC traits to structure? - // Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only - // for dual conversion. For this basic application it is never used. + // Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only + // for dual conversion. For this basic application it is never used. LL_GPIO_SetPinMode(pin_port(pin->port), (uint32_t)pin_mask(pin->number), LL_GPIO_MODE_ANALOG); if (pin->adc_unit & 0x01) { - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); } else if (pin->adc_unit == 0x04) { #ifdef LL_APB2_GRP1_PERIPH_ADC3 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC3); @@ -62,7 +62,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self, } bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { @@ -70,7 +70,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { return; } reset_pin_number(self->pin->port,self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { @@ -116,10 +116,10 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); HAL_ADC_Start(&AdcHandle); - HAL_ADC_PollForConversion(&AdcHandle,1); + HAL_ADC_PollForConversion(&AdcHandle,1); uint16_t value = (uint16_t)HAL_ADC_GetValue(&AdcHandle); HAL_ADC_Stop(&AdcHandle); - + // // Shift the value to be 16 bit. return value << 4; } diff --git a/ports/stm32f4/common-hal/analogio/AnalogOut.c b/ports/stm32f4/common-hal/analogio/AnalogOut.c index 79ced0492..2ea969f50 100644 --- a/ports/stm32f4/common-hal/analogio/AnalogOut.c +++ b/ports/stm32f4/common-hal/analogio/AnalogOut.c @@ -39,7 +39,7 @@ #include "stm32f4xx_hal.h" -//DAC is shared between both channels. +//DAC is shared between both channels. #if HAS_DAC DAC_HandleTypeDef handle; #endif @@ -97,7 +97,7 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { #if HAS_DAC reset_pin_number(self->pin->port,self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; dac_on[self->dac_index] = false; //turn off the DAC if both channels are off diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c index 1437e5e78..8e98b966d 100644 --- a/ports/stm32f4/common-hal/busio/I2C.c +++ b/ports/stm32f4/common-hal/busio/I2C.c @@ -100,14 +100,14 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = self->sda->altfn_index; + GPIO_InitStruct.Alternate = self->sda->altfn_index; HAL_GPIO_Init(pin_port(sda->port), &GPIO_InitStruct); GPIO_InitStruct.Pin = pin_mask(scl->number); GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = self->scl->altfn_index; + GPIO_InitStruct.Alternate = self->scl->altfn_index; HAL_GPIO_Init(pin_port(scl->port), &GPIO_InitStruct); //Note: due to I2C soft reboot issue, do not relocate clock init. @@ -144,7 +144,7 @@ void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { } bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { - return self->sda->pin == mp_const_none; + return self->sda == NULL; } void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { @@ -158,8 +158,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->sda->pin->port,self->sda->pin->number); reset_pin_number(self->scl->pin->port,self->scl->pin->number); - self->sda = mp_const_none; - self->scl = mp_const_none; + self->sda = NULL; + self->scl = NULL; } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { @@ -169,7 +169,7 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { bool grabbed_lock = false; - //Critical section code that may be required at some point. + //Critical section code that may be required at some point. // uint32_t store_primask = __get_PRIMASK(); // __disable_irq(); // __DMB(); @@ -195,19 +195,19 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, const uint8_t *data, size_t len, bool transmit_stop_bit) { - HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr << 1), + HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr << 1), (uint8_t *)data, (uint16_t)len, 500); return result == HAL_OK ? 0 : MP_EIO; } uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, uint8_t *data, size_t len) { - return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500) + return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500) == HAL_OK ? 0 : MP_EIO; } STATIC void i2c_clock_enable(uint8_t mask) { - //Note: hard reset required due to soft reboot issue. + //Note: hard reset required due to soft reboot issue. #ifdef I2C1 if (mask & (1 << 0)) { __HAL_RCC_I2C1_CLK_ENABLE(); diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c index e00b5e9f0..7e25e0a57 100644 --- a/ports/stm32f4/common-hal/busio/SPI.c +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -49,7 +49,7 @@ STATIC void spi_clock_enable(uint8_t mask); STATIC void spi_clock_disable(uint8_t mask); STATIC uint32_t get_busclock(SPI_TypeDef * instance) { - //SPI2 and 3 are on PCLK1, if they exist. + //SPI2 and 3 are on PCLK1, if they exist. #ifdef SPI2 if (instance == SPI2) return HAL_RCC_GetPCLK1Freq(); #endif @@ -113,7 +113,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, for (uint i = 0; i < sck_len; i++) { if (mcu_spi_sck_list[i].pin == sck) { //if both MOSI and MISO exist, loop search normally - if ((mosi != mp_const_none) && (miso != mp_const_none)) { + if ((mosi != NULL) && (miso != NULL)) { //MOSI for (uint j = 0; j < mosi_len; j++) { if (mcu_spi_mosi_list[j].pin == mosi) { @@ -133,11 +133,11 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, self->miso = &mcu_spi_miso_list[k]; break; } - } + } } } // if just MISO, reduce search - } else if (miso != mp_const_none) { + } else if (miso != NULL) { for (uint j = 0; j < miso_len; j++) { if ((mcu_spi_miso_list[j].pin == miso) //only SCK and MISO need the same index && (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[j].spi_index)) { @@ -152,9 +152,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, self->miso = &mcu_spi_miso_list[j]; break; } - } + } // if just MOSI, reduce search - } else if (mosi != mp_const_none) { + } else if (mosi != NULL) { for (uint j = 0; j < mosi_len; j++) { if ((mcu_spi_mosi_list[j].pin == mosi) //only SCK and MOSI need the same index && (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[j].spi_index)) { @@ -169,7 +169,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, self->miso = NULL; break; } - } + } } else { //throw an error immediately mp_raise_ValueError(translate("Must provide MISO or MOSI pin")); @@ -179,8 +179,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, //handle typedef selection, errors if ( (self->sck != NULL && self->mosi != NULL && self->miso != NULL) || - (self->sck != NULL && self->mosi != NULL && miso == mp_const_none) || - (self->sck != NULL && self->miso != NULL && mosi == mp_const_none)) { + (self->sck != NULL && self->mosi != NULL && miso == NULL) || + (self->sck != NULL && self->miso != NULL && mosi == NULL)) { SPIx = mcu_spi_banks[self->sck->spi_index - 1]; } else { if (spi_taken) { @@ -196,7 +196,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = self->sck->altfn_index; + GPIO_InitStruct.Alternate = self->sck->altfn_index; HAL_GPIO_Init(pin_port(sck->port), &GPIO_InitStruct); if (self->mosi != NULL) { @@ -204,7 +204,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = self->mosi->altfn_index; + GPIO_InitStruct.Alternate = self->mosi->altfn_index; HAL_GPIO_Init(pin_port(mosi->port), &GPIO_InitStruct); } @@ -213,14 +213,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = self->miso->altfn_index; + GPIO_InitStruct.Alternate = self->miso->altfn_index; HAL_GPIO_Init(pin_port(miso->port), &GPIO_InitStruct); } spi_clock_enable(1 << (self->sck->spi_index - 1)); reserved_spi[self->sck->spi_index - 1] = true; - - self->handle.Instance = SPIx; + + self->handle.Instance = SPIx; self->handle.Init.Mode = SPI_MODE_MASTER; // Direction change only required for RX-only, see RefMan RM0090:884 self->handle.Init.Direction = (self->mosi == NULL) ? SPI_CR1_RXONLY : SPI_DIRECTION_2LINES; @@ -269,7 +269,7 @@ void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { } bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) { - return self->sck->pin == mp_const_none; + return self->sck->pin == NULL; } void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { @@ -287,15 +287,15 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { if (self->miso != NULL) { reset_pin_number(self->miso->pin->port,self->miso->pin->number); } - self->sck = mp_const_none; - self->mosi = mp_const_none; - self->miso = mp_const_none; + self->sck = NULL; + self->mosi = NULL; + self->miso = NULL; } bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { //This resets the SPI, so check before updating it redundantly - if (baudrate == self->baudrate && polarity== self->polarity + if (baudrate == self->baudrate && polarity== self->polarity && phase == self->phase && bits == self->bits) { return true; } @@ -307,7 +307,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, self->handle.Init.CLKPolarity = (polarity) ? SPI_POLARITY_HIGH : SPI_POLARITY_LOW; self->handle.Init.CLKPhase = (phase) ? SPI_PHASE_2EDGE : SPI_PHASE_1EDGE; - self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler, + self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler, get_busclock(self->handle.Instance)); if (HAL_SPI_Init(&self->handle) != HAL_OK) @@ -325,7 +325,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { bool grabbed_lock = false; - //Critical section code that may be required at some point. + //Critical section code that may be required at some point. // uint32_t store_primask = __get_PRIMASK(); // __disable_irq(); // __DMB(); @@ -367,7 +367,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self, return result == HAL_OK; } -bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, +bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) { if (self->miso == NULL || self->mosi == NULL) { mp_raise_ValueError(translate("Missing MISO or MOSI Pin")); diff --git a/ports/stm32f4/common-hal/busio/UART.c b/ports/stm32f4/common-hal/busio/UART.c index 3c1909259..0b434fd02 100644 --- a/ports/stm32f4/common-hal/busio/UART.c +++ b/ports/stm32f4/common-hal/busio/UART.c @@ -86,12 +86,12 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, bool uart_taken = false; uint8_t uart_index = 0; //origin 0 corrected - if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert == true)) { + if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert == true)) { mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device")); } - + //Can have both pins, or either - if ((tx != mp_const_none) && (rx != mp_const_none)) { + if ((tx != NULL) && (rx != NULL)) { //normal find loop if both pins exist for (uint i = 0; i < tx_len; i++) { if (mcu_uart_tx_list[i].pin == tx) { @@ -115,7 +115,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, uart_index = self->tx->uart_index - 1; USARTx = assign_uart_or_throw(self, (self->tx != NULL && self->rx != NULL), uart_index, uart_taken); - } else if (tx == mp_const_none) { + } else if (tx == NULL) { //If there is no tx, run only rx for (uint i = 0; i < rx_len; i++) { if (mcu_uart_rx_list[i].pin == rx) { @@ -132,7 +132,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, uart_index = self->rx->uart_index - 1; USARTx = assign_uart_or_throw(self, (self->rx != NULL), uart_index, uart_taken); - } else if (rx == mp_const_none) { + } else if (rx == NULL) { //If there is no rx, run only tx for (uint i = 0; i < tx_len; i++) { if (mcu_uart_tx_list[i].pin == tx) { @@ -236,7 +236,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, } bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { - return self->tx->pin == mp_const_none; + return self->tx->pin == NULL; } void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { @@ -244,8 +244,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { reset_pin_number(self->tx->pin->port,self->tx->pin->number); reset_pin_number(self->rx->pin->port,self->rx->pin->number); - self->tx = mp_const_none; - self->rx = mp_const_none; + self->tx = NULL; + self->rx = NULL; gc_free(self->rbuf.buf); self->rbuf.size = 0; self->rbuf.iput = self->rbuf.iget = 0; diff --git a/ports/stm32f4/common-hal/digitalio/DigitalInOut.c b/ports/stm32f4/common-hal/digitalio/DigitalInOut.c index 36c1075e2..be2db4dac 100644 --- a/ports/stm32f4/common-hal/digitalio/DigitalInOut.c +++ b/ports/stm32f4/common-hal/digitalio/DigitalInOut.c @@ -54,7 +54,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct( } bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { - return self->pin == mp_const_none; + return self->pin == NULL; } void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) { @@ -63,7 +63,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self } reset_pin_number(self->pin->port, self->pin->number); - self->pin = mp_const_none; + self->pin = NULL; } void common_hal_digitalio_digitalinout_switch_to_input( @@ -90,7 +90,7 @@ void common_hal_digitalio_digitalinout_switch_to_output( digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( digitalio_digitalinout_obj_t *self) { - return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number)) + return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number)) == LL_GPIO_MODE_INPUT) ? DIRECTION_INPUT : DIRECTION_OUTPUT; } @@ -111,7 +111,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode( digitalio_drive_mode_t drive_mode) { GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = pin_mask(self->pin->number); - GPIO_InitStruct.Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ? + GPIO_InitStruct.Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ? GPIO_MODE_OUTPUT_OD : GPIO_MODE_OUTPUT_PP); GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; @@ -121,7 +121,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode( digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( digitalio_digitalinout_obj_t *self) { - return LL_GPIO_GetPinOutputType(pin_port(self->pin->port), pin_mask(self->pin->number)) + return LL_GPIO_GetPinOutputType(pin_port(self->pin->port), pin_mask(self->pin->number)) == LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL; } @@ -145,7 +145,7 @@ void common_hal_digitalio_digitalinout_set_pull( digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { - + switch (LL_GPIO_GetPinPull(pin_port(self->pin->port), pin_mask(self->pin->number))) { case LL_GPIO_PULL_UP: diff --git a/ports/stm32f4/common-hal/pulseio/PWMOut.c b/ports/stm32f4/common-hal/pulseio/PWMOut.c index 50bacbb51..c23fa7462 100644 --- a/ports/stm32f4/common-hal/pulseio/PWMOut.c +++ b/ports/stm32f4/common-hal/pulseio/PWMOut.c @@ -72,7 +72,7 @@ STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) { return (duty*period) / ((1 << 16) - 1); } -STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler, +STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler, uint32_t frequency, uint32_t source_freq) { //Find the largest possible period supported by this frequency for (int i = 0; i < (1 << 16); i++) { @@ -139,7 +139,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, first_time_setup = false; //skip setting up the timer } //No problems taken, so set it up - self->tim = l_tim; + self->tim = l_tim; break; } } @@ -182,7 +182,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, uint32_t prescaler = 0; //prescaler is 15 bit uint32_t period = 0; //period is 16 bit - timer_get_optimal_divisors(&period, &prescaler, frequency, + timer_get_optimal_divisors(&period, &prescaler, frequency, timer_get_source_freq(self->tim->tim_index)); //Timer init @@ -240,7 +240,7 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { } bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { - return self->tim == mp_const_none; + return self->tim == NULL; } void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { @@ -255,7 +255,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { HAL_TIM_PWM_Stop(&self->handle, self->channel); } reset_pin_number(self->tim->pin->port,self->tim->pin->number); - self->tim = mp_const_none; + self->tim = NULL; //if reserved timer has no active channels, we can disable it if (!reserved_tim[self->tim->tim_index - 1]) { @@ -276,13 +276,13 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) { //don't halt setup for the same frequency - if (frequency == self->frequency) { + if (frequency == self->frequency) { return; } uint32_t prescaler = 0; uint32_t period = 0; - timer_get_optimal_divisors(&period, &prescaler, frequency, + timer_get_optimal_divisors(&period, &prescaler, frequency, timer_get_source_freq(self->tim->tim_index)); //shut down @@ -290,7 +290,7 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_ //Only change altered values self->handle.Init.Period = period - 1; - self->handle.Init.Prescaler = prescaler - 1; + self->handle.Init.Prescaler = prescaler - 1; //restart everything, adjusting for new speed if (HAL_TIM_PWM_Init(&self->handle) != HAL_OK) { diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index 9a9b525d8..9d1312dd8 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -63,16 +63,13 @@ STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type, mp_arg_check_num(n_args, kw_args, 1, 1, false); // 1st argument is the pin - mp_obj_t pin_obj = args[0]; - assert_pin(pin_obj, false); + const mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); analogio_analogin_obj_t *self = m_new_obj(analogio_analogin_obj_t); self->base.type = &analogio_analogin_type; - const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj); - assert_pin_free(pin); common_hal_analogio_analogin_construct(self, pin); - return (mp_obj_t) self; + return MP_OBJ_FROM_PTR(self); } //| .. method:: deinit() @@ -141,7 +138,7 @@ STATIC mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) { float reference_voltage = common_hal_analogio_analogin_get_reference_voltage(self); if (reference_voltage <= 0.0f) { - return mp_const_none; + return mp_const_none; } else { return mp_obj_new_float(reference_voltage); } diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index 0816da465..2496f1784 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -62,15 +62,13 @@ STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t // check arguments mp_arg_check_num(n_args, kw_args, 1, 1, false); - assert_pin(args[0], false); - const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(args[0]); + const mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); analogio_analogout_obj_t *self = m_new_obj(analogio_analogout_obj_t); self->base.type = &analogio_analogout_type; - assert_pin_free(pin); common_hal_analogio_analogout_construct(self, pin); - return self; + return MP_OBJ_FROM_PTR(self); } //| .. method:: deinit() diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 8f7382fde..45f703795 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -105,17 +105,9 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t bit_clock_obj = args[ARG_bit_clock].u_obj; - assert_pin(bit_clock_obj, false); - const mcu_pin_obj_t *bit_clock = MP_OBJ_TO_PTR(bit_clock_obj); - - mp_obj_t word_select_obj = args[ARG_word_select].u_obj; - assert_pin(word_select_obj, false); - const mcu_pin_obj_t *word_select = MP_OBJ_TO_PTR(word_select_obj); - - mp_obj_t data_obj = args[ARG_data].u_obj; - assert_pin(data_obj, false); - const mcu_pin_obj_t *data = MP_OBJ_TO_PTR(data_obj); + const mcu_pin_obj_t *bit_clock = validate_is_free_pin(args[ARG_bit_clock].u_obj); + const mcu_pin_obj_t *word_select = validate_is_free_pin(args[ARG_word_select].u_obj); + const mcu_pin_obj_t *data = validate_is_free_pin(args[ARG_data].u_obj); audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t); self->base.type = &audiobusio_i2sout_type; diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 0c92c2478..65bc5a9d2 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -104,15 +104,8 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t clock_pin_obj = args[ARG_clock_pin].u_obj; - assert_pin(clock_pin_obj, false); - const mcu_pin_obj_t *clock_pin = MP_OBJ_TO_PTR(clock_pin_obj); - assert_pin_free(clock_pin); - - mp_obj_t data_pin_obj = args[ARG_data_pin].u_obj; - assert_pin(data_pin_obj, false); - const mcu_pin_obj_t *data_pin = MP_OBJ_TO_PTR(data_pin_obj); - assert_pin_free(data_pin); + const mcu_pin_obj_t *clock_pin = validate_is_free_pin(args[ARG_clock_pin].u_obj); + const mcu_pin_obj_t *data_pin = validate_is_free_pin(args[ARG_data_pin].u_obj); // create PDMIn object from the given pin audiobusio_pdmin_obj_t *self = m_new_obj(audiobusio_pdmin_obj_t); diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index eb4ef1fc6..687db22d3 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -104,16 +104,8 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t left_channel_obj = args[ARG_left_channel].u_obj; - assert_pin(left_channel_obj, false); - const mcu_pin_obj_t *left_channel_pin = MP_OBJ_TO_PTR(left_channel_obj); - - mp_obj_t right_channel_obj = args[ARG_right_channel].u_obj; - const mcu_pin_obj_t *right_channel_pin = NULL; - if (right_channel_obj != mp_const_none) { - assert_pin(right_channel_obj, false); - right_channel_pin = MP_OBJ_TO_PTR(right_channel_obj); - } + const mcu_pin_obj_t *left_channel_pin = validate_is_free_pin(args[ARG_left_channel].u_obj); + const mcu_pin_obj_t *right_channel_pin = validate_is_free_pin_or_none(args[ARG_right_channel].u_obj); // create AudioOut object from the given pin audioio_audioout_obj_t *self = m_new_obj(audioio_audioout_obj_t); diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c index 60bf08500..c1c11f9cd 100644 --- a/shared-bindings/audiopwmio/PWMAudioOut.c +++ b/shared-bindings/audiopwmio/PWMAudioOut.c @@ -107,16 +107,8 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t left_channel_obj = args[ARG_left_channel].u_obj; - assert_pin(left_channel_obj, false); - const mcu_pin_obj_t *left_channel_pin = MP_OBJ_TO_PTR(left_channel_obj); - - mp_obj_t right_channel_obj = args[ARG_right_channel].u_obj; - const mcu_pin_obj_t *right_channel_pin = NULL; - if (right_channel_obj != mp_const_none) { - assert_pin(right_channel_obj, false); - right_channel_pin = MP_OBJ_TO_PTR(right_channel_obj); - } + const mcu_pin_obj_t *left_channel_pin = validate_is_free_pin(args[ARG_left_channel].u_obj); + const mcu_pin_obj_t *right_channel_pin = validate_is_free_pin_or_none(args[ARG_right_channel].u_obj) // create AudioOut object from the given pin audiopwmio_pwmaudioout_obj_t *self = m_new_obj(audiopwmio_pwmaudioout_obj_t); diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index 01a128393..bdfbfb2ca 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -63,10 +63,9 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_scl].u_obj, false); - assert_pin(args[ARG_sda].u_obj, false); - const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj); - const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj); + + const mcu_pin_obj_t* scl = validate_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_is_free_pin(args[ARG_sda].u_obj); bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t); self->base.type = &bitbangio_i2c_type; diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c index 73bedcd8d..20ca81c5d 100644 --- a/shared-bindings/bitbangio/OneWire.c +++ b/shared-bindings/bitbangio/OneWire.c @@ -69,9 +69,8 @@ STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_a }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_pin].u_obj, false); - const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); - assert_pin_free(pin); + + const mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); bitbangio_onewire_obj_t *self = m_new_obj(bitbangio_onewire_obj_t); self->base.type = &bitbangio_onewire_type; diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 9a51bde66..462352352 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -71,12 +71,10 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_clock].u_obj, false); - assert_pin(args[ARG_MOSI].u_obj, true); - assert_pin(args[ARG_MISO].u_obj, true); - const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(args[ARG_clock].u_obj); - const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(args[ARG_MOSI].u_obj); - const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(args[ARG_MISO].u_obj); + + const mcu_pin_obj_t* clock = validate_is_free_pin(args[ARG_clock].u_obj); + const mcu_pin_obj_t* mosi = validate_is_free_pin_or_none(args[ARG_MOSI].u_obj); + const mcu_pin_obj_t* miso = validate_is_free_pin_or_none(args[ARG_MISO].u_obj); bitbangio_spi_obj_t *self = m_new_obj(bitbangio_spi_obj_t); self->base.type = &bitbangio_spi_type; diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 50a95beb2..618a5ad32 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -76,12 +76,10 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_scl].u_obj, false); - assert_pin(args[ARG_sda].u_obj, false); - const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj); - assert_pin_free(scl); - const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj); - assert_pin_free(sda); + + const mcu_pin_obj_t* scl = validate_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_is_free_pin(args[ARG_sda].u_obj); + common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; } diff --git a/shared-bindings/busio/OneWire.c b/shared-bindings/busio/OneWire.c index aca2a3ef2..b28495096 100644 --- a/shared-bindings/busio/OneWire.c +++ b/shared-bindings/busio/OneWire.c @@ -69,9 +69,7 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_pin].u_obj, false); - const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); - assert_pin_free(pin); + const mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); busio_onewire_obj_t *self = m_new_obj(busio_onewire_obj_t); self->base.type = &busio_onewire_type; diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 828ffb8d0..ca84c0f24 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -89,17 +89,13 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_clock].u_obj, false); - assert_pin(args[ARG_MOSI].u_obj, true); - assert_pin(args[ARG_MISO].u_obj, true); - const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(args[ARG_clock].u_obj); - assert_pin_free(clock); - const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(args[ARG_MOSI].u_obj); - assert_pin_free(mosi); - const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(args[ARG_MISO].u_obj); - assert_pin_free(miso); + + const mcu_pin_obj_t* clock = validate_is_free_pin(args[ARG_clock].u_obj); + const mcu_pin_obj_t* mosi = validate_is_free_pin_or_none(args[ARG_MOSI].u_obj); + const mcu_pin_obj_t* miso = validate_is_free_pin_or_none(args[ARG_MISO].u_obj); + common_hal_busio_spi_construct(self, clock, mosi, miso); - return (mp_obj_t)self; + return MP_OBJ_FROM_PTR(self); } //| .. method:: deinit() diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 02c5afb16..ffa50fd7d 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -105,13 +105,12 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_rx].u_obj, true); - const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(args[ARG_rx].u_obj); - assert_pin_free(rx); + const mcu_pin_obj_t* rx = validate_is_free_pin_or_none(args[ARG_rx].u_obj); + const mcu_pin_obj_t* tx = validate_is_free_pin_or_none(args[ARG_tx].u_obj); - assert_pin(args[ARG_tx].u_obj, true); - const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(args[ARG_tx].u_obj); - assert_pin_free(tx); + if ( (tx == NULL) && (rx == NULL) ) { + mp_raise_ValueError(translate("tx and rx cannot both be None")); + } uint8_t bits = args[ARG_bits].u_int; if (bits < 7 || bits > 9) { @@ -133,12 +132,11 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); validate_timeout(timeout); - const mcu_pin_obj_t* rts = MP_OBJ_TO_PTR(args[ARG_rts].u_obj); - - const mcu_pin_obj_t* cts = MP_OBJ_TO_PTR(args[ARG_cts].u_obj); + const mcu_pin_obj_t* rts = validate_is_free_pin_or_none(args[ARG_rts].u_obj); + const mcu_pin_obj_t* cts = validate_is_free_pin_or_none(args[ARG_cts].u_obj); + const mcu_pin_obj_t* rs485_dir = validate_is_free_pin_or_none(args[ARG_rs485_dir].u_obj); - const mcu_pin_obj_t* rs485_dir = args[ARG_rs485_dir].u_obj; - bool rs485_invert = args[ARG_rs485_invert].u_bool; + const bool rs485_invert = args[ARG_rs485_invert].u_bool; common_hal_busio_uart_construct(self, tx, rx, rts, cts, rs485_dir, rs485_invert, args[ARG_baudrate].u_int, bits, parity, stop, timeout, diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 16472c12c..1610c83f8 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -68,12 +68,10 @@ STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type, digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t); self->base.type = &digitalio_digitalinout_type; - assert_pin(args[0], false); - mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(args[0]); - assert_pin_free(pin); + mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); common_hal_digitalio_digitalinout_construct(self, pin); - return (mp_obj_t)self; + return MP_OBJ_FROM_PTR(self); } //| .. method:: deinit() diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 5759e8ad2..9fa976b86 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -141,13 +141,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_init_sequence].u_obj, &bufinfo, MP_BUFFER_READ); - mp_obj_t backlight_pin_obj = args[ARG_backlight_pin].u_obj; - assert_pin(backlight_pin_obj, true); - const mcu_pin_obj_t* backlight_pin = NULL; - if (backlight_pin_obj != NULL && backlight_pin_obj != mp_const_none) { - backlight_pin = MP_OBJ_TO_PTR(backlight_pin_obj); - assert_pin_free(backlight_pin); - } + const mcu_pin_obj_t* backlight_pin = validate_is_free_pin_or_none(args[ARG_backlight_pin].u_obj); mp_float_t brightness = mp_obj_get_float(args[ARG_brightness].u_obj); diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 81e06f82f..60a3838a4 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -129,13 +129,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size mp_get_buffer_raise(args[ARG_stop_sequence].u_obj, &stop_bufinfo, MP_BUFFER_READ); - mp_obj_t busy_pin_obj = args[ARG_busy_pin].u_obj; - assert_pin(busy_pin_obj, true); - const mcu_pin_obj_t* busy_pin = NULL; - if (busy_pin_obj != NULL && busy_pin_obj != mp_const_none) { - busy_pin = MP_OBJ_TO_PTR(busy_pin_obj); - assert_pin_free(busy_pin); - } + const mcu_pin_obj_t* busy_pin = validate_is_free_pin_or_none(args[ARG_busy_pin].u_obj); mp_int_t rotation = args[ARG_rotation].u_int; if (rotation % 90 != 0) { diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index e2b924c07..349ef7e97 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -87,9 +87,7 @@ STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_pin].u_obj, false); - mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); - assert_pin_free(pin); + mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); const uint16_t capture_period = args[ARG_capture_period].u_int; diff --git a/shared-bindings/i2cslave/I2CSlave.c b/shared-bindings/i2cslave/I2CSlave.c index c98ea52e0..b7980d517 100644 --- a/shared-bindings/i2cslave/I2CSlave.c +++ b/shared-bindings/i2cslave/I2CSlave.c @@ -77,12 +77,8 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_scl].u_obj, false); - assert_pin(args[ARG_sda].u_obj, false); - const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj); - assert_pin_free(scl); - const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj); - assert_pin_free(sda); + const mcu_pin_obj_t* scl = validate_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_is_free_pin(args[ARG_sda].u_obj); mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_addresses].u_obj, &iter_buf); diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 3635f0afb..ef8008827 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -84,10 +84,35 @@ const mp_obj_type_t mcu_pin_type = { .print = mcu_pin_print }; -void assert_pin(mp_obj_t obj, bool none_ok) { - if ((obj != mp_const_none || !none_ok) && !MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) { +mcu_pin_obj_t *validate_is_pin(mp_obj_t obj) { + if (!MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) { mp_raise_TypeError_varg(translate("Expected a %q"), mcu_pin_type.name); } + return MP_OBJ_TO_PTR(obj); +} + +// Validate that the obj is a pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly. +mcu_pin_obj_t *validate_is_pin_or_none(mp_obj_t obj) { + if (obj == mp_const_none) { + return NULL; + } + return validate_is_pin(obj); +} + +mcu_pin_obj_t *validate_is_free_pin(mp_obj_t obj) { + mcu_pin_obj_t *pin = validate_is_pin(obj); + assert_pin_free(pin); + return pin; +} + +// Validate that the obj is a free pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly. +mcu_pin_obj_t *validate_is_free_pin_or_none(mp_obj_t obj) { + if (obj == mp_const_none) { + return NULL; + } + mcu_pin_obj_t *pin = validate_is_pin(obj); + assert_pin_free(pin); + return pin; } void assert_pin_free(const mcu_pin_obj_t* pin) { diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index 2d15dd5c5..2b4083827 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -33,7 +33,11 @@ // Type object used in Python. Should be shared between ports. extern const mp_obj_type_t mcu_pin_type; -void assert_pin(mp_obj_t obj, bool none_ok); +mcu_pin_obj_t *validate_is_pin(mp_obj_t obj); +mcu_pin_obj_t *validate_is_pin_or_none(mp_obj_t obj); +mcu_pin_obj_t *validate_is_free_pin(mp_obj_t obj); +mcu_pin_obj_t *validate_is_free_pin_or_none(mp_obj_t obj); + void assert_pin_free(const mcu_pin_obj_t* pin); bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin); diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c index fb5c24b85..f5aa70907 100644 --- a/shared-bindings/ps2io/Ps2.c +++ b/shared-bindings/ps2io/Ps2.c @@ -77,12 +77,9 @@ STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, con }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_clkpin].u_obj, false); - assert_pin(args[ARG_datapin].u_obj, false); - const mcu_pin_obj_t* clkpin = MP_OBJ_TO_PTR(args[ARG_clkpin].u_obj); - assert_pin_free(clkpin); - const mcu_pin_obj_t* datapin = MP_OBJ_TO_PTR(args[ARG_datapin].u_obj); - assert_pin_free(datapin); + + const mcu_pin_obj_t* clkpin = validate_is_free_pin(args[ARG_clkpin].u_obj); + const mcu_pin_obj_t* datapin = validate_is_free_pin(args[ARG_datapin].u_obj); ps2io_ps2_obj_t *self = m_new_obj(ps2io_ps2_obj_t); self->base.type = &ps2io_ps2_type; diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index 53b88c61a..d04b469c1 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -96,10 +96,7 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args mp_arg_val_t parsed_args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args); - mp_obj_t pin_obj = parsed_args[ARG_pin].u_obj; - assert_pin(pin_obj, false); - const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj); - assert_pin_free(pin); + const mcu_pin_obj_t *pin = validate_is_free_pin(parsed_args[ARG_pin].u_obj); uint16_t duty_cycle = parsed_args[ARG_duty_cycle].u_int; uint32_t frequency = parsed_args[ARG_frequency].u_int; diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 8b69109f0..dbab253af 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -90,9 +90,7 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_pin].u_obj, false); - const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj); - assert_pin_free(pin); + const mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); pulseio_pulsein_obj_t *self = m_new_obj(pulseio_pulsein_obj_t); self->base.type = &pulseio_pulsein_type; diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index f2f157847..78dccacb5 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -73,13 +73,8 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - assert_pin(args[ARG_pin_a].u_obj, false); - const mcu_pin_obj_t* pin_a = MP_OBJ_TO_PTR(args[ARG_pin_a].u_obj); - assert_pin_free(pin_a); - - assert_pin(args[ARG_pin_b].u_obj, false); - const mcu_pin_obj_t* pin_b = MP_OBJ_TO_PTR(args[ARG_pin_b].u_obj); - assert_pin_free(pin_b); + const mcu_pin_obj_t* pin_a = validate_is_free_pin(args[ARG_pin_a].u_obj); + const mcu_pin_obj_t* pin_b = validate_is_free_pin(args[ARG_pin_b].u_obj); rotaryio_incrementalencoder_obj_t *self = m_new_obj(rotaryio_incrementalencoder_obj_t); self->base.type = &rotaryio_incrementalencoder_type; diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 33d369c74..5eadb2cc4 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -66,10 +66,7 @@ STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, mp_arg_check_num(n_args, kw_args, 1, 1, false); // 1st argument is the pin - mp_obj_t pin_obj = args[0]; - assert_pin(pin_obj, false); - const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj); - assert_pin_free(pin); + const mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); touchio_touchin_obj_t *self = m_new_obj(touchio_touchin_obj_t); self->base.type = &touchio_touchin_type; diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index ac89cc691..1b7f76e12 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -78,10 +78,10 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); // TODO check type of ARG_spi? - assert_pin(args[ARG_cs].u_obj, false); - assert_pin(args[ARG_rst].u_obj, true); // may be NULL + const mcu_pin_obj_t *cs = validate_is_free_pin(args[ARG_cs].u_obj); + const mcu_pin_obj_t *rst = validate_is_free_pin_or_none(args[ARG_rst].u_obj); - mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, args[ARG_cs].u_obj, args[ARG_rst].u_obj); + mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, cs, rst); if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp(); return ret; } diff --git a/shared-module/bitbangio/SPI.c b/shared-module/bitbangio/SPI.c index d02adf34f..e0ff1184f 100644 --- a/shared-module/bitbangio/SPI.c +++ b/shared-module/bitbangio/SPI.c @@ -45,7 +45,7 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self, } common_hal_digitalio_digitalinout_switch_to_output(&self->clock, self->polarity == 1, DRIVE_MODE_PUSH_PULL); - if (mosi != mp_const_none) { + if (mosi != NULL) { result = common_hal_digitalio_digitalinout_construct(&self->mosi, mosi); if (result != DIGITALINOUT_OK) { common_hal_digitalio_digitalinout_deinit(&self->clock); @@ -55,12 +55,12 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self, common_hal_digitalio_digitalinout_switch_to_output(&self->mosi, false, DRIVE_MODE_PUSH_PULL); } - if (miso != mp_const_none) { + if (miso != NULL) { // Starts out as input by default, no need to change. result = common_hal_digitalio_digitalinout_construct(&self->miso, miso); if (result != DIGITALINOUT_OK) { common_hal_digitalio_digitalinout_deinit(&self->clock); - if (mosi != mp_const_none) { + if (mosi != NULL) { common_hal_digitalio_digitalinout_deinit(&self->mosi); } mp_raise_ValueError(translate("MISO pin init failed.")); diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index bbf177384..789318a05 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -103,12 +103,12 @@ mp_obj_t common_hal_board_create_uart(void) { #ifdef DEFAULT_UART_BUS_RTS const mcu_pin_obj_t* rts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RTS); #else - const mcu_pin_obj_t* rts = mp_const_none; + const mcu_pin_obj_t* rts = NULL; #endif #ifdef DEFAULT_UART_BUS_CTS const mcu_pin_obj_t* cts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_CTS); #else - const mcu_pin_obj_t* cts = mp_const_none; + const mcu_pin_obj_t* cts = NULL; #endif #ifdef DEFAULT_UART_IS_RS485 const mcu_pin_obj_t* rs485_dir = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RS485DIR); @@ -118,7 +118,7 @@ mp_obj_t common_hal_board_create_uart(void) { const bool rs485_invert = false; #endif #else - const mcu_pin_obj_t* rs485_dir = mp_const_none; + const mcu_pin_obj_t* rs485_dir = NULL; const bool rs485_invert = false; #endif -- cgit v1.2.3 From 817b5be320b36b9cac59b195b1c19359783fe032 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 5 Mar 2020 16:35:31 -0500 Subject: rename routines to be clearer; fix wiznet arg types --- shared-bindings/analogio/AnalogIn.c | 2 +- shared-bindings/analogio/AnalogOut.c | 2 +- shared-bindings/audiobusio/I2SOut.c | 6 +++--- shared-bindings/audiobusio/PDMIn.c | 4 ++-- shared-bindings/audioio/AudioOut.c | 4 ++-- shared-bindings/audiopwmio/PWMAudioOut.c | 4 ++-- shared-bindings/bitbangio/I2C.c | 4 ++-- shared-bindings/bitbangio/OneWire.c | 2 +- shared-bindings/bitbangio/SPI.c | 6 +++--- shared-bindings/busio/I2C.c | 4 ++-- shared-bindings/busio/OneWire.c | 2 +- shared-bindings/busio/SPI.c | 6 +++--- shared-bindings/busio/UART.c | 10 +++++----- shared-bindings/digitalio/DigitalInOut.c | 2 +- shared-bindings/displayio/Display.c | 2 +- shared-bindings/displayio/EPaperDisplay.c | 2 +- shared-bindings/displayio/FourWire.c | 6 +++--- shared-bindings/displayio/I2CDisplay.c | 2 +- shared-bindings/displayio/ParallelBus.c | 12 ++++++------ shared-bindings/frequencyio/FrequencyIn.c | 2 +- shared-bindings/i2cslave/I2CSlave.c | 4 ++-- shared-bindings/microcontroller/Pin.c | 14 +++++++------- shared-bindings/microcontroller/Pin.h | 8 ++++---- shared-bindings/ps2io/Ps2.c | 4 ++-- shared-bindings/pulseio/PWMOut.c | 2 +- shared-bindings/pulseio/PulseIn.c | 2 +- shared-bindings/rotaryio/IncrementalEncoder.c | 4 ++-- shared-bindings/touchio/TouchIn.c | 2 +- shared-bindings/wiznet/wiznet5k.c | 4 ++-- shared-module/wiznet/wiznet5k.c | 4 ++-- shared-module/wiznet/wiznet5k.h | 2 +- 31 files changed, 67 insertions(+), 67 deletions(-) (limited to 'shared-bindings/microcontroller/Pin.c') diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index 9d1312dd8..b4eeb2af1 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -63,7 +63,7 @@ STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type, mp_arg_check_num(n_args, kw_args, 1, 1, false); // 1st argument is the pin - const mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); analogio_analogin_obj_t *self = m_new_obj(analogio_analogin_obj_t); self->base.type = &analogio_analogin_type; diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index 2496f1784..89cf147b2 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -62,7 +62,7 @@ STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t // check arguments mp_arg_check_num(n_args, kw_args, 1, 1, false); - const mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); analogio_analogout_obj_t *self = m_new_obj(analogio_analogout_obj_t); self->base.type = &analogio_analogout_type; diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 45f703795..cd662acb5 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -105,9 +105,9 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t *bit_clock = validate_is_free_pin(args[ARG_bit_clock].u_obj); - const mcu_pin_obj_t *word_select = validate_is_free_pin(args[ARG_word_select].u_obj); - const mcu_pin_obj_t *data = validate_is_free_pin(args[ARG_data].u_obj); + const mcu_pin_obj_t *bit_clock = validate_obj_is_free_pin(args[ARG_bit_clock].u_obj); + const mcu_pin_obj_t *word_select = validate_obj_is_free_pin(args[ARG_word_select].u_obj); + const mcu_pin_obj_t *data = validate_obj_is_free_pin(args[ARG_data].u_obj); audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t); self->base.type = &audiobusio_i2sout_type; diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 65bc5a9d2..fce6cf7a2 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -104,8 +104,8 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t *clock_pin = validate_is_free_pin(args[ARG_clock_pin].u_obj); - const mcu_pin_obj_t *data_pin = validate_is_free_pin(args[ARG_data_pin].u_obj); + const mcu_pin_obj_t *clock_pin = validate_obj_is_free_pin(args[ARG_clock_pin].u_obj); + const mcu_pin_obj_t *data_pin = validate_obj_is_free_pin(args[ARG_data_pin].u_obj); // create PDMIn object from the given pin audiobusio_pdmin_obj_t *self = m_new_obj(audiobusio_pdmin_obj_t); diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 687db22d3..ea1efcdff 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -104,8 +104,8 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t *left_channel_pin = validate_is_free_pin(args[ARG_left_channel].u_obj); - const mcu_pin_obj_t *right_channel_pin = validate_is_free_pin_or_none(args[ARG_right_channel].u_obj); + const mcu_pin_obj_t *left_channel_pin = validate_obj_is_free_pin(args[ARG_left_channel].u_obj); + const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj); // create AudioOut object from the given pin audioio_audioout_obj_t *self = m_new_obj(audioio_audioout_obj_t); diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c index ab1d9c9fc..9fa2b1578 100644 --- a/shared-bindings/audiopwmio/PWMAudioOut.c +++ b/shared-bindings/audiopwmio/PWMAudioOut.c @@ -107,8 +107,8 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t *left_channel_pin = validate_is_free_pin(args[ARG_left_channel].u_obj); - const mcu_pin_obj_t *right_channel_pin = validate_is_free_pin_or_none(args[ARG_right_channel].u_obj); + const mcu_pin_obj_t *left_channel_pin = validate_obj_is_free_pin(args[ARG_left_channel].u_obj); + const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj); // create AudioOut object from the given pin audiopwmio_pwmaudioout_obj_t *self = m_new_obj(audiopwmio_pwmaudioout_obj_t); diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index bdfbfb2ca..3c4f13777 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -64,8 +64,8 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* scl = validate_is_free_pin(args[ARG_scl].u_obj); - const mcu_pin_obj_t* sda = validate_is_free_pin(args[ARG_sda].u_obj); + const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t); self->base.type = &bitbangio_i2c_type; diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c index 20ca81c5d..95bbd0679 100644 --- a/shared-bindings/bitbangio/OneWire.c +++ b/shared-bindings/bitbangio/OneWire.c @@ -70,7 +70,7 @@ STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_a mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); + const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); bitbangio_onewire_obj_t *self = m_new_obj(bitbangio_onewire_obj_t); self->base.type = &bitbangio_onewire_type; diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 462352352..b1a94c184 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -72,9 +72,9 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* clock = validate_is_free_pin(args[ARG_clock].u_obj); - const mcu_pin_obj_t* mosi = validate_is_free_pin_or_none(args[ARG_MOSI].u_obj); - const mcu_pin_obj_t* miso = validate_is_free_pin_or_none(args[ARG_MISO].u_obj); + const mcu_pin_obj_t* clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); + const mcu_pin_obj_t* mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj); + const mcu_pin_obj_t* miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj); bitbangio_spi_obj_t *self = m_new_obj(bitbangio_spi_obj_t); self->base.type = &bitbangio_spi_type; diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 618a5ad32..c89215acd 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -77,8 +77,8 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* scl = validate_is_free_pin(args[ARG_scl].u_obj); - const mcu_pin_obj_t* sda = validate_is_free_pin(args[ARG_sda].u_obj); + const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; diff --git a/shared-bindings/busio/OneWire.c b/shared-bindings/busio/OneWire.c index b28495096..022d6afcf 100644 --- a/shared-bindings/busio/OneWire.c +++ b/shared-bindings/busio/OneWire.c @@ -69,7 +69,7 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); + const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); busio_onewire_obj_t *self = m_new_obj(busio_onewire_obj_t); self->base.type = &busio_onewire_type; diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index ca84c0f24..043c1089d 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -90,9 +90,9 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* clock = validate_is_free_pin(args[ARG_clock].u_obj); - const mcu_pin_obj_t* mosi = validate_is_free_pin_or_none(args[ARG_MOSI].u_obj); - const mcu_pin_obj_t* miso = validate_is_free_pin_or_none(args[ARG_MISO].u_obj); + const mcu_pin_obj_t* clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); + const mcu_pin_obj_t* mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj); + const mcu_pin_obj_t* miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj); common_hal_busio_spi_construct(self, clock, mosi, miso); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index ffa50fd7d..f231924d5 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -105,8 +105,8 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* rx = validate_is_free_pin_or_none(args[ARG_rx].u_obj); - const mcu_pin_obj_t* tx = validate_is_free_pin_or_none(args[ARG_tx].u_obj); + const mcu_pin_obj_t* rx = validate_obj_is_free_pin_or_none(args[ARG_rx].u_obj); + const mcu_pin_obj_t* tx = validate_obj_is_free_pin_or_none(args[ARG_tx].u_obj); if ( (tx == NULL) && (rx == NULL) ) { mp_raise_ValueError(translate("tx and rx cannot both be None")); @@ -132,9 +132,9 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); validate_timeout(timeout); - const mcu_pin_obj_t* rts = validate_is_free_pin_or_none(args[ARG_rts].u_obj); - const mcu_pin_obj_t* cts = validate_is_free_pin_or_none(args[ARG_cts].u_obj); - const mcu_pin_obj_t* rs485_dir = validate_is_free_pin_or_none(args[ARG_rs485_dir].u_obj); + const mcu_pin_obj_t* rts = validate_obj_is_free_pin_or_none(args[ARG_rts].u_obj); + const mcu_pin_obj_t* cts = validate_obj_is_free_pin_or_none(args[ARG_cts].u_obj); + const mcu_pin_obj_t* rs485_dir = validate_obj_is_free_pin_or_none(args[ARG_rs485_dir].u_obj); const bool rs485_invert = args[ARG_rs485_invert].u_bool; diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 1610c83f8..39da00cf7 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -68,7 +68,7 @@ STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type, digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t); self->base.type = &digitalio_digitalinout_type; - mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); + mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); common_hal_digitalio_digitalinout_construct(self, pin); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 9fa976b86..991c828be 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -141,7 +141,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_init_sequence].u_obj, &bufinfo, MP_BUFFER_READ); - const mcu_pin_obj_t* backlight_pin = validate_is_free_pin_or_none(args[ARG_backlight_pin].u_obj); + const mcu_pin_obj_t* backlight_pin = validate_obj_is_free_pin_or_none(args[ARG_backlight_pin].u_obj); mp_float_t brightness = mp_obj_get_float(args[ARG_brightness].u_obj); diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 60a3838a4..25a4a41e9 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -129,7 +129,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size mp_get_buffer_raise(args[ARG_stop_sequence].u_obj, &stop_bufinfo, MP_BUFFER_READ); - const mcu_pin_obj_t* busy_pin = validate_is_free_pin_or_none(args[ARG_busy_pin].u_obj); + const mcu_pin_obj_t* busy_pin = validate_obj_is_free_pin_or_none(args[ARG_busy_pin].u_obj); mp_int_t rotation = args[ARG_rotation].u_int; if (rotation % 90 != 0) { diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c index f013cc18f..2cbceec48 100644 --- a/shared-bindings/displayio/FourWire.c +++ b/shared-bindings/displayio/FourWire.c @@ -73,9 +73,9 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mcu_pin_obj_t *command = validate_is_free_pin(args[ARG_command].u_obj); - mcu_pin_obj_t *chip_select = validate_is_free_pin(args[ARG_chip_select].u_obj); - mcu_pin_obj_t *reset = validate_is_free_pin_or_none(args[ARG_reset].u_obj); + mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj); + mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj); + mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj); displayio_fourwire_obj_t* self = NULL; mp_obj_t spi = args[ARG_spi_bus].u_obj; diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c index 03779fba9..2e312aa14 100644 --- a/shared-bindings/displayio/I2CDisplay.c +++ b/shared-bindings/displayio/I2CDisplay.c @@ -69,7 +69,7 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mcu_pin_obj_t *reset = validate_is_free_pin_or_none(args[ARG_reset].u_obj); + mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj); displayio_i2cdisplay_obj_t* self = NULL; mp_obj_t i2c = args[ARG_i2c_bus].u_obj; diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c index 33a165af9..ea1753f31 100644 --- a/shared-bindings/displayio/ParallelBus.c +++ b/shared-bindings/displayio/ParallelBus.c @@ -76,12 +76,12 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mcu_pin_obj_t *data0 = validate_is_free_pin(args[ARG_data0].u_obj); - mcu_pin_obj_t *command = validate_is_free_pin(args[ARG_command].u_obj); - mcu_pin_obj_t *chip_select = validate_is_free_pin(args[ARG_chip_select].u_obj); - mcu_pin_obj_t *write = validate_is_free_pin(args[ARG_write].u_obj); - mcu_pin_obj_t *read = validate_is_free_pin(args[ARG_read].u_obj); - mcu_pin_obj_t *reset = validate_is_free_pin(args[ARG_reset].u_obj); + mcu_pin_obj_t *data0 = validate_obj_is_free_pin(args[ARG_data0].u_obj); + mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj); + mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj); + mcu_pin_obj_t *write = validate_obj_is_free_pin(args[ARG_write].u_obj); + mcu_pin_obj_t *read = validate_obj_is_free_pin(args[ARG_read].u_obj); + mcu_pin_obj_t *reset = validate_obj_is_free_pin(args[ARG_reset].u_obj); displayio_parallelbus_obj_t* self = NULL; for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 349ef7e97..6743f8706 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -87,7 +87,7 @@ STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); + mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); const uint16_t capture_period = args[ARG_capture_period].u_int; diff --git a/shared-bindings/i2cslave/I2CSlave.c b/shared-bindings/i2cslave/I2CSlave.c index b7980d517..e28eb3f25 100644 --- a/shared-bindings/i2cslave/I2CSlave.c +++ b/shared-bindings/i2cslave/I2CSlave.c @@ -77,8 +77,8 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* scl = validate_is_free_pin(args[ARG_scl].u_obj); - const mcu_pin_obj_t* sda = validate_is_free_pin(args[ARG_sda].u_obj); + const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_addresses].u_obj, &iter_buf); diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index ef8008827..67aecaf66 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -84,7 +84,7 @@ const mp_obj_type_t mcu_pin_type = { .print = mcu_pin_print }; -mcu_pin_obj_t *validate_is_pin(mp_obj_t obj) { +mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj) { if (!MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) { mp_raise_TypeError_varg(translate("Expected a %q"), mcu_pin_type.name); } @@ -92,25 +92,25 @@ mcu_pin_obj_t *validate_is_pin(mp_obj_t obj) { } // Validate that the obj is a pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly. -mcu_pin_obj_t *validate_is_pin_or_none(mp_obj_t obj) { +mcu_pin_obj_t *validate_obj_is_pin_or_none(mp_obj_t obj) { if (obj == mp_const_none) { return NULL; } - return validate_is_pin(obj); + return validate_obj_is_pin(obj); } -mcu_pin_obj_t *validate_is_free_pin(mp_obj_t obj) { - mcu_pin_obj_t *pin = validate_is_pin(obj); +mcu_pin_obj_t *validate_obj_is_free_pin(mp_obj_t obj) { + mcu_pin_obj_t *pin = validate_obj_is_pin(obj); assert_pin_free(pin); return pin; } // Validate that the obj is a free pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly. -mcu_pin_obj_t *validate_is_free_pin_or_none(mp_obj_t obj) { +mcu_pin_obj_t *validate_obj_is_free_pin_or_none(mp_obj_t obj) { if (obj == mp_const_none) { return NULL; } - mcu_pin_obj_t *pin = validate_is_pin(obj); + mcu_pin_obj_t *pin = validate_obj_is_pin(obj); assert_pin_free(pin); return pin; } diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index 2b4083827..4f29322a0 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -33,10 +33,10 @@ // Type object used in Python. Should be shared between ports. extern const mp_obj_type_t mcu_pin_type; -mcu_pin_obj_t *validate_is_pin(mp_obj_t obj); -mcu_pin_obj_t *validate_is_pin_or_none(mp_obj_t obj); -mcu_pin_obj_t *validate_is_free_pin(mp_obj_t obj); -mcu_pin_obj_t *validate_is_free_pin_or_none(mp_obj_t obj); +mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj); +mcu_pin_obj_t *validate_obj_is_pin_or_none(mp_obj_t obj); +mcu_pin_obj_t *validate_obj_is_free_pin(mp_obj_t obj); +mcu_pin_obj_t *validate_obj_is_free_pin_or_none(mp_obj_t obj); void assert_pin_free(const mcu_pin_obj_t* pin); diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c index f5aa70907..89ed0a76c 100644 --- a/shared-bindings/ps2io/Ps2.c +++ b/shared-bindings/ps2io/Ps2.c @@ -78,8 +78,8 @@ STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, con mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* clkpin = validate_is_free_pin(args[ARG_clkpin].u_obj); - const mcu_pin_obj_t* datapin = validate_is_free_pin(args[ARG_datapin].u_obj); + const mcu_pin_obj_t* clkpin = validate_obj_is_free_pin(args[ARG_clkpin].u_obj); + const mcu_pin_obj_t* datapin = validate_obj_is_free_pin(args[ARG_datapin].u_obj); ps2io_ps2_obj_t *self = m_new_obj(ps2io_ps2_obj_t); self->base.type = &ps2io_ps2_type; diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index d04b469c1..2491a5c3f 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -96,7 +96,7 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args mp_arg_val_t parsed_args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args); - const mcu_pin_obj_t *pin = validate_is_free_pin(parsed_args[ARG_pin].u_obj); + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(parsed_args[ARG_pin].u_obj); uint16_t duty_cycle = parsed_args[ARG_duty_cycle].u_int; uint32_t frequency = parsed_args[ARG_frequency].u_int; diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index dbab253af..6c01a4c17 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -90,7 +90,7 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* pin = validate_is_free_pin(args[ARG_pin].u_obj); + const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); pulseio_pulsein_obj_t *self = m_new_obj(pulseio_pulsein_obj_t); self->base.type = &pulseio_pulsein_type; diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index 78dccacb5..058241d24 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -73,8 +73,8 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mcu_pin_obj_t* pin_a = validate_is_free_pin(args[ARG_pin_a].u_obj); - const mcu_pin_obj_t* pin_b = validate_is_free_pin(args[ARG_pin_b].u_obj); + const mcu_pin_obj_t* pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj); + const mcu_pin_obj_t* pin_b = validate_obj_is_free_pin(args[ARG_pin_b].u_obj); rotaryio_incrementalencoder_obj_t *self = m_new_obj(rotaryio_incrementalencoder_obj_t); self->base.type = &rotaryio_incrementalencoder_type; diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 5eadb2cc4..db53ec1bc 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -66,7 +66,7 @@ STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, mp_arg_check_num(n_args, kw_args, 1, 1, false); // 1st argument is the pin - const mcu_pin_obj_t *pin = validate_is_free_pin(args[0]); + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); touchio_touchin_obj_t *self = m_new_obj(touchio_touchin_obj_t); self->base.type = &touchio_touchin_type; diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index 1b7f76e12..786978bfe 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -78,8 +78,8 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); // TODO check type of ARG_spi? - const mcu_pin_obj_t *cs = validate_is_free_pin(args[ARG_cs].u_obj); - const mcu_pin_obj_t *rst = validate_is_free_pin_or_none(args[ARG_rst].u_obj); + const mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj); + const mcu_pin_obj_t *rst = validate_obj_is_free_pin_or_none(args[ARG_rst].u_obj); mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, cs, rst); if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp(); diff --git a/shared-module/wiznet/wiznet5k.c b/shared-module/wiznet/wiznet5k.c index 3c5c5f0c8..a603a5593 100644 --- a/shared-module/wiznet/wiznet5k.c +++ b/shared-module/wiznet/wiznet5k.c @@ -379,12 +379,12 @@ void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket) { } /// Create and return a WIZNET5K object. -mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) { +mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, const mcu_pin_obj_t *rst_in) { // init the wiznet5k object wiznet5k_obj.base.type = (mp_obj_type_t*)&mod_network_nic_type_wiznet5k; wiznet5k_obj.cris_state = 0; - wiznet5k_obj.spi = MP_OBJ_TO_PTR(spi_in); + wiznet5k_obj.spi = spi_in; wiznet5k_obj.socket_used = 0; wiznet5k_obj.dhcp_socket = -1; diff --git a/shared-module/wiznet/wiznet5k.h b/shared-module/wiznet/wiznet5k.h index 0154831c7..19823ae55 100644 --- a/shared-module/wiznet/wiznet5k.h +++ b/shared-module/wiznet/wiznet5k.h @@ -59,7 +59,7 @@ int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, m void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket); void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket); mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in); -mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in); +mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, const mcu_pin_obj_t *rst_in); int wiznet5k_start_dhcp(void); int wiznet5k_stop_dhcp(void); -- cgit v1.2.3 From e31e9eeaa1e1dad1bd2243b7be76012aa2ee64b8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 7 May 2020 15:59:52 -0400 Subject: Did math, microcontroller, and multiterminal --- shared-bindings/math/__init__.c | 164 ++++++++++++++-------------- shared-bindings/microcontroller/Pin.c | 19 ++-- shared-bindings/microcontroller/Processor.c | 49 ++++----- shared-bindings/microcontroller/RunMode.c | 37 +++---- shared-bindings/microcontroller/__init__.c | 78 +++++++------ shared-bindings/multiterminal/__init__.c | 32 +++--- 6 files changed, 184 insertions(+), 195 deletions(-) (limited to 'shared-bindings/microcontroller/Pin.c') diff --git a/shared-bindings/math/__init__.c b/shared-bindings/math/__init__.c index 0bf8047c9..755bf7589 100644 --- a/shared-bindings/math/__init__.c +++ b/shared-bindings/math/__init__.c @@ -38,7 +38,7 @@ #define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846) -//| :mod:`math` --- mathematical functions +//| """:mod:`math` --- mathematical functions //| ======================================================== //| //| .. module:: math @@ -46,7 +46,7 @@ //| :platform: SAMD21/SAMD51 //| //| The `math` module provides some basic mathematical functions for -//| working with floating-point numbers. +//| working with floating-point numbers.""" //| STATIC NORETURN void math_error(void) { @@ -86,117 +86,113 @@ STATIC NORETURN void math_error(void) { //| Constants //| --------- //| - //| .. data:: e + //| e: Any = ... + //| """base of the natural logarithm""" //| - //| base of the natural logarithm - //| - //| .. data:: pi - //| - //| the ratio of a circle's circumference to its diameter + //| pi: Any = ... + //| """the ratio of a circle's circumference to its diameter""" //| //| Functions //| --------- //| - //| .. function:: acos(x) - //| - //| Return the inverse cosine of ``x``. - //| - //| .. function:: asin(x) - //| - //| Return the inverse sine of ``x``. - //| - //| .. function:: atan(x) - //| - //| Return the inverse tangent of ``x``. - //| - //| .. function:: atan2(y,x) - //| - //| Return the principal value of the inverse tangent of ``y/x``. - //| - //| .. function:: ceil(x) - //| - //| Return an integer, being ``x`` rounded towards positive infinity. - //| - //| .. function:: copysign(x,y) - //| - //| Return ``x`` with the sign of ``y``. - //| - //| .. function:: cos(x) - //| - //| Return the cosine of ``x``. - //| - //| .. function:: degrees(x) - //| - //| Return radians ``x`` converted to degrees. - //| - //| .. function:: exp(x) - //| - //| Return the exponential of ``x``. - //| - //| .. function:: fabs(x) - //| - //| Return the absolute value of ``x``. - //| - //| .. function:: floor(x) - //| - //| Return an integer, being ``x`` rounded towards negative infinity. - //| - //| .. function:: fmod(x,y) - //| - //| Return the remainder of ``x/y``. - //| - //| .. function:: frexp(x) + //| def acos(x: Any) -> Any: + //| """Return the inverse cosine of ``x``.""" + //| ... //| - //| Decomposes a floating-point number into its mantissa and exponent. - //| The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e`` - //| exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise - //| the relation ``0.5 <= abs(m) < 1`` holds. + //| def asin(x: Any) -> Any: + //| """Return the inverse sine of ``x``.""" + //| ... //| - //| .. function:: isfinite(x) + //| def atan(x: Any) -> Any: + //| """Return the inverse tangent of ``x``.""" + //| ... //| - //| Return ``True`` if ``x`` is finite. + //| def atan2(y: Any, x: Any) -> Any: + //| """Return the principal value of the inverse tangent of ``y/x``.""" + //| ... //| - //| .. function:: isinf(x) + //| def ceil(x: Any) -> Any: + //| """Return an integer, being ``x`` rounded towards positive infinity.""" + //| ... //| - //| Return ``True`` if ``x`` is infinite. + //| def copysign(x: Any, y: Any) -> Any: + //| """Return ``x`` with the sign of ``y``.""" + //| ... //| - //| .. function:: isnan(x) + //| def cos(x: Any) -> Any: + //| """Return the cosine of ``x``.""" + //| ... //| - //| Return ``True`` if ``x`` is not-a-number + //| def degrees(x: Any) -> Any: + //| """Return radians ``x`` converted to degrees.""" + //| ... //| - //| .. function:: ldexp(x, exp) + //| def exp(x: Any) -> Any: + //| """Return the exponential of ``x``.""" + //| ... //| - //| Return ``x * (2**exp)``. + //| def fabs(x: Any) -> Any: + //| """Return the absolute value of ``x``.""" + //| ... //| - //| .. function:: modf(x) + //| def floor(x: Any) -> Any: + //| """Return an integer, being ``x`` rounded towards negative infinity.""" + //| ... //| - //| Return a tuple of two floats, being the fractional and integral parts of - //| ``x``. Both return values have the same sign as ``x``. + //| def fmod(x: Any, y: Any) -> Any: + //| """Return the remainder of ``x/y``.""" + //| ... //| - //| .. function:: pow(x, y) + //| def frexp(x: Any) -> Any: + //| """Decomposes a floating-point number into its mantissa and exponent. + //| The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e`` + //| exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise + //| the relation ``0.5 <= abs(m) < 1`` holds.""" + //| ... //| - //| Returns ``x`` to the power of ``y``. + //| def isfinite(x: Any) -> Any: + //| """Return ``True`` if ``x`` is finite.""" + //| ... //| - //| .. function:: radians(x) + //| def isinf(x: Any) -> Any: + //| """Return ``True`` if ``x`` is infinite.""" + //| ... //| - //| Return degrees ``x`` converted to radians. + //| def isnan(x: Any) -> Any: + //| """Return ``True`` if ``x`` is not-a-number""" + //| ... //| - //| .. function:: sin(x) + //| def ldexp(x: Any, exp: Any) -> Any: + //| """Return ``x * (2**exp)``.""" + //| ... //| - //| Return the sine of ``x``. + //| def modf(x: Any) -> Any: + //| """Return a tuple of two floats, being the fractional and integral parts of + //| ``x``. Both return values have the same sign as ``x``.""" + //| ... //| - //| .. function:: sqrt(x) + //| def pow(x: Any, y: Any) -> Any: + //| """Returns ``x`` to the power of ``y``.""" //| - //| Returns the square root of ``x``. + //| def radians(x: Any) -> Any: + //| """Return degrees ``x`` converted to radians.""" //| - //| .. function:: tan(x) + //| def sin(x: Any) -> Any: + //| """Return the sine of ``x``.""" + //| ... //| - //| Return the tangent of ``x``. + //| def sqrt(x: Any) -> Any: + //| """Returns the square root of ``x``.""" + //| ... //| - //| .. function:: trunc(x) + //| def tan(x: Any) -> Any: ... + //| """Return the tangent of ``x``.""" + //| ... //| - //| Return an integer, being ``x`` rounded towards 0. + //| def trunc(x: Any) -> Any: + //| """Return an integer, being ``x`` rounded towards 0.""" + //| ... //| MATH_FUN_1_ERRCOND(sqrt, sqrt, (x < (mp_float_t)0.0)) diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 67aecaf66..cad0d67b1 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -33,18 +33,19 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -//| .. currentmodule:: microcontroller +//| class Pin: +//| """.. currentmodule:: microcontroller //| -//| :class:`Pin` --- Pin reference -//| ------------------------------------------ +//| :class:`Pin` --- Pin reference +//| ------------------------------------------ //| -//| Identifies an IO pin on the microcontroller. +//| Identifies an IO pin on the microcontroller.""" //| -//| .. class:: Pin() -//| -//| Identifies an IO pin on the microcontroller. They are fixed by the -//| hardware so they cannot be constructed on demand. Instead, use -//| `board` or `microcontroller.pin` to reference the desired pin. +//| def __init__(self, ): +//| """Identifies an IO pin on the microcontroller. They are fixed by the +//| hardware so they cannot be constructed on demand. Instead, use +//| `board` or `microcontroller.pin` to reference the desired pin.""" +//| ... //| static void get_pin_name(const mcu_pin_obj_t *self, qstr* package, qstr* module, qstr* name) { diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index 023f063e0..dedb5a27c 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -34,29 +34,29 @@ #include "py/runtime.h" -//| .. currentmodule:: microcontroller +//| class Processor: +//| """.. currentmodule:: microcontroller //| -//| :class:`Processor` --- Microcontroller CPU information and control -//| ------------------------------------------------------------------ +//| :class:`Processor` --- Microcontroller CPU information and control +//| ------------------------------------------------------------------ //| -//| Get information about the microcontroller CPU and control it. +//| Get information about the microcontroller CPU and control it. //| -//| Usage:: +//| 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: Any = ... +//| """The CPU operating frequency as an `int`, 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 +72,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 +92,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,11 +111,10 @@ const mp_obj_property_t mcu_processor_uid_obj = { }, }; -//| .. attribute:: voltage -//| -//| The input voltage to the microcontroller, as a float. (read-only) +//| voltage: Any = ... +//| """The input voltage to the microcontroller, as a float. (read-only) //| -//| Is `None` if the voltage is not available. +//| 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(); diff --git a/shared-bindings/microcontroller/RunMode.c b/shared-bindings/microcontroller/RunMode.c index 913242ad2..df3ff4186 100644 --- a/shared-bindings/microcontroller/RunMode.c +++ b/shared-bindings/microcontroller/RunMode.c @@ -26,34 +26,31 @@ #include "shared-bindings/microcontroller/RunMode.h" -//| .. currentmodule:: microcontroller +//| class RunMode: +//| """.. currentmodule:: microcontroller //| -//| :class:`RunMode` -- run state of the microcontroller -//| ============================================================= +//| :class:`RunMode` -- run state of the microcontroller +//| =============================================================""" //| -//| .. class:: RunMode() +//| def __init__(self, ): +//| """Enum-like class to define the run mode of the microcontroller and +//| CircuitPython.""" //| -//| Enum-like class to define the run mode of the microcontroller and -//| CircuitPython. +//| NORMAL: Any = ... +//| """Run CircuitPython as normal. //| -//| .. attribute:: NORMAL +//| :type microcontroller.RunMode:""" //| -//| Run CircuitPython as normal. +//| SAFE_MODE: Any = ... +//| """Run CircuitPython in safe mode. User code will not be run and the +//| file system will be writeable over USB. //| -//| :type microcontroller.RunMode: +//| :type microcontroller.RunMode:""" //| -//| .. attribute:: SAFE_MODE +//| BOOTLOADER: Any = ... +//| """Run the bootloader. //| -//| Run CircuitPython in safe mode. User code will not be run and the -//| file system will be writeable over USB. -//| -//| :type microcontroller.RunMode: -//| -//| .. attribute:: BOOTLOADER -//| -//| Run the bootloader. -//| -//| :type microcontroller.RunMode: +//| :type microcontroller.RunMode:""" //| const mp_obj_type_t mcu_runmode_type; diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c index 090c4564d..75b763980 100644 --- a/shared-bindings/microcontroller/__init__.c +++ b/shared-bindings/microcontroller/__init__.c @@ -42,7 +42,7 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -//| :mod:`microcontroller` --- Pin references and cpu functionality +//| """:mod:`microcontroller` --- Pin references and cpu functionality //| ================================================================ //| //| .. module:: microcontroller @@ -59,24 +59,23 @@ //| //| Pin //| Processor -//| RunMode +//| RunMode""" //| -//| .. data:: cpu -//| -//| CPU information and control, such as ``cpu.temperature`` and ``cpu.frequency`` -//| (clock frequency). -//| This object is the sole instance of `microcontroller.Processor`. +//| cpu: Any = ... +//| """CPU information and control, such as ``cpu.temperature`` and ``cpu.frequency`` +//| (clock frequency). +//| This object is the sole instance of `microcontroller.Processor`.""" //| -//| .. function:: delay_us(delay) -//| -//| Dedicated delay method used for very short delays. **Do not** do long delays -//| because this stops all other functions from completing. Think of this as an empty -//| ``while`` loop that runs for the specified ``(delay)`` time. If you have other -//| code or peripherals (e.g audio recording) that require specific timing or -//| processing while you are waiting, explore a different avenue such as using -//| `time.sleep()`. +//| def delay_us(delay: Any) -> Any: +//| """Dedicated delay method used for very short delays. **Do not** do long delays +//| because this stops all other functions from completing. Think of this as an empty +//| ``while`` loop that runs for the specified ``(delay)`` time. If you have other +//| code or peripherals (e.g audio recording) that require specific timing or +//| processing while you are waiting, explore a different avenue such as using +//| `time.sleep()`.""" +//| ... //| STATIC mp_obj_t mcu_delay_us(mp_obj_t delay_obj) { uint32_t delay = mp_obj_get_int(delay_obj); @@ -87,9 +86,9 @@ STATIC mp_obj_t mcu_delay_us(mp_obj_t delay_obj) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mcu_delay_us_obj, mcu_delay_us); -//| .. function:: disable_interrupts() -//| -//| Disable all interrupts. Be very careful, this can stall everything. +//| def disable_interrupts() -> Any: +//| """Disable all interrupts. Be very careful, this can stall everything.""" +//| ... //| STATIC mp_obj_t mcu_disable_interrupts(void) { common_hal_mcu_disable_interrupts(); @@ -97,9 +96,9 @@ STATIC mp_obj_t mcu_disable_interrupts(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_disable_interrupts_obj, mcu_disable_interrupts); -//| .. function:: enable_interrupts() -//| -//| Enable the interrupts that were enabled at the last disable. +//| def enable_interrupts() -> Any: +//| """Enable the interrupts that were enabled at the last disable.""" +//| ... //| STATIC mp_obj_t mcu_enable_interrupts(void) { common_hal_mcu_enable_interrupts(); @@ -107,12 +106,12 @@ STATIC mp_obj_t mcu_enable_interrupts(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_enable_interrupts_obj, mcu_enable_interrupts); -//| .. function:: on_next_reset(run_mode) +//| def on_next_reset(run_mode: microcontroller.RunMode) -> Any: +//| """Configure the run mode used the next time the microcontroller is reset but +//| not powered down. //| -//| Configure the run mode used the next time the microcontroller is reset but -//| not powered down. -//| -//| :param ~microcontroller.RunMode run_mode: The next run mode +//| :param ~microcontroller.RunMode run_mode: The next run mode""" +//| ... //| STATIC mp_obj_t mcu_on_next_reset(mp_obj_t run_mode_obj) { mcu_runmode_t run_mode; @@ -132,14 +131,14 @@ STATIC mp_obj_t mcu_on_next_reset(mp_obj_t run_mode_obj) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mcu_on_next_reset_obj, mcu_on_next_reset); -//| .. function:: reset() -//| -//| Reset the microcontroller. After reset, the microcontroller will enter the -//| run mode last set by `on_next_reset`. +//| def reset() -> Any: +//| """Reset the microcontroller. After reset, the microcontroller will enter the +//| run mode last set by `on_next_reset`. //| -//| .. warning:: This may result in file system corruption when connected to a -//| host computer. Be very careful when calling this! Make sure the device -//| "Safely removed" on Windows or "ejected" on Mac OSX and Linux. +//| .. warning:: This may result in file system corruption when connected to a +//| host computer. Be very careful when calling this! Make sure the device +//| "Safely removed" on Windows or "ejected" on Mac OSX and Linux.""" +//| ... //| STATIC mp_obj_t mcu_reset(void) { common_hal_mcu_reset(); @@ -148,22 +147,21 @@ STATIC mp_obj_t mcu_reset(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_reset_obj, mcu_reset); -//| .. data:: nvm -//| -//| Available non-volatile memory. -//| This object is the sole instance of `nvm.ByteArray` when available or ``None`` otherwise. +//| nvm: Any = ... +//| """Available non-volatile memory. +//| This object is the sole instance of `nvm.ByteArray` when available or ``None`` otherwise. //| -//| :type: nvm.ByteArray or None +//| :type: nvm.ByteArray or None""" //| -//| :mod:`microcontroller.pin` --- Microcontroller pin names +//| """:mod:`microcontroller.pin` --- Microcontroller pin names //| -------------------------------------------------------- //| //| .. module:: microcontroller.pin //| :synopsis: Microcontroller pin names //| :platform: SAMD21 //| -//| References to pins as named by the microcontroller +//| References to pins as named by the microcontroller""" //| const mp_obj_module_t mcu_pin_module = { .base = { &mp_type_module }, diff --git a/shared-bindings/multiterminal/__init__.c b/shared-bindings/multiterminal/__init__.c index 8de3c50d7..3a4065019 100644 --- a/shared-bindings/multiterminal/__init__.c +++ b/shared-bindings/multiterminal/__init__.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -//| :mod:`multiterminal` --- Manage additional terminal sources +//| """:mod:`multiterminal` --- Manage additional terminal sources //| =========================================================== //| //| .. module:: multiterminal @@ -39,25 +39,25 @@ //| //| The `multiterminal` module allows you to configure an additional serial //| terminal source. Incoming characters are accepted from both the internal -//| serial connection and the optional secondary connection. +//| serial connection and the optional secondary connection.""" //| -//| .. function:: get_secondary_terminal() -//| -//| Returns the current secondary terminal. +//| def get_secondary_terminal() -> Any: +//| """Returns the current secondary terminal.""" +//| ... //| STATIC mp_obj_t multiterminal_obj_get_secondary_terminal() { return common_hal_multiterminal_get_secondary_terminal(); } MP_DEFINE_CONST_FUN_OBJ_0(multiterminal_get_secondary_terminal_obj, multiterminal_obj_get_secondary_terminal); -//| .. function:: set_secondary_terminal(stream) -//| -//| Read additional input from the given stream and write out back to it. +//| def set_secondary_terminal(stream: stream) -> Any: +//| """Read additional input from the given stream and write out back to it. //| This doesn't replace the core stream (usually UART or native USB) but is //| mixed in instead. //| -//| :param stream stream: secondary stream +//| :param stream stream: secondary stream""" +//| ... //| STATIC mp_obj_t multiterminal_obj_set_secondary_terminal(mp_obj_t secondary_terminal) { mp_obj_t write_m[3]; @@ -73,9 +73,9 @@ STATIC mp_obj_t multiterminal_obj_set_secondary_terminal(mp_obj_t secondary_term } MP_DEFINE_CONST_FUN_OBJ_1(multiterminal_set_secondary_terminal_obj, multiterminal_obj_set_secondary_terminal); -//| .. function:: clear_secondary_terminal() -//| -//| Clears the secondary terminal. +//| def clear_secondary_terminal() -> Any: +//| """Clears the secondary terminal.""" +//| ... //| STATIC mp_obj_t multiterminal_obj_clear_secondary_terminal() { common_hal_multiterminal_clear_secondary_terminal(); @@ -83,11 +83,11 @@ STATIC mp_obj_t multiterminal_obj_clear_secondary_terminal() { } MP_DEFINE_CONST_FUN_OBJ_0(multiterminal_clear_secondary_terminal_obj, multiterminal_obj_clear_secondary_terminal); -//| .. function:: schedule_secondary_terminal_read(socket) -//| -//| In cases where the underlying OS is doing task scheduling, this notifies +//| def schedule_secondary_terminal_read(socket: Any) -> Any: +//| """In cases where the underlying OS is doing task scheduling, this notifies //| the OS when more data is available on the socket to read. This is useful -//| as a callback for lwip sockets. +//| as a callback for lwip sockets.""" +//| ... //| // TODO(tannewt): This is a funny API. Replace it with a direct call into the OS // by the lwip object. -- cgit v1.2.3 From 4e8de3c554024d3ac89e9ee77b958a6932a64bec Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 12 May 2020 17:15:28 -0700 Subject: Swap sphinx to autoapi and the inline stubs --- .github/workflows/build.yml | 2 +- .gitignore | 2 + Makefile | 6 +- conf.py | 14 +- docs/c2rst.py | 31 -- ports/atmel-samd/README.rst | 2 +- ports/atmel-samd/bindings/samd/Clock.c | 36 +- ports/atmel-samd/bindings/samd/__init__.c | 19 +- setup.py | 8 +- shared-bindings/_bleio/Adapter.c | 5 +- shared-bindings/_bleio/Address.c | 9 +- shared-bindings/_bleio/Attribute.c | 6 +- shared-bindings/_bleio/Characteristic.c | 9 +- shared-bindings/_bleio/CharacteristicBuffer.c | 7 +- shared-bindings/_bleio/Connection.c | 14 +- shared-bindings/_bleio/Descriptor.c | 6 +- shared-bindings/_bleio/PacketBuffer.c | 26 +- shared-bindings/_bleio/ScanEntry.c | 9 +- shared-bindings/_bleio/ScanResults.c | 7 +- shared-bindings/_bleio/Service.c | 7 +- shared-bindings/_bleio/UUID.c | 9 +- shared-bindings/_bleio/__init__.c | 26 +- shared-bindings/_eve/__init__.c | 22 +- shared-bindings/_pew/PewPew.c | 7 +- shared-bindings/_pew/__init__.c | 12 +- shared-bindings/_pixelbuf/PixelBuf.c | 7 +- shared-bindings/_pixelbuf/__init__.c | 27 +- shared-bindings/_stage/Layer.c | 5 +- shared-bindings/_stage/Text.c | 7 +- shared-bindings/_stage/__init__.c | 16 +- shared-bindings/aesio/__init__.c | 17 +- shared-bindings/aesio/aes.c | 64 ++- shared-bindings/analogio/AnalogIn.c | 5 +- shared-bindings/analogio/AnalogOut.c | 7 +- shared-bindings/analogio/__init__.c | 15 +- shared-bindings/audiobusio/I2SOut.c | 7 +- shared-bindings/audiobusio/PDMIn.c | 7 +- shared-bindings/audiobusio/__init__.c | 15 +- shared-bindings/audiocore/RawSample.c | 13 +- shared-bindings/audiocore/WaveFile.c | 5 +- shared-bindings/audiocore/__init__.c | 17 +- shared-bindings/audioio/AudioOut.c | 7 +- shared-bindings/audioio/__init__.c | 14 +- shared-bindings/audiomixer/Mixer.c | 7 +- shared-bindings/audiomixer/MixerVoice.c | 5 +- shared-bindings/audiomixer/__init__.c | 16 +- shared-bindings/audiomp3/MP3Decoder.c | 7 +- shared-bindings/audiomp3/__init__.c | 15 +- shared-bindings/audiopwmio/PWMAudioOut.c | 7 +- shared-bindings/audiopwmio/__init__.c | 14 +- shared-bindings/bitbangio/I2C.c | 5 +- shared-bindings/bitbangio/OneWire.c | 5 +- shared-bindings/bitbangio/SPI.c | 5 +- shared-bindings/bitbangio/__init__.c | 16 +- shared-bindings/board/__init__.c | 6 +- shared-bindings/busio/I2C.c | 5 +- shared-bindings/busio/OneWire.c | 5 +- shared-bindings/busio/SPI.c | 7 +- shared-bindings/busio/UART.c | 5 +- shared-bindings/busio/__init__.c | 17 +- shared-bindings/digitalio/DigitalInOut.c | 5 +- shared-bindings/digitalio/Direction.c | 5 +- shared-bindings/digitalio/DriveMode.c | 5 +- shared-bindings/digitalio/Pull.c | 5 +- shared-bindings/digitalio/__init__.c | 17 +- shared-bindings/displayio/Bitmap.c | 7 +- shared-bindings/displayio/ColorConverter.c | 7 +- shared-bindings/displayio/Display.c | 5 +- shared-bindings/displayio/EPaperDisplay.c | 5 +- shared-bindings/displayio/FourWire.c | 7 +- shared-bindings/displayio/Group.c | 7 +- shared-bindings/displayio/I2CDisplay.c | 7 +- shared-bindings/displayio/OnDiskBitmap.c | 7 +- shared-bindings/displayio/Palette.c | 7 +- shared-bindings/displayio/ParallelBus.c | 7 +- shared-bindings/displayio/Shape.c | 7 +- shared-bindings/displayio/TileGrid.c | 5 +- shared-bindings/displayio/__init__.c | 27 +- shared-bindings/fontio/BuiltinFont.c | 7 +- shared-bindings/fontio/Glyph.c | 31 +- shared-bindings/fontio/__init__.c | 17 +- shared-bindings/framebufferio/FramebufferDisplay.c | 5 +- shared-bindings/framebufferio/__init__.c | 16 +- shared-bindings/frequencyio/FrequencyIn.c | 5 +- shared-bindings/frequencyio/__init__.c | 17 +- shared-bindings/gamepad/GamePad.c | 7 +- shared-bindings/gamepad/__init__.c | 12 +- shared-bindings/gamepadshift/GamePadShift.c | 5 +- shared-bindings/gamepadshift/__init__.c | 12 +- shared-bindings/help.c | 34 -- shared-bindings/help.rst | 31 ++ shared-bindings/i2cslave/I2CSlave.c | 36 +- shared-bindings/i2cslave/__init__.c | 14 +- shared-bindings/index.rst | 10 +- shared-bindings/math/__init__.c | 7 +- shared-bindings/microcontroller/Pin.c | 7 +- shared-bindings/microcontroller/Processor.c | 11 +- shared-bindings/microcontroller/RunMode.c | 5 +- shared-bindings/microcontroller/__init__.c | 20 +- shared-bindings/multiterminal/__init__.c | 7 +- shared-bindings/neopixel_write/__init__.c | 13 +- shared-bindings/network/__init__.c | 7 +- shared-bindings/nvm/ByteArray.c | 8 +- shared-bindings/nvm/__init__.c | 17 +- shared-bindings/os/__init__.c | 7 +- shared-bindings/ps2io/Ps2.c | 5 +- shared-bindings/ps2io/__init__.c | 14 +- shared-bindings/pulseio/PWMOut.c | 7 +- shared-bindings/pulseio/PulseIn.c | 12 +- shared-bindings/pulseio/PulseOut.c | 13 +- shared-bindings/pulseio/__init__.c | 16 +- shared-bindings/random/__init__.c | 7 +- shared-bindings/rgbmatrix/RGBMatrix.c | 14 +- shared-bindings/rgbmatrix/__init__.c | 11 +- shared-bindings/rotaryio/IncrementalEncoder.c | 7 +- shared-bindings/rotaryio/__init__.c | 18 +- shared-bindings/rtc/RTC.c | 13 +- shared-bindings/rtc/__init__.c | 16 +- shared-bindings/socket/__init__.c | 8 +- shared-bindings/storage/__init__.c | 7 +- shared-bindings/struct/__init__.c | 9 +- shared-bindings/supervisor/Runtime.c | 11 +- shared-bindings/supervisor/__init__.c | 30 +- shared-bindings/terminalio/Terminal.c | 5 +- shared-bindings/terminalio/__init__.c | 16 +- shared-bindings/time/__init__.c | 7 +- shared-bindings/touchio/TouchIn.c | 5 +- shared-bindings/touchio/__init__.c | 14 +- shared-bindings/uheap/__init__.c | 6 +- shared-bindings/ulab/__init__.pyi | 523 +++++++++++++++++++++ shared-bindings/ulab/__init__.rst | 523 --------------------- shared-bindings/usb_hid/Device.c | 5 +- shared-bindings/usb_hid/__init__.c | 15 +- shared-bindings/usb_midi/PortIn.c | 7 +- shared-bindings/usb_midi/PortOut.c | 5 +- shared-bindings/usb_midi/__init__.c | 17 +- shared-bindings/ustack/__init__.c | 10 +- shared-bindings/wiznet/__init__.c | 16 +- shared-bindings/wiznet/wiznet5k.c | 5 +- tools/extract_pyi.py | 12 +- 140 files changed, 860 insertions(+), 1762 deletions(-) delete mode 100644 docs/c2rst.py delete mode 100644 shared-bindings/help.c create mode 100644 shared-bindings/help.rst create mode 100644 shared-bindings/ulab/__init__.pyi delete mode 100644 shared-bindings/ulab/__init__.rst (limited to 'shared-bindings/microcontroller/Pin.c') diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3dda76db4..057395eee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: run: | sudo apt-get install -y eatmydata sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64 - pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinxcontrib-svg2pdfconverter polib pyyaml + pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml - name: Versions run: | gcc --version diff --git a/.gitignore b/.gitignore index 435ed73a7..403fcc299 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ ############ dist/ *.egg-info +.eggs # Logs and Databases ###################### @@ -51,6 +52,7 @@ _build # Generated rst files ###################### genrst/ +autoapi/ # ctags and similar ################### diff --git a/Makefile b/Makefile index aa8fc26d1..1971076a3 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ clean: rm -rf $(BUILDDIR)/* rm -rf $(STUBDIR) $(DISTDIR) *.egg-info -html: +html: stubs $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." @@ -213,8 +213,10 @@ check-translate: locale/circuitpython.pot $(wildcard locale/*.po) $(PYTHON) tools/check_translations.py $^ stubs: + mkdir -p circuitpython-stubs python tools/extract_pyi.py shared-bindings/ $(STUBDIR) - #python setup.py sdist + python tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR) + python setup.py sdist update-frozen-libraries: @echo "Updating all frozen libraries to latest tagged version." diff --git a/conf.py b/conf.py index 2e503737c..aea84dd21 100644 --- a/conf.py +++ b/conf.py @@ -55,7 +55,6 @@ extensions = [ 'sphinx.ext.todo', 'sphinx.ext.coverage', 'rstjinja', - 'c2rst', 'recommonmark', ] @@ -66,9 +65,17 @@ templates_path = ['templates'] source_suffix = { '.rst': 'restructuredtext', '.md': 'markdown', - '.c': '' } +extensions.append('autoapi.extension') + +autoapi_type = 'python' +# Uncomment this if debugging autoapi +# autoapi_keep_files = True +autoapi_dirs = ['circuitpython-stubs'] +autoapi_add_toctree_entry = False +autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary'] +autoapi_template_dir = 'docs/autoapi/templates' # The encoding of source files. #source_encoding = 'utf-8-sig' @@ -78,7 +85,7 @@ source_suffix = { # General information about the project. project = 'Adafruit CircuitPython' -copyright = '2014-2018, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)' +copyright = '2014-2020, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)' # These are overwritten on ReadTheDocs. # The version info for the project you're documenting, acts as replacement for @@ -105,6 +112,7 @@ exclude_patterns = ["**/build*", ".git", ".venv", ".direnv", + "docs/autoapi", "docs/README.md", "drivers", "examples", diff --git a/docs/c2rst.py b/docs/c2rst.py deleted file mode 100644 index 76489dca3..000000000 --- a/docs/c2rst.py +++ /dev/null @@ -1,31 +0,0 @@ -def c2rst(app, docname, source): - """ Pre-parse '.c' & '.h' files that contain rST source. - """ - # Make sure we're outputting HTML - if app.builder.format != 'html': - return - - fname = app.env.doc2path(docname) - if (not fname.endswith(".c") and - not fname.endswith(".h")): - #print("skipping:", fname) - return - - src = source[0] - - stripped = [] - for line in src.split("\n"): - line = line.strip() - if line == "//|": - stripped.append("") - elif line.startswith("//| "): - stripped.append(line[len("//| "):]) - stripped = "\r\n".join(stripped) - - rendered = app.builder.templates.render_string( - stripped, app.config.html_context - ) - source[0] = rendered - -def setup(app): - app.connect("source-read", c2rst) diff --git a/ports/atmel-samd/README.rst b/ports/atmel-samd/README.rst index 721177275..a6881902e 100644 --- a/ports/atmel-samd/README.rst +++ b/ports/atmel-samd/README.rst @@ -21,4 +21,4 @@ Port Specific modules --------------------- .. toctree:: - bindings/samd/__init__ + ../../autoapi/samd/index diff --git a/ports/atmel-samd/bindings/samd/Clock.c b/ports/atmel-samd/bindings/samd/Clock.c index b88bb82e2..24e425e8c 100644 --- a/ports/atmel-samd/bindings/samd/Clock.c +++ b/ports/atmel-samd/bindings/samd/Clock.c @@ -30,18 +30,12 @@ #include "py/objproperty.h" #include "py/runtime.h" -//| .. currentmodule:: samd +//| import typing +//| class Clock: +//| """Identifies a clock on the microcontroller. //| -//| :class:`Clock` --- Clock reference -//| ------------------------------------------ -//| -//| Identifies a clock on the microcontroller. -//| -//| .. class:: Clock -//| -//| Identifies a clock on the microcontroller. They are fixed by the -//| hardware so they cannot be constructed on demand. Instead, use -//| `samd.clock` to reference the desired clock. +//| They are fixed by the hardware so they cannot be constructed on demand. Instead, use +//| ``samd.clock`` to reference the desired clock.""" //| STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { @@ -50,9 +44,8 @@ STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print mp_printf(print, "%q.%q.%q", MP_QSTR_samd, MP_QSTR_clock, self->name); } -//| .. attribute:: enabled -//| -//| Is the clock enabled? (read-only) +//| enabled: bool = ... +//| """Is the clock enabled? (read-only)""" //| STATIC mp_obj_t samd_clock_get_enabled(mp_obj_t self_in) { samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -69,9 +62,8 @@ const mp_obj_property_t samd_clock_enabled_obj = { }, }; -//| .. attribute:: parent -//| -//| Clock parent. (read-only) +//| parent: typing.Union(Clock | None) = ... +//| """Clock parent. (read-only)""" //| STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) { samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -98,9 +90,8 @@ const mp_obj_property_t samd_clock_parent_obj = { }, }; -//| .. attribute:: frequency -//| -//| Clock frequency. (read-only) +//| frequency: int = ... +//| """Clock frequency in Herz. (read-only)""" //| STATIC mp_obj_t samd_clock_get_frequency(mp_obj_t self_in) { samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -117,9 +108,8 @@ const mp_obj_property_t samd_clock_frequency_obj = { }, }; -//| .. attribute:: calibration -//| -//| Clock calibration. Not all clocks can be calibrated. +//| calibration: int = ... +//| """Clock calibration. Not all clocks can be calibrated.""" //| STATIC mp_obj_t samd_clock_get_calibration(mp_obj_t self_in) { samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/atmel-samd/bindings/samd/__init__.c b/ports/atmel-samd/bindings/samd/__init__.c index 55a10001d..6e9b68ccc 100644 --- a/ports/atmel-samd/bindings/samd/__init__.c +++ b/ports/atmel-samd/bindings/samd/__init__.c @@ -30,29 +30,16 @@ #include "bindings/samd/Clock.h" -//| :mod:`samd` --- SAMD implementation settings -//| ================================================= -//| -//| .. module:: samd -//| :synopsis: SAMD implementation settings -//| :platform: SAMD21 -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Clock -//| +//| """SAMD implementation settings""" -//| :mod:`samd.clock` --- samd clock names +//| """:mod:`samd.clock` --- samd clock names //| -------------------------------------------------------- //| //| .. module:: samd.clock //| :synopsis: samd clock names //| :platform: SAMD21 //| -//| References to clocks as named by the microcontroller +//| References to clocks as named by the microcontroller""" //| const mp_obj_module_t samd_clock_module = { .base = { &mp_type_module }, diff --git a/setup.py b/setup.py index 1e0d81da3..37afb6f1b 100644 --- a/setup.py +++ b/setup.py @@ -5,18 +5,16 @@ from pathlib import Path stub_root = Path("circuitpython-stubs") stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")] -now = datetime.utcnow() -version = now.strftime("%Y.%m.%d") - setup( name="circuitpython-stubs", description="PEP 561 type stubs for CircuitPython", url="https://github.com/adafruit/circuitpython", maintainer="CircuitPythonistas", author_email="circuitpython@adafruit.com", - version=version, + use_scm_version=True, license="MIT", package_data={"circuitpython-stubs": stubs}, packages=["circuitpython-stubs"], - setup_requires=["setuptools>=38.6.0"], + setup_requires=["setuptools>=38.6.0", + "setuptools_scm"], ) diff --git a/shared-bindings/_bleio/Adapter.c b/shared-bindings/_bleio/Adapter.c index 6fb5c323d..4816294f7 100644 --- a/shared-bindings/_bleio/Adapter.c +++ b/shared-bindings/_bleio/Adapter.c @@ -48,10 +48,7 @@ #define WINDOW_DEFAULT (0.1f) //| class Adapter: -//| """.. currentmodule:: _bleio -//| -//| :class:`Adapter` --- BLE adapter -//| ---------------------------------------------------- +//| """BLE adapter //| //| The Adapter manages the discovery and connection to other nearby Bluetooth Low Energy devices. //| This part of the Bluetooth Low Energy Specification is known as Generic Access Profile (GAP). diff --git a/shared-bindings/_bleio/Address.c b/shared-bindings/_bleio/Address.c index 2071bd3b2..ccbab1b9d 100644 --- a/shared-bindings/_bleio/Address.c +++ b/shared-bindings/_bleio/Address.c @@ -35,12 +35,7 @@ #include "shared-module/_bleio/Address.h" //| class Address: -//| """.. currentmodule:: _bleio -//| -//| :class:`Address` -- BLE address -//| ========================================================= -//| -//| Encapsulates the address of a BLE device.""" +//| """Encapsulates the address of a BLE device.""" //| //| def __init__(self, address: buf, address_type: Any): @@ -97,7 +92,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, //| >>> _bleio.adapter.address //|
//| >>> _bleio.adapter.address.address_bytes -//| b'5\xa8\xed\xf5\x1d\xc8'""" +//| b'5\\xa8\\xed\\xf5\\x1d\\xc8'""" //| STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/_bleio/Attribute.c b/shared-bindings/_bleio/Attribute.c index 72fd13d1c..6c47c87ba 100644 --- a/shared-bindings/_bleio/Attribute.c +++ b/shared-bindings/_bleio/Attribute.c @@ -30,12 +30,8 @@ #include "shared-bindings/_bleio/UUID.h" //| class Attribute: -//| """.. currentmodule:: _bleio +//| """Definitions associated with all BLE attributes: characteristics, descriptors, etc. //| -//| :class:`Attribute` -- BLE Attribute -//| ========================================================= -//| -//| Definitions associated with all BLE attributes: characteristics, descriptors, etc. //| :py:class:`~_bleio.Attribute` is, notionally, a superclass of //| :py:class:`~Characteristic` and :py:class:`~Descriptor`, //| but is not defined as a Python superclass of those classes.""" diff --git a/shared-bindings/_bleio/Characteristic.c b/shared-bindings/_bleio/Characteristic.c index f8f18d0bd..785b677d6 100644 --- a/shared-bindings/_bleio/Characteristic.c +++ b/shared-bindings/_bleio/Characteristic.c @@ -34,13 +34,8 @@ #include "shared-bindings/_bleio/UUID.h" //| class Characteristic: -//| """.. currentmodule:: _bleio -//| -//| :class:`Characteristic` -- BLE service characteristic -//| ========================================================= -//| -//| Stores information about a BLE service characteristic and allows reading -//| and writing of the characteristic's value.""" +//| """Stores information about a BLE service characteristic and allows reading +//| and writing of the characteristic's value.""" //| //| def __init__(self, ): //| """There is no regular constructor for a Characteristic. A new local Characteristic can be created diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c index f38f650d9..6cbd587c6 100644 --- a/shared-bindings/_bleio/CharacteristicBuffer.c +++ b/shared-bindings/_bleio/CharacteristicBuffer.c @@ -42,12 +42,7 @@ STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self } //| class CharacteristicBuffer: -//| """.. currentmodule:: _bleio -//| -//| :class:`CharacteristicBuffer` -- BLE Service incoming values buffer. -//| ===================================================================== -//| -//| Accumulates a Characteristic's incoming values in a FIFO buffer.""" +//| """Accumulates a Characteristic's incoming values in a FIFO buffer.""" //| //| def __init__(self, characteristic: Characteristic, *, timeout: int = 1, buffer_size: int = 64): //| diff --git a/shared-bindings/_bleio/Connection.c b/shared-bindings/_bleio/Connection.c index 93600e76d..0a96d8a11 100644 --- a/shared-bindings/_bleio/Connection.c +++ b/shared-bindings/_bleio/Connection.c @@ -43,12 +43,7 @@ #include "shared-bindings/_bleio/Service.h" //| class Connection: -//| """.. currentmodule:: _bleio -//| -//| :class:`Connection` -- A BLE connection -//| ========================================================= -//| -//| A BLE connection to another device. Used to discover and interact with services on the other +//| """A BLE connection to another device. Used to discover and interact with services on the other //| device. //| //| Usage:: @@ -211,15 +206,14 @@ STATIC mp_obj_t bleio_connection_get_connection_interval(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_get_connection_interval_obj, bleio_connection_get_connection_interval); -//| .. attribute:: max_packet_length -//| -//| The maximum number of data bytes that can be sent in a single transmission, +//| attribute: Any = ... +//| """The maximum number of data bytes that can be sent in a single transmission, //| not including overhead bytes. //| //| This is the maximum number of bytes that can be sent in a notification, //| which must be sent in a single packet. //| But for a regular characteristic read or write, may be sent in multiple packets, -//| so this limit does not apply. +//| so this limit does not apply.""" //| STATIC mp_obj_t bleio_connection_get_max_packet_length(mp_obj_t self_in) { bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c index 00b3bacf5..9d7020849 100644 --- a/shared-bindings/_bleio/Descriptor.c +++ b/shared-bindings/_bleio/Descriptor.c @@ -34,12 +34,8 @@ #include "shared-bindings/_bleio/UUID.h" //| class Descriptor: -//| """.. currentmodule:: _bleio +//| """Stores information about a BLE descriptor. //| -//| :class:`Descriptor` -- BLE descriptor -//| ========================================================= -//| -//| Stores information about a BLE descriptor. //| Descriptors are attached to BLE characteristics and provide contextual //| information about the characteristic.""" //| diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c index 80beadb15..907bfabd2 100644 --- a/shared-bindings/_bleio/PacketBuffer.c +++ b/shared-bindings/_bleio/PacketBuffer.c @@ -36,12 +36,7 @@ #include "shared-bindings/util.h" //| class PacketBuffer: -//| """.. currentmodule:: _bleio -//| -//| :class:`PacketBuffer` -- Packet-oriented characteristic usage. -//| ===================================================================== -//| -//| Accumulates a Characteristic's incoming packets in a FIFO buffer and facilitates packet aware +//| """Accumulates a Characteristic's incoming packets in a FIFO buffer and facilitates packet aware //| outgoing writes. A packet's size is either the characteristic length or the maximum transmission //| unit (MTU) minus overhead, whichever is smaller. The MTU can change so check `incoming_packet_length` //| and `outgoing_packet_length` before creating a buffer to store data. @@ -60,7 +55,7 @@ //| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic //| in a remote Service that a Central has connected to. //| :param int buffer_size: Size of ring buffer (in packets of the Characteristic's maximum -//| length) that stores incoming packets coming from the peer. +//| length) that stores incoming packets coming from the peer.""" //| ... //| STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -126,11 +121,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_ //| """Writes all bytes from data into the same outgoing packet. The bytes from header are included //| before data when the pending packet is currently empty. //| -//| This does not block until the data is sent. It only blocks until the data is pending.""" -//| ... +//| This does not block until the data is sent. It only blocks until the data is pending. //| -//| :return: number of bytes written. May include header bytes when packet is empty. -//| :rtype: int +//| :return: number of bytes written. May include header bytes when packet is empty. +//| :rtype: int""" +//| ... //| // TODO: Add a kwarg `merge=False` to dictate whether subsequent writes are merged into a pending // one. @@ -174,7 +169,7 @@ STATIC mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_ } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_packet_buffer_write_obj, 1, bleio_packet_buffer_write); -//| def deinit(self, ) -> Any: +//| def deinit(self) -> Any: //| """Disable permanently.""" //| ... STATIC mp_obj_t bleio_packet_buffer_deinit(mp_obj_t self_in) { @@ -184,7 +179,7 @@ STATIC mp_obj_t bleio_packet_buffer_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_packet_buffer_deinit_obj, bleio_packet_buffer_deinit); -//| packet_size: Any = ... +//| packet_size: int = ... //| """`packet_size` is the same as `incoming_packet_length`. //| The name `packet_size` is deprecated and //| will be removed in CircuitPython 6.0.0.""" @@ -210,9 +205,8 @@ const mp_obj_property_t bleio_packet_buffer_incoming_packet_length_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. attribute:: outgoing_packet_length -//| -//| Maximum length in bytes of a packet we are writing. +//| outgoing_packet_length: int = ... +//| """Maximum length in bytes of a packet we are writing.""" //| STATIC mp_obj_t bleio_packet_buffer_get_outgoing_packet_length(mp_obj_t self_in) { bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/_bleio/ScanEntry.c b/shared-bindings/_bleio/ScanEntry.c index a92b247be..905bea81d 100644 --- a/shared-bindings/_bleio/ScanEntry.c +++ b/shared-bindings/_bleio/ScanEntry.c @@ -36,12 +36,7 @@ #include "shared-module/_bleio/ScanEntry.h" //| class ScanEntry: -//| """.. currentmodule:: _bleio -//| -//| :class:`ScanEntry` -- BLE scan data -//| ========================================================= -//| -//| Encapsulates information about a device that was received during scanning. It can be +//| """Encapsulates information about a device that was received during scanning. It can be //| advertisement or scan response data. This object may only be created by a `_bleio.ScanResults`: //| it has no user-visible constructor.""" //| @@ -68,7 +63,7 @@ STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - + mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_prefixes].u_obj, &bufinfo, MP_BUFFER_READ); return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, args[ARG_all].u_bool)); diff --git a/shared-bindings/_bleio/ScanResults.c b/shared-bindings/_bleio/ScanResults.c index 4b274fc68..6077dcbda 100644 --- a/shared-bindings/_bleio/ScanResults.c +++ b/shared-bindings/_bleio/ScanResults.c @@ -33,12 +33,7 @@ #include "shared-bindings/_bleio/ScanResults.h" //| class ScanResults: -//| """.. currentmodule:: _bleio -//| -//| :class:`ScanResults` -- An Iterator over BLE scanning results -//| =============================================================== -//| -//| Iterates over advertising data received while scanning. This object is always created +//| """Iterates over advertising data received while scanning. This object is always created //| by a `_bleio.Adapter`: it has no user-visible constructor.""" //| STATIC mp_obj_t scanresults_iternext(mp_obj_t self_in) { diff --git a/shared-bindings/_bleio/Service.c b/shared-bindings/_bleio/Service.c index 3526ce189..5ca7504f2 100644 --- a/shared-bindings/_bleio/Service.c +++ b/shared-bindings/_bleio/Service.c @@ -33,12 +33,7 @@ #include "shared-bindings/_bleio/UUID.h" //| class Service: -//| """.. currentmodule:: _bleio -//| -//| :class:`Service` -- BLE GATT Service -//| ========================================================= -//| -//| Stores information about a BLE service and its characteristics.""" +//| """Stores information about a BLE service and its characteristics.""" //| //| def __init__(self, uuid: UUID, *, secondary: bool = False): //| """Create a new Service identified by the specified UUID. It can be accessed by all diff --git a/shared-bindings/_bleio/UUID.c b/shared-bindings/_bleio/UUID.c index d4b0f84ca..78161b956 100644 --- a/shared-bindings/_bleio/UUID.c +++ b/shared-bindings/_bleio/UUID.c @@ -34,12 +34,7 @@ #include "shared-bindings/_bleio/UUID.h" //| class UUID: -//| """.. currentmodule:: _bleio -//| -//| :class:`UUID` -- BLE UUID -//| ========================================================= -//| -//| A 16-bit or 128-bit UUID. Can be used for services, characteristics, descriptors and more.""" +//| """A 16-bit or 128-bit UUID. Can be used for services, characteristics, descriptors and more.""" //| //| def __init__(self, value: Any): //| """Create a new UUID or UUID object encapsulating the uuid value. @@ -207,7 +202,7 @@ STATIC mp_obj_t bleio_uuid_pack_into(mp_uint_t n_args, const mp_obj_t *pos_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - + mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_WRITE); diff --git a/shared-bindings/_bleio/__init__.c b/shared-bindings/_bleio/__init__.c index da7bfdd81..90b185f79 100644 --- a/shared-bindings/_bleio/__init__.c +++ b/shared-bindings/_bleio/__init__.c @@ -41,13 +41,7 @@ #include "shared-bindings/_bleio/Service.h" #include "shared-bindings/_bleio/UUID.h" -//| """:mod:`_bleio` --- Bluetooth Low Energy (BLE) communication -//| ================================================================ -//| -//| .. module:: _bleio -//| :synopsis: Bluetooth Low Energy functionality -//| :platform: nRF -//| +//| """ //| The `_bleio` module provides necessary low-level functionality for communicating //| using Bluetooth Low Energy (BLE). The '_' prefix indicates this module is meant //| for internal use by libraries but not by the end user. Its API may change incompatibly @@ -58,24 +52,6 @@ //| provides higher-level convenience functionality, including predefined beacons, clients, //| servers. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Address -//| Adapter -//| Attribute -//| Characteristic -//| CharacteristicBuffer -//| Connection -//| Descriptor -//| PacketBuffer -//| ScanEntry -//| ScanResults -//| Service -//| UUID -//| //| .. attribute:: adapter //| //| BLE Adapter used to manage device discovery and connections. diff --git a/shared-bindings/_eve/__init__.c b/shared-bindings/_eve/__init__.c index 0e78cea16..4fa48f2c7 100644 --- a/shared-bindings/_eve/__init__.c +++ b/shared-bindings/_eve/__init__.c @@ -34,28 +34,10 @@ #include "shared-module/_eve/__init__.h" #include "shared-bindings/_eve/__init__.h" - - - - - - - - - - - - - -//| """:mod:`_eve` --- low-level BridgeTek EVE bindings -//| ================================================ -//| -//| .. module:: _eve -//| :synopsis: low-level BridgeTek EVE bindings -//| :platform: SAMD21/SAMD51 +//| """Low-level BridgeTek EVE bindings //| //| The `_eve` module provides a class _EVE which -//| contains methods for constructing EVE command +//| contains methods for constructing EVE command //| buffers and appending basic graphics commands.""" //| diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 37188d2b7..82bf04a61 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -35,12 +35,7 @@ #include "supervisor/shared/translate.h" //| class PewPew: -//| """.. currentmodule:: _pew -//| -//| :class:`PewPew` -- LED matrix and button driver -//| =============================================== -//| -//| This is an internal module to be used by the ``pew.py`` library from +//| """This is an internal module to be used by the ``pew.py`` library from //| https://github.com/pewpew-game/pew-pewpew-standalone-10.x to handle the //| LED matrix display and buttons on the ``pewpew10`` board. //| diff --git a/shared-bindings/_pew/__init__.c b/shared-bindings/_pew/__init__.c index b6aab6726..6e0070d8e 100644 --- a/shared-bindings/_pew/__init__.c +++ b/shared-bindings/_pew/__init__.c @@ -41,17 +41,7 @@ STATIC mp_obj_t get_pressed(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_pressed_obj, get_pressed); -//| """:mod:`_pew` --- LED matrix driver -//| ================================== -//| -//| .. module:: _pew -//| :synopsis: LED matrix driver -//| :platform: SAMD21 -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| PewPew""" +//| """LED matrix driver""" //| STATIC const mp_rom_map_elem_t pew_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pew) }, diff --git a/shared-bindings/_pixelbuf/PixelBuf.c b/shared-bindings/_pixelbuf/PixelBuf.c index 2d1f4fff2..71a91d707 100644 --- a/shared-bindings/_pixelbuf/PixelBuf.c +++ b/shared-bindings/_pixelbuf/PixelBuf.c @@ -45,12 +45,7 @@ extern const int32_t colorwheel(float pos); static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t* parsed); //| class PixelBuf: -//| """.. currentmodule:: _pixelbuf -//| -//| :class:`PixelBuf` -- A fast RGB[W] pixel buffer for LED and similar devices -//| =========================================================================== -//| -//| :class:`~_pixelbuf.PixelBuf` implements an RGB[W] bytearray abstraction.""" +//| """A fast RGB[W] pixel buffer for LED and similar devices.""" //| //| def __init__(self, size: int, *, byteorder: str = "BGR", brightness: float = 0, auto_write: bool = False, header: bytes = b"", trailer: bytes = b""): //| """Create a PixelBuf object of the specified size, byteorder, and bits per pixel. diff --git a/shared-bindings/_pixelbuf/__init__.c b/shared-bindings/_pixelbuf/__init__.c index 30656f1c7..bfd479fde 100644 --- a/shared-bindings/_pixelbuf/__init__.c +++ b/shared-bindings/_pixelbuf/__init__.c @@ -33,35 +33,22 @@ #include "shared-bindings/_pixelbuf/PixelBuf.h" -//| """:mod:`_pixelbuf` --- Fast RGB(W) pixel buffer and helpers -//| =========================================================== - -//| .. module:: _pixelbuf -//| :synopsis: A fast RGB(W) pixel buffer library for like NeoPixel and DotStar. +//| """A fast RGB(W) pixel buffer library for like NeoPixel and DotStar. //| //| The `_pixelbuf` module provides the :py:class:`PixelBuf` class to accelerate //| RGB(W) strip/matrix manipulation, such as DotStar and Neopixel. //| -//| Byteorders are configured with strings, such as "RGB" or "RGBD". -//| TODO: Pull in docs from pypixelbuf. +//| Byteorders are configured with strings, such as "RGB" or "RGBD".""" +// TODO: Pull in docs from pypixelbuf. -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| PixelBuf""" - -//| def colorwheel(n: Any) -> Any: ... -//| - -//| def wheel(n: Any) -> Any: +//| def colorwheel(n: int) -> Any: //| """C implementation of the common wheel() function found in many examples. //| Returns the colorwheel RGB value as an integer value for n (usable in :py:class:`PixelBuf`, neopixel, and dotstar).""" //| ... //| -//| .. function:: wheel(n) -//| Use of wheel() is deprecated. Please use colorwheel(). +//| def wheel(n: Any) -> Any: +//| """Use of wheel() is deprecated. Please use colorwheel().""" +//| STATIC mp_obj_t pixelbuf_colorwheel(mp_obj_t n) { return MP_OBJ_NEW_SMALL_INT(colorwheel(MP_OBJ_IS_SMALL_INT(n) ? MP_OBJ_SMALL_INT_VALUE(n) : mp_obj_float_get(n))); diff --git a/shared-bindings/_stage/Layer.c b/shared-bindings/_stage/Layer.c index 437114cd3..0f8260e53 100644 --- a/shared-bindings/_stage/Layer.c +++ b/shared-bindings/_stage/Layer.c @@ -31,10 +31,7 @@ #include "supervisor/shared/translate.h" //| class Layer: -//| """.. currentmodule:: _stage -//| -//| :class:`Layer` -- Keep information about a single layer of graphics -//| ===================================================================""" +//| """Keep information about a single layer of graphics""" //| //| def __init__(self, width: int, height: int, graphic: bytearray, palette: bytearray, grid: bytearray): //| """Keep internal information about a layer of graphics (either a diff --git a/shared-bindings/_stage/Text.c b/shared-bindings/_stage/Text.c index 8797f74db..b0ff1525c 100644 --- a/shared-bindings/_stage/Text.c +++ b/shared-bindings/_stage/Text.c @@ -31,13 +31,10 @@ #include "supervisor/shared/translate.h" //| class Text: -//| """.. currentmodule:: _stage -//| -//| :class:`Text` -- Keep information about a single text of text -//| ==============================================================""" +//| """Keep information about a single grid of text""" //| //| def __init__(self, width: int, height: int, font: bytearray, palette: bytearray, chars: bytearray): -//| """Keep internal information about a text of text +//| """Keep internal information about a grid of text //| in a format suitable for fast rendering //| with the ``render()`` function. //| diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 6b5c4fd8b..6a5638185 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -34,22 +34,10 @@ #include "Layer.h" #include "Text.h" -//| """:mod:`_stage` --- C-level helpers for animation of sprites on a stage -//| ===================================================================== -//| -//| .. module:: _stage -//| :synopsis: C-level helpers for animation of sprites on a stage -//| :platform: SAMD21 +//| """C-level helpers for animation of sprites on a stage //| //| The `_stage` module contains native code to speed-up the ```stage`` Library -//| `_. -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Layer -//| Text""" +//| `_.""" //| //| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> Any: //| """Render and send to the display a fragment of the screen. diff --git a/shared-bindings/aesio/__init__.c b/shared-bindings/aesio/__init__.c index 43dc73e8b..fa2a2c426 100644 --- a/shared-bindings/aesio/__init__.c +++ b/shared-bindings/aesio/__init__.c @@ -31,23 +31,10 @@ #include "__init__.h" -//| :mod:`aesio` --- AES encryption routines -//| ======================================== -//| -//| .. module:: aesio -//| :synopsis: Embedded implementation of AES +//| """AES encryption routines //| //| The `AES` module contains classes used to implement encryption -//| and decryption. It aims to be low overhead in terms of memory. -//| -//| - -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| aes +//| and decryption. It aims to be low overhead in terms of memory.""" STATIC const mp_obj_tuple_t mp_aes_key_size_obj = { diff --git a/shared-bindings/aesio/aes.c b/shared-bindings/aesio/aes.c index 4ddcfa898..7a559b0bb 100644 --- a/shared-bindings/aesio/aes.c +++ b/shared-bindings/aesio/aes.c @@ -9,35 +9,31 @@ // Defined at the end of this file -//| .. currentmodule:: aesio +//| class AES: +//| """Encrypt and decrypt AES streams""" //| -//| :class:`aesio` -- Encrypt and decrypt AES streams -//| ===================================================== +//| def __init__(self, key, mode=0, iv=None, segment_size=8) -> Any: +//| """Create a new AES state with the given key. //| -//| An object that represents an AES stream, including the current state. +//| :param bytearray key: A 16-, 24-, or 32-byte key +//| :param int mode: AES mode to use. One of: AES.MODE_ECB, AES.MODE_CBC, or +//| AES.MODE_CTR +//| :param bytearray iv: Initialization vector to use for CBC or CTR mode //| -//| .. class:: AES(key, mode=0, iv=None, segment_size=8) +//| Additional arguments are supported for legacy reasons. //| -//| Create a new AES state with the given key. +//| Encrypting a string:: //| -//| :param bytearray key: A 16-, 24-, or 32-byte key -//| :param int mode: AES mode to use. One of: AES.MODE_ECB, AES.MODE_CBC, or -//| AES.MODE_CTR -//| :param bytearray iv: Initialization vector to use for CBC or CTR mode +//| import aesio +//| from binascii import hexlify //| -//| Additional arguments are supported for legacy reasons. -//| -//| Encrypting a string:: -//| -//| import aesio -//| from binascii import hexlify -//| -//| key = b'Sixteen byte key' -//| inp = b'Circuit Python!!' # Note: 16-bytes long -//| outp = bytearray(len(inp)) -//| cipher = aesio.AES(key, aesio.mode.MODE_ECB) -//| cipher.encrypt_into(inp, outp) -//| hexlify(outp) +//| key = b'Sixteen byte key' +//| inp = b'Circuit Python!!' # Note: 16-bytes long +//| outp = bytearray(len(inp)) +//| cipher = aesio.AES(key, aesio.mode.MODE_ECB) +//| cipher.encrypt_into(inp, outp) +//| hexlify(outp)""" +//| ... //| STATIC mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args, @@ -154,12 +150,13 @@ STATIC void validate_length(aesio_aes_obj_t *self, size_t src_length, } } -//| .. method:: encrypt_into(src, dest) +//| def encrypt_into(src, dest) -> None: +//| """Encrypt the buffer from ``src`` into ``dest``. //| -//| Encrypt the buffer from ``src`` into ``dest``. -//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the -//| buffers must be a multiple of 16 bytes, and must be equal length. For -//| CTX mode, there are no restrictions. +//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the +//| buffers must be a multiple of 16 bytes, and must be equal length. For +//| CTX mode, there are no restrictions.""" +//| ... //| STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src, mp_obj_t dest) { @@ -184,12 +181,13 @@ STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src, STATIC MP_DEFINE_CONST_FUN_OBJ_3(aesio_aes_encrypt_into_obj, aesio_aes_encrypt_into); -//| .. method:: decrypt_into(src, dest) +//| def decrypt_into(src, dest) -> None: //| -//| Decrypt the buffer from ``src`` into ``dest``. -//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the -//| buffers must be a multiple of 16 bytes, and must be equal length. For -//| CTX mode, there are no restrictions. +//| """Decrypt the buffer from ``src`` into ``dest``. +//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the +//| buffers must be a multiple of 16 bytes, and must be equal length. For +//| CTX mode, there are no restrictions.""" +//| ... //| STATIC mp_obj_t aesio_aes_decrypt_into(mp_obj_t aesio_obj, mp_obj_t src, mp_obj_t dest) { diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index 2fb5051eb..bafa287ff 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -37,10 +37,7 @@ #include "shared-bindings/util.h" //| class AnalogIn: -//| """.. currentmodule:: analogio -//| -//| :class:`AnalogIn` -- read analog voltage -//| ============================================ +//| """Read analog voltage levels //| //| Usage:: //| diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index 9064bb5dc..a8edcc0ae 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class AnalogOut: -//| """.. currentmodule:: analogio -//| -//| :class:`AnalogOut` -- output analog voltage -//| ============================================ -//| -//| The AnalogOut is used to output analog values (a specific voltage). +//| """Output analog values (a specific voltage). //| //| Example usage:: //| diff --git a/shared-bindings/analogio/__init__.c b/shared-bindings/analogio/__init__.c index 79627f16a..1f059f340 100644 --- a/shared-bindings/analogio/__init__.c +++ b/shared-bindings/analogio/__init__.c @@ -34,25 +34,12 @@ #include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/analogio/AnalogOut.h" -//| """:mod:`analogio` --- Analog hardware support -//| ================================================= -//| -//| .. module:: analogio -//| :synopsis: Analog hardware support -//| :platform: SAMD21, ESP8266 +//| """Analog hardware support //| //| The `analogio` module contains classes to provide access to analog IO //| typically implemented with digital-to-analog (DAC) and analog-to-digital //| (ADC) converters. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| AnalogIn -//| AnalogOut -//| //| 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 diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 724a65a34..d965aac89 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -36,12 +36,7 @@ #include "supervisor/shared/translate.h" //| class I2SOut: -//| """.. currentmodule:: audiobusio -//| -//| :class:`I2SOut` -- Output an I2S audio signal -//| ======================================================== -//| -//| I2S is used to output an audio signal on an I2S bus.""" +//| """Output an I2S audio signal""" //| //| def __init__(self, bit_clock: microcontroller.Pin, word_select: microcontroller.Pin, data: microcontroller.Pin, *, left_justified: bool): //| """Create a I2SOut object associated with the given pins. diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 6cc834724..5b950297b 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class PDMIn: -//| """.. currentmodule:: audiobusio -//| -//| :class:`PDMIn` -- Record an input PDM audio stream -//| ======================================================== -//| -//| PDMIn can be used to record an input audio signal on a given set of pins.""" +//| """Record an input PDM audio stream""" //| //| def __init__(self, clock_pin: microcontroller.Pin, data_pin: microcontroller.Pin, *, sample_rate: int = 16000, bit_depth: int = 8, mono: bool = True, oversample: int = 64, startup_delay: float = 0.11): //| """Create a PDMIn object associated with the given pins. This allows you to diff --git a/shared-bindings/audiobusio/__init__.c b/shared-bindings/audiobusio/__init__.c index c5c387361..89ccbb88b 100644 --- a/shared-bindings/audiobusio/__init__.c +++ b/shared-bindings/audiobusio/__init__.c @@ -34,26 +34,13 @@ #include "shared-bindings/audiobusio/I2SOut.h" #include "shared-bindings/audiobusio/PDMIn.h" -//| """:mod:`audiobusio` --- Support for audio input and output over digital bus -//| ========================================================================= -//| -//| .. module:: audiobusio -//| :synopsis: Support for audio input and output over digital bus -//| :platform: SAMD21 +//| """Support for audio input and output over digital buses //| //| The `audiobusio` module contains classes to provide access to audio IO //| over digital buses. These protocols are used to communicate audio to other //| chips in the same circuit. It doesn't include audio interconnect protocols //| such as S/PDIF. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| I2SOut -//| PDMIn -//| //| All libraries change hardware state and should be deinitialized when they //| are no longer needed. To do so, either call :py:meth:`!deinit` or use a //| context manager.""" diff --git a/shared-bindings/audiocore/RawSample.c b/shared-bindings/audiocore/RawSample.c index 6091fbfc0..c0f9325e6 100644 --- a/shared-bindings/audiocore/RawSample.c +++ b/shared-bindings/audiocore/RawSample.c @@ -35,19 +35,8 @@ #include "shared-bindings/audiocore/RawSample.h" #include "supervisor/shared/translate.h" - - - - - - //| class RawSample: -//| """.. currentmodule:: audiocore -//| -//| :class:`RawSample` -- A raw audio sample buffer -//| ======================================================== -//| -//| An in-memory sound sample""" +//| """A raw audio sample buffer in memory""" //| //| def __init__(self, buffer: array.array, *, channel_count: int = 1, sample_rate: int = 8000): //| """Create a RawSample based on the given buffer of signed values. If channel_count is more than diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c index 65b42fb6c..a067f6cda 100644 --- a/shared-bindings/audiocore/WaveFile.c +++ b/shared-bindings/audiocore/WaveFile.c @@ -34,10 +34,7 @@ #include "supervisor/shared/translate.h" //| class WaveFile: -//| """.. currentmodule:: audiocore -//| -//| :class:`WaveFile` -- Load a wave file for audio playback -//| ======================================================== +//| """Load a wave file for audio playback //| //| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must //| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating diff --git a/shared-bindings/audiocore/__init__.c b/shared-bindings/audiocore/__init__.c index 38f91d8ee..b400b9454 100644 --- a/shared-bindings/audiocore/__init__.c +++ b/shared-bindings/audiocore/__init__.c @@ -35,22 +35,7 @@ #include "shared-bindings/audiocore/WaveFile.h" //#include "shared-bindings/audiomixer/Mixer.h" -//| """:mod:`audiocore` --- Support for audio samples and mixer -//| ======================================================== -//| -//| .. module:: audiocore -//| :synopsis: Support for audio samples and mixer -//| :platform: SAMD21 -//| -//| The `audiocore` module contains core classes for audio IO -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| RawSample -//| WaveFile""" +//| """Support for audio samples""" //| STATIC const mp_rom_map_elem_t audiocore_module_globals_table[] = { diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 84e5e4422..574868202 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class AudioOut: -//| """.. currentmodule:: audioio -//| -//| :class:`AudioOut` -- Output an analog audio signal -//| ======================================================== -//| -//| AudioOut can be used to output an analog audio signal on a given pin.""" +//| """Output an analog audio signal""" //| //| def __init__(self, left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 0x8000): //| """Create a AudioOut object associated with the given pin(s). This allows you to diff --git a/shared-bindings/audioio/__init__.c b/shared-bindings/audioio/__init__.c index bc2e26cfc..7ec927834 100644 --- a/shared-bindings/audioio/__init__.c +++ b/shared-bindings/audioio/__init__.c @@ -42,22 +42,10 @@ #include "shared-bindings/audiomixer/Mixer.h" #endif -//| """:mod:`audioio` --- Support for audio input and output -//| ====================================================== -//| -//| .. module:: audioio -//| :synopsis: Support for audio input and output -//| :platform: SAMD21 +//| """Support for audio output //| //| The `audioio` module contains classes to provide access to audio IO. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| AudioOut -//| //| 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 diff --git a/shared-bindings/audiomixer/Mixer.c b/shared-bindings/audiomixer/Mixer.c index 966581d45..31e62cdae 100644 --- a/shared-bindings/audiomixer/Mixer.c +++ b/shared-bindings/audiomixer/Mixer.c @@ -39,12 +39,7 @@ #include "supervisor/shared/translate.h" //| class Mixer: -//| """.. currentmodule:: audiomixer -//| -//| :class:`Mixer` -- Mixes one or more audio samples together -//| =========================================================== -//| -//| Mixer mixes multiple samples into one sample.""" +//| """Mixes one or more audio samples together into one sample.""" //| //| def __init__(self, voice_count: int = 2, buffer_size: int = 1024, channel_count: int = 2, bits_per_sample: int = 16, samples_signed: bool = True, sample_rate: int = 8000): //| """Create a Mixer object that can mix multiple channels with the same sample rate. diff --git a/shared-bindings/audiomixer/MixerVoice.c b/shared-bindings/audiomixer/MixerVoice.c index 257d9507b..ec5768d2f 100644 --- a/shared-bindings/audiomixer/MixerVoice.c +++ b/shared-bindings/audiomixer/MixerVoice.c @@ -38,10 +38,7 @@ #include "supervisor/shared/translate.h" //| class MixerVoice: -//| """.. currentmodule:: audiomixer -//| -//| :class:`MixerVoice` -- Voice objects used with Mixer -//| ===================================================== +//| """Voice objects used with Mixer //| //| Used to access and control samples with `audiomixer.Mixer`.""" //| diff --git a/shared-bindings/audiomixer/__init__.c b/shared-bindings/audiomixer/__init__.c index c90a4a0e6..1146bb798 100644 --- a/shared-bindings/audiomixer/__init__.c +++ b/shared-bindings/audiomixer/__init__.c @@ -32,21 +32,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiomixer/Mixer.h" -//| """:mod:`audiomixer` --- Support for audio mixer -//| ======================================================== -//| -//| .. module:: audiomixer -//| :synopsis: Support for audio mixer -//| -//| The `audiomixer` module contains core classes for mixing audio sources -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Mixer -//| MixerVoice""" +//| """Support for audio mixing""" //| STATIC const mp_rom_map_elem_t audiomixer_module_globals_table[] = { diff --git a/shared-bindings/audiomp3/MP3Decoder.c b/shared-bindings/audiomp3/MP3Decoder.c index d9c85bbf6..e6d48e32c 100644 --- a/shared-bindings/audiomp3/MP3Decoder.c +++ b/shared-bindings/audiomp3/MP3Decoder.c @@ -35,12 +35,7 @@ #include "supervisor/shared/translate.h" //| class MP3: -//| """.. currentmodule:: audiomp3 -//| -//| :class:`MP3Decoder` -- Load a mp3 file for audio playback -//| ========================================================= -//| -//| An object that decodes MP3 files for playback on an audio device.""" +//| """Load a mp3 file for audio playback""" //| //| def __init__(self, file: typing.BinaryIO, buffer: bytearray): //| diff --git a/shared-bindings/audiomp3/__init__.c b/shared-bindings/audiomp3/__init__.c index 50b29da52..62e5f56cb 100644 --- a/shared-bindings/audiomp3/__init__.c +++ b/shared-bindings/audiomp3/__init__.c @@ -31,20 +31,7 @@ #include "shared-bindings/audiomp3/MP3Decoder.h" -//| """:mod:`audiomp3` --- Support for MP3-compressed audio files -//| ========================================================== -//| -//| .. module:: audiomp3 -//| :synopsis: Support for mp3 files -//| -//| The `audiomp3` module contains an mp3 decoder -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| MP3Decoder""" +//| """Support for MP3-compressed audio files""" //| STATIC const mp_rom_map_elem_t audiomp3_module_globals_table[] = { diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c index 17f82e3f6..d6b102317 100644 --- a/shared-bindings/audiopwmio/PWMAudioOut.c +++ b/shared-bindings/audiopwmio/PWMAudioOut.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class PWMAudioOut: -//| """.. currentmodule:: audiopwmio -//| -//| :class:`PWMAudioOut` -- Output an analog audio signal -//| ======================================================== -//| -//| AudioOut can be used to output an analog audio signal on a given pin.""" +//| """Output an analog audio signal by varying the PWM duty cycle.""" //| //| def __init__(self, left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 0x8000): //| """Create a PWMAudioOut object associated with the given pin(s). This allows you to diff --git a/shared-bindings/audiopwmio/__init__.c b/shared-bindings/audiopwmio/__init__.c index 74d22b45e..5caea1420 100644 --- a/shared-bindings/audiopwmio/__init__.c +++ b/shared-bindings/audiopwmio/__init__.c @@ -33,22 +33,10 @@ #include "shared-bindings/audiopwmio/__init__.h" #include "shared-bindings/audiopwmio/PWMAudioOut.h" -//| """:mod:`audiopwmio` --- Support for audio input and output -//| ======================================================== -//| -//| .. module:: audiopwmio -//| :synopsis: Support for audio output via digital PWM -//| :platform: NRF52 +//| """Audio output via digital PWM //| //| The `audiopwmio` module contains classes to provide access to audio IO. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| PWMAudioOut -//| //| 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 diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index a682e050e..2043fc903 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -38,10 +38,7 @@ #include "supervisor/shared/translate.h" //| class I2C: -//| """.. currentmodule:: bitbangio -//| -//| :class:`I2C` --- Two wire serial protocol -//| ------------------------------------------""" +//| """Two wire serial protocol""" //| //| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 400000, timeout: int): //| """I2C is a two-wire protocol for communicating between devices. At the diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c index 1c9405bd8..a236f4c2a 100644 --- a/shared-bindings/bitbangio/OneWire.c +++ b/shared-bindings/bitbangio/OneWire.c @@ -35,10 +35,7 @@ #include "shared-bindings/util.h" //| class OneWire: -//| """.. currentmodule:: bitbangio -//| -//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol -//| =============================================================== +//| """Lowest-level of the Maxim OneWire protocol //| //| :class:`~bitbangio.OneWire` implements the timing-sensitive foundation of //| the Maxim (formerly Dallas Semi) OneWire protocol. diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 38e0926e8..08bbf1257 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -40,10 +40,7 @@ #include "supervisor/shared/translate.h" //| class SPI: -//| """.. currentmodule:: bitbangio -//| -//| :class:`SPI` -- a 3-4 wire serial protocol -//| ----------------------------------------------- +//| """A 3-4 wire serial protocol //| //| SPI is a serial protocol that has exclusive pins for data in and out of the //| master. It is typically faster than :py:class:`~bitbangio.I2C` because a diff --git a/shared-bindings/bitbangio/__init__.c b/shared-bindings/bitbangio/__init__.c index e9600a7e6..e04bdf701 100644 --- a/shared-bindings/bitbangio/__init__.c +++ b/shared-bindings/bitbangio/__init__.c @@ -40,12 +40,7 @@ #include "py/runtime.h" -//| """:mod:`bitbangio` --- Digital protocols implemented by the CPU -//| ============================================================= -//| -//| .. module:: bitbangio -//| :synopsis: Digital protocols implemented by the CPU -//| :platform: SAMD21, ESP8266 +//| """Digital protocols implemented by the CPU //| //| The `bitbangio` module contains classes to provide digital bus protocol //| support regardless of whether the underlying hardware exists to use the @@ -55,15 +50,6 @@ //| hardware to implement the protocols. Native implementations will be faster //| than bitbanged versions and have more capabilities. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| I2C -//| OneWire -//| SPI -//| //| 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 diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 77675e093..010a9fb92 100644 --- a/shared-bindings/board/__init__.c +++ b/shared-bindings/board/__init__.c @@ -29,11 +29,7 @@ #include "shared-bindings/board/__init__.h" -//| """:mod:`board` --- Board specific pin names -//| ======================================================== -//| -//| .. module:: board -//| :synopsis: Board specific pin names +//| """Board specific pin names //| //| Common container for board base pin names. These will vary from board to //| board so don't expect portability when using this module. diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 8ae3658ee..7e8af765f 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -37,10 +37,7 @@ #include "supervisor/shared/translate.h" //| class I2C: -//| """.. currentmodule:: busio -//| -//| :class:`I2C` --- Two wire serial protocol -//| ------------------------------------------""" +//| """Two wire serial protocol""" //| //| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 400000, timeout: int = 255): //| diff --git a/shared-bindings/busio/OneWire.c b/shared-bindings/busio/OneWire.c index 556e567ef..723cc031a 100644 --- a/shared-bindings/busio/OneWire.c +++ b/shared-bindings/busio/OneWire.c @@ -35,10 +35,7 @@ #include "shared-bindings/util.h" //| class OneWire: -//| """.. currentmodule:: busio -//| -//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol -//| =================================================================""" +//| """Lowest-level of the Maxim OneWire protocol""" //| //| def __init__(self, pin: microcontroller.Pin): //| """(formerly Dallas Semi) OneWire protocol. diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 5b1881702..2ba9a4c22 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -42,10 +42,7 @@ //| class SPI: -//| """.. currentmodule:: busio -//| -//| `SPI` -- a 3-4 wire serial protocol -//| ----------------------------------------------- +//| """A 3-4 wire serial protocol //| //| SPI is a serial protocol that has exclusive pins for data in and out of the //| master. It is typically faster than :py:class:`~busio.I2C` because a @@ -147,7 +144,7 @@ STATIC void check_for_deinit(busio_spi_obj_t *self) { //| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any: //| """Configures the SPI bus. The SPI object must be locked. //| -//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower +//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower //| due to the granularity of available clock settings. //| Check the `frequency` attribute for the actual clock rate. //| :param int polarity: the base state of the clock line (0 or 1) diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 5984194a9..d4642225c 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -43,10 +43,7 @@ // #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) //| class UART: -//| """.. currentmodule:: busio -//| -//| :class:`UART` -- a bidirectional serial protocol -//| =================================================""" +//| """A bidirectional serial protocol""" //| def __init__(self, tx: microcontroller.Pin, rx: microcontroller.Pin, *, baudrate: int = 9600, bits: int = 8, parity: Parity = None, stop: int = 1, timeout: float = 1, receiver_buffer_size: int = 64): //| """A common bidirectional serial protocol that uses an an agreed upon speed //| rather than a shared clock line. diff --git a/shared-bindings/busio/__init__.c b/shared-bindings/busio/__init__.c index 212b3218c..04632c2f4 100644 --- a/shared-bindings/busio/__init__.c +++ b/shared-bindings/busio/__init__.c @@ -38,12 +38,7 @@ #include "py/runtime.h" -//| """:mod:`busio` --- Hardware accelerated behavior -//| ================================================= -//| -//| .. module:: busio -//| :synopsis: Hardware accelerated behavior -//| :platform: SAMD21 +//| """Hardware accelerated external bus access //| //| The `busio` module contains classes to support a variety of serial //| protocols. @@ -54,16 +49,6 @@ //| then a RuntimeError will be raised. Use the `bitbangio` module to explicitly //| bitbang a serial protocol on any general purpose pins. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| I2C -//| OneWire -//| SPI -//| UART -//| //| 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 diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 5fffb3f65..54ced099d 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -44,10 +44,7 @@ #include "supervisor/shared/translate.h" //| class DigitalInOut: -//| """.. currentmodule:: digitalio -//| -//| :class:`DigitalInOut` -- digital input and output -//| ========================================================= +//| """Digital input and output //| //| A DigitalInOut is used to digitally control I/O pins. For analog control of //| a pin, see the :py:class:`analogio.AnalogIn` and diff --git a/shared-bindings/digitalio/Direction.c b/shared-bindings/digitalio/Direction.c index 0586e95de..dbd0e93e4 100644 --- a/shared-bindings/digitalio/Direction.c +++ b/shared-bindings/digitalio/Direction.c @@ -39,10 +39,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" //| class Direction: -//| """.. currentmodule:: digitalio -//| -//| :class:`Direction` -- defines the direction of a digital pin -//| =============================================================""" +//| """Defines the direction of a digital pin""" //| //| def __init__(self, ): //| """Enum-like class to define which direction the digital values are diff --git a/shared-bindings/digitalio/DriveMode.c b/shared-bindings/digitalio/DriveMode.c index 23745b046..31b682d38 100644 --- a/shared-bindings/digitalio/DriveMode.c +++ b/shared-bindings/digitalio/DriveMode.c @@ -27,10 +27,7 @@ #include "shared-bindings/digitalio/DriveMode.h" //| class DriveMode: -//| """.. currentmodule:: digitalio -//| -//| :class:`DriveMode` -- defines the drive mode of a digital pin -//| =============================================================""" +//| """Defines the drive mode of a digital pin""" //| //| def __init__(self, ): //| """Enum-like class to define the drive mode used when outputting diff --git a/shared-bindings/digitalio/Pull.c b/shared-bindings/digitalio/Pull.c index 1e64d0788..9aeec1f33 100644 --- a/shared-bindings/digitalio/Pull.c +++ b/shared-bindings/digitalio/Pull.c @@ -27,10 +27,7 @@ #include "shared-bindings/digitalio/Pull.h" //| class Pull: -//| """.. currentmodule:: digitalio -//| -//| :class:`Pull` -- defines the pull of a digital input pin -//| =============================================================""" +//| """Defines the pull of a digital input pin""" //| //| def __init__(self, ): //| """Enum-like class to define the pull value, if any, used while reading diff --git a/shared-bindings/digitalio/__init__.c b/shared-bindings/digitalio/__init__.c index 5a11436a2..f8f45b158 100644 --- a/shared-bindings/digitalio/__init__.c +++ b/shared-bindings/digitalio/__init__.c @@ -38,25 +38,10 @@ #include "py/runtime.h" -//| """:mod:`digitalio` --- Basic digital pin support -//| ================================================= -//| -//| .. module:: digitalio -//| :synopsis: Basic digital pin support -//| :platform: SAMD21, ESP8266 +//| """Basic digital pin support //| //| The `digitalio` module contains classes to provide access to basic digital IO. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| DigitalInOut -//| Direction -//| DriveMode -//| Pull -//| //| 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 diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index d15c3b107..a52840f2e 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class Bitmap: -//| """.. currentmodule:: displayio -//| -//| :class:`Bitmap` -- Stores values in a 2D array -//| ========================================================================== -//| -//| Stores values of a certain size in a 2D array""" +//| """Stores values of a certain size in a 2D array""" //| //| def __init__(self, width: int, height: int, value_count: int): //| """Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index 1d6e5a0cc..505e9f766 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class ColorConverter: -//| """.. currentmodule:: displayio -//| -//| :class:`ColorConverter` -- Converts one color format to another -//| ========================================================================================= -//| -//| Converts one color format to another.""" +//| """Converts one color format to another.""" //| //| def __init__(self, *, dither: bool = False): //| """Create a ColorConverter object to convert color formats. Only supports RGB888 to RGB565 diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 12abec1c8..62ef0f5d0 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -40,10 +40,7 @@ #include "supervisor/shared/translate.h" //| class Display: -//| """.. currentmodule:: displayio -//| -//| :class:`Display` -- Manage updating a display over a display bus -//| ========================================================================== +//| """Manage updating a display over a display bus //| //| This initializes a display and connects it into CircuitPython. Unlike other //| objects in CircuitPython, Display objects live until `displayio.release_displays()` diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 8b03ddc06..8b77e4df3 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -40,10 +40,7 @@ #include "supervisor/shared/translate.h" //| class EPaperDisplay: -//| """.. currentmodule:: displayio -//| -//| :class:`EPaperDisplay` -- Manage updating an epaper display over a display bus -//| ============================================================================== +//| """Manage updating an epaper display over a display bus //| //| This initializes an epaper display and connects it into CircuitPython. Unlike other //| objects in CircuitPython, EPaperDisplay objects live until `displayio.release_displays()` diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c index 649045039..5ee4ec5a9 100644 --- a/shared-bindings/displayio/FourWire.c +++ b/shared-bindings/displayio/FourWire.c @@ -39,12 +39,7 @@ #include "supervisor/shared/translate.h" //| class FourWire: -//| """.. currentmodule:: displayio -//| -//| :class:`FourWire` -- Manage updating a display over SPI four wire protocol -//| ========================================================================== -//| -//| Manage updating a display over SPI four wire protocol in the background while Python code runs. +//| """Manage updating a display over SPI four wire protocol in the background while Python code runs. //| It doesn't handle display initialization.""" //| //| def __init__(self, spi_bus: busio.SPI, *, command: microcontroller.Pin, chip_select: microcontroller.Pin, reset: microcontroller.Pin = None, baudrate: int = 24000000, polarity: int = 0, phase: int = 0): diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 36e137dc9..b6f96883b 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -36,12 +36,7 @@ #include "supervisor/shared/translate.h" //| class Group: -//| """.. currentmodule:: displayio -//| -//| :class:`Group` -- Group together sprites and subgroups -//| ========================================================================== -//| -//| Manage a group of sprites and groups and how they are inter-related.""" +//| """Manage a group of sprites and groups and how they are inter-related.""" //| //| def __init__(self, *, max_size: int = 4, scale: int = 1, x: int = 0, y: int = 0): //| """Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2 diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c index e2402dc49..0cfac6672 100644 --- a/shared-bindings/displayio/I2CDisplay.c +++ b/shared-bindings/displayio/I2CDisplay.c @@ -39,12 +39,7 @@ #include "supervisor/shared/translate.h" //| class I2CDisplay: -//| """.. currentmodule:: displayio -//| -//| :class:`I2CDisplay` -- Manage updating a display over I2C -//| ========================================================================== -//| -//| Manage updating a display over I2C in the background while Python code runs. +//| """Manage updating a display over I2C in the background while Python code runs. //| It doesn't handle display initialization.""" //| //| def __init__(self, i2c_bus: busio.I2C, *, device_address: int, reset: microcontroller.Pin = None): diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index 95c890c3b..170873653 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -34,12 +34,7 @@ #include "shared-bindings/displayio/OnDiskBitmap.h" //| class OnDiskBitmap: -//| """.. currentmodule:: displayio -//| -//| :class:`OnDiskBitmap` -- Loads pixels straight from disk -//| ========================================================================== -//| -//| Loads values straight from disk. This minimizes memory use but can lead to +//| """Loads values straight from disk. This minimizes memory use but can lead to //| much slower pixel load times. These load times may result in frame tearing where only part of //| the image is visible. //| diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 5df11d2b1..871b2b06a 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -43,12 +43,7 @@ //| class Palette: -//| """.. currentmodule:: displayio -//| -//| :class:`Palette` -- Stores a mapping from bitmap pixel palette_indexes to display colors -//| ========================================================================================= -//| -//| Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to +//| """Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to //| save memory.""" //| //| def __init__(self, color_count: int): diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c index cedcf1de5..eb75ecc03 100644 --- a/shared-bindings/displayio/ParallelBus.c +++ b/shared-bindings/displayio/ParallelBus.c @@ -38,12 +38,7 @@ #include "supervisor/shared/translate.h" //| class ParallelBus: -//| """.. currentmodule:: displayio -//| -//| :class:`ParallelBus` -- Manage updating a display over 8-bit parallel bus -//| ============================================================================== -//| -//| Manage updating a display over 8-bit parallel bus in the background while Python code runs. This +//| """Manage updating a display over 8-bit parallel bus in the background while Python code runs. This //| protocol may be refered to as 8080-I Series Parallel Interface in datasheets. It doesn't handle //| display initialization.""" //| diff --git a/shared-bindings/displayio/Shape.c b/shared-bindings/displayio/Shape.c index 0f22bb2a3..fce89c771 100644 --- a/shared-bindings/displayio/Shape.c +++ b/shared-bindings/displayio/Shape.c @@ -35,12 +35,7 @@ #include "supervisor/shared/translate.h" //| class Shape: -//| """.. currentmodule:: displayio -//| -//| :class:`Shape` -- Represents a shape by defining its bounds on each row -//| ========================================================================== -//| -//| Represents any shape made by defining boundaries that may be mirrored.""" +//| """Represents a shape made by defining boundaries that may be mirrored.""" //| //| def __init__(self, width: int, height: int, *, mirror_x: bool = False, mirror_y: bool = False): //| """Create a Shape object with the given fixed size. Each pixel is one bit and is stored by the diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index e7410e4b6..01fba46a5 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -41,10 +41,7 @@ #include "supervisor/shared/translate.h" //| class TileGrid: -//| """.. currentmodule:: displayio -//| -//| :class:`TileGrid` -- A grid of tiles sourced out of one bitmap -//| ========================================================================== +//| """A grid of tiles sourced out of one bitmap //| //| Position a grid of tiles sourced from a bitmap and pixel_shader combination. Multiple grids //| can share bitmaps and pixel shaders. diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 37c025329..b791336b5 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -43,33 +43,10 @@ #include "shared-bindings/displayio/Shape.h" #include "shared-bindings/displayio/TileGrid.h" -//| """:mod:`displayio` --- Native display driving -//| ========================================================================= -//| -//| .. module:: displayio -//| :synopsis: Native helpers for driving displays -//| :platform: SAMD21, SAMD51, nRF52 +//| """Native helpers for driving displays //| //| The `displayio` module contains classes to manage display output -//| including synchronizing with refresh rates and partial updating. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Bitmap -//| ColorConverter -//| Display -//| EPaperDisplay -//| FourWire -//| Group -//| I2CDisplay -//| OnDiskBitmap -//| Palette -//| ParallelBus -//| Shape -//| TileGrid""" +//| including synchronizing with refresh rates and partial updating.""" //| diff --git a/shared-bindings/fontio/BuiltinFont.c b/shared-bindings/fontio/BuiltinFont.c index f60c9e36c..bf9a65873 100644 --- a/shared-bindings/fontio/BuiltinFont.c +++ b/shared-bindings/fontio/BuiltinFont.c @@ -37,12 +37,7 @@ #include "supervisor/shared/translate.h" //| class BuiltinFont: -//| """.. currentmodule:: fontio -//| -//| :class:`BuiltinFont` -- A font built into CircuitPython -//| ========================================================================================= -//| -//| A font built into CircuitPython.""" +//| """A font built into CircuitPython""" //| //| def __init__(self, ): //| """Creation not supported. Available fonts are defined when CircuitPython is built. See the diff --git a/shared-bindings/fontio/Glyph.c b/shared-bindings/fontio/Glyph.c index 6235dbc46..6558e2e7a 100644 --- a/shared-bindings/fontio/Glyph.c +++ b/shared-bindings/fontio/Glyph.c @@ -29,22 +29,27 @@ #include //| class Glyph: -//| """.. currentmodule:: fontio +//| """Storage of glyph info""" //| -//| :class:`Glyph` -- Storage of glyph info -//| ==========================================================================""" -//| -//| def __init__(self, bitmap: displayio.Bitmap, tile_index: int, width: int, height: int, dx: int, dy: int, shift_x: int, shift_y: int): +//| def __init__(self, +//| bitmap: displayio.Bitmap, +//| tile_index: int, +//| width: int, +//| height: int, +//| dx: int, +//| dy: int, +//| shift_x: int, +//| shift_y: int): //| """Named tuple used to capture a single glyph and its attributes. //| -//| :param displayio.Bitmap bitmap: the bitmap including the glyph -//| :param int tile_index: the tile index within the bitmap -//| :param int width: the width of the glyph's bitmap -//| :param int height: the height of the glyph's bitmap -//| :param int dx: x adjustment to the bitmap's position -//| :param int dy: y adjustment to the bitmap's position -//| :param int shift_x: the x difference to the next glyph -//| :param int shift_y: the y difference to the next glyph""" +//| :param bitmap: the bitmap including the glyph +//| :param tile_index: the tile index within the bitmap +//| :param width: the width of the glyph's bitmap +//| :param height: the height of the glyph's bitmap +//| :param dx: x adjustment to the bitmap's position +//| :param dy: y adjustment to the bitmap's position +//| :param shift_x: the x difference to the next glyph +//| :param shift_y: the y difference to the next glyph""" //| ... //| const mp_obj_namedtuple_type_t fontio_glyph_type = { diff --git a/shared-bindings/fontio/__init__.c b/shared-bindings/fontio/__init__.c index 478fc1806..f376f3503 100644 --- a/shared-bindings/fontio/__init__.c +++ b/shared-bindings/fontio/__init__.c @@ -33,22 +33,7 @@ #include "shared-bindings/fontio/BuiltinFont.h" #include "shared-bindings/fontio/Glyph.h" -//| """:mod:`fontio` --- Core font related data structures -//| ========================================================================= -//| -//| .. module:: fontio -//| :synopsis: Core font related data structures -//| :platform: SAMD21, SAMD51, nRF52 -//| -//| The `fontio` module contains classes to store font related information. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| BuiltinFont -//| Glyph""" +//| """Core font related data structures""" //| STATIC const mp_rom_map_elem_t fontio_module_globals_table[] = { diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 5e63b988e..51ef09059 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -41,10 +41,7 @@ #include "supervisor/shared/translate.h" //| class FramebufferDisplay: -//| """.. currentmodule:: framebufferio -//| -//| :class:`FramebufferDisplay` -- Manage updating a display with framebuffer in RAM -//| ================================================================================ +//| """Manage updating a display with framebuffer in RAM //| //| This initializes a display and connects it into CircuitPython. Unlike other //| objects in CircuitPython, Display objects live until `displayio.release_displays()` diff --git a/shared-bindings/framebufferio/__init__.c b/shared-bindings/framebufferio/__init__.c index 50725c515..492423464 100644 --- a/shared-bindings/framebufferio/__init__.c +++ b/shared-bindings/framebufferio/__init__.c @@ -28,25 +28,13 @@ #include "shared-bindings/framebufferio/__init__.h" #include "shared-bindings/framebufferio/FramebufferDisplay.h" -//| """:mod:`framebufferio` --- Native framebuffer display driving -//| ========================================================================= -//| -//| .. module:: framebufferio -//| :synopsis: Native helpers for driving displays -//| :platform: SAMD51, nRF52 +//| """Native framebuffer display driving //| //| The `framebufferio` module contains classes to manage display output //| including synchronizing with refresh rates and partial updating. //| It is used in conjunction with classes from `displayio` to actually //| place items on the display; and classes like `RGBMatrix` to actually -//| drive the display. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| FramebufferDisplay""" +//| drive the display.""" //| #if CIRCUITPY_FRAMEBUFFERIO diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 270fa87c3..2d628088b 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -36,10 +36,7 @@ #include "supervisor/shared/translate.h" //| class FrequencyIn: -//| """.. currentmodule:: frequencyio -//| -//| :class:`FrequencyIn` -- Read a frequency signal -//| ======================================================== +//| """Read a frequency signal //| //| FrequencyIn is used to measure the frequency, in hertz, of a digital signal //| on an incoming pin. Accuracy has shown to be within 10%, if not better. It diff --git a/shared-bindings/frequencyio/__init__.c b/shared-bindings/frequencyio/__init__.c index 219d5f645..031004d4b 100644 --- a/shared-bindings/frequencyio/__init__.c +++ b/shared-bindings/frequencyio/__init__.c @@ -33,23 +33,8 @@ #include "shared-bindings/frequencyio/__init__.h" #include "shared-bindings/frequencyio/FrequencyIn.h" -//| """:mod:`frequencyio` --- Support for frequency based protocols -//| ============================================================= +//| """Support for frequency based protocols //| -//| .. module:: frequencyio -//| :synopsis: Support for frequency based protocols -//| :platform: SAMD51 -//| -//| The `frequencyio` module contains classes to provide access to basic frequency IO. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| FrequencyIn -//| - //| .. warning:: This module is not available in SAMD21 builds. See the //| :ref:`module-support-matrix` for more info. //| diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 946a24dbf..a750892fe 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -35,10 +35,7 @@ #include "supervisor/shared/translate.h" //| class GamePad: -//| """.. currentmodule:: gamepad -//| -//| :class:`GamePad` -- Scan buttons for presses -//| ============================================ +//| """Scan buttons for presses //| //| Usage:: //| @@ -90,7 +87,7 @@ //| on delays. //| //| They button presses are accumulated, until the ``get_pressed`` method -//| is called, at which point the button state is cleared, and the new +//| is called, at which point the button state is cleared, and the new //| button presses start to be recorded.""" //| ... //| diff --git a/shared-bindings/gamepad/__init__.c b/shared-bindings/gamepad/__init__.c index 0c32fd6c1..557777f50 100644 --- a/shared-bindings/gamepad/__init__.c +++ b/shared-bindings/gamepad/__init__.c @@ -29,17 +29,7 @@ #include "shared-bindings/gamepad/GamePad.h" #include "shared-bindings/util.h" -//| """:mod:`gamepad` --- Button handling -//| ================================== -//| -//| .. module:: gamepad -//| :synopsis: Button handling -//| :platform: SAMD21 -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| GamePad""" +//| """Button handling in the background""" //| STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) }, diff --git a/shared-bindings/gamepadshift/GamePadShift.c b/shared-bindings/gamepadshift/GamePadShift.c index 37be3d957..48b579457 100644 --- a/shared-bindings/gamepadshift/GamePadShift.c +++ b/shared-bindings/gamepadshift/GamePadShift.c @@ -33,10 +33,7 @@ #include "supervisor/shared/translate.h" //| class GamePadShift: -//| """.. currentmodule:: gamepadshift -//| -//| :class:`GamePadShift` -- Scan buttons for presses through a shift register -//| ===========================================================================""" +//| """Scan buttons for presses through a shift register""" //| //| def __init__(self, clock: Any, data: Any, latch: Any): //| """Initializes button scanning routines. diff --git a/shared-bindings/gamepadshift/__init__.c b/shared-bindings/gamepadshift/__init__.c index 3763b0487..f17135893 100644 --- a/shared-bindings/gamepadshift/__init__.c +++ b/shared-bindings/gamepadshift/__init__.c @@ -30,17 +30,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" -//| """:mod:`gamepadshift` --- Tracks button presses read through a shift register -//| =========================================================================== -//| -//| .. module:: gamepadshift -//| :synopsis: Tracks button presses read through a shift register -//| :platform: SAMD21, SAMD51 -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| GamePadShift""" +//| """Tracks button presses read through a shift register""" //| STATIC const mp_rom_map_elem_t gamepadshift_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepadshift) }, diff --git a/shared-bindings/help.c b/shared-bindings/help.c deleted file mode 100644 index 4e7c3a78b..000000000 --- a/shared-bindings/help.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -//| :func:`help` - Built-in method to provide helpful information -//| ============================================================== -//| -//| .. function:: help(object=None) -//| -//| Prints a help method about the given object. When ``object`` is none, -//| prints general port information. -//| diff --git a/shared-bindings/help.rst b/shared-bindings/help.rst new file mode 100644 index 000000000..63991bff2 --- /dev/null +++ b/shared-bindings/help.rst @@ -0,0 +1,31 @@ +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +:func:`help` - Built-in method to provide helpful information +============================================================== + +.. function:: help(object=None) + + Prints a help method about the given object. When ``object`` is none, + prints general port information. diff --git a/shared-bindings/i2cslave/I2CSlave.c b/shared-bindings/i2cslave/I2CSlave.c index 5bab2af74..80875ce75 100644 --- a/shared-bindings/i2cslave/I2CSlave.c +++ b/shared-bindings/i2cslave/I2CSlave.c @@ -50,10 +50,7 @@ STATIC mp_obj_t mp_obj_new_i2cslave_i2c_slave_request(i2cslave_i2c_slave_obj_t * } //| class I2CSlave: -//| """.. currentmodule:: i2cslave -//| -//| :class:`I2CSlave` --- Two wire serial protocol slave -//| ----------------------------------------------------""" +//| """Two wire serial protocol slave""" //| //| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: tuple, smbus: bool = False): //| """I2C is a two-wire protocol for communicating between devices. @@ -229,17 +226,15 @@ const mp_obj_type_t i2cslave_i2c_slave_type = { }; //| class I2CSlaveRequest: -//| """:class:`I2CSlaveRequest` --- I2C Slave Request -//| ----------------------------------------------""" //| //| def __init__(self, slave: i2cslave.I2CSlave, address: int, is_read: bool, is_restart: bool): //| """I2C transfer request from a master. //| This cannot be instantiated directly, but is returned by :py:meth:`I2CSlave.request`. //| -//| :param ~i2cslave.I2CSlave slave: The I2C Slave receiving this request -//| :param int address: I2C address -//| :param bool is_read: I2C Master read request -//| :param bool is_restart: Repeated Start Condition""" +//| :param slave: The I2C Slave receiving this request +//| :param address: I2C address +//| :param is_read: I2C Master read request +//| :param is_restart: Repeated Start Condition""" //| STATIC mp_obj_t i2cslave_i2c_slave_request_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, 4, 4, false); @@ -264,7 +259,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_obj___exit__(size_t n_args, const mp_ } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave_request___exit___obj, 4, 4, i2cslave_i2c_slave_request_obj___exit__); -//| address: Any = ... +//| address: int = ... //| """The I2C address of the request.""" //| STATIC mp_obj_t i2cslave_i2c_slave_request_get_address(mp_obj_t self_in) { @@ -274,7 +269,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_get_address(mp_obj_t self_in) { } MP_DEFINE_CONST_PROP_GET(i2cslave_i2c_slave_request_address_obj, i2cslave_i2c_slave_request_get_address); -//| is_read: Any = ... +//| is_read: bool = ... //| """The I2C master is reading from the device.""" //| STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_read(mp_obj_t self_in) { @@ -284,7 +279,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_read(mp_obj_t self_in) { } MP_DEFINE_CONST_PROP_GET(i2cslave_i2c_slave_request_is_read_obj, i2cslave_i2c_slave_request_get_is_read); -//| is_restart: Any = ... +//| is_restart: bool = ... //| """Is Repeated Start Condition.""" //| STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_restart(mp_obj_t self_in) { @@ -294,14 +289,13 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_restart(mp_obj_t self_in) { } MP_DEFINE_CONST_PROP_GET(i2cslave_i2c_slave_request_is_restart_obj, i2cslave_i2c_slave_request_get_is_restart); -//| def read(self, n: int = -1, ack: bool = True) -> Any: +//| def read(self, n: int = -1, ack: bool = True) -> bytearray: //| """Read data. //| If ack=False, the caller is responsible for calling :py:meth:`I2CSlaveRequest.ack`. //| -//| :param int n: Number of bytes to read (negative means all) -//| :param bool ack: Whether or not to send an ACK after the n'th byte -//| :return: Bytes read -//| :rtype: bytearray""" +//| :param n: Number of bytes to read (negative means all) +//| :param ack: Whether or not to send an ACK after the n'th byte +//| :return: Bytes read""" //| ... //| STATIC mp_obj_t i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -355,10 +349,10 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *p } MP_DEFINE_CONST_FUN_OBJ_KW(i2cslave_i2c_slave_request_read_obj, 1, i2cslave_i2c_slave_request_read); -//| def write(self, buffer: bytearray) -> Any: +//| def write(self, buffer: bytearray) -> int: //| """Write the data contained in buffer. //| -//| :param bytearray buffer: Write out the data in this buffer +//| :param buffer: Write out the data in this buffer //| :return: Number of bytes written""" //| ... //| @@ -393,7 +387,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cslave_i2c_slave_request_write_obj, i2cslave_ //| """Acknowledge or Not Acknowledge last byte received. //| Use together with :py:meth:`I2CSlaveRequest.read` ack=False. //| -//| :param bool ack: Whether to send an ACK or NACK""" +//| :param ack: Whether to send an ACK or NACK""" //| ... //| STATIC mp_obj_t i2cslave_i2c_slave_request_ack(uint n_args, const mp_obj_t *args) { diff --git a/shared-bindings/i2cslave/__init__.c b/shared-bindings/i2cslave/__init__.c index ffeb216fa..41b42fef8 100644 --- a/shared-bindings/i2cslave/__init__.c +++ b/shared-bindings/i2cslave/__init__.c @@ -35,22 +35,10 @@ #include "py/runtime.h" -//| """:mod:`i2cslave` --- Two wire serial protocol slave -//| ================================================== -//| -//| .. module:: i2cslave -//| :synopsis: Two wire serial protocol slave -//| :platform: SAMD21, SAMD51 +//| """Two wire serial protocol slave //| //| The `i2cslave` module contains classes to support a I2C slave. //| -//| Classes -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| I2CSlave -//| //| Example emulating 2 devices:: //| //| import board diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index cbffdb614..d94177394 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -7,13 +7,17 @@ present or if flash space is limited. For example, a microcontroller without analog features will not have `analogio`. See the `support_matrix` page for a list of modules supported on each board. +.. toctree:: + :hidden: + + support_matrix + Modules --------- .. toctree:: :glob: - :maxdepth: 3 + :maxdepth: 2 - support_matrix - */__init__ + ../autoapi/*/index help diff --git a/shared-bindings/math/__init__.c b/shared-bindings/math/__init__.c index 755bf7589..56155306f 100644 --- a/shared-bindings/math/__init__.c +++ b/shared-bindings/math/__init__.c @@ -38,12 +38,7 @@ #define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846) -//| """:mod:`math` --- mathematical functions -//| ======================================================== -//| -//| .. module:: math -//| :synopsis: mathematical functions -//| :platform: SAMD21/SAMD51 +//| """mathematical functions //| //| The `math` module provides some basic mathematical functions for //| working with floating-point numbers.""" diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index cad0d67b1..765e602e5 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -34,12 +34,7 @@ #include "supervisor/shared/translate.h" //| class Pin: -//| """.. currentmodule:: microcontroller -//| -//| :class:`Pin` --- Pin reference -//| ------------------------------------------ -//| -//| Identifies an IO pin on the microcontroller.""" +//| """Identifies an IO pin on the microcontroller.""" //| //| def __init__(self, ): //| """Identifies an IO pin on the microcontroller. They are fixed by the diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index dedb5a27c..c4b249124 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -35,12 +35,7 @@ #include "py/runtime.h" //| class Processor: -//| """.. currentmodule:: microcontroller -//| -//| :class:`Processor` --- Microcontroller CPU information and control -//| ------------------------------------------------------------------ -//| -//| Get information about the microcontroller CPU and control it. +//| """Microcontroller CPU information and control //| //| Usage:: //| @@ -55,8 +50,8 @@ //| ... //| -//| frequency: Any = ... -//| """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()); diff --git a/shared-bindings/microcontroller/RunMode.c b/shared-bindings/microcontroller/RunMode.c index df3ff4186..6db315d8d 100644 --- a/shared-bindings/microcontroller/RunMode.c +++ b/shared-bindings/microcontroller/RunMode.c @@ -27,10 +27,7 @@ #include "shared-bindings/microcontroller/RunMode.h" //| class RunMode: -//| """.. currentmodule:: microcontroller -//| -//| :class:`RunMode` -- run state of the microcontroller -//| =============================================================""" +//| """run state of the microcontroller""" //| //| def __init__(self, ): //| """Enum-like class to define the run mode of the microcontroller and diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c index 75b763980..21e1c90a9 100644 --- a/shared-bindings/microcontroller/__init__.c +++ b/shared-bindings/microcontroller/__init__.c @@ -42,27 +42,13 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -//| """:mod:`microcontroller` --- Pin references and cpu functionality -//| ================================================================ -//| -//| .. module:: microcontroller -//| :synopsis: Pin references and core functionality -//| :platform: SAMD21, ESP8266 +//| """Pin references and cpu functionality //| //| The `microcontroller` module defines the pins from the perspective of the -//| microcontroller. See `board` for board-specific pin mappings. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Pin -//| Processor -//| RunMode""" +//| microcontroller. See `board` for board-specific pin mappings.""" //| -//| cpu: Any = ... +//| cpu: Processor = ... //| """CPU information and control, such as ``cpu.temperature`` and ``cpu.frequency`` //| (clock frequency). //| This object is the sole instance of `microcontroller.Processor`.""" diff --git a/shared-bindings/multiterminal/__init__.c b/shared-bindings/multiterminal/__init__.c index 3a4065019..baf2fb674 100644 --- a/shared-bindings/multiterminal/__init__.c +++ b/shared-bindings/multiterminal/__init__.c @@ -30,12 +30,7 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -//| """:mod:`multiterminal` --- Manage additional terminal sources -//| =========================================================== -//| -//| .. module:: multiterminal -//| :synopsis: Manage additional terminal sources -//| :platform: ESP8266 +//| """Manage additional terminal sources //| //| The `multiterminal` module allows you to configure an additional serial //| terminal source. Incoming characters are accepted from both the internal diff --git a/shared-bindings/neopixel_write/__init__.c b/shared-bindings/neopixel_write/__init__.c index f18c7fdfd..5e5bc31eb 100644 --- a/shared-bindings/neopixel_write/__init__.c +++ b/shared-bindings/neopixel_write/__init__.c @@ -31,12 +31,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "supervisor/shared/translate.h" -//| """:mod:`neopixel_write` --- Low-level neopixel implementation -//| =========================================================== -//| -//| .. module:: neopixel_write -//| :synopsis: Low-level neopixel implementation -//| :platform: SAMD21 +//| """Low-level neopixel implementation //| //| The `neopixel_write` module contains a helper method to write out bytes in //| the 800khz neopixel protocol. @@ -55,11 +50,11 @@ //| pixel_off = bytearray([0, 0, 0]) //| neopixel_write.neopixel_write(pin, pixel_off)""" //| -//| def neopixel_write(digitalinout: digitalio.DigitalInOut, buf: bytearray) -> Any: +//| def neopixel_write(digitalinout: digitalio.DigitalInOut, buf: bytearray) -> None: //| """Write buf out on the given DigitalInOut. //| -//| :param ~digitalio.DigitalInOut digitalinout: the DigitalInOut to output with -//| :param bytearray buf: The bytes to clock out. No assumption is made about color order""" +//| :param digitalinout: the DigitalInOut to output with +//| :param buf: The bytes to clock out. No assumption is made about color order""" //| ... STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) { if (!MP_OBJ_IS_TYPE(digitalinout_obj, &digitalio_digitalinout_type)) { diff --git a/shared-bindings/network/__init__.c b/shared-bindings/network/__init__.c index 4f03781cf..6af86688e 100644 --- a/shared-bindings/network/__init__.c +++ b/shared-bindings/network/__init__.c @@ -38,12 +38,7 @@ #if CIRCUITPY_NETWORK -//| """:mod:`network` --- Network Interface Management -//| =============================================== -//| -//| .. module:: network -//| :synopsis: Network Interface Management -//| :platform: SAMD +//| """Network Interface Management //| //| This module provides a registry of configured NICs. //| It is used by the 'socket' module to look up a suitable diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index a28c2c4f9..326f719a8 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -31,14 +31,8 @@ #include "shared-bindings/nvm/ByteArray.h" #include "supervisor/shared/translate.h" - - - //| class ByteArray: -//| """.. currentmodule:: nvm -//| -//| :class:`ByteArray` -- Presents a stretch of non-volatile memory as a bytearray. -//| ================================================================================ +//| """Presents a stretch of non-volatile memory as a bytearray. //| //| Non-volatile memory is available as a byte array that persists over reloads //| and power cycles. Each assignment causes an erase and write cycle so its recommended to assign diff --git a/shared-bindings/nvm/__init__.c b/shared-bindings/nvm/__init__.c index 3bd9a309b..51c5bb278 100644 --- a/shared-bindings/nvm/__init__.c +++ b/shared-bindings/nvm/__init__.c @@ -31,23 +31,10 @@ #include "shared-bindings/nvm/__init__.h" #include "shared-bindings/nvm/ByteArray.h" -//| """:mod:`nvm` --- Non-volatile memory -//| =========================================================== -//| -//| .. module:: nvm -//| :synopsis: Non-volatile memory -//| :platform: SAMD21 +//| """Non-volatile memory //| //| The `nvm` module allows you to store whatever raw bytes you wish in a -//| reserved section non-volatile memory. -//| - -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| ByteArray""" +//| reserved section non-volatile memory.""" //| STATIC const mp_rom_map_elem_t nvm_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_nvm) }, diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index 2a6b13c9b..4e991d089 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -37,12 +37,7 @@ #include "py/runtime.h" #include "shared-bindings/os/__init__.h" -//| """:mod:`os` --- functions that an OS normally provides -//| ======================================================== -//| -//| .. module:: os -//| :synopsis: functions that an OS normally provides -//| :platform: SAMD21 +//| """functions that an OS normally provides //| //| The `os` module is a strict subset of the CPython `cpython:os` module. So, //| code written in CircuitPython will work in CPython but not necessarily the diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c index d327d4180..a87b14ddd 100644 --- a/shared-bindings/ps2io/Ps2.c +++ b/shared-bindings/ps2io/Ps2.c @@ -37,10 +37,7 @@ #include "supervisor/shared/translate.h" //| class Ps2: -//| """.. currentmodule:: ps2io -//| -//| :class:`Ps2` -- Communicate with a PS/2 keyboard or mouse -//| ========================================================= +//| """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 diff --git a/shared-bindings/ps2io/__init__.c b/shared-bindings/ps2io/__init__.c index 081127bac..38a70b1a2 100644 --- a/shared-bindings/ps2io/__init__.c +++ b/shared-bindings/ps2io/__init__.c @@ -33,22 +33,10 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/ps2io/Ps2.h" -//| """:mod:`ps2io` --- Support for PS/2 protocol -//| ===================================================== -//| -//| .. module:: ps2io -//| :synopsis: Support for PS/2 based devices -//| :platform: SAMD21 +//| """Support for PS/2 protocol //| //| The `ps2io` module contains classes to provide PS/2 communication. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Ps2 -//| //| .. warning:: This module is not available in some SAMD21 builds. See the //| :ref:`module-support-matrix` for more info. diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index 3a25d6938..7970c02f3 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -36,12 +36,7 @@ #include "supervisor/shared/translate.h" //| class PWMOut: -//| """.. currentmodule:: pulseio -//| -//| :class:`PWMOut` -- Output a Pulse Width Modulated signal -//| ======================================================== -//| -//| PWMOut can be used to output a PWM signal on a given pin.""" +//| """Output a Pulse Width Modulated signal on a given pin.""" //| //| 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 diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 9024f53e3..5c52b2582 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -36,15 +36,9 @@ #include "supervisor/shared/translate.h" //| class PulseIn: -//| """.. currentmodule:: pulseio -//| -//| :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.""" +//| """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.""" //| //| 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 diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 9c650731b..16b0a6f0c 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -37,14 +37,9 @@ #include "supervisor/shared/translate.h" //| class PulseOut: -//| """.. currentmodule:: pulseio -//| -//| :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.""" +//| """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.""" //| //| def __init__(self, carrier: pulseio.PWMOut): //| """Create a PulseOut object associated with the given PWMout object. @@ -115,7 +110,7 @@ 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__); -//| def send(self, pulses: array.array) -> Any: +//| 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). diff --git a/shared-bindings/pulseio/__init__.c b/shared-bindings/pulseio/__init__.c index 70cb61fc3..87946e5f0 100644 --- a/shared-bindings/pulseio/__init__.c +++ b/shared-bindings/pulseio/__init__.c @@ -35,24 +35,10 @@ #include "shared-bindings/pulseio/PulseOut.h" #include "shared-bindings/pulseio/PWMOut.h" -//| """:mod:`pulseio` --- Support for pulse based protocols -//| ===================================================== -//| -//| .. module:: pulseio -//| :synopsis: Support for pulse based protocols -//| :platform: SAMD21, ESP8266 +//| """Support for pulse based protocols //| //| The `pulseio` module contains classes to provide access to basic pulse IO. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| PulseIn -//| PulseOut -//| PWMOut -//| //| 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 diff --git a/shared-bindings/random/__init__.c b/shared-bindings/random/__init__.c index d8b266be0..c0124df41 100644 --- a/shared-bindings/random/__init__.c +++ b/shared-bindings/random/__init__.c @@ -33,12 +33,7 @@ #include "shared-bindings/random/__init__.h" #include "supervisor/shared/translate.h" -//| """:mod:`random` --- pseudo-random numbers and choices -//| ======================================================== -//| -//| .. module:: random -//| :synopsis: pseudo-random numbers and choices -//| :platform: SAMD21, ESP8266 +//| """pseudo-random numbers and choices //| //| The `random` module is a strict subset of the CPython `cpython:random` //| module. So, code written in CircuitPython will work in CPython but not diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index e2393eb61..cbf570958 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -39,10 +39,7 @@ #include "shared-module/framebufferio/FramebufferDisplay.h" //| class RGBMatrix: -//| """.. currentmodule:: rgbmatrix -//| -//| :class:`RGBMatrix` -- Driver for HUB75-style RGB LED matrices -//| ================================================================ +//| """Displays an in-memory framebuffer to a HUB75-style RGB LED matrix.""" //| extern Protomatter_core *_PM_protoPtr; @@ -134,9 +131,6 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ } } - -//| :class:`~rgbmatrix.RGBMatrix` displays an in-memory framebuffer to an LED matrix.""" -//| //| def __init__(self, *, width: Any, bit_depth: Any, rgb_pins: Any, addr_pins: Any, clock_pin: Any, latch_pin: Any, output_enable_pin: Any, doublebuffer: Any = True, framebuffer: Any = None, height: Any = 0): //| """Create a RGBMatrix object with the given attributes. The height of //| the display is determined by the number of rgb and address pins: @@ -297,7 +291,7 @@ const mp_obj_property_t rgbmatrix_rgbmatrix_brightness_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| def refresh(self, ) -> Any: ... +//| def refresh(self) -> Any: ... //| """Transmits the color data in the buffer to the pixels so that //| they are shown.""" //| @@ -309,7 +303,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_refresh(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rgbmatrix_rgbmatrix_refresh_obj, rgbmatrix_rgbmatrix_refresh); -//| width: Any = ... +//| width: int = ... //| """The width of the display, in pixels""" //| STATIC mp_obj_t rgbmatrix_rgbmatrix_get_width(mp_obj_t self_in) { @@ -325,7 +319,7 @@ const mp_obj_property_t rgbmatrix_rgbmatrix_width_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| height: Any = ... +//| height: int = ... //| """The height of the display, in pixels""" //| STATIC mp_obj_t rgbmatrix_rgbmatrix_get_height(mp_obj_t self_in) { diff --git a/shared-bindings/rgbmatrix/__init__.c b/shared-bindings/rgbmatrix/__init__.c index f61002a78..7f0576652 100644 --- a/shared-bindings/rgbmatrix/__init__.c +++ b/shared-bindings/rgbmatrix/__init__.c @@ -31,16 +31,7 @@ #include "shared-bindings/rgbmatrix/RGBMatrix.h" -//| """:mod:`rgbmatrix` --- Low-level routines for bitbanged LED matrices -//| ===================================================================== -//| -//| .. module:: rgbmatrix -//| :synopsis: Low-level routines for bitbanged LED matrices -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| RGBMatrix""" +//| """Low-level routines for bitbanged LED matrices""" //| STATIC const mp_rom_map_elem_t rgbmatrix_module_globals_table[] = { diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index a10fb6fd5..8b2723866 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -35,12 +35,7 @@ #include "shared-bindings/util.h" //| class IncrementalEncoder: -//| """.. currentmodule:: rotaryio -//| -//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder -//| ==================================================================================== -//| -//| IncrementalEncoder determines the relative rotational position based on two series of pulses.""" +//| """IncrementalEncoder determines the relative rotational position based on two series of pulses.""" //| //| def __init__(self, pin_a: microcontroller.Pin, pin_b: microcontroller.Pin): //| """Create an IncrementalEncoder object associated with the given pins. It tracks the positional diff --git a/shared-bindings/rotaryio/__init__.c b/shared-bindings/rotaryio/__init__.c index 0cc8eb556..0fa457ca7 100644 --- a/shared-bindings/rotaryio/__init__.c +++ b/shared-bindings/rotaryio/__init__.c @@ -33,27 +33,13 @@ #include "shared-bindings/rotaryio/__init__.h" #include "shared-bindings/rotaryio/IncrementalEncoder.h" -//| """:mod:`rotaryio` --- Support for reading rotation sensors -//| ======================================================== -//| -//| .. module:: rotaryio -//| :synopsis: Support for reading rotation sensors -//| :platform: SAMD +//| """Support for reading rotation sensors //| //| The `rotaryio` module contains classes to read different rotation encoding schemes. See //| `Wikipedia's Rotary Encoder page `_ for more //| background. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| IncrementalEncoder -//| -//| .. warning:: This module is not available in some SAMD21 (aka M0) builds. See the -//| :ref:`module-support-matrix` for more info. +//| .. warning:: This module is not available in some SAMD21 (aka M0) builds. See the :ref:`module-support-matrix` for more info. //| //| All classes change hardware state and should be deinitialized when they diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 663f5be6c..58fe308f5 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -38,15 +38,8 @@ const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; - - - - //| class RTC: -//| """.. currentmodule:: rtc -//| -//| :class:`RTC` --- Real Time Clock -//| --------------------------------""" +//| """Real Time Clock""" //| //| def __init__(self, ): //| """This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance.""" @@ -60,7 +53,7 @@ STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const return (mp_obj_t)&rtc_rtc_obj; } -//| datetime: Any = ... +//| datetime: time.struct_time = ... //| """The current date and time of the RTC as a `time.struct_time`. //| //| This must be set to the current date and time whenever the board loses power:: @@ -101,7 +94,7 @@ const mp_obj_property_t rtc_rtc_datetime_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| calibration: Any = ... +//| calibration: int = ... //| """The RTC calibration value as an `int`. //| //| A positive value speeds up the clock and a negative value slows it down. diff --git a/shared-bindings/rtc/__init__.c b/shared-bindings/rtc/__init__.c index 66669ca5f..b204d511c 100644 --- a/shared-bindings/rtc/__init__.c +++ b/shared-bindings/rtc/__init__.c @@ -31,23 +31,11 @@ #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" -//| """:mod:`rtc` --- Real Time Clock -//| ======================================================== -//| -//| .. module:: rtc -//| :synopsis: Real Time Clock -//| :platform: SAMD21, SAMD51, nRF52 +//| """Real Time Clock //| //| The `rtc` module provides support for a Real Time Clock. You can access and manage the //| RTC using :class:`rtc.RTC`. It also backs the :func:`time.time` and :func:`time.localtime` -//| functions using the onboard RTC if present. -//| -//| Classes -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| RTC""" +//| functions using the onboard RTC if present.""" //| void rtc_reset(void) { diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index 4c0811bdb..19c4850cd 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -37,12 +37,7 @@ #include "shared-module/network/__init__.h" -//| """:mod:`socket` --- TCP, UDP and RAW socket support -//| ================================================= -//| -//| .. module:: socket -//| :synopsis: TCP, UDP and RAW sockets -//| :platform: SAMD21, SAMD51 +//| """TCP, UDP and RAW socket support //| //| Create TCP, UDP and RAW sockets for communicating over the Internet.""" //| @@ -50,7 +45,6 @@ STATIC const mp_obj_type_t socket_type; //| class socket: -//| """.. currentmodule:: socket""" //| //| def __init__(self, family: int, type: int, proto: int): //| """Create a new socket diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index feb1a9bd7..8ac08d8c9 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -35,12 +35,7 @@ #include "shared-bindings/storage/__init__.h" #include "supervisor/shared/translate.h" -//| """:mod:`storage` --- storage management -//| ======================================================== -//| -//| .. module:: storage -//| :synopsis: storage management -//| :platform: SAMD21, SAMD51 +//| """Storage management //| //| The `storage` provides storage management functionality such as mounting and //| unmounting which is typically handled by the operating system hosting Python. diff --git a/shared-bindings/struct/__init__.c b/shared-bindings/struct/__init__.c index 3772f93a7..256b385c8 100644 --- a/shared-bindings/struct/__init__.c +++ b/shared-bindings/struct/__init__.c @@ -38,12 +38,7 @@ #include "shared-module/struct/__init__.h" #include "supervisor/shared/translate.h" -//| """:mod:`struct` --- manipulation of c-style data -//| ======================================================== -//| -//| .. module:: struct -//| :synopsis: byte data control -//| :platform: SAMD21 +//| """Manipulation of c-style data //| //| This module implements a subset of the corresponding CPython module, //| as described below. For more information, refer to the original CPython @@ -56,7 +51,7 @@ //| -//| def calcsize(fmt: Any) -> Any: +//| def calcsize(fmt: str) -> int: //| """Return the number of bytes needed to store the given fmt.""" //| ... //| diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 05921899c..a420d5b80 100755 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -30,12 +30,7 @@ //TODO: add USB, REPL to description once they're operational //| class Runtime: -//| """.. currentmodule:: supervisor -//| -//| :class:`Runtime` --- Supervisor Runtime information -//| ---------------------------------------------------- -//| -//| Get current status of runtime objects. +//| """Current status of runtime objects. //| //| Usage:: //| @@ -50,7 +45,7 @@ //| ... //| -//| runtime.serial_connected: Any = ... +//| serial_connected: bool = ... //| """Returns the USB serial communication status (read-only). //| //| .. note:: @@ -78,7 +73,7 @@ const mp_obj_property_t supervisor_serial_connected_obj = { }; -//| runtime.serial_bytes_available: Any = ... +//| serial_bytes_available: int = ... //| """Returns the whether any bytes are available to read //| on the USB serial input. Allows for polling to see whether //| to call the built-in input() or wait. (read-only)""" diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index 7fe6668f4..1830308b7 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -36,30 +36,16 @@ #include "shared-bindings/supervisor/__init__.h" #include "shared-bindings/supervisor/Runtime.h" -//| """:mod:`supervisor` --- Supervisor settings -//| ================================================= -//| -//| .. module:: supervisor -//| :synopsis: Supervisor settings -//| :platform: SAMD21/51 (All), nRF (Runtime only) -//| -//| The `supervisor` module. (TODO: expand description) -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Runtime""" +//| """Supervisor settings""" //| -//| runtime: Any = ... -//| """Runtime information, such as `runtime.serial_connected` +//| runtime: Runtime = ... +//| """Runtime information, such as ``runtime.serial_connected`` //| (USB serial connection status). //| This object is the sole instance of `supervisor.Runtime`.""" //| -//| def enable_autoreload(self, ) -> Any: +//| def enable_autoreload(self) -> None: //| """Enable autoreload based on USB file write activity.""" //| ... //| @@ -69,7 +55,7 @@ STATIC mp_obj_t supervisor_enable_autoreload(void) { } MP_DEFINE_CONST_FUN_OBJ_0(supervisor_enable_autoreload_obj, supervisor_enable_autoreload); -//| def disable_autoreload(self, ) -> Any: +//| def disable_autoreload(self) -> None: //| """Disable autoreload based on USB file write activity until //| `enable_autoreload` is called.""" //| ... @@ -80,7 +66,7 @@ STATIC mp_obj_t supervisor_disable_autoreload(void) { } MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_autoreload_obj, supervisor_disable_autoreload); -//| def set_rgb_status_brightness(self, ) -> Any: +//| def set_rgb_status_brightness(self, brightness: int) -> None: //| """Set brightness of status neopixel from 0-255 //| `set_rgb_status_brightness` is called.""" //| ... @@ -96,7 +82,7 @@ STATIC mp_obj_t supervisor_set_rgb_status_brightness(mp_obj_t lvl){ } MP_DEFINE_CONST_FUN_OBJ_1(supervisor_set_rgb_status_brightness_obj, supervisor_set_rgb_status_brightness); -//| def reload(self, ) -> Any: +//| def reload(self) -> None: //| """Reload the main Python code and run it (equivalent to hitting Ctrl-D at the REPL).""" //| ... //| @@ -107,7 +93,7 @@ STATIC mp_obj_t supervisor_reload(void) { } MP_DEFINE_CONST_FUN_OBJ_0(supervisor_reload_obj, supervisor_reload); -//| def set_next_stack_limit(self, size: Any) -> Any: +//| def set_next_stack_limit(self, size: int) -> None: //| """Set the size of the stack for the next vm run. If its too large, the default will be used.""" //| ... //| diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index 1288b7018..5c045fdee 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -38,10 +38,7 @@ #include "supervisor/shared/translate.h" //| class Terminal: -//| """.. currentmodule:: terminalio -//| -//| :class:`Terminal` -- display a character stream with a TileGrid -//| ================================================================""" +//| """Display a character stream with a TileGrid""" //| //| def __init__(self, tilegrid: Any, font: Any): //| """Terminal manages tile indices and cursor position based on VT100 commands. The font should be diff --git a/shared-bindings/terminalio/__init__.c b/shared-bindings/terminalio/__init__.c index 591be839a..589211139 100644 --- a/shared-bindings/terminalio/__init__.c +++ b/shared-bindings/terminalio/__init__.c @@ -35,22 +35,10 @@ #include "py/runtime.h" -//| """:mod:`terminalio` --- Displays text in a TileGrid -//| ================================================= -//| -//| .. module:: terminalio -//| :synopsis: Displays text in a TileGrid +//| """Displays text in a TileGrid //| //| The `terminalio` module contains classes to display a character stream on a display. The built -//| in font is available as ``terminalio.FONT``. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Terminal""" -//| +//| in font is available as ``terminalio.FONT``.""" //| STATIC const mp_rom_map_elem_t terminalio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_terminalio) }, diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 36eaa27f6..20277d6b0 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -36,12 +36,7 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" -//| """:mod:`time` --- time and timing related functions -//| ======================================================== -//| -//| .. module:: time -//| :synopsis: time and timing related functions -//| :platform: SAMD21 +//| """time and timing related functions //| //| The `time` module is a strict subset of the CPython `cpython:time` module. So, code //| written in MicroPython will work in CPython but not necessarily the other diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 6d59a1744..4c1d534ea 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -39,10 +39,7 @@ #include "supervisor/shared/translate.h" //| class TouchIn: -//| """.. currentmodule:: touchio -//| -//| :class:`TouchIn` -- Read the state of a capacitive touch sensor -//| =================================================================== +//| """Read the state of a capacitive touch sensor //| //| Usage:: //| diff --git a/shared-bindings/touchio/__init__.c b/shared-bindings/touchio/__init__.c index 96367f082..92e067cf6 100644 --- a/shared-bindings/touchio/__init__.c +++ b/shared-bindings/touchio/__init__.c @@ -35,23 +35,11 @@ #include "py/runtime.h" -//| """:mod:`touchio` --- Touch related IO -//| ================================================= -//| -//| .. module:: touchio -//| :synopsis: Hardware accelerated behavior -//| :platform: SAMD21 +//| """Touch related IO //| //| The `touchio` module contains classes to provide access to touch IO typically //| accelerated by hardware on the onboard microcontroller. //| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| TouchIn -//| //| 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 diff --git a/shared-bindings/uheap/__init__.c b/shared-bindings/uheap/__init__.c index f1be30424..f089f2922 100644 --- a/shared-bindings/uheap/__init__.c +++ b/shared-bindings/uheap/__init__.c @@ -31,11 +31,7 @@ #include "shared-bindings/uheap/__init__.h" -//| """:mod:`uheap` --- Heap size analysis -//| ================================================================ -//| -//| .. module:: uheap -//| :synopsis: Heap size analysis""" +//| """Heap size analysis""" //| //| def info(object: Any) -> Any: diff --git a/shared-bindings/ulab/__init__.pyi b/shared-bindings/ulab/__init__.pyi new file mode 100644 index 000000000..d2ff7eb80 --- /dev/null +++ b/shared-bindings/ulab/__init__.pyi @@ -0,0 +1,523 @@ + +:mod:`ulab` --- Manipulate numeric data similar to numpy +======================================================== + +.. module:: ulab + :synopsis: Manipulate numeric data similar to numpy + +`ulab` is a numpy-like module for micropython, meant to simplify and +speed up common mathematical operations on arrays. The primary goal was to +implement a small subset of numpy that might be useful in the context of a +microcontroller. This means low-level data processing of linear (array) and +two-dimensional (matrix) data. + +`ulab` is adapted from micropython-ulab, and the original project's +documentation can be found at +https://micropython-ulab.readthedocs.io/en/latest/ + +`ulab` is modeled after numpy, and aims to be a compatible subset where +possible. Numpy's documentation can be found at +https://docs.scipy.org/doc/numpy/index.html + +.. contents:: + +.. attribute:: __version__ + +The closest corresponding version of micropython-ulab + +ulab.array -- 1- and 2- dimensional array +----------------------------------------- + +.. class:: ulab.array(values, \*, dtype=float) + + :param sequence values: Sequence giving the initial content of the array. + :param dtype: The type of array values, ``int8``, ``uint8``, ``int16``, ``uint16``, or ``float`` + + The `values` sequence can either be another ~ulab.array, sequence of numbers + (in which case a 1-dimensional array is created), or a sequence where each + subsequence has the same length (in which case a 2-dimensional array is + created). + + Passing a ~ulab.array and a different dtype can be used to convert an array + from one dtype to another. + + In many cases, it is more convenient to create an array from a function + like `zeros` or `linspace`. + + `ulab.array` implements the buffer protocol, so it can be used in many + places an `array.array` can be used. + + .. attribute:: shape + + The size of the array, a tuple of length 1 or 2 + + .. attribute:: size + + The number of elements in the array + + .. attribute:: itemsize + + The number of elements in the array + + .. method:: flatten(\*, order='C') + + :param order: Whether to flatten by rows ('C') or columns ('F') + + Returns a new `ulab.array` object which is always 1 dimensional. + If order is 'C' (the default", then the data is ordered in rows; + If it is 'F', then the data is ordered in columns. "C" and "F" refer + to the typical storage organization of the C and Fortran languages. + + .. method:: sort(\*, axis=1) + + :param axis: Whether to sort elements within rows (0), columns (1), or elements (None) + + .. method:: transpose() + + Swap the rows and columns of a 2-dimensional array + + .. method:: __add__() + + Adds corresponding elements of the two arrays, or adds a number to all + elements of the array. If both arguments are arrays, their sizes must match. + + .. method:: __sub__() + + Subtracts corresponding elements of the two arrays, or adds a number to all + elements of the array. If both arguments are arrays, their sizes must match. + + .. method:: __mul__() + + Multiplies corresponding elements of the two arrays, or multiplies + all elements of the array by a number. If both arguments are arrays, + their sizes must match. + + .. method:: __div__() + + Multiplies corresponding elements of the two arrays, or divides + all elements of the array by a number. If both arguments are arrays, + their sizes must match. + + .. method:: __pow__() + + Computes the power (x**y) of corresponding elements of the the two arrays, + or one number and one array. If both arguments are arrays, their sizes + must match. + + .. method:: __getitem__() + + Retrieve an element of the array. + + .. method:: __setitem__() + + Set an element of the array. + +Array type codes +---------------- +.. attribute:: int8 + + Type code for signed integers in the range -128 .. 127 inclusive, like the 'b' typecode of `array.array` + +.. attribute:: int16 + + Type code for signed integers in the range -32768 .. 32767 inclusive, like the 'h' typecode of `array.array` + +.. attribute:: float + + Type code for floating point values, like the 'f' typecode of `array.array` + +.. attribute:: uint8 + + Type code for unsigned integers in the range 0 .. 255 inclusive, like the 'H' typecode of `array.array` + +.. attribute:: uint16 + + Type code for unsigned integers in the range 0 .. 65535 inclusive, like the 'h' typecode of `array.array` + + +Basic Array defining functions +------------------------------ + +.. method:: ones(shape, \*, dtype=float) + + .. param: shape + Shape of the array, either an integer (for a 1-D array) or a tuple of 2 integers (for a 2-D array) + + .. param: dtype + Type of values in the array + + Return a new array of the given shape with all elements set to 1. + +.. method:: zeros + + .. param: shape + Shape of the array, either an integer (for a 1-D array) or a tuple of 2 integers (for a 2-D array) + + .. param: dtype + Type of values in the array + + Return a new array of the given shape with all elements set to 0. + + +.. method:: eye(size, \*, dtype=float) + + Return a new square array of size, with the diagonal elements set to 1 + and the other elements set to 0. + +.. method:: linspace(start, stop, \*, dtype=float, num=50, endpoint=True) + + .. param: start + + First value in the array + + .. param: stop + + Final value in the array + + .. param int: num + + Count of values in the array + + .. param: dtype + + Type of values in the array + + .. param bool: endpoint + + Whether the ``stop`` value is included. Note that even when + endpoint=True, the exact ``stop`` value may not be included due to the + inaccuracy of floating point arithmetic. + + Return a new 1-D array with ``num`` elements ranging from ``start`` to ``stop`` linearly. + + +:mod:`ulab.compare` --- Comparison functions +============================================ + +.. module::ulab.compare + +.. method:: clip(x1, x2, x3) + + Constrain the values from ``x1`` to be between ``x2`` and ``x3``. + ``x2`` is assumed to be less than or equal to ``x3``. + + Arguments may be ulab arrays or numbers. All array arguments + must be the same size. If the inputs are all scalars, a 1-element + array is returned. + + Shorthand for ``ulab.maximum(x2, ulab.minimum(x1, x3))`` + +.. method:: maximum(x1, x2) + + Compute the element by element maximum of the arguments. + + Arguments may be ulab arrays or numbers. All array arguments + must be the same size. If the inputs are both scalars, a number is + returned + +.. method:: minimum(x1, x2) + + Compute the element by element minimum of the arguments. + + Arguments may be ulab arrays or numbers. All array arguments + must be the same size. If the inputs are both scalars, a number is + returned + + +:mod:`ulab.vector` --- Element-by-element functions +=================================================== + +.. module:: ulab.vector + +These functions can operate on numbers, 1-D arrays, or 2-D arrays by +applying the function to every element in the array. This is typically +much more efficient than expressing the same operation as a Python loop. + +.. method:: acos + + Computes the inverse cosine function + +.. method:: acosh + + Computes the inverse hyperbolic cosine function + +.. method:: asin + + Computes the inverse sine function + +.. method:: asinh + + Computes the inverse hyperbolic sine function + +.. method:: around(a, \*, decimals) + + Returns a new float array in which each element is rounded to + ``decimals`` places. + +.. method:: atan + + Computes the inverse tangent function; the return values are in the + range [-pi/2,pi/2]. + +.. method:: atan2(y,x) + + Computes the inverse tangent function of y/x; the return values are in + the range [-pi, pi]. + +.. method:: atanh + + Computes the inverse hyperbolic tangent function + +.. method:: ceil + + Rounds numbers up to the next whole number + +.. method:: cos + + Computes the cosine function + +.. method:: erf + + Computes the error function, which has applications in statistics + +.. method:: erfc + + Computes the complementary error function, which has applications in statistics + +.. method:: exp + + Computes the exponent function. + +.. method:: expm1 + + Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the `exp` function. + +.. method:: floor + + Rounds numbers up to the next whole number + +.. method:: gamma + + Computes the gamma function + +.. method:: lgamma + + Computes the natural log of the gamma function + +.. method:: log + + Computes the natural log + +.. method:: log10 + + Computes the log base 10 + +.. method:: log2 + + Computes the log base 2 + +.. method:: sin + + Computes the sine + +.. method:: sinh + + Computes the hyperbolic sine + +.. method:: sqrt + + Computes the square root + +.. method:: tan + + Computes the tangent + +.. method:: tanh + + Computes the hyperbolic tangent + +:mod:`ulab.linalg` - Linear algebra functions +============================================= + +.. module:: ulab.linalg + +.. method:: cholesky(A) + + :param ~ulab.array A: a positive definite, symmetric square matrix + :return ~ulab.array L: a square root matrix in the lower triangular form + :raises ValueError: If the input does not fulfill the necessary conditions + + The returned matrix satisfies the equation m=LL* + +.. method:: det + + :param: m, a square matrix + :return float: The determinant of the matrix + + Computes the eigenvalues and eigenvectors of a square matrix + +.. method:: dot(m1, m2) + + :param ~ulab.array m1: a matrix + :param ~ulab.array m2: a matrix + + Computes the matrix product of two matrices + + **WARNING:** Unlike ``numpy``, this function cannot be used to compute the dot product of two vectors + +.. method:: eig(m) + + :param m: a square matrix + :return tuple (eigenvectors, eigenvalues): + + Computes the eigenvalues and eigenvectors of a square matrix + +.. method:: inv(m) + + :param ~ulab.array m: a square matrix + :return: The inverse of the matrix, if it exists + :raises ValueError: if the matrix is not invertible + + Computes the inverse of a square matrix + +.. method:: size(array) + + Return the total number of elements in the array, as an integer. + +.. method:: trace(m) + + :param m: a square matrix + + Compute the trace of the matrix, the sum of its diagonal elements. + +:mod:`ulab.filter` --- Filtering functions +========================================== + +.. module:: ulab.filter + +.. method:: convolve(r, c=None) + + :param ulab.array a: + :param ulab.array v: + + Returns the discrete, linear convolution of two one-dimensional sequences. + The result is always an array of float. Only the ``full`` mode is supported, + and the ``mode`` named parameter of numpy is not accepted. Note that all other + modes can be had by slicing a ``full`` result. + + Convolution filters can implement high pass, low pass, band pass, etc., + filtering operations. Convolution filters are typically constructed ahead + of time. This can be done using desktop python with scipy, or on web pages + such as https://fiiir.com/ + + Convolution is most time-efficient when both inputs are of float type. + +:mod:`ulab.fft` --- Frequency-domain functions +============================================== + +.. module:: ulab.fft + +.. method:: fft(r, c=None) + + :param ulab.array r: A 1-dimension array of values whose size is a power of 2 + :param ulab.array c: An optional 1-dimension array of values whose size is a power of 2, giving the complex part of the value + :return tuple (r, c): The real and complex parts of the FFT + + Perform a Fast Fourier Transform from the time domain into the frequency domain + + See also ~ulab.extras.spectrum, which computes the magnitude of the fft, + rather than separately returning its real and imaginary parts. + +.. method:: ifft(r, c=None) + + :param ulab.array r: A 1-dimension array of values whose size is a power of 2 + :param ulab.array c: An optional 1-dimension array of values whose size is a power of 2, giving the complex part of the value + :return tuple (r, c): The real and complex parts of the inverse FFT + + Perform an Inverse Fast Fourier Transform from the frequeny domain into the time domain + +:mod:`ulab.numerical` --- Numerical and Statistical functions +============================================================= + +.. module:: ulab.numerical + +Most of these functions take an "axis" argument, which indicates whether to +operate over the flattened array (None), rows (0), or columns (1). + +.. method:: argmax(array, \*, axis=None) + + Return the index of the maximum element of the 1D array + +.. method:: argmin(array, \*, axis=None) + + Return the index of the minimum element of the 1D array + +.. method:: argsort(array, \*, axis=None) + + Returns an array which gives indices into the input array from least to greatest. + +.. method:: diff(array, \*, axis=1) + + Return the numerical derivative of successive elements of the array, as + an array. axis=None is not supported. + +.. method:: flip(array, \*, axis=None) + + Returns a new array that reverses the order of the elements along the + given axis, or along all axes if axis is None. + +.. method:: max(array, \*, axis=None) + + Return the maximum element of the 1D array + +.. method:: mean(array, \*, axis=None) + + Return the mean element of the 1D array, as a number if axis is None, otherwise as an array. + +.. method:: min(array, \*, axis=None) + + Return the minimum element of the 1D array + +.. method:: roll(array, distance, \*, axis=None) + + Shift the content of a vector by the positions given as the second + argument. If the ``axis`` keyword is supplied, the shift is applied to + the given axis. The array is modified in place. + +.. method:: std(array, \*, axis=None) + + Return the standard deviation of the array, as a number if axis is None, otherwise as an array. + +.. method:: sum(array, \*, axis=None) + + Return the sum of the array, as a number if axis is None, otherwise as an array. + +.. method:: sort(array, \*, axis=0) + + Sort the array along the given axis, or along all axes if axis is None. + The array is modified in place. + +:mod:`ulab.poly` --- Polynomial functions +========================================= + +.. module:: ulab.poly + +.. method:: polyfit([x, ] y, degree) + + Return a polynomial of given degree that approximates the function + f(x)=y. If x is not supplied, it is the range(len(y)). + +.. method:: polyval(p, x) + + Evaluate the polynomial p at the points x. x must be an array. + +:mod:`ulab.extras` --- Additional functions not in numpy +======================================================== + +.. method:: spectrum(r): + + :param ulab.array r: A 1-dimension array of values whose size is a power of 2 + + Computes the spectrum of the input signal. This is the absolute value of the (complex-valued) fft of the signal. + + This function is similar to scipy's ``scipy.signal.spectrogram``. diff --git a/shared-bindings/ulab/__init__.rst b/shared-bindings/ulab/__init__.rst deleted file mode 100644 index d2ff7eb80..000000000 --- a/shared-bindings/ulab/__init__.rst +++ /dev/null @@ -1,523 +0,0 @@ - -:mod:`ulab` --- Manipulate numeric data similar to numpy -======================================================== - -.. module:: ulab - :synopsis: Manipulate numeric data similar to numpy - -`ulab` is a numpy-like module for micropython, meant to simplify and -speed up common mathematical operations on arrays. The primary goal was to -implement a small subset of numpy that might be useful in the context of a -microcontroller. This means low-level data processing of linear (array) and -two-dimensional (matrix) data. - -`ulab` is adapted from micropython-ulab, and the original project's -documentation can be found at -https://micropython-ulab.readthedocs.io/en/latest/ - -`ulab` is modeled after numpy, and aims to be a compatible subset where -possible. Numpy's documentation can be found at -https://docs.scipy.org/doc/numpy/index.html - -.. contents:: - -.. attribute:: __version__ - -The closest corresponding version of micropython-ulab - -ulab.array -- 1- and 2- dimensional array ------------------------------------------ - -.. class:: ulab.array(values, \*, dtype=float) - - :param sequence values: Sequence giving the initial content of the array. - :param dtype: The type of array values, ``int8``, ``uint8``, ``int16``, ``uint16``, or ``float`` - - The `values` sequence can either be another ~ulab.array, sequence of numbers - (in which case a 1-dimensional array is created), or a sequence where each - subsequence has the same length (in which case a 2-dimensional array is - created). - - Passing a ~ulab.array and a different dtype can be used to convert an array - from one dtype to another. - - In many cases, it is more convenient to create an array from a function - like `zeros` or `linspace`. - - `ulab.array` implements the buffer protocol, so it can be used in many - places an `array.array` can be used. - - .. attribute:: shape - - The size of the array, a tuple of length 1 or 2 - - .. attribute:: size - - The number of elements in the array - - .. attribute:: itemsize - - The number of elements in the array - - .. method:: flatten(\*, order='C') - - :param order: Whether to flatten by rows ('C') or columns ('F') - - Returns a new `ulab.array` object which is always 1 dimensional. - If order is 'C' (the default", then the data is ordered in rows; - If it is 'F', then the data is ordered in columns. "C" and "F" refer - to the typical storage organization of the C and Fortran languages. - - .. method:: sort(\*, axis=1) - - :param axis: Whether to sort elements within rows (0), columns (1), or elements (None) - - .. method:: transpose() - - Swap the rows and columns of a 2-dimensional array - - .. method:: __add__() - - Adds corresponding elements of the two arrays, or adds a number to all - elements of the array. If both arguments are arrays, their sizes must match. - - .. method:: __sub__() - - Subtracts corresponding elements of the two arrays, or adds a number to all - elements of the array. If both arguments are arrays, their sizes must match. - - .. method:: __mul__() - - Multiplies corresponding elements of the two arrays, or multiplies - all elements of the array by a number. If both arguments are arrays, - their sizes must match. - - .. method:: __div__() - - Multiplies corresponding elements of the two arrays, or divides - all elements of the array by a number. If both arguments are arrays, - their sizes must match. - - .. method:: __pow__() - - Computes the power (x**y) of corresponding elements of the the two arrays, - or one number and one array. If both arguments are arrays, their sizes - must match. - - .. method:: __getitem__() - - Retrieve an element of the array. - - .. method:: __setitem__() - - Set an element of the array. - -Array type codes ----------------- -.. attribute:: int8 - - Type code for signed integers in the range -128 .. 127 inclusive, like the 'b' typecode of `array.array` - -.. attribute:: int16 - - Type code for signed integers in the range -32768 .. 32767 inclusive, like the 'h' typecode of `array.array` - -.. attribute:: float - - Type code for floating point values, like the 'f' typecode of `array.array` - -.. attribute:: uint8 - - Type code for unsigned integers in the range 0 .. 255 inclusive, like the 'H' typecode of `array.array` - -.. attribute:: uint16 - - Type code for unsigned integers in the range 0 .. 65535 inclusive, like the 'h' typecode of `array.array` - - -Basic Array defining functions ------------------------------- - -.. method:: ones(shape, \*, dtype=float) - - .. param: shape - Shape of the array, either an integer (for a 1-D array) or a tuple of 2 integers (for a 2-D array) - - .. param: dtype - Type of values in the array - - Return a new array of the given shape with all elements set to 1. - -.. method:: zeros - - .. param: shape - Shape of the array, either an integer (for a 1-D array) or a tuple of 2 integers (for a 2-D array) - - .. param: dtype - Type of values in the array - - Return a new array of the given shape with all elements set to 0. - - -.. method:: eye(size, \*, dtype=float) - - Return a new square array of size, with the diagonal elements set to 1 - and the other elements set to 0. - -.. method:: linspace(start, stop, \*, dtype=float, num=50, endpoint=True) - - .. param: start - - First value in the array - - .. param: stop - - Final value in the array - - .. param int: num - - Count of values in the array - - .. param: dtype - - Type of values in the array - - .. param bool: endpoint - - Whether the ``stop`` value is included. Note that even when - endpoint=True, the exact ``stop`` value may not be included due to the - inaccuracy of floating point arithmetic. - - Return a new 1-D array with ``num`` elements ranging from ``start`` to ``stop`` linearly. - - -:mod:`ulab.compare` --- Comparison functions -============================================ - -.. module::ulab.compare - -.. method:: clip(x1, x2, x3) - - Constrain the values from ``x1`` to be between ``x2`` and ``x3``. - ``x2`` is assumed to be less than or equal to ``x3``. - - Arguments may be ulab arrays or numbers. All array arguments - must be the same size. If the inputs are all scalars, a 1-element - array is returned. - - Shorthand for ``ulab.maximum(x2, ulab.minimum(x1, x3))`` - -.. method:: maximum(x1, x2) - - Compute the element by element maximum of the arguments. - - Arguments may be ulab arrays or numbers. All array arguments - must be the same size. If the inputs are both scalars, a number is - returned - -.. method:: minimum(x1, x2) - - Compute the element by element minimum of the arguments. - - Arguments may be ulab arrays or numbers. All array arguments - must be the same size. If the inputs are both scalars, a number is - returned - - -:mod:`ulab.vector` --- Element-by-element functions -=================================================== - -.. module:: ulab.vector - -These functions can operate on numbers, 1-D arrays, or 2-D arrays by -applying the function to every element in the array. This is typically -much more efficient than expressing the same operation as a Python loop. - -.. method:: acos - - Computes the inverse cosine function - -.. method:: acosh - - Computes the inverse hyperbolic cosine function - -.. method:: asin - - Computes the inverse sine function - -.. method:: asinh - - Computes the inverse hyperbolic sine function - -.. method:: around(a, \*, decimals) - - Returns a new float array in which each element is rounded to - ``decimals`` places. - -.. method:: atan - - Computes the inverse tangent function; the return values are in the - range [-pi/2,pi/2]. - -.. method:: atan2(y,x) - - Computes the inverse tangent function of y/x; the return values are in - the range [-pi, pi]. - -.. method:: atanh - - Computes the inverse hyperbolic tangent function - -.. method:: ceil - - Rounds numbers up to the next whole number - -.. method:: cos - - Computes the cosine function - -.. method:: erf - - Computes the error function, which has applications in statistics - -.. method:: erfc - - Computes the complementary error function, which has applications in statistics - -.. method:: exp - - Computes the exponent function. - -.. method:: expm1 - - Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the `exp` function. - -.. method:: floor - - Rounds numbers up to the next whole number - -.. method:: gamma - - Computes the gamma function - -.. method:: lgamma - - Computes the natural log of the gamma function - -.. method:: log - - Computes the natural log - -.. method:: log10 - - Computes the log base 10 - -.. method:: log2 - - Computes the log base 2 - -.. method:: sin - - Computes the sine - -.. method:: sinh - - Computes the hyperbolic sine - -.. method:: sqrt - - Computes the square root - -.. method:: tan - - Computes the tangent - -.. method:: tanh - - Computes the hyperbolic tangent - -:mod:`ulab.linalg` - Linear algebra functions -============================================= - -.. module:: ulab.linalg - -.. method:: cholesky(A) - - :param ~ulab.array A: a positive definite, symmetric square matrix - :return ~ulab.array L: a square root matrix in the lower triangular form - :raises ValueError: If the input does not fulfill the necessary conditions - - The returned matrix satisfies the equation m=LL* - -.. method:: det - - :param: m, a square matrix - :return float: The determinant of the matrix - - Computes the eigenvalues and eigenvectors of a square matrix - -.. method:: dot(m1, m2) - - :param ~ulab.array m1: a matrix - :param ~ulab.array m2: a matrix - - Computes the matrix product of two matrices - - **WARNING:** Unlike ``numpy``, this function cannot be used to compute the dot product of two vectors - -.. method:: eig(m) - - :param m: a square matrix - :return tuple (eigenvectors, eigenvalues): - - Computes the eigenvalues and eigenvectors of a square matrix - -.. method:: inv(m) - - :param ~ulab.array m: a square matrix - :return: The inverse of the matrix, if it exists - :raises ValueError: if the matrix is not invertible - - Computes the inverse of a square matrix - -.. method:: size(array) - - Return the total number of elements in the array, as an integer. - -.. method:: trace(m) - - :param m: a square matrix - - Compute the trace of the matrix, the sum of its diagonal elements. - -:mod:`ulab.filter` --- Filtering functions -========================================== - -.. module:: ulab.filter - -.. method:: convolve(r, c=None) - - :param ulab.array a: - :param ulab.array v: - - Returns the discrete, linear convolution of two one-dimensional sequences. - The result is always an array of float. Only the ``full`` mode is supported, - and the ``mode`` named parameter of numpy is not accepted. Note that all other - modes can be had by slicing a ``full`` result. - - Convolution filters can implement high pass, low pass, band pass, etc., - filtering operations. Convolution filters are typically constructed ahead - of time. This can be done using desktop python with scipy, or on web pages - such as https://fiiir.com/ - - Convolution is most time-efficient when both inputs are of float type. - -:mod:`ulab.fft` --- Frequency-domain functions -============================================== - -.. module:: ulab.fft - -.. method:: fft(r, c=None) - - :param ulab.array r: A 1-dimension array of values whose size is a power of 2 - :param ulab.array c: An optional 1-dimension array of values whose size is a power of 2, giving the complex part of the value - :return tuple (r, c): The real and complex parts of the FFT - - Perform a Fast Fourier Transform from the time domain into the frequency domain - - See also ~ulab.extras.spectrum, which computes the magnitude of the fft, - rather than separately returning its real and imaginary parts. - -.. method:: ifft(r, c=None) - - :param ulab.array r: A 1-dimension array of values whose size is a power of 2 - :param ulab.array c: An optional 1-dimension array of values whose size is a power of 2, giving the complex part of the value - :return tuple (r, c): The real and complex parts of the inverse FFT - - Perform an Inverse Fast Fourier Transform from the frequeny domain into the time domain - -:mod:`ulab.numerical` --- Numerical and Statistical functions -============================================================= - -.. module:: ulab.numerical - -Most of these functions take an "axis" argument, which indicates whether to -operate over the flattened array (None), rows (0), or columns (1). - -.. method:: argmax(array, \*, axis=None) - - Return the index of the maximum element of the 1D array - -.. method:: argmin(array, \*, axis=None) - - Return the index of the minimum element of the 1D array - -.. method:: argsort(array, \*, axis=None) - - Returns an array which gives indices into the input array from least to greatest. - -.. method:: diff(array, \*, axis=1) - - Return the numerical derivative of successive elements of the array, as - an array. axis=None is not supported. - -.. method:: flip(array, \*, axis=None) - - Returns a new array that reverses the order of the elements along the - given axis, or along all axes if axis is None. - -.. method:: max(array, \*, axis=None) - - Return the maximum element of the 1D array - -.. method:: mean(array, \*, axis=None) - - Return the mean element of the 1D array, as a number if axis is None, otherwise as an array. - -.. method:: min(array, \*, axis=None) - - Return the minimum element of the 1D array - -.. method:: roll(array, distance, \*, axis=None) - - Shift the content of a vector by the positions given as the second - argument. If the ``axis`` keyword is supplied, the shift is applied to - the given axis. The array is modified in place. - -.. method:: std(array, \*, axis=None) - - Return the standard deviation of the array, as a number if axis is None, otherwise as an array. - -.. method:: sum(array, \*, axis=None) - - Return the sum of the array, as a number if axis is None, otherwise as an array. - -.. method:: sort(array, \*, axis=0) - - Sort the array along the given axis, or along all axes if axis is None. - The array is modified in place. - -:mod:`ulab.poly` --- Polynomial functions -========================================= - -.. module:: ulab.poly - -.. method:: polyfit([x, ] y, degree) - - Return a polynomial of given degree that approximates the function - f(x)=y. If x is not supplied, it is the range(len(y)). - -.. method:: polyval(p, x) - - Evaluate the polynomial p at the points x. x must be an array. - -:mod:`ulab.extras` --- Additional functions not in numpy -======================================================== - -.. method:: spectrum(r): - - :param ulab.array r: A 1-dimension array of values whose size is a power of 2 - - Computes the spectrum of the input signal. This is the absolute value of the (complex-valued) fft of the signal. - - This function is similar to scipy's ``scipy.signal.spectrogram``. diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index bcea5b2c5..8c0c364ff 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -28,10 +28,7 @@ #include "shared-bindings/usb_hid/Device.h" //| class Device: -//| """.. currentmodule:: usb_hid -//| -//| :class:`Device` -- HID Device -//| ============================================ +//| """HID Device //| //| Usage:: //| diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 3d0978d62..e12ea8da4 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -31,12 +31,7 @@ #include "shared-bindings/usb_hid/__init__.h" #include "shared-bindings/usb_hid/Device.h" -//| """:mod:`usb_hid` --- USB Human Interface Device -//| =========================================================== -//| -//| .. module:: usb_hid -//| :synopsis: USB Human Interface Device -//| :platform: SAMD21 +//| """USB Human Interface Device //| //| The `usb_hid` module allows you to output data as a HID device.""" //| @@ -44,14 +39,6 @@ //| usb_hid.devices: Any = ... //| """Tuple of all active HID device interfaces.""" //| - -//| """Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| Device""" -//| STATIC const mp_rom_map_elem_t usb_hid_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, { MP_ROM_QSTR(MP_QSTR_devices), MP_ROM_PTR(&common_hal_usb_hid_devices) }, diff --git a/shared-bindings/usb_midi/PortIn.c b/shared-bindings/usb_midi/PortIn.c index 55a5865ca..9d9310b47 100644 --- a/shared-bindings/usb_midi/PortIn.c +++ b/shared-bindings/usb_midi/PortIn.c @@ -36,12 +36,9 @@ #include "supervisor/shared/translate.h" //| class PortIn: -//| """.. currentmodule:: usb_midi +//| """Receives midi commands over USB""" //| -//| :class:`PortIn` -- receives midi commands over USB -//| ===================================================""" -//| -//| def __init__(self, ): +//| def __init__(self): //| """You cannot create an instance of `usb_midi.PortIn`. //| //| PortIn objects are constructed for every corresponding entry in the USB diff --git a/shared-bindings/usb_midi/PortOut.c b/shared-bindings/usb_midi/PortOut.c index d83eb53b6..14ed0e767 100644 --- a/shared-bindings/usb_midi/PortOut.c +++ b/shared-bindings/usb_midi/PortOut.c @@ -36,10 +36,7 @@ #include "supervisor/shared/translate.h" //| class PortOut: -//| """.. currentmodule:: usb_midi -//| -//| :class:`PortOut` -- sends midi messages to a computer over USB -//| ==============================================================""" +//| """Sends midi messages to a computer over USB""" //| //| def __init__(self, ): //| """You cannot create an instance of `usb_midi.PortOut`. diff --git a/shared-bindings/usb_midi/__init__.c b/shared-bindings/usb_midi/__init__.c index 2631d8a88..5570b601c 100644 --- a/shared-bindings/usb_midi/__init__.c +++ b/shared-bindings/usb_midi/__init__.c @@ -35,22 +35,7 @@ #include "py/runtime.h" -//| """:mod:`usb_midi` --- MIDI over USB -//| ================================================= -//| -//| .. module:: usb_midi -//| :synopsis: MIDI over USB -//| -//| The `usb_midi` module contains classes to transmit and receive MIDI messages over USB -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| PortIn -//| PortOut""" -//| +//| """Classes to transmit and receive MIDI messages over USB""" //| mp_map_elem_t usb_midi_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) }, diff --git a/shared-bindings/ustack/__init__.c b/shared-bindings/ustack/__init__.c index 073840aba..e5fac6941 100644 --- a/shared-bindings/ustack/__init__.c +++ b/shared-bindings/ustack/__init__.c @@ -34,15 +34,11 @@ -//| """:mod:`ustack` --- Stack information and analysis -//| ======================================================== -//| -//| .. module:: ustack -//| :synopsis: stack information functions""" +//| """Stack information and analysis""" //| #if MICROPY_MAX_STACK_USAGE -//| def max_stack_usage() -> Any: +//| def max_stack_usage() -> int: //| """Return the maximum excursion of the stack so far.""" //| ... //| @@ -53,7 +49,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(max_stack_usage_obj, max_stack_usage); #endif // MICROPY_MAX_STACK_USAGE -//| def stack_size() -> Any: +//| def stack_size() -> int: //| """Return the size of the entire stack. //| Same as in micropython.mem_info(), but returns a value instead //| of just printing it.""" diff --git a/shared-bindings/wiznet/__init__.c b/shared-bindings/wiznet/__init__.c index 5c8e8d3fd..0b0b7b14b 100644 --- a/shared-bindings/wiznet/__init__.c +++ b/shared-bindings/wiznet/__init__.c @@ -35,21 +35,7 @@ #include "shared-module/network/__init__.h" -//| """:mod:`wiznet` --- Support for WizNet hardware -//| ============================================= -//| -//| .. module:: wiznet -//| :synopsis: Support for WizNet hardware -//| :platform: SAMD -//| -//| Support for WizNet hardware, including the WizNet 5500 Ethernet adaptor. -//| -//| Libraries -//| -//| .. toctree:: -//| :maxdepth: 3 -//| -//| wiznet5k""" +//| """Support for WizNet hardware, including the WizNet 5500 Ethernet adaptor.""" //| extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k; diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index 2e2ee3949..2f49dffea 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -47,10 +47,7 @@ #include "shared-module/wiznet/wiznet5k.h" //| class WIZNET5K: -//| """.. currentmodule:: wiznet -//| -//| :class:`WIZNET5K` -- wrapper for Wiznet 5500 Ethernet interface -//| ===============================================================""" +//| """Wrapper for Wiznet 5500 Ethernet interface""" //| //| def __init__(self, spi: busio.SPI, cs: microcontroller.Pin, rst: microcontroller.Pin, dhcp: bool = True): //| """Create a new WIZNET5500 interface using the specified pins diff --git a/tools/extract_pyi.py b/tools/extract_pyi.py index de783eb27..95370f761 100644 --- a/tools/extract_pyi.py +++ b/tools/extract_pyi.py @@ -22,7 +22,7 @@ for module in modules: pyi_lines = [] classes = os.listdir(module_path) classes = [x for x in sorted(classes) if x.endswith(".c")] - if classes[-1] == "__init__.c": + if classes and classes[-1] == "__init__.c": classes.insert(0, classes.pop()) for class_file in classes: class_path = os.path.join(module_path, class_file) @@ -37,6 +37,13 @@ for module in modules: continue pyi_lines.append(line) + raw_stubs = [x for x in sorted(classes) if x.endswith(".pyi")] + if raw_stubs and raw_stubs[-1] == "__init__.pyi": + raw_stubs.insert(0, raw_stubs.pop()) + for raw_stub in raw_stubs: + raw_stub_path = os.path.join(module_path, raw_stub) + with open(raw_stub_path, "r") as f: + pyi_lines.extend(f.readlines()) stub_filename = os.path.join(stub_directory, module + ".pyi") print(stub_filename) stub_contents = "".join(pyi_lines) @@ -54,3 +61,6 @@ for module in modules: print() print(f"{ok} ok out of {total}") + +if ok != total: + sys.exit(total - ok) -- cgit v1.2.3