This commit is contained in:
cpq committed 2026-05-18 10:38:59 +01:00
1 parent af54beffa9
commit ce1a7181a3
5 files changed
+148 -1

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.13)
# If you will set board type here, do it BEFORE including the SDK
set(PICO_BOARD pico2_w)
include(pico_sdk_import.cmake)
project(firmware)
pico_sdk_init()
add_executable(firmware main.c mongoose.c)
target_link_libraries(firmware pico_stdlib hardware_spi pico_rand pico_cyw43_driver pico_cyw43_arch_none hardware_flash pico_bootrom)
pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
pico_enable_stdio_usb(firmware 1) # Route stdio
# Prevent extreme optimization from breaking OTA
target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns)
+40
View File
@@ -0,0 +1,40 @@
# Environment setup: https://mongoose.ws/docs/getting-started/build-environment/
CWD = $(realpath $(PWD))
SDK_PATH ?= $(CWD)/pico-sdk
RM = rm -rf
MKBUILD = test -d build || mkdir build
ifeq ($(OS),Windows_NT)
RM = cmd /C del /Q /F /S
MKBUILD = if not exist build mkdir build
endif
.PHONY: build
all build: build/firmware.uf2
build/firmware.uf2: pico_sdk_import.cmake mongoose.c mongoose.h
pico_sdk_import.cmake: $(SDK_PATH)
cp $(SDK_PATH)/external/$@ $@
mongoose.c mongoose.h:
cp ../../../$@ .
build/firmware.uf2: $(SDK_PATH) $(wildcard *.[ch]) CMakeLists.txt Makefile
$(MKBUILD)
cd build && PICO_SDK_PATH=$(SDK_PATH) cmake -G "Unix Makefiles" .. && make
flash: build/firmware.uf2
picotool load $< -f
clean:
$(RM) build pico_sdk_import.cmake mongoose.c mongoose.h
fullclean: clean
$(RM) $(SDK_PATH)
$(SDK_PATH):
git clone -c advice.detachedHead=false --quiet --depth 1 -b 2.1.1 https://github.com/raspberrypi/pico-sdk $@
cd $@ && git submodule update --quiet --init
+60
View File
@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2024 Cesanta Software Limited
// SPDX-License-Identifier: GPL-2.0-only or commercial
#define WIFI_NAME "mywifi"
#define WIFI_PASS "mypassword"
#define WIFI_AP_NAME "mywifi2"
#define WIFI_AP_PASS "mypassword2"
#define ENABLE_AP 0
#include "mongoose.h"
void wifi_setconfig(void *data) {
struct mg_tcpip_driver_pico_w_data *d =
(struct mg_tcpip_driver_pico_w_data *) data;
struct mg_wifi_data *wifi = &d->wifi;
wifi->ssid = WIFI_NAME;
wifi->pass = WIFI_PASS;
wifi->apssid = WIFI_AP_NAME;
wifi->appass = WIFI_AP_PASS;
wifi->apip = MG_IPV4(192, 168, 111, 1);
wifi->apmask = MG_IPV4(255, 255, 255, 0);
wifi->security = 0;
wifi->apsecurity = 0;
wifi->apchannel = 10;
wifi->apmode = ENABLE_AP;
}
static void blink_timer(void *arg) {
(void) arg;
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN,
!cyw43_arch_gpio_get(CYW43_WL_GPIO_LED_PIN));
}
static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { // New HTTP request received
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
uint64_t tick = to_ms_since_boot(get_absolute_time());
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), tick);
} else {
mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", tick);
}
}
}
int main(void) {
stdio_init_all();
// do not access the CYW43 LED before Mongoose initializes !
MG_INFO(("Hardware initialised, starting firmware..."));
struct mg_mgr mgr;
mg_mgr_init(&mgr);
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
for (;;) {
mg_mgr_poll(&mgr, 1);
}
return 0;
}
@@ -0,0 +1,14 @@
#pragma once
// Build options: https://mongoose.ws/docs/getting-started/build-options/
#define MG_ARCH MG_ARCH_PICOSDK
#define MG_OTA MG_OTA_PICOSDK
#define MG_IO_SIZE 2048
#define MG_ENABLE_TCPIP 1
#define MG_ENABLE_DRIVER_PICO_W 1
// MAC address is read from OTP by the driver
// Set your Wi-Fi configuration using a custom function:
extern void wifi_setconfig(void *data);
#define MG_SET_WIFI_CONFIG(data) wifi_setconfig(data)