Merge pull request #6933 from jepler/🥧🐮

Implement a useful subset of `wifi` and `socketpool` modules on 🥧🐮
This commit is contained in:
Dan Halbert 2022-09-28 18:09:24 -04:00 committed by GitHub
commit db065a299f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 3710 additions and 110 deletions

6
.gitmodules vendored
View File

@ -310,3 +310,9 @@
[submodule "ports/espressif/esp32-camera"]
path = ports/espressif/esp32-camera
url = https://github.com/adafruit/esp32-camera/
[submodule "ports/raspberrypi/lib/cyw43-driver"]
path = ports/raspberrypi/lib/cyw43-driver
url = https://github.com/georgerobotics/cyw43-driver.git
[submodule "ports/raspberrypi/lib/lwip"]
path = ports/raspberrypi/lib/lwip
url = https://github.com/lwip-tcpip/lwip.git

View File

@ -95,6 +95,7 @@ msgstr ""
msgid "%q failure: %d"
msgstr ""
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/microcontroller/Pin.c
msgid "%q in use"
msgstr ""
@ -302,7 +303,7 @@ msgstr ""
msgid "'%s' object doesn't support item deletion"
msgstr ""
#: py/runtime.c
#: ports/raspberrypi/common-hal/wifi/Radio.c py/runtime.c
msgid "'%s' object has no attribute '%q'"
msgstr ""
@ -488,6 +489,7 @@ msgid "Already running"
msgstr ""
#: ports/espressif/common-hal/wifi/Radio.c
#: ports/raspberrypi/common-hal/wifi/Radio.c
msgid "Already scanning for wifi networks"
msgstr ""
@ -916,6 +918,10 @@ msgstr ""
msgid "Expected a %q"
msgstr ""
#: ports/raspberrypi/bindings/cyw43/__init__.c
msgid "Expected a %q or %q"
msgstr ""
#: shared-bindings/alarm/__init__.c
msgid "Expected an %q"
msgstr ""
@ -1177,7 +1183,7 @@ msgstr ""
msgid "Internal watchdog timer expired."
msgstr ""
#: py/argcheck.c
#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c
msgid "Invalid %q"
msgstr ""
@ -2203,6 +2209,11 @@ msgstr ""
msgid "Unknown system firmware error: %d"
msgstr ""
#: ports/raspberrypi/common-hal/wifi/__init__.c
#, c-format
msgid "Unkown error code %d"
msgstr ""
#: shared-bindings/adafruit_pixelbuf/PixelBuf.c
#, c-format
msgid "Unmatched number of items on RHS (expected %d, got %d)."
@ -4115,14 +4126,10 @@ msgstr ""
msgid "type is not an acceptable base type"
msgstr ""
#: py/runtime.c
#: py/objgenerator.c py/runtime.c
msgid "type object '%q' has no attribute '%q'"
msgstr ""
#: py/objgenerator.c
msgid "type object 'generator' has no attribute '__await__'"
msgstr ""
#: py/objtype.c
msgid "type takes 1 or 3 arguments"
msgstr ""
@ -4253,9 +4260,14 @@ msgid "width must be greater than zero"
msgstr ""
#: ports/espressif/common-hal/wifi/Radio.c
#: ports/raspberrypi/common-hal/wifi/Radio.c
msgid "wifi is not enabled"
msgstr ""
#: ports/raspberrypi/common-hal/wifi/Monitor.c
msgid "wifi.Monitor not available"
msgstr ""
#: shared-bindings/_bleio/Adapter.c
msgid "window must be <= interval"
msgstr ""

1
main.c
View File

@ -784,6 +784,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
mp_printf(&mp_plat_print, "%02X", raw_id[i]);
}
mp_printf(&mp_plat_print, "\n");
port_boot_info();
#endif
bool found_boot = maybe_run_list(boot_py_filenames);

View File

@ -20,3 +20,5 @@ override undefine PROG
endif
include mpy-cross.mk
CFLAGS += -g
STRIP = :

View File

@ -11,3 +11,4 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_RAINBOWIO = 0

View File

@ -66,11 +66,12 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->output = false;
// This also sets direction to input.
common_hal_digitalio_digitalinout_set_pull(self, pull);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -151,7 +152,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
}
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
enum gpio_pull_mode asf_pull = GPIO_PULL_OFF;
switch (pull) {
@ -168,6 +169,7 @@ void common_hal_digitalio_digitalinout_set_pull(
// Must set pull after setting direction.
gpio_set_pin_direction(self->pin->number, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(self->pin->number, asf_pull);
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -63,11 +63,12 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->output = false;
// This also sets direction to input.
common_hal_digitalio_digitalinout_set_pull(self, pull);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -134,7 +135,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
}
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
const uint8_t pin = self->pin->number;
BP_PULL_Enum bp_pull = BP_PULL_NONE;
@ -144,6 +145,7 @@ void common_hal_digitalio_digitalinout_set_pull(
bp_pull = BP_PULL_DOWN;
}
gpio_set_pull(pin, bp_pull);
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -64,11 +64,12 @@ bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *se
return self->pin == NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->input = true;
self->pull = pull;
board_gpio_write(self->pin->number, -1);
board_gpio_config(self->pin->number, 0, true, true, pull);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode) {
@ -124,10 +125,11 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitali
return self->open_drain ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
}
void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->pull = pull;
board_gpio_write(self->pin->number, -1);
board_gpio_config(self->pin->number, 0, true, true, pull);
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self) {

View File

@ -82,10 +82,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
common_hal_digitalio_digitalinout_set_pull(self, pull);
gpio_set_direction(self->pin->number, GPIO_MODE_INPUT);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -140,7 +141,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
return DRIVE_MODE_PUSH_PULL;
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
gpio_num_t number = self->pin->number;
gpio_pullup_dis(number);
@ -150,6 +151,7 @@ void common_hal_digitalio_digitalinout_set_pull(
} else if (pull == PULL_DOWN) {
gpio_pulldown_en(number);
}
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -58,10 +58,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
(void)pull;
touch_oe_write(touch_oe_read() & ~(1 << self->pin->number));
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -111,10 +112,11 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
}
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
(void)self;
(void)pull;
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -88,12 +88,13 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->output = false;
// This also sets direction to input.
common_hal_digitalio_digitalinout_set_pull(self, pull);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -150,7 +151,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
}
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->pull = pull;
@ -158,6 +159,7 @@ void common_hal_digitalio_digitalinout_set_pull(
const gpio_pin_config_t config = { kGPIO_DigitalInput, 0, kGPIO_NoIntmode };
GPIO_PinInit(self->pin->gpio, self->pin->number, &config);
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -59,10 +59,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
nrf_gpio_cfg_input(self->pin->number, NRF_GPIO_PIN_NOPULL);
common_hal_digitalio_digitalinout_set_pull(self, pull);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -120,7 +121,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
}
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
nrf_gpio_pin_pull_t hal_pull = NRF_GPIO_PIN_NOPULL;
@ -137,6 +138,7 @@ void common_hal_digitalio_digitalinout_set_pull(
}
nrf_gpio_cfg_input(self->pin->number, hal_pull);
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -57,54 +57,134 @@ CROSS_COMPILE = arm-none-eabi-
HAL_DIR=hal/$(MCU_SERIES)
INC += -I. \
-I../.. \
-I../lib/mp-readline \
-I../shared/timeutils \
-Iboards/$(BOARD) \
-Iboards/ \
-isystem sdk/ \
-isystem sdk/src/common/pico_base/include/ \
-isystem sdk/src/common/pico_binary_info/include/ \
-isystem sdk/src/common/pico_stdlib/include/ \
-isystem sdk/src/common/pico_sync/include/ \
-isystem sdk/src/common/pico_time/include/ \
-isystem sdk/src/common/pico_util/include/ \
-isystem sdk/src/rp2040/hardware_regs/include/ \
-isystem sdk/src/rp2040/hardware_structs/include/ \
-isystem sdk/src/rp2_common/hardware_adc/include/ \
-isystem sdk/src/rp2_common/hardware_base/include/ \
-isystem sdk/src/rp2_common/hardware_claim/include/ \
-isystem sdk/src/rp2_common/hardware_clocks/include/ \
-isystem sdk/src/rp2_common/hardware_divider/include/ \
-isystem sdk/src/rp2_common/hardware_dma/include/ \
-isystem sdk/src/rp2_common/hardware_flash/include/ \
-isystem sdk/src/rp2_common/hardware_gpio/include/ \
-isystem sdk/src/rp2_common/hardware_irq/include/ \
-isystem sdk/src/rp2_common/hardware_i2c/include/ \
-isystem sdk/src/rp2_common/hardware_pio/include/ \
-isystem sdk/src/rp2_common/hardware_pll/include/ \
-isystem sdk/src/rp2_common/hardware_resets/include/ \
-isystem sdk/src/rp2_common/hardware_rtc/include/ \
-isystem sdk/src/rp2_common/hardware_spi/include/ \
-isystem sdk/src/rp2_common/hardware_sync/include/ \
-isystem sdk/src/rp2_common/hardware_timer/include/ \
-isystem sdk/src/rp2_common/hardware_uart/include/ \
-isystem sdk/src/rp2_common/hardware_watchdog/include/ \
-isystem sdk/src/rp2_common/hardware_xosc/include/ \
-isystem sdk/src/rp2_common/pico_multicore/include/ \
-isystem sdk/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/include/ \
-isystem sdk/src/rp2_common/pico_stdio/include/ \
-isystem sdk/src/rp2_common/pico_printf/include/ \
-isystem sdk/src/rp2_common/pico_float/include/ \
-isystem sdk/src/rp2_common/pico_platform/include/ \
-isystem sdk/src/rp2_common/pico_runtime/printf/include/ \
-isystem sdk/src/rp2_common/pico_bootrom/include/ \
-isystem sdk/src/rp2_common/pico_unique_id/include/ \
-Isdk_config \
-I../../lib/tinyusb/src \
-I../../supervisor/shared/usb \
-I$(BUILD)
ifeq ($(CIRCUITPY_CYW43),1)
INC_CYW43 := \
-isystem lib/cyw43-driver/firmware \
-isystem lib/cyw43-driver/src \
-isystem lib/lwip/src/include \
-isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \
-isystem sdk/src/rp2_common/pico_lwip/include/ \
CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DCYW43_LOGIC_DEBUG=0
SRC_SDK_CYW43 := \
src/common/pico_sync/sem.c \
src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \
src/rp2_common/pico_cyw43_arch/cyw43_arch.c \
src/rp2_common/pico_cyw43_arch/cyw43_arch_threadsafe_background.c \
src/rp2_common/pico_lwip/nosys.c \
src/rp2_common/pico_lwip/random.c \
SRC_LWIP := \
shared/netutils/netutils.c \
$(wildcard lib/lwip/src/core/*.c) \
$(wildcard lib/lwip/src/core/ipv4/*.c) \
lib/lwip/src/netif/ethernet.c \
$(wildcard lwip_src/*.c) \
SRC_CYW43 := \
$(wildcard bindings/cyw43/*.c) \
lib/cyw43-driver/src/cyw43_stats.c \
lib/cyw43-driver/src/cyw43_ctrl.c \
lib/cyw43-driver/src/cyw43_ll.c \
lib/cyw43-driver/src/cyw43_lwip.c \
PIOASM = $(BUILD)/pioasm/pioasm/pioasm
.PHONY: PioasmBuild
PioasmBuild: $(PIOASM)
$(PIOASM):
$(Q)cmake -S pioasm -B $(BUILD)/pioasm
$(Q)$(MAKE) -C $(BUILD)/pioasm PioasmBuild
$(BUILD)/cyw43_bus_pio_spi.pio.h: sdk/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.pio $(PIOASM)
$(Q)$(PIOASM) -o c-sdk $< $@
$(BUILD)/sdk/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.o: $(BUILD)/cyw43_bus_pio_spi.pio.h
CYW43_FIRMWARE_BIN = 43439A0-7.95.49.00.combined
$(BUILD)/cyw43_resource.o: lib/cyw43-driver/firmware/$(CYW43_FIRMWARE_BIN)
$(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
--readonly-text \
--rename-section .data=.big_const,contents,alloc,load,readonly,data \
--redefine-sym _binary_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_start=fw_43439A0_7_95_49_00_start \
--redefine-sym _binary_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_size=fw_43439A0_7_95_49_00_size \
--redefine-sym _binary_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_end=fw_43439A0_7_95_49_00_end \
$< $@
OBJ_CYW43 := $(BUILD)/cyw43_resource.o
# need to do the equivalent of this in cmake
### # cyw43_resource.o contains the WiFi and BT firmware as a binary blob
### add_custom_command(
### OUTPUT ${CYW43_FIRMWARE_OBJ}
### DEPENDS ${PICO_CYW43_DRIVER_PATH}/firmware/${CYW43_FIRMWARE_BIN}
### WORKING_DIRECTORY ${PICO_CYW43_DRIVER_PATH}/firmware
### COMMAND ${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm
### --readonly-text
### --rename-section .data=${RESOURCE_SECNAME},${RESOURCE_SECFLAGS}
### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_start=${CYW43_FIRMWARE_PRETTY}_start
### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_end=${CYW43_FIRMWARE_PRETTY}_end
### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_size=${CYW43_FIRMWARE_PRETTY}_size
### ${CYW43_FIRMWARE_BIN} ${CYW43_FIRMWARE_OBJ}
### )
###
else
INC_CYW43 :=
CFLAGS_CYW43 :=
SRC_SDK_CYW43 :=
SRC_CYW43 :=
OBJ_CYW43 :=
SRC_LWIP :=
endif
INC += \
-I. \
-Ilwip_inc \
-I../.. \
-I../lib/mp-readline \
-I../shared/timeutils \
-Iboards/$(BOARD) \
-Iboards/ \
-isystem sdk/ \
-isystem sdk/src/common/pico_base/include/ \
-isystem sdk/src/common/pico_binary_info/include/ \
-isystem sdk/src/common/pico_stdlib/include/ \
-isystem sdk/src/common/pico_sync/include/ \
-isystem sdk/src/common/pico_time/include/ \
-isystem sdk/src/common/pico_util/include/ \
-isystem sdk/src/rp2040/hardware_regs/include/ \
-isystem sdk/src/rp2040/hardware_structs/include/ \
-isystem sdk/src/rp2_common/hardware_adc/include/ \
-isystem sdk/src/rp2_common/hardware_base/include/ \
-isystem sdk/src/rp2_common/hardware_claim/include/ \
-isystem sdk/src/rp2_common/hardware_clocks/include/ \
-isystem sdk/src/rp2_common/hardware_divider/include/ \
-isystem sdk/src/rp2_common/hardware_dma/include/ \
-isystem sdk/src/rp2_common/hardware_flash/include/ \
-isystem sdk/src/rp2_common/hardware_gpio/include/ \
-isystem sdk/src/rp2_common/hardware_irq/include/ \
-isystem sdk/src/rp2_common/hardware_i2c/include/ \
-isystem sdk/src/rp2_common/hardware_pio/include/ \
-isystem sdk/src/rp2_common/hardware_pll/include/ \
-isystem sdk/src/rp2_common/hardware_resets/include/ \
-isystem sdk/src/rp2_common/hardware_rtc/include/ \
-isystem sdk/src/rp2_common/hardware_spi/include/ \
-isystem sdk/src/rp2_common/hardware_sync/include/ \
-isystem sdk/src/rp2_common/hardware_timer/include/ \
-isystem sdk/src/rp2_common/hardware_uart/include/ \
-isystem sdk/src/rp2_common/hardware_watchdog/include/ \
-isystem sdk/src/rp2_common/hardware_xosc/include/ \
-isystem sdk/src/rp2_common/pico_multicore/include/ \
-isystem sdk/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/include/ \
-isystem sdk/src/rp2_common/pico_stdio/include/ \
-isystem sdk/src/rp2_common/pico_printf/include/ \
-isystem sdk/src/rp2_common/pico_float/include/ \
-isystem sdk/src/rp2_common/pico_platform/include/ \
-isystem sdk/src/rp2_common/pico_runtime/printf/include/ \
-isystem sdk/src/rp2_common/pico_bootrom/include/ \
-isystem sdk/src/rp2_common/pico_unique_id/include/ \
$(INC_CYW43) \
-Isdk_config \
-I../../lib/tinyusb/src \
-I../../supervisor/shared/usb \
-I$(BUILD)
# Pico specific configuration
CFLAGS += -DRASPBERRYPI -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=0 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0
@ -115,6 +195,9 @@ CFLAGS += -DTUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 -DCFG_TUSB_MCU=OPT_MCU_R
# option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk
CFLAGS += $(OPTIMIZATION_FLAGS)
# flags specific to wifi / cyw43
CFLAGS += $(CFLAGS_CYW43)
#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb3 -O3
@ -185,9 +268,10 @@ SRC_SDK := \
src/rp2_common/pico_runtime/runtime.c \
src/rp2_common/pico_stdio/stdio.c \
src/rp2_common/pico_unique_id/unique_id.c \
$(SRC_SDK_CYW43) \
SRC_SDK := $(addprefix sdk/, $(SRC_SDK))
$(patsubst %.c,$(BUILD)/%.o,$(SRC_SDK)): CFLAGS += -Wno-missing-prototypes -Wno-undef
$(patsubst %.c,$(BUILD)/%.o,$(SRC_SDK) $(SRC_CYW43)): CFLAGS += -Wno-missing-prototypes -Wno-undef
SRC_C += \
boards/$(BOARD)/board.c \
@ -204,6 +288,8 @@ SRC_C += \
lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \
lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \
mphalport.c \
$(SRC_CYW43) \
$(SRC_LWIP) \
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
@ -243,6 +329,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
OBJ += $(BUILD)/boot2_padded_checksummed.o
OBJ += $(OBJ_CYW43)
$(BUILD)/boot2_padded_checksummed.o: $(BUILD)/boot2_padded_checksummed.S
$(STEPECHO) "CC $<"
@ -276,12 +363,13 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_M
all: $(BUILD)/firmware.uf2
$(BUILD)/firmware.elf: $(OBJ) link.ld
LINK_LD := $(firstword $(wildcard boards/$(BOARD)/link.ld link.ld))
$(BUILD)/firmware.elf: $(OBJ) $(LINK_LD)
$(STEPECHO) "LINK $@"
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs
$(Q)echo $(PICO_LDFLAGS) > $(BUILD)/firmware.ldflags
$(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,link.ld -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs
$(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py link.ld
$(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,$(LINK_LD) -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs
$(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINK_LD)
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(STEPECHO) "Create $@"

View File

@ -0,0 +1,70 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Jeff Epler for Adafruit Industries
* Copyright (c) 2016 Scott Shawcroft
*
* 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.
*/
#include "py/runtime.h"
#include "shared-bindings/board/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "bindings/cyw43/__init__.h"
const mp_obj_type_t cyw43_pin_type = {
{ &mp_type_type },
.flags = MP_TYPE_FLAG_EXTENDED,
.name = MP_QSTR_CywPin,
.print = shared_bindings_microcontroller_pin_print,
MP_TYPE_EXTENDED_FIELDS(
.unary_op = mp_generic_unary_op,
)
};
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj) {
if (!mp_obj_is_type(obj, &mcu_pin_type) && !mp_obj_is_type(obj, &cyw43_pin_type)) {
mp_raise_TypeError_varg(translate("Expected a %q or %q"), mcu_pin_type.name, cyw43_pin_type.name);
}
return MP_OBJ_TO_PTR(obj);
}
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj) {
const mcu_pin_obj_t *pin = validate_obj_is_pin_including_cyw43(obj);
assert_pin_free(pin);
return pin;
}
STATIC const mp_rom_map_elem_t cyw43_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cyw43) },
{ MP_ROM_QSTR(MP_QSTR_CywPin), MP_ROM_QSTR(MP_QSTR_CywPin) },
};
STATIC MP_DEFINE_CONST_DICT(cyw43_module_globals, cyw43_module_globals_table);
const mp_obj_module_t cyw43_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&cyw43_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_cyw43, cyw43_module, CIRCUITPY_CYW43);

View File

@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Jeff Epler for Adafruit Industries
* Copyright (c) 2016 Scott Shawcroft
*
* 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.
*/
#pragma once
#include "py/obj.h"
extern const mp_obj_type_t cyw43_pin_type;
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj);
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj);

View File

@ -0,0 +1,29 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 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.
*/
#include "supervisor/board.h"
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

View File

@ -0,0 +1,293 @@
/* Based on GCC ARM embedded samples.
Defines the following symbols for use by code:
__exidx_start
__exidx_end
__etext
__data_start__
__preinit_array_start
__preinit_array_end
__init_array_start
__init_array_end
__fini_array_start
__fini_array_end
__data_end__
__bss_start__
__bss_end__
__end__
end
__HeapLimit
__StackLimit
__StackTop
__stack (== StackTop)
*/
MEMORY
{
FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1788k
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k
SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}
ENTRY(_entry_point)
SECTIONS
{
/* Second stage bootloader is prepended to the image. It must be 256 bytes big
and checksummed. It is usually built by the boot_stage2 target
in the Pico SDK
*/
.flash_begin : {
__flash_binary_start = .;
} > FLASH_FIRMWARE
.boot2 : {
__boot2_start__ = .;
KEEP (*(.boot2))
__boot2_end__ = .;
} > FLASH_FIRMWARE
ASSERT(__boot2_end__ - __boot2_start__ == 256,
"ERROR: Pico second stage bootloader must be 256 bytes in size")
/* The second stage will always enter the image at the start of .text.
The debugger will use the ELF entry point, which is the _entry_point
symbol if present, otherwise defaults to start of .text.
This can be used to transfer control back to the bootrom on debugger
launches only, to perform proper flash setup.
*/
.text : {
__logical_binary_start = .;
KEEP (*(.vectors))
KEEP (*(.binary_info_header))
__binary_info_header_end = .;
KEEP (*(.reset))
/* TODO revisit this now memset/memcpy/float in ROM */
/* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
* FLASH ... we will include any thing excluded here in .data below by default */
*(.init)
__property_getter_start = .;
*(.property_getter)
__property_getter_end = .;
__property_getset_start = .;
*(.property_getset)
__property_getset_end = .;
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*)
*(.fini)
/* Pull all c'tors into .text */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* Followed by destructors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.eh_frame*)
. = ALIGN(4);
} > FLASH_FIRMWARE
.rodata : {
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
. = ALIGN(4);
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
. = ALIGN(4);
} > FLASH_FIRMWARE
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH_FIRMWARE
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH_FIRMWARE
__exidx_end = .;
/* Machine inspectable binary information */
. = ALIGN(4);
__binary_info_start = .;
.binary_info :
{
KEEP(*(.binary_info.keep.*))
*(.binary_info.*)
} > FLASH_FIRMWARE
__binary_info_end = .;
. = ALIGN(4);
/* End of .text-like segments */
__etext = .;
.ram_vector_table (COPY): {
*(.ram_vector_table)
} > RAM
.data : {
__data_start__ = .;
*(vtable)
*(.time_critical*)
/* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
*(.text*)
. = ALIGN(4);
*(.rodata*)
. = ALIGN(4);
*(.data*)
. = ALIGN(4);
*(.after_data.*)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__mutex_array_start = .);
KEEP(*(SORT(.mutex_array.*)))
KEEP(*(.mutex_array))
PROVIDE_HIDDEN (__mutex_array_end = .);
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(SORT(.preinit_array.*)))
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
*(SORT(.fini_array.*))
*(.fini_array)
PROVIDE_HIDDEN (__fini_array_end = .);
*(.jcr)
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM AT> FLASH_FIRMWARE
.itcm :
{
. = ALIGN(4);
*(.itcm.*)
. = ALIGN(4);
} > RAM AT> FLASH_FIRMWARE
_ld_itcm_destination = ADDR(.itcm);
_ld_itcm_flash_copy = LOADADDR(.itcm);
_ld_itcm_size = SIZEOF(.itcm);
.dtcm_data :
{
. = ALIGN(4);
*(.dtcm_data.*)
. = ALIGN(4);
} > RAM AT> FLASH_FIRMWARE
_ld_dtcm_data_destination = ADDR(.dtcm_data);
_ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data);
_ld_dtcm_data_size = SIZEOF(.dtcm_data);
.dtcm_bss :
{
. = ALIGN(4);
*(.dtcm_bss.*)
. = ALIGN(4);
} > RAM AT> RAM
_ld_dtcm_bss_start = ADDR(.dtcm_bss);
_ld_dtcm_bss_size = SIZEOF(.dtcm_bss);
.uninitialized_data (COPY): {
. = ALIGN(4);
*(.uninitialized_data*)
} > RAM
/* Start and end symbols must be word-aligned */
.scratch_x : {
__scratch_x_start__ = .;
*(.scratch_x.*)
. = ALIGN(4);
__scratch_x_end__ = .;
} > SCRATCH_X AT > FLASH_FIRMWARE
__scratch_x_source__ = LOADADDR(.scratch_x);
.scratch_y : {
__scratch_y_start__ = .;
*(.scratch_y.*)
. = ALIGN(4);
__scratch_y_end__ = .;
} > SCRATCH_Y AT > FLASH_FIRMWARE
__scratch_y_source__ = LOADADDR(.scratch_y);
.bss : {
. = ALIGN(4);
__bss_start__ = .;
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM
.heap (COPY):
{
__end__ = .;
end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
/* .stack*_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later
*
* stack1 section may be empty/missing if platform_launch_core1 is not used */
/* by default we put core 0 stack at the end of scratch Y, so that if core 1
* stack is not used then all of SCRATCH_X is free.
*/
.stack1_dummy (COPY):
{
*(.stack1*)
} > SCRATCH_X
.stack_dummy (COPY):
{
*(.stack*)
} > SCRATCH_Y
.flash_end : {
__flash_binary_end = .;
} > FLASH_FIRMWARE
/* stack limit is poorly named, but historically is maximum heap ptr */
__StackLimit = ORIGIN(RAM) + LENGTH(RAM);
__StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
__StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
__StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
__StackBottom = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
/* todo assert on extra code */
}

View File

@ -0,0 +1,5 @@
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico W"
#define MICROPY_HW_MCU_NAME "rp2040"
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1)
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1)

View File

@ -0,0 +1,21 @@
USB_VID = 0x239A
USB_PID = 0x8120
USB_PRODUCT = "Pico W"
USB_MANUFACTURER = "Raspberry Pi"
CHIP_VARIANT = RP2040
CHIP_FAMILY = rp2
EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
CIRCUITPY__EVE = 1
CIRCUITPY_CYW43 = 1
CIRCUITPY_SSL = 0
CIRCUITPY_HASHLIB = 0
CIRCUITPY_WEB_WORKFLOW = 0
CIRCUITPY_MDNS = 0
CIRCUITPY_SOCKETPOOL = 1
CIRCUITPY_WIFI = 1
CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0

View File

@ -0,0 +1 @@
// Put board-specific pico-sdk definitions here. This file must exist.

View File

@ -0,0 +1,54 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
{ MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO24) },
{ MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) },
{ MP_ROM_QSTR(MP_QSTR_CYW0), MP_ROM_PTR(&pin_CYW0) },
{ MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -31,11 +31,18 @@
#include "py/mphal.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "supervisor/shared/translate/translate.h"
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
#if CIRCUITPY_CYW43
#include "pico/cyw43_arch.h"
#include "bindings/cyw43/__init__.h"
#define IS_CYW(self) ((self)->pin->base.type == &cyw43_pin_type)
#endif
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
claim_pin(pin);
@ -61,20 +68,31 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
if (common_hal_digitalio_digitalinout_deinited(self)) {
return;
}
reset_pin_number(self->pin->number);
common_hal_reset_pin(self->pin);
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
self->output = false;
// This also sets direction to input.
common_hal_digitalio_digitalinout_set_pull(self, pull);
return common_hal_digitalio_digitalinout_set_pull(self, pull);
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t *self, bool value,
digitalio_drive_mode_t drive_mode) {
#if CIRCUITPY_CYW43
if (IS_CYW(self)) {
if (drive_mode != DRIVE_MODE_PUSH_PULL) {
return DIGITALINOUT_INVALID_DRIVE_MODE;
}
cyw43_arch_gpio_put(self->pin->number, value);
self->output = true;
self->open_drain = false;
return DIGITALINOUT_OK;
}
#endif
const uint8_t pin = self->pin->number;
gpio_disable_pulls(pin);
@ -99,6 +117,12 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
void common_hal_digitalio_digitalinout_set_value(
digitalio_digitalinout_obj_t *self, bool value) {
const uint8_t pin = self->pin->number;
#if CIRCUITPY_CYW43
if (IS_CYW(self)) {
cyw43_arch_gpio_put(pin, value);
return;
}
#endif
if (self->open_drain && value) {
// If true and open-drain, set the direction -before- setting
// the pin value, to to avoid a high glitch on the pin before
@ -122,6 +146,13 @@ bool common_hal_digitalio_digitalinout_get_value(
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t *self,
digitalio_drive_mode_t drive_mode) {
#if CIRCUITPY_CYW43
if (IS_CYW(self)) {
if (drive_mode != DRIVE_MODE_PUSH_PULL) {
return DIGITALINOUT_INVALID_DRIVE_MODE;
}
}
#endif
const uint8_t pin = self->pin->number;
bool value = common_hal_digitalio_digitalinout_get_value(self);
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
@ -142,11 +173,23 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
}
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
#if CIRCUITPY_CYW43
if (IS_CYW(self)) {
if (pull != PULL_NONE) {
return DIGITALINOUT_INVALID_PULL;
}
cyw43_arch_gpio_get(self->pin->number);
self->output = false;
return DIGITALINOUT_OK;
}
#endif
const uint8_t pin = self->pin->number;
gpio_set_pulls(pin, pull == PULL_UP, pull == PULL_DOWN);
gpio_set_dir(pin, GPIO_IN);
self->output = false;
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
@ -170,6 +213,11 @@ bool common_hal_digitalio_has_reg_op(digitalinout_reg_op_t op) {
}
volatile uint32_t *common_hal_digitalio_digitalinout_get_reg(digitalio_digitalinout_obj_t *self, digitalinout_reg_op_t op, uint32_t *mask) {
#if CIRCUITPY_CYW43
if (IS_CYW(self)) {
return NULL;
}
#endif
const uint8_t pin = self->pin->number;
*mask = 1u << pin;

View File

@ -31,6 +31,18 @@
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
#if CIRCUITPY_CYW43
#include "bindings/cyw43/__init__.h"
#include "pico/cyw43_arch.h"
bool cyw_ever_init;
static uint32_t cyw_pin_claimed;
void reset_pin_number_cyw(uint8_t pin_no) {
cyw_pin_claimed &= ~(1 << pin_no);
}
#endif
STATIC uint32_t never_reset_pins;
void reset_all_pins(void) {
@ -40,6 +52,14 @@ void reset_all_pins(void) {
}
reset_pin_number(i);
}
#if CIRCUITPY_CYW43
if (cyw_ever_init) {
for (size_t i = 0; i < 1; i++) {
cyw43_arch_gpio_put(i, 0);
}
}
cyw_pin_claimed = 0;
#endif
}
void never_reset_pin_number(uint8_t pin_number) {
@ -71,10 +91,21 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) {
}
void common_hal_reset_pin(const mcu_pin_obj_t *pin) {
#if CIRCUITPY_CYW43
if (pin->base.type == &cyw43_pin_type) {
reset_pin_number_cyw(pin->number);
return;
}
#endif
reset_pin_number(pin->number);
}
void claim_pin(const mcu_pin_obj_t *pin) {
#if CIRCUITPY_CYW43
if (pin->base.type == &cyw43_pin_type) {
cyw_pin_claimed |= (1 << pin->number);
}
#endif
// Nothing to do because all changes will set the GPIO settings.
}
@ -89,6 +120,11 @@ bool pin_number_is_free(uint8_t pin_number) {
}
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
#if CIRCUITPY_CYW43
if (pin->base.type == &cyw43_pin_type) {
return !(cyw_pin_claimed & (1 << pin->number));
}
#endif
return pin_number_is_free(pin->number);
}

View File

@ -42,4 +42,9 @@ void never_reset_pin_number(uint8_t pin_number);
void claim_pin(const mcu_pin_obj_t *pin);
bool pin_number_is_free(uint8_t pin_number);
#if CIRCUITPY_CYW43
extern bool cyw_ever_init;
void reset_pin_number_cyw(uint8_t pin_number);
#endif
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_MICROCONTROLLER_PIN_H

View File

@ -175,10 +175,15 @@ const mp_rom_map_elem_t mcu_pin_global_dict_table[TOTAL_GPIO_COUNT] = {
{ MP_ROM_QSTR(MP_QSTR_GPIO22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_GPIO23), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_GPIO24), MP_ROM_PTR(&pin_GPIO24) },
#if !defined(IGNORE_GPIO25)
{ MP_ROM_QSTR(MP_QSTR_GPIO25), MP_ROM_PTR(&pin_GPIO25) },
#endif
{ MP_ROM_QSTR(MP_QSTR_GPIO26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_GPIO27), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_GPIO28), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_GPIO29), MP_ROM_PTR(&pin_GPIO29) },
#if CIRCUITPY_CYW43
{ MP_ROM_QSTR(MP_QSTR_CYW0), MP_ROM_PTR(&pin_CYW0) },
#endif
};
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013-2019 Damien P. George
* Copyright (c) 2015 Galen Hazelwood
* Copyright (c) 2015-2017 Paul Sokolovsky
* Copyright (c) 2022 Jeff Epler 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.
*/
#pragma once
#include "py/obj.h"
#include "common-hal/socketpool/SocketPool.h"
typedef struct _lwip_socket_obj_t {
mp_obj_base_t base;
volatile union {
struct tcp_pcb *tcp;
struct udp_pcb *udp;
struct raw_pcb *raw;
} pcb;
volatile union {
struct pbuf *pbuf;
struct {
uint8_t alloc;
uint8_t iget;
uint8_t iput;
union {
struct tcp_pcb *item; // if alloc == 0
struct tcp_pcb **array; // if alloc != 0
} tcp;
} connection;
} incoming;
mp_obj_t callback;
byte peer[4];
mp_uint_t peer_port;
mp_uint_t timeout;
uint16_t recv_offset;
uint8_t domain;
uint8_t type;
#define STATE_NEW 0
#define STATE_LISTENING 1
#define STATE_CONNECTING 2
#define STATE_CONNECTED 3
#define STATE_PEER_CLOSED 4
#define STATE_ACTIVE_UDP 5
// Negative value is lwIP error
int8_t state;
socketpool_socketpool_obj_t *pool;
} socketpool_socket_obj_t;
void socket_user_reset(void);

View File

@ -0,0 +1,110 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#include "shared-bindings/socketpool/SocketPool.h"
#include "common-hal/socketpool/Socket.h"
#include "shared/runtime/interrupt_char.h"
#include "py/runtime.h"
#include "shared-bindings/wifi/__init__.h"
#include "lwip/dns.h"
#include "lwip/inet.h"
void common_hal_socketpool_socketpool_construct(socketpool_socketpool_obj_t *self, mp_obj_t radio) {
if (radio != MP_OBJ_FROM_PTR(&common_hal_wifi_radio_obj)) {
mp_raise_ValueError(translate("SocketPool can only be used with wifi.radio"));
}
}
// common_hal_socketpool_socket is in socketpool/Socket.c to centralize open socket tracking.
typedef struct _getaddrinfo_state_t {
volatile int status;
volatile ip_addr_t ipaddr;
} getaddrinfo_state_t;
STATIC void lwip_getaddrinfo_cb(const char *name, const ip_addr_t *ipaddr, void *arg) {
getaddrinfo_state_t *state = arg;
if (ipaddr != NULL) {
state->status = 1;
state->ipaddr = *ipaddr;
} else {
// error
state->status = -2;
}
}
int socketpool_resolve_host(socketpool_socketpool_obj_t *self, const char *host, ip_addr_t *addr) {
getaddrinfo_state_t state;
state.status = 0;
MICROPY_PY_LWIP_ENTER
err_t ret = dns_gethostbyname(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state);
MICROPY_PY_LWIP_EXIT
switch (ret) {
case ERR_OK:
// cached
state.status = 1;
break;
case ERR_INPROGRESS:
while (state.status == 0) {
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {
break;
}
}
break;
default:
state.status = ret;
}
if (state.status < 0) {
return state.status;
// TODO: CPython raises gaierror, we raise with native lwIP negative error
// values, to differentiate from normal errno's at least in such way.
mp_raise_OSError(state.status);
}
*addr = state.ipaddr;
return 0;
}
mp_obj_t common_hal_socketpool_socketpool_gethostbyname(socketpool_socketpool_obj_t *self,
const char *host) {
ip_addr_t addr;
int result = socketpool_resolve_host(self, host, &addr);
if (result < 0) {
mp_raise_OSError(-result);
}
char ip_str[IP4ADDR_STRLEN_MAX];
inet_ntoa_r(addr, ip_str, IP4ADDR_STRLEN_MAX);
mp_obj_t ip_obj = mp_obj_new_str(ip_str, strlen(ip_str));
return ip_obj;
}

View File

@ -0,0 +1,35 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#pragma once
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
} socketpool_socketpool_obj_t;
int socketpool_resolve_host(socketpool_socketpool_obj_t *self, const char *host, ip_addr_t *addr);

View File

@ -0,0 +1,33 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#include "shared-bindings/socketpool/__init__.h"
#include "common-hal/socketpool/Socket.h"
void socketpool_user_reset(void) {
socket_user_reset();
}

View File

@ -0,0 +1,27 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#pragma once

View File

@ -0,0 +1,74 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 microDev
*
* 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.
*/
#include <string.h>
#include "py/mpstate.h"
#include "py/runtime.h"
#include "shared-bindings/wifi/Monitor.h"
#include "shared-bindings/wifi/Packet.h"
#define MONITOR_PAYLOAD_FCS_LEN (4)
#define MONITOR_QUEUE_TIMEOUT_TICK (0)
typedef struct {
} monitor_packet_t;
void common_hal_wifi_monitor_construct(wifi_monitor_obj_t *self, uint8_t channel, size_t queue) {
mp_raise_NotImplementedError(translate("wifi.Monitor not available"));
}
bool common_hal_wifi_monitor_deinited(void) {
return true;
}
void common_hal_wifi_monitor_deinit(wifi_monitor_obj_t *self) {
}
void common_hal_wifi_monitor_set_channel(wifi_monitor_obj_t *self, uint8_t channel) {
}
mp_obj_t common_hal_wifi_monitor_get_channel(wifi_monitor_obj_t *self) {
return MP_OBJ_NEW_SMALL_INT(0);
}
mp_obj_t common_hal_wifi_monitor_get_queue(wifi_monitor_obj_t *self) {
return mp_obj_new_int_from_uint(0);
}
mp_obj_t common_hal_wifi_monitor_get_lost(wifi_monitor_obj_t *self) {
return mp_obj_new_int_from_uint(0);
}
mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self) {
return mp_obj_new_int_from_uint(0);
}
mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) {
return mp_const_none;
}

View File

@ -0,0 +1,40 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 microDev
* Copyright (c) 2022 Jeff Epler 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.
*/
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI_MONITOR_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI_MONITOR_H
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
uint8_t channel;
size_t lost;
size_t queue_length;
} wifi_monitor_obj_t;
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI_MONITOR_H

View File

@ -0,0 +1,81 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#include <string.h>
#include "shared-bindings/wifi/Network.h"
#include "shared-bindings/wifi/AuthMode.h"
mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self) {
const char *cstr = (const char *)self->record.ssid;
return mp_obj_new_str(cstr, self->record.ssid_len);
}
#define MAC_ADDRESS_LENGTH 6
mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self) {
return mp_obj_new_bytes(self->record.bssid, MAC_ADDRESS_LENGTH);
}
mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self) {
return mp_obj_new_int(self->record.rssi);
}
mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self) {
return mp_obj_new_int(self->record.channel);
}
mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) {
return (mp_obj_t)MP_QSTR_;
}
mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) {
uint8_t authmode_mask = 0;
if (self->record.auth_mode == 0) {
authmode_mask = (1 << AUTHMODE_OPEN);
}
if (self->record.auth_mode & 1) {
authmode_mask |= (1 << AUTHMODE_PSK);
}
;
if (self->record.auth_mode & 2) {
authmode_mask |= (1 << AUTHMODE_WPA);
}
;
if (self->record.auth_mode & 4) {
authmode_mask |= (1 << AUTHMODE_WPA2);
}
;
mp_obj_t authmode_list = mp_obj_new_list(0, NULL);
if (authmode_mask != 0) {
for (uint8_t i = 0; i < 8; i++) {
if ((authmode_mask >> i) & 1) {
mp_obj_list_append(authmode_list, cp_enum_find(&wifi_authmode_type, i));
}
}
}
return authmode_list;
}

View File

@ -0,0 +1,36 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#pragma once
#include "py/obj.h"
#include "pico/cyw43_arch.h"
typedef struct {
mp_obj_base_t base;
cyw43_ev_scan_result_t record;
} wifi_network_obj_t;

View File

@ -0,0 +1,313 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#include "supervisor/port.h"
#include "shared-bindings/wifi/Radio.h"
#include "shared-bindings/wifi/Network.h"
#include <math.h>
#include <string.h>
#include "common-hal/wifi/__init__.h"
#include "shared/runtime/interrupt_char.h"
#include "py/gc.h"
#include "py/runtime.h"
#include "shared-bindings/ipaddress/IPv4Address.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
#include "shared-bindings/wifi/AuthMode.h"
#include "shared-bindings/time/__init__.h"
#include "shared-module/ipaddress/__init__.h"
#if CIRCUITPY_MDNS
#include "components/mdns/include/mdns.h"
#endif
#include "lwip/dns.h"
#include "lwip/icmp.h"
#include "lwip/raw.h"
#include "lwip_src/ping.h"
#ifndef PING_ID
#define PING_ID 0xAFAF
#endif
#define MAC_ADDRESS_LENGTH 6
#define NETIF_STA (&cyw43_state.netif[CYW43_ITF_STA])
#define NETIF_AP (&cyw43_state.netif[CYW43_ITF_AP])
NORETURN static void ro_attribute(int attr) {
mp_raise_msg_varg(&mp_type_AttributeError, MP_ERROR_TEXT("'%s' object has no attribute '%q'"), "Radio", attr);
}
bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {
return true;
}
void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
if (!enabled) {
ro_attribute(MP_QSTR_enabled);
}
}
mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self) {
if (!NETIF_STA->hostname) {
return mp_const_none;
}
return mp_obj_new_str(NETIF_STA->hostname, strlen(NETIF_STA->hostname));
}
void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname) {
ro_attribute(MP_QSTR_hostname);
}
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
return mp_obj_new_bytes(cyw43_state.mac, MAC_ADDRESS_LENGTH);
}
void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t *mac) {
ro_attribute(MP_QSTR_mac_address);
}
mp_float_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self) {
return MICROPY_FLOAT_CONST(0.);
}
void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const mp_float_t tx_power) {
ro_attribute(MP_QSTR_tx_power);
}
mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) {
return common_hal_wifi_radio_get_mac_address(self);
}
void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint8_t *mac) {
ro_attribute(MP_QSTR_mac_address_ap);
}
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
if (self->current_scan) {
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
}
if (!common_hal_wifi_radio_get_enabled(self)) {
mp_raise_RuntimeError(translate("wifi is not enabled"));
}
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
scan->base.type = &wifi_scannednetworks_type;
mp_obj_t args[] = { mp_const_empty_tuple, MP_OBJ_NEW_SMALL_INT(16) };
scan->results = mp_type_deque.make_new(&mp_type_deque, 2, 0, args);
self->current_scan = scan;
wifi_scannednetworks_start_scan(scan);
return scan;
}
void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
self->current_scan = NULL;
}
void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) {
cyw43_arch_enable_sta_mode();
}
void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
}
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) {
mp_raise_NotImplementedError(NULL);
}
void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) {
mp_raise_NotImplementedError(NULL);
}
wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) {
if (!common_hal_wifi_radio_get_enabled(self)) {
mp_raise_RuntimeError(translate("wifi is not enabled"));
}
unsigned timeout_ms = timeout <= 0 ? 8000 : (unsigned)MAX(0, MICROPY_FLOAT_C_FUN(ceil)(timeout * 1000));
// TODO use connect_async so we can service bg tasks & check for ctrl-c during
// connect
int result = cyw43_arch_wifi_connect_timeout_ms((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK, timeout_ms);
switch (result) {
case 0:
return WIFI_RADIO_ERROR_NONE;
// case CYW43_LINK_DOWN:
// case CYW43_LINK_JOIN:
// case CYW43_LINK_NOIP:
// case CYW43_LINK_UP:
case CYW43_LINK_FAIL:
return WIFI_RADIO_ERROR_CONNECTION_FAIL;
case CYW43_LINK_NONET:
return WIFI_RADIO_ERROR_NO_AP_FOUND;
case CYW43_LINK_BADAUTH:
return WIFI_RADIO_ERROR_AUTH_FAIL;
default:
return WIFI_RADIO_ERROR_UNSPECIFIED;
}
}
mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) {
mp_raise_NotImplementedError(NULL);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) {
if (!netif_is_up(NETIF_STA)) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(NETIF_STA->gw.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self) {
if (!netif_is_up(NETIF_AP)) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(NETIF_AP->gw.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
if (!netif_is_up(NETIF_STA)) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(NETIF_STA->netmask.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) {
if (!netif_is_up(NETIF_AP)) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(NETIF_AP->netmask.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
if (!netif_is_up(NETIF_STA)) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(NETIF_STA->ip_addr.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self) {
if (!netif_is_up(NETIF_AP)) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(NETIF_AP->ip_addr.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) {
uint32_t addr = dns_getserver(0)->addr;
if (!netif_is_up(NETIF_STA) || addr == 0) {
return mp_const_none;
}
return common_hal_ipaddress_new_ipv4address(addr);
}
void common_hal_wifi_radio_set_ipv4_dns(wifi_radio_obj_t *self, mp_obj_t ipv4_dns_addr) {
mp_raise_NotImplementedError(NULL);
}
void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self) {
mp_raise_NotImplementedError(NULL);
}
void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self) {
mp_raise_NotImplementedError(NULL);
}
void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway, mp_obj_t ipv4_dns) {
mp_raise_NotImplementedError(NULL);
}
volatile bool ping_received;
static u8_t
ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) {
struct icmp_echo_hdr *iecho;
LWIP_ASSERT("p != NULL", p != NULL);
if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) &&
pbuf_remove_header(p, PBUF_IP_HLEN) == 0) {
iecho = (struct icmp_echo_hdr *)p->payload;
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
LWIP_DEBUGF(PING_DEBUG, ("ping: recv "));
ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF(PING_DEBUG, (" %"U32_F " ms\n", (sys_now() - ping_time)));
/* do some ping result processing */
ping_received = true;
pbuf_free(p);
return 1; /* eat the packet */
}
/* not eaten, restore original packet */
pbuf_add_header(p, PBUF_IP_HLEN);
}
return 0; /* don't eat the packet */
}
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) {
ip_addr_t ping_addr;
ipaddress_ipaddress_to_lwip(ip_address, &ping_addr);
struct raw_pcb *ping_pcb;
MICROPY_PY_LWIP_ENTER
ping_pcb = raw_new(IP_PROTO_ICMP);
if (!ping_pcb) {
MICROPY_PY_LWIP_EXIT
return -1;
}
raw_recv(ping_pcb, ping_recv, NULL);
raw_bind(ping_pcb, IP_ADDR_ANY);
MICROPY_PY_LWIP_EXIT
ping_received = false;
ping_send(ping_pcb, &ping_addr);
size_t timeout_ms = (size_t)MICROPY_FLOAT_C_FUN(ceil)(timeout * 1000);
uint64_t start = port_get_raw_ticks(NULL);
uint64_t deadline = start + timeout_ms;
while (port_get_raw_ticks(NULL) < deadline && !ping_received) {
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {
break;
}
}
mp_int_t result = -1;
if (ping_received) {
uint64_t now = port_get_raw_ticks(NULL);
result = now - start;
}
MICROPY_PY_LWIP_ENTER;
raw_remove(ping_pcb);
MICROPY_PY_LWIP_EXIT;
return result;
}
void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self) {
// Only bother to scan the actual object references.
gc_collect_ptr(self->current_scan);
}

View File

@ -0,0 +1,39 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Jeff Epler 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.
*/
#pragma once
#include "py/obj.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
#include "shared-bindings/wifi/Network.h"
typedef struct {
mp_obj_base_t base;
wifi_scannednetworks_obj_t *current_scan;
} wifi_radio_obj_t;
extern void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self);

View File

@ -0,0 +1,120 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
* Copyright (c) 2017 Glenn Ruben Bakke
*
* 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.
*/
#include <string.h>
#include "shared/runtime/interrupt_char.h"
#include "py/gc.h"
#include "py/objstr.h"
#include "py/runtime.h"
#include "common-hal/wifi/__init__.h"
#include "shared-bindings/wifi/__init__.h"
#include "shared-bindings/wifi/Network.h"
#include "shared-bindings/wifi/Radio.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
#define NUM_SCAN (16)
static cyw43_ev_scan_result_t scan_results[NUM_SCAN];
static uint8_t scan_put, scan_get;
static bool scan_full;
static void scan_result_clear() {
scan_put = scan_get = 0;
scan_full = false;
}
static void scan_result_put(const cyw43_ev_scan_result_t *result) {
if (!scan_full) {
scan_results[scan_put] = *result;
scan_put = (scan_put + 1) % NUM_SCAN;
scan_full = (scan_put == scan_get);
}
}
static bool scan_result_available() {
return scan_full || (scan_get != scan_put);
}
static cyw43_ev_scan_result_t *scan_result_get(cyw43_ev_scan_result_t *result) {
if (!scan_result_available()) {
return NULL;
}
*result = scan_results[scan_get];
scan_get = (scan_get + 1) % NUM_SCAN;
scan_full = false;
return result;
}
// Note: It's not OK to allocate memory in here, we can be called at a bad time
// which messes up the gc allocator
static int scan_result(void *env, const cyw43_ev_scan_result_t *result) {
wifi_scannednetworks_obj_t *self = common_hal_wifi_radio_obj.current_scan;
// scan ended or something
if (!self) {
return 0;
}
scan_result_put(result);
return 0;
}
mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self) {
// no results available, wait for some
while (!scan_result_available(self) && cyw43_wifi_scan_active(&cyw43_state)) {
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {
return mp_const_none;
}
cyw43_arch_poll();
}
if (!scan_result_available(self)) {
common_hal_wifi_radio_obj.current_scan = NULL;
return mp_const_none;
}
wifi_network_obj_t *entry = m_new_obj(wifi_network_obj_t);
entry->base.type = &wifi_network_type;
scan_result_get(&entry->record);
return MP_OBJ_FROM_PTR(entry);
}
void wifi_scannednetworks_deinit(wifi_scannednetworks_obj_t *self) {
// there's actually no way to stop an ongoing scan in cyw43!
common_hal_wifi_radio_obj.current_scan = NULL;
}
void wifi_scannednetworks_start_scan(wifi_scannednetworks_obj_t *self) {
cyw43_wifi_scan_options_t scan_options = {0};
CHECK_CYW_RESULT(cyw43_wifi_scan(&cyw43_state, &scan_options, NULL, scan_result));
}

View File

@ -0,0 +1,42 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
*
* 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.
*/
#pragma once
#include <stdint.h>
#include "py/obj.h"
#include "cyw43.h"
typedef struct {
mp_obj_base_t base;
mp_obj_t results;
bool done;
} wifi_scannednetworks_obj_t;
void wifi_scannednetworks_deinit(wifi_scannednetworks_obj_t *self);
void wifi_scannednetworks_start_scan(wifi_scannednetworks_obj_t *self);

View File

@ -0,0 +1,125 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 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.
*/
#include "common-hal/wifi/__init__.h"
#include "shared-bindings/wifi/__init__.h"
#include "shared-bindings/ipaddress/IPv4Address.h"
#include "shared-bindings/wifi/Monitor.h"
#include "shared-bindings/wifi/Radio.h"
#include "py/mperrno.h"
#include "py/mpstate.h"
#include "py/runtime.h"
wifi_radio_obj_t common_hal_wifi_radio_obj;
#include "supervisor/port.h"
#include "supervisor/shared/status_bar.h"
#include "supervisor/workflow.h"
static bool wifi_inited;
static bool wifi_ever_inited;
static bool wifi_user_initiated;
void common_hal_wifi_init(bool user_initiated) {
wifi_radio_obj_t *self = &common_hal_wifi_radio_obj;
if (wifi_inited) {
if (user_initiated && !wifi_user_initiated) {
common_hal_wifi_radio_set_enabled(self, true);
}
return;
}
wifi_inited = true;
wifi_user_initiated = user_initiated;
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
common_hal_wifi_radio_obj.current_scan = NULL;
if (!wifi_ever_inited) {
}
wifi_ever_inited = true;
// set station mode to avoid the default SoftAP
common_hal_wifi_radio_start_station(self);
// start wifi
common_hal_wifi_radio_set_enabled(self, true);
}
void wifi_user_reset(void) {
if (wifi_user_initiated) {
// wifi_reset();
wifi_user_initiated = false;
}
}
void wifi_reset(void) {
if (!wifi_inited) {
return;
}
// the cyw43 wifi chip is not reset due to https://github.com/raspberrypi/pico-sdk/issues/980
common_hal_wifi_monitor_deinit(MP_STATE_VM(wifi_monitor_singleton));
wifi_radio_obj_t *radio = &common_hal_wifi_radio_obj;
common_hal_wifi_radio_obj.current_scan = NULL;
// common_hal_wifi_radio_set_enabled(radio, false);
supervisor_workflow_request_background();
}
void common_hal_wifi_gc_collect(void) {
common_hal_wifi_radio_gc_collect(&common_hal_wifi_radio_obj);
}
void raise_cyw_error(int err) {
int mp_errno;
switch (err) {
case -CYW43_EIO:
mp_errno = MP_EIO;
break;
case -CYW43_EPERM:
mp_errno = MP_EPERM;
break;
case -CYW43_EINVAL:
mp_errno = MP_EINVAL;
break;
case -CYW43_ETIMEDOUT:
mp_errno = MP_ETIMEDOUT;
break;
default:
mp_raise_OSError_msg_varg(translate("Unkown error code %d"), err);
}
mp_raise_OSError(mp_errno);
}
void ipaddress_ipaddress_to_lwip(mp_obj_t ip_address, ip_addr_t *lwip_ip_address) {
if (!mp_obj_is_type(ip_address, &ipaddress_ipv4address_type)) {
mp_raise_ValueError(translate("Only IPv4 addresses supported"));
}
mp_obj_t packed = common_hal_ipaddress_ipv4address_get_packed(ip_address);
size_t len;
const char *bytes = mp_obj_str_get_data(packed, &len);
IP_ADDR4(lwip_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]);
}

View File

@ -0,0 +1,37 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Jeff Epler 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.
*/
#pragma once
#include "py/obj.h"
#include "py/mpconfig.h"
#include "lwip/ip_addr.h"
void wifi_reset(void);
NORETURN void raise_cyw_error(int err);
#define CHECK_CYW_RESULT(x) do { int res = (x); if (res != 0) raise_cyw_error(res); } while (0)
void ipaddress_ipaddress_to_lwip(mp_obj_t ip_address, ip_addr_t *lwip_ip_address);

@ -0,0 +1 @@
Subproject commit 195dfcc10bb6f379e3dea45147590db2203d3c7b

@ -0,0 +1 @@
Subproject commit 239918ccc173cb2c2a62f41a40fd893f57faf1d6

View File

@ -0,0 +1 @@
// empty

View File

@ -0,0 +1,94 @@
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
#define _LWIPOPTS_EXAMPLE_COMMONH_H
// Common settings used in most of the pico_w examples
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
// allow override in some examples
#ifndef NO_SYS
#define NO_SYS 1
#endif
// allow override in some examples
#ifndef LWIP_SOCKET
#define LWIP_SOCKET 0
#endif
#if PICO_CYW43_ARCH_POLL
#define MEM_LIBC_MALLOC 1
#else
// MEM_LIBC_MALLOC is incompatible with non polling versions
#define MEM_LIBC_MALLOC 0
#endif
#define MEM_ALIGNMENT 4
#define MEM_SIZE 4000
#define MEMP_NUM_TCP_SEG 32
#define MEMP_NUM_ARP_QUEUE 10
#define PBUF_POOL_SIZE 24
#define LWIP_ARP 1
#define LWIP_ETHERNET 1
#define LWIP_ICMP 1
#define LWIP_RAW 1
#define TCP_WND (8 * TCP_MSS)
#define TCP_MSS 1460
#define TCP_SND_BUF (8 * TCP_MSS)
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETCONN 0
#define MEM_STATS 0
#define SYS_STATS 0
#define MEMP_STATS 0
#define LINK_STATS 0
// #define ETH_PAD_SIZE 2
#define LWIP_CHKSUM_ALGORITHM 3
#define LWIP_DHCP 1
#define LWIP_IPV4 1
#define LWIP_TCP 1
#define LWIP_UDP 1
#define LWIP_DNS 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#define DHCP_DOES_ARP_CHECK 0
#define LWIP_DHCP_DOES_ACD_CHECK 0
#ifndef NDEBUG
#define LWIP_DEBUG 1
#define LWIP_STATS 1
#define LWIP_STATS_DISPLAY 1
#endif
#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#define LWIP_TIMEVAL_PRIVATE 0
#define LWIP_NO_CTYPE_H 1
#endif /* __LWIPOPTS_H__ */

View File

@ -0,0 +1,390 @@
/**
* @file
* Ping sender module
*
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
/**
* This is an example of a "ping" sender (with raw API and socket API).
* It can be used as a start point to maintain opened a network connection, or
* like a network "watchdog" for your device.
*
*/
#include "lwip/opt.h"
#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
#include "ping.h"
#include "lwip/mem.h"
#include "lwip/raw.h"
#include "lwip/icmp.h"
#include "lwip/netif.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
#include "lwip/inet_chksum.h"
#include "lwip/prot/ip4.h"
#if PING_USE_SOCKETS
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include <string.h>
#endif /* PING_USE_SOCKETS */
/**
* PING_DEBUG: Enable debugging for PING.
*/
#ifndef PING_DEBUG
#define PING_DEBUG LWIP_DBG_ON
#endif
/** ping receive timeout - in milliseconds */
#ifndef PING_RCV_TIMEO
#define PING_RCV_TIMEO 1000
#endif
/** ping delay - in milliseconds */
#ifndef PING_DELAY
#define PING_DELAY 1000
#endif
/** ping identifier - must fit on a u16_t */
#ifndef PING_ID
#define PING_ID 0xAFAF
#endif
/** ping additional data size to include in the packet */
#ifndef PING_DATA_SIZE
#define PING_DATA_SIZE 32
#endif
/** ping result action - no default action */
#ifndef PING_RESULT
#define PING_RESULT(ping_ok)
#endif
/* ping variables */
static const ip_addr_t *ping_target;
u16_t ping_seq_num;
#ifdef LWIP_DEBUG
static u32_t ping_time;
#endif /* LWIP_DEBUG */
#if !PING_USE_SOCKETS
static struct raw_pcb *ping_pcb;
#endif /* PING_USE_SOCKETS */
/** Prepare a echo ICMP request */
void
ping_prepare_echo(struct icmp_echo_hdr *iecho, u16_t len) {
size_t i;
size_t data_len = len - sizeof(struct icmp_echo_hdr);
ICMPH_TYPE_SET(iecho, ICMP_ECHO);
ICMPH_CODE_SET(iecho, 0);
iecho->chksum = 0;
iecho->id = PING_ID;
iecho->seqno = lwip_htons(++ping_seq_num);
/* fill the additional data buffer with some data */
for (i = 0; i < data_len; i++) {
((char *)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
}
iecho->chksum = inet_chksum(iecho, len);
}
#if PING_USE_SOCKETS
/* Ping using the socket ip */
err_t
ping_send(int s, const ip_addr_t *addr) {
int err;
struct icmp_echo_hdr *iecho;
struct sockaddr_storage to;
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff);
#if LWIP_IPV6
if (IP_IS_V6(addr) && !ip6_addr_isipv4mappedipv6(ip_2_ip6(addr))) {
/* todo: support ICMP6 echo */
return ERR_VAL;
}
#endif /* LWIP_IPV6 */
iecho = (struct icmp_echo_hdr *)mem_malloc((mem_size_t)ping_size);
if (!iecho) {
return ERR_MEM;
}
ping_prepare_echo(iecho, (u16_t)ping_size);
#if LWIP_IPV4
if (IP_IS_V4(addr)) {
struct sockaddr_in *to4 = (struct sockaddr_in *)&to;
to4->sin_len = sizeof(*to4);
to4->sin_family = AF_INET;
inet_addr_from_ip4addr(&to4->sin_addr, ip_2_ip4(addr));
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
if (IP_IS_V6(addr)) {
struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&to;
to6->sin6_len = sizeof(*to6);
to6->sin6_family = AF_INET6;
inet6_addr_from_ip6addr(&to6->sin6_addr, ip_2_ip6(addr));
}
#endif /* LWIP_IPV6 */
err = lwip_sendto(s, iecho, ping_size, 0, (struct sockaddr *)&to, sizeof(to));
mem_free(iecho);
return err ? ERR_OK : ERR_VAL;
}
static void
ping_recv(int s) {
char buf[64];
int len;
struct sockaddr_storage from;
int fromlen = sizeof(from);
while ((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)&fromlen)) > 0) {
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
ip_addr_t fromaddr;
memset(&fromaddr, 0, sizeof(fromaddr));
#if LWIP_IPV4
if (from.ss_family == AF_INET) {
struct sockaddr_in *from4 = (struct sockaddr_in *)&from;
inet_addr_to_ip4addr(ip_2_ip4(&fromaddr), &from4->sin_addr);
IP_SET_TYPE_VAL(fromaddr, IPADDR_TYPE_V4);
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
if (from.ss_family == AF_INET6) {
struct sockaddr_in6 *from6 = (struct sockaddr_in6 *)&from;
inet6_addr_to_ip6addr(ip_2_ip6(&fromaddr), &from6->sin6_addr);
IP_SET_TYPE_VAL(fromaddr, IPADDR_TYPE_V6);
}
#endif /* LWIP_IPV6 */
LWIP_DEBUGF(PING_DEBUG, ("ping: recv "));
ip_addr_debug_print_val(PING_DEBUG, fromaddr);
LWIP_DEBUGF(PING_DEBUG, (" %"U32_F " ms\n", (sys_now() - ping_time)));
/* todo: support ICMP6 echo */
#if LWIP_IPV4
if (IP_IS_V4_VAL(fromaddr)) {
struct ip_hdr *iphdr;
struct icmp_echo_hdr *iecho;
iphdr = (struct ip_hdr *)buf;
iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
/* do some ping result processing */
PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));
return;
} else {
LWIP_DEBUGF(PING_DEBUG, ("ping: drop\n"));
}
}
#endif /* LWIP_IPV4 */
}
fromlen = sizeof(from);
}
if (len == 0) {
LWIP_DEBUGF(PING_DEBUG, ("ping: recv - %"U32_F " ms - timeout\n", (sys_now() - ping_time)));
}
/* do some ping result processing */
PING_RESULT(0);
}
static void
ping_thread(void *arg) {
int s;
int ret;
#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
int timeout = PING_RCV_TIMEO;
#else
struct timeval timeout;
timeout.tv_sec = PING_RCV_TIMEO / 1000;
timeout.tv_usec = (PING_RCV_TIMEO % 1000) * 1000;
#endif
LWIP_UNUSED_ARG(arg);
#if LWIP_IPV6
if (IP_IS_V4(ping_target) || ip6_addr_isipv4mappedipv6(ip_2_ip6(ping_target))) {
s = lwip_socket(AF_INET6, SOCK_RAW, IP_PROTO_ICMP);
} else {
s = lwip_socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
}
#else
s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
#endif
if (s < 0) {
return;
}
ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
LWIP_ASSERT("setting receive timeout failed", ret == 0);
LWIP_UNUSED_ARG(ret);
while (1) {
if (ping_send(s, ping_target) == ERR_OK) {
LWIP_DEBUGF(PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, ping_target);
LWIP_DEBUGF(PING_DEBUG, ("\n"));
#ifdef LWIP_DEBUG
ping_time = sys_now();
#endif /* LWIP_DEBUG */
ping_recv(s);
} else {
LWIP_DEBUGF(PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, ping_target);
LWIP_DEBUGF(PING_DEBUG, (" - error\n"));
}
sys_msleep(PING_DELAY);
}
}
#else /* PING_USE_SOCKETS */
/* Ping using the raw ip */
static u8_t
ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) {
struct icmp_echo_hdr *iecho;
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(addr);
LWIP_ASSERT("p != NULL", p != NULL);
if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) &&
pbuf_remove_header(p, PBUF_IP_HLEN) == 0) {
iecho = (struct icmp_echo_hdr *)p->payload;
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
LWIP_DEBUGF(PING_DEBUG, ("ping: recv "));
ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF(PING_DEBUG, (" %"U32_F " ms\n", (sys_now() - ping_time)));
/* do some ping result processing */
PING_RESULT(1);
pbuf_free(p);
return 1; /* eat the packet */
}
/* not eaten, restore original packet */
pbuf_add_header(p, PBUF_IP_HLEN);
}
return 0; /* don't eat the packet */
}
int
ping_send(struct raw_pcb *raw, const ip_addr_t *addr) {
struct pbuf *p;
struct icmp_echo_hdr *iecho;
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
LWIP_DEBUGF(PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF(PING_DEBUG, ("\n"));
LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff);
p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
if (!p) {
return 0;
}
if ((p->len == p->tot_len) && (p->next == NULL)) {
iecho = (struct icmp_echo_hdr *)p->payload;
ping_prepare_echo(iecho, (u16_t)ping_size);
raw_sendto(raw, p, addr);
#ifdef LWIP_DEBUG
ping_time = sys_now();
#endif /* LWIP_DEBUG */
}
pbuf_free(p);
return 1;
}
static void
ping_timeout(void *arg) {
struct raw_pcb *pcb = (struct raw_pcb *)arg;
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
ping_send(pcb, ping_target);
sys_timeout(PING_DELAY, ping_timeout, pcb);
}
static void
ping_raw_init(void) {
if (ping_pcb) {
return;
}
ping_pcb = raw_new(IP_PROTO_ICMP);
LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
raw_recv(ping_pcb, ping_recv, NULL);
raw_bind(ping_pcb, IP_ADDR_ANY);
sys_timeout(PING_DELAY, ping_timeout, ping_pcb);
}
static void
ping_send_now(void) {
LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
ping_send(ping_pcb, ping_target);
}
#endif /* PING_USE_SOCKETS */
void
ping_init(const ip_addr_t *ping_addr) {
ping_target = ping_addr;
#if PING_USE_SOCKETS
sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#else /* PING_USE_SOCKETS */
ping_raw_init();
#endif /* PING_USE_SOCKETS */
}
#endif /* LWIP_RAW */

View File

@ -0,0 +1,25 @@
#ifndef LWIP_PING_H
#define LWIP_PING_H
#include "lwip/raw.h"
#include "lwip/ip_addr.h"
#include "lwip/prot/icmp.h"
/**
* PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used
*/
#ifndef PING_USE_SOCKETS
#define PING_USE_SOCKETS LWIP_SOCKET
#endif
void ping_init(const ip_addr_t *ping_addr);
void ping_prepare_echo(struct icmp_echo_hdr *iecho, u16_t len);
extern u16_t ping_seq_num;
#if !PING_USE_SOCKETS
void ping_set_target(const ip_addr_t *ping_addr);
int ping_send(struct raw_pcb *raw, const ip_addr_t *addr);
// u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr);
#endif /* !PING_USE_SOCKETS */
#endif /* LWIP_PING_H */

View File

@ -49,4 +49,11 @@
mp_obj_t background_pio[NUM_DMA_CHANNELS]; \
CIRCUITPY_COMMON_ROOT_POINTERS;
#if CIRCUITPY_CYW43
#include "pico/cyw43_arch.h"
#define MICROPY_PY_LWIP_ENTER cyw43_arch_lwip_begin();
#define MICROPY_PY_LWIP_REENTER MICROPY_PY_LWIP_ENTER
#define MICROPY_PY_LWIP_EXIT cyw43_arch_lwip_end();
#endif
#endif // __INCLUDED_MPCONFIGPORT_H

View File

@ -27,6 +27,7 @@
#include "pins.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "bindings/cyw43/__init__.h"
// This macro is used to simplify pin definition in boards/<board>/pins.c
#define PIN(p_number) \
@ -34,6 +35,11 @@
{ &mcu_pin_type }, \
.number = p_number \
}
#define CYW_PIN(p_number) \
const mcu_pin_obj_t pin_CYW##p_number = { \
{ &cyw43_pin_type }, \
.number = p_number \
}
PIN(0);
PIN(1);
@ -60,8 +66,13 @@ PIN(21);
PIN(22);
PIN(23);
PIN(24);
#if !defined(IGNORE_GPIO25)
PIN(25);
#endif
PIN(26);
PIN(27);
PIN(28);
PIN(29);
#if CIRCUITPY_CYW43
CYW_PIN(0);
#endif

View File

@ -62,10 +62,16 @@ extern const mcu_pin_obj_t pin_GPIO21;
extern const mcu_pin_obj_t pin_GPIO22;
extern const mcu_pin_obj_t pin_GPIO23;
extern const mcu_pin_obj_t pin_GPIO24;
#if !defined(IGNORE_GPIO25)
extern const mcu_pin_obj_t pin_GPIO25;
#endif
extern const mcu_pin_obj_t pin_GPIO26;
extern const mcu_pin_obj_t pin_GPIO27;
extern const mcu_pin_obj_t pin_GPIO28;
extern const mcu_pin_obj_t pin_GPIO29;
#if CIRCUITPY_CYW43
extern const mcu_pin_obj_t pin_CYW0;
#endif
#endif // MICROPY_INCLUDED_RASPBERRYPI_PERIPHERALS_PINS_H

View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(pioasm)
set(PICO_TINYUSB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/tinyusb)
include(../sdk/pico_sdk_init.cmake)
pico_sdk_init()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools)
find_package(Pioasm REQUIRED)

View File

@ -41,6 +41,10 @@
#include "shared-bindings/rtc/__init__.h"
#include "shared-bindings/pwmio/PWMOut.h"
#if CIRCUITPY_WIFI
#include "common-hal/wifi/__init__.h"
#endif
#include "common-hal/rtc/RTC.h"
#include "common-hal/busio/UART.h"
@ -53,12 +57,17 @@
#include "src/rp2_common/hardware_uart/include/hardware/uart.h"
#include "src/rp2_common/hardware_sync/include/hardware/sync.h"
#include "src/rp2_common/hardware_timer/include/hardware/timer.h"
#if CIRCUITPY_CYW43
#include "pico/cyw43_arch.h"
#endif
#include "src/common/pico_time/include/pico/time.h"
#include "src/common/pico_binary_info/include/pico/binary_info.h"
#include "pico/bootrom.h"
#include "hardware/watchdog.h"
#include "supervisor/serial.h"
extern volatile bool mp_msc_enabled;
STATIC void _tick_callback(uint alarm_num);
@ -122,6 +131,17 @@ safe_mode_t port_init(void) {
// Check brownout.
#if CIRCUITPY_CYW43
never_reset_pin_number(23);
never_reset_pin_number(24);
never_reset_pin_number(25);
never_reset_pin_number(29);
if (cyw43_arch_init()) {
serial_write("WiFi init failed\n");
} else {
cyw_ever_init = true;
}
#endif
if (board_requests_safe_mode()) {
return USER_SAFE_MODE;
}
@ -159,6 +179,10 @@ void reset_port(void) {
audio_dma_reset();
#endif
#if CIRCUITPY_WIFI
wifi_reset();
#endif
reset_all_pins();
}
@ -261,3 +285,19 @@ __attribute__((used)) void HardFault_Handler(void) {
asm ("nop;");
}
}
void port_yield() {
#if CIRCUITPY_CYW43
cyw43_arch_poll();
#endif
}
void port_boot_info(void) {
#if CIRCUITPY_CYW43
mp_printf(&mp_plat_print, "MAC");
for (int i = 0; i < 6; i++) {
mp_printf(&mp_plat_print, ":%02X", cyw43_state.mac[i]);
}
mp_printf(&mp_plat_print, "\n");
#endif
}

View File

@ -77,7 +77,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
@ -88,6 +88,7 @@ void common_hal_digitalio_digitalinout_switch_to_input(
HAL_GPIO_Init(pin_port(self->pin->port), &GPIO_InitStruct);
common_hal_digitalio_digitalinout_set_pull(self, pull);
return DIGITALINOUT_OK;
}
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@ -138,7 +139,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
== LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
}
void common_hal_digitalio_digitalinout_set_pull(
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
switch (pull) {
@ -154,6 +155,7 @@ void common_hal_digitalio_digitalinout_set_pull(
default:
break;
}
return DIGITALINOUT_OK;
}
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

View File

@ -170,6 +170,9 @@ endif
ifeq ($(CIRCUITPY_COUNTIO),1)
SRC_PATTERNS += countio/%
endif
ifeq ($(CIRCUITPY_CYW43),1)
SRC_PATTERNS += cyw43/%
endif
ifeq ($(CIRCUITPY_DIGITALIO),1)
SRC_PATTERNS += digitalio/%
endif

View File

@ -588,6 +588,15 @@ void supervisor_run_background_tasks_if_tick(void);
#define MICROPY_WRAP_MP_EXECUTE_BYTECODE PLACE_IN_ITCM
#endif
#ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (0)
#endif
#ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (0)
#endif
#define MICROPY_PY_OPTIMIZE_PROPERTY_FLASH_SIZE (CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE)
#endif // __INCLUDED_MPCONFIG_CIRCUITPY_H

View File

@ -159,6 +159,9 @@ CFLAGS += -DCIRCUITPY_CAMERA=$(CIRCUITPY_CAMERA)
CIRCUITPY_CANIO ?= 0
CFLAGS += -DCIRCUITPY_CANIO=$(CIRCUITPY_CANIO)
CIRCUITPY_CYW43 ?= 0
CFLAGS += -DCIRCUITPY_CYW43=$(CIRCUITPY_CYW43)
CIRCUITPY_DIGITALIO ?= 1
CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO)

View File

@ -330,7 +330,8 @@ STATIC mp_obj_t gen_instance_await(mp_obj_t self_in) {
if (!self->coroutine_generator) {
// Pretend like a generator does not have this coroutine behavior.
// Pay no attention to the dir() behind the curtain
mp_raise_AttributeError(MP_ERROR_TEXT("type object 'generator' has no attribute '__await__'"));
mp_raise_msg_varg(&mp_type_AttributeError, MP_ERROR_TEXT("type object '%q' has no attribute '%q'"),
MP_QSTR_generator, MP_QSTR___await__);
}
// You can directly call send on a coroutine generator or you can __await__ then send on the return of that.
return self;

View File

@ -43,6 +43,29 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate/translate.h"
#if CIRCUITPY_CYW43
#include "bindings/cyw43/__init__.h"
#endif
STATIC void check_result(digitalinout_result_t result) {
switch (result) {
case DIGITALINOUT_OK:
return;
case DIGITALINOUT_PIN_BUSY:
mp_raise_ValueError_varg(translate("%q in use"), MP_QSTR_Pin);
case DIGITALINOUT_INPUT_ONLY:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_direction);
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
case DIGITALINOUT_INVALID_PULL:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_pull);
#endif
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE
case DIGITALINOUT_INVALID_DRIVE_MODE:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_drive_mode);
#endif
}
}
//| class DigitalInOut:
//| """Digital input and output
//|
@ -64,7 +87,14 @@ 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;
#if CIRCUITPY_CYW43
// The GPIO pin attached to the CYW43 co-processor can only be used for
// DigitalInOut, not for other purposes like PWM. That's why this check
// is here, and it's not rolled into validate_obj_is_free_pin.
const mcu_pin_obj_t *pin = validate_obj_is_free_pin_including_cyw43(args[0]);
#else
const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]);
#endif
common_hal_digitalio_digitalinout_construct(self, pin);
return MP_OBJ_FROM_PTR(self);
@ -128,10 +158,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_
drive_mode = DRIVE_MODE_OPEN_DRAIN;
}
// do the transfer
digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(self, args[ARG_value].u_bool, drive_mode);
if (result == DIGITALINOUT_INPUT_ONLY) {
mp_raise_NotImplementedError(translate("Pin is input only"));
}
check_result(common_hal_digitalio_digitalinout_switch_to_output(self, args[ARG_value].u_bool, drive_mode));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_output_obj, 1, digitalio_digitalinout_switch_to_output);
@ -162,7 +189,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_o
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);
common_hal_digitalio_digitalinout_switch_to_input(self, validate_pull(args[ARG_pull].u_rom_obj, MP_QSTR_pull));
check_result(common_hal_digitalio_digitalinout_switch_to_input(self, validate_pull(args[ARG_pull].u_rom_obj, MP_QSTR_pull)));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_input_obj, 1, digitalio_digitalinout_switch_to_input);
@ -195,12 +222,9 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_direction(mp_obj_t self_in, mp_ob
digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
if (value == MP_ROM_PTR(&digitalio_direction_input_obj)) {
common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE);
check_result(common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE));
} else if (value == MP_ROM_PTR(&digitalio_direction_output_obj)) {
digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(self, false, DRIVE_MODE_PUSH_PULL);
if (result == DIGITALINOUT_INPUT_ONLY) {
mp_raise_NotImplementedError(translate("Pin is input only"));
}
check_result(common_hal_digitalio_digitalinout_switch_to_output(self, false, DRIVE_MODE_PUSH_PULL));
} else {
mp_arg_error_invalid(MP_QSTR_direction);
}
@ -269,7 +293,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_drive_mode(mp_obj_t self_in, mp_o
if (drive_mode == MP_ROM_PTR(&digitalio_drive_mode_open_drain_obj)) {
c_drive_mode = DRIVE_MODE_OPEN_DRAIN;
}
common_hal_digitalio_digitalinout_set_drive_mode(self, c_drive_mode);
check_result(common_hal_digitalio_digitalinout_set_drive_mode(self, c_drive_mode));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_drive_mode_obj, digitalio_digitalinout_obj_set_drive_mode);
@ -311,7 +335,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t p
return mp_const_none;
}
common_hal_digitalio_digitalinout_set_pull(self, validate_pull(pull_obj, MP_QSTR_pull));
check_result(common_hal_digitalio_digitalinout_set_pull(self, validate_pull(pull_obj, MP_QSTR_pull)));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_pull_obj, digitalio_digitalinout_obj_set_pull);

View File

@ -38,7 +38,13 @@ extern const mp_obj_type_t digitalio_digitalinout_type;
typedef enum {
DIGITALINOUT_OK,
DIGITALINOUT_PIN_BUSY,
DIGITALINOUT_INPUT_ONLY
DIGITALINOUT_INPUT_ONLY,
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
DIGITALINOUT_INVALID_PULL,
#endif
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE
DIGITALINOUT_INVALID_DRIVE_MODE,
#endif
} digitalinout_result_t;
typedef enum {
@ -52,14 +58,14 @@ typedef enum {
digitalinout_result_t common_hal_digitalio_digitalinout_construct(digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin);
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self);
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self);
void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull);
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull);
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode);
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(digitalio_digitalinout_obj_t *self);
void common_hal_digitalio_digitalinout_set_value(digitalio_digitalinout_obj_t *self, bool value);
bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self);
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode);
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitalio_digitalinout_obj_t *self);
void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull);
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull);
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self);
void common_hal_digitalio_digitalinout_never_reset(digitalio_digitalinout_obj_t *self);
digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj);

View File

@ -68,7 +68,7 @@ static void get_pin_name(const mcu_pin_obj_t *self, qstr *package, qstr *module,
}
}
STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
void shared_bindings_microcontroller_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
mcu_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
qstr package = MP_QSTR_Pin;
qstr module;
@ -86,7 +86,7 @@ const mp_obj_type_t mcu_pin_type = {
{ &mp_type_type },
.flags = MP_TYPE_FLAG_EXTENDED,
.name = MP_QSTR_Pin,
.print = mcu_pin_print,
.print = shared_bindings_microcontroller_pin_print,
MP_TYPE_EXTENDED_FIELDS(
.unary_op = mp_generic_unary_op,
)

View File

@ -55,6 +55,8 @@ void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin);
void common_hal_mcu_pin_claim_number(uint8_t pin_no);
void common_hal_mcu_pin_reset_number(uint8_t pin_no);
void shared_bindings_microcontroller_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
#define COMMON_HAL_MCU_NO_PIN ((uint8_t)0xff)
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H

View File

@ -174,7 +174,7 @@ STATIC mp_obj_t socketpool_socket_recvfrom_into(mp_obj_t self_in, mp_obj_t data_
mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_WRITE);
byte ip[4];
mp_uint_t port;
uint32_t port;
mp_int_t ret = common_hal_socketpool_socket_recvfrom_into(self,
(byte *)bufinfo.buf, bufinfo.len, ip, &port);
mp_obj_t tuple_contents[2];

View File

@ -29,7 +29,7 @@
#include "common-hal/wifi/Monitor.h"
const mp_obj_type_t wifi_monitor_type;
extern const mp_obj_type_t wifi_monitor_type;
void common_hal_wifi_monitor_construct(wifi_monitor_obj_t *self,
uint8_t channel, size_t queue);

View File

@ -33,7 +33,7 @@
#include "py/objstr.h"
const mp_obj_type_t wifi_network_type;
extern const mp_obj_type_t wifi_network_type;
extern mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self);

View File

@ -27,7 +27,6 @@
#include "shared-bindings/wifi/__init__.h"
#include "shared-bindings/wifi/AuthMode.h"
#include <regex.h>
#include <string.h>
#include "py/runtime.h"
@ -35,6 +34,43 @@
#define MAC_ADDRESS_LENGTH 6
STATIC bool hostname_valid(const char *ptr, size_t len) {
#if 0 // validated by mp_arg_validate_length_range
if (len == 0 || len > 253) {
// at most 253 characters long
return false;
}
#endif
int partlen = 0;
while (len) {
char c = *ptr++;
len--;
if (c == '.') {
if (partlen == 0 || partlen > 63) {
return false;
}
partlen = 0;
continue;
}
partlen++;
if (c == '-') {
if (partlen == 1) {
return false; // part cannot begin with a dash
}
continue;
} else if (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9')) {
continue;
}
return false;
}
// check length of last part
return !(partlen > 63);
}
//| class Radio:
//| """Native wifi radio.
//|
@ -85,14 +121,9 @@ STATIC mp_obj_t wifi_radio_set_hostname(mp_obj_t self_in, mp_obj_t hostname_in)
mp_arg_validate_length_range(hostname.len, 1, 253, MP_QSTR_hostname);
#ifndef CONFIG_IDF_TARGET_ESP32C3
regex_t regex; // validate hostname according to RFC 1123
regcomp(&regex,"^(([a-z0-9]|[a-z0-9][a-z0-9\\-]{0,61}[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]{0,61}[a-z0-9])$", REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (regexec(&regex, hostname.buf, 0, NULL, 0)) {
if (!hostname_valid(hostname.buf, hostname.len)) {
mp_raise_ValueError(translate("invalid hostname"));
}
regfree(&regex);
#endif
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_wifi_radio_set_hostname(self, hostname.buf);

View File

@ -33,7 +33,7 @@
#include "py/objstr.h"
const mp_obj_type_t wifi_radio_type;
extern const mp_obj_type_t wifi_radio_type;
typedef enum {
// 0 is circuitpython-specific; 1-53 are IEEE; 200+ are Espressif

View File

@ -120,4 +120,8 @@ void port_yield(void);
// A default weak implementation is provided that does nothing.
void port_post_boot_py(bool heap_valid);
// Some ports want to add information to boot_out.txt.
// A default weak implementation is provided that does nothing.
void port_boot_info(void);
#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H

View File

@ -34,3 +34,6 @@ MP_WEAK void port_wake_main_task_from_isr(void) {
MP_WEAK void port_yield(void) {
}
MP_WEAK void port_boot_info(void) {
}

View File

@ -67,6 +67,8 @@ EXCLUSIONS = [
"tests/**/repl_*.py",
# needs careful attention before applying automatic formatting
"tests/basics/*.py",
# don't reindent this third-party code we vendored in
"ports/raspberrypi/lwip_src",
]
# None of the standard Python path matching routines implement the matching

View File

@ -1,3 +1,3 @@
#!/bin/sh
# Add any supplied arguments.
git describe --first-parent --dirty --tags --always --match "[1-9].*" "$@"
git describe --first-parent --dirty --tags --match "[1-9].*" "$@"