Skip to content

Commit 4d8940c

Browse files
committed
more wifi work
1 parent 95179be commit 4d8940c

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

ports/zephyr-cp/boards/nordic/nrf7002dk/autogen_board_info.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ usb_midi = false
101101
usb_video = false
102102
ustack = false
103103
vectorio = false
104-
warnings = false
104+
warnings = true
105105
watchdog = false
106106
wifi = true # Zephyr board has wifi
107107
zephyr_kernel = false

ports/zephyr-cp/common-hal/wifi/Radio.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,13 @@ void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
222222
}
223223

224224
void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) {
225+
printk("common_hal_wifi_radio_start_station\n");
225226
// set_mode_station(self, true);
226227
}
227228

228229
void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
230+
printk("common_hal_wifi_radio_stop_station\n");
231+
229232
// set_mode_station(self, false);
230233
}
231234

@@ -317,12 +320,38 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
317320
if (!common_hal_wifi_radio_get_enabled(self)) {
318321
mp_raise_RuntimeError(MP_ERROR_TEXT("wifi is not enabled"));
319322
}
320-
// wifi_config_t *config = &self->sta_config;
321-
322-
// size_t timeout_ms = timeout * 1000;
323-
// uint32_t start_time = common_hal_time_monotonic_ms();
324-
// uint32_t end_time = start_time + timeout_ms;
323+
printk("common_hal_wifi_radio_connect\n");
324+
printk("ssid: %s\n", ssid);
325+
326+
// k_poll_signal_init(&self->channel_done);
327+
// k_poll_event_init(&self->events[2],
328+
// K_POLL_TYPE_SIGNAL,
329+
// K_POLL_MODE_NOTIFY_ONLY,
330+
// &self->channel_done);
331+
332+
struct wifi_connect_req_params params = {0};
333+
params.ssid = ssid;
334+
params.ssid_length = ssid_len;
335+
params.psk = password;
336+
params.psk_length = password_len;
337+
params.timeout = (int)timeout;
338+
if (channel > 0) {
339+
params.band = WIFI_FREQ_BAND_2_4_GHZ;
340+
params.channel = channel;
341+
}
342+
if (bssid_len > 0) {
343+
memcpy(params.bssid, bssid, bssid_len);
344+
}
345+
int res = net_mgmt(NET_REQUEST_WIFI_CONNECT, self->sta_netif, &params, sizeof(params));
346+
if (res != 0) {
347+
printk("Failed to start connect to wifi %d\n", res);
348+
return WIFI_RADIO_ERROR_AUTH_FAIL;
349+
}
350+
printk("sleeping past timeout %f\n", timeout);
351+
k_sleep(K_SECONDS(timeout + 2));
325352

353+
printk("sleeping 30 more seconds\n");
354+
k_sleep(K_SECONDS(30));
326355
// EventBits_t bits;
327356
// // can't block since both bits are false after wifi_init
328357
// // both bits are true after an existing connection stops
@@ -420,6 +449,7 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
420449
}
421450

422451
bool common_hal_wifi_radio_get_connected(wifi_radio_obj_t *self) {
452+
printk("common_hal_wifi_radio_get_connected\n");
423453
// return self->sta_mode && esp_netif_is_netif_up(self->netif);
424454
return false;
425455
}

ports/zephyr-cp/common-hal/wifi/ScannedNetworks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self) {
107107
raise_zephyr_error(res);
108108
wifi_scannednetworks_done(self);
109109
} else {
110+
printk("Scanning channel %d\n", next_channel);
110111
self->channel_scan_in_progress = true;
111112
}
112113
}

ports/zephyr-cp/common-hal/wifi/__init__.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ void common_hal_wifi_init(bool user_initiated) {
265265
// self->sta_mode = 0;
266266
// self->ap_mode = 0;
267267

268+
printk("registering event callbacks\n");
268269
net_mgmt_init_event_callback(&wifi_cb, _event_handler,
269270
NET_EVENT_WIFI_SCAN_DONE |
270271
NET_EVENT_WIFI_CONNECT_RESULT |

ports/zephyr-cp/cptools/build_circuitpython.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252
"random",
5353
"digitalio",
5454
"zephyr_serial",
55+
"errno",
56+
"warnings",
57+
"io"
5558
]
56-
MPCONFIG_FLAGS = ["ulab", "nvm", "displayio", "warnings", "alarm", "array", "json"]
59+
MPCONFIG_FLAGS = ["ulab", "warnings", "alarm", "array", "json", "errno", "io"]
5760

5861

5962
async def preprocess_and_split_defs(compiler, source_file, build_path, flags):
@@ -204,7 +207,7 @@ async def build_circuitpython():
204207
circuitpython_flags = ["-DCIRCUITPY"]
205208
port_flags = []
206209
enable_mpy_native = False
207-
full_build = False
210+
full_build = True
208211
usb_host = False
209212
tusb_mem_align = 4
210213
board = cmake_args["BOARD_ALIAS"]
@@ -496,6 +499,9 @@ async def build_circuitpython():
496499
hal_source.extend(top.glob(f"shared-bindings/{module.name}/*.c"))
497500
hal_source.extend(top.glob(f"shared-module/{module.name}/*.c"))
498501

502+
if module.name == "os":
503+
circuitpython_flags.append("-DCIRCUITPY_OS_GETENV=1")
504+
499505
if os.environ.get("CI", "false") == "true":
500506
# Fail the build if it isn't up to date.
501507
if (
@@ -512,8 +518,12 @@ async def build_circuitpython():
512518
for mpflag in MPCONFIG_FLAGS:
513519
enabled = mpflag in DEFAULT_MODULES
514520
circuitpython_flags.append(f"-DCIRCUITPY_{mpflag.upper()}={1 if enabled else 0}")
521+
logger.info(f"CIRCUITPY_{mpflag} enabled: {enabled}")
522+
if mpflag == "io":
523+
enabled = enabled and "jpegio" in enabled_modules
524+
circuitpython_flags.append(f"-DCIRCUITPY_IO_IOBASE={1 if enabled else 0}")
515525

516-
source_files = supervisor_source + hal_source + ["extmod/vfs.c"]
526+
source_files = supervisor_source + hal_source + ["extmod/vfs.c", "extmod/modjson.c"]
517527
assembly_files = []
518528
for file in top.glob("py/*.c"):
519529
source_files.append(file)

0 commit comments

Comments
 (0)