diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 77a0edc..8b5daf6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -67,6 +67,54 @@ "clear": true } }, + { + "label": "Flash Access Point", + "detail": "Build and flash access point", + "type": "shell", + "dependsOn": [ + "Configure" + ], + "command": "make", + "args": [ + "-C", + "build", + "-j$(nproc)", + "Flash_Access_Point" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Flash Station", + "detail": "Build and flash station", + "type": "shell", + "dependsOn": [ + "Configure" + ], + "command": "make", + "args": [ + "-C", + "build", + "-j$(nproc)", + "Flash_Station" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, { "label": "Clean", "detail": "Clean build directory and executable", diff --git a/CMakeLists.txt b/CMakeLists.txt index d397c47..136e70a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,29 +15,49 @@ set(CMAKE_CXX_STANDARD 17) pico_sdk_init() -# Sources -add_executable(PicoW_UDP_Tests - src/main.c +# Executables and sources +add_executable(PicoW_Access_Point + src/main_access_point.c +) + +add_executable(PicoW_Station + src/main_station.c ) # Libs add_subdirectory(lib/PicoW_WiFi_Operator) add_subdirectory(lib/PicoW_UDP) -target_link_libraries(PicoW_UDP_Tests + +target_link_libraries(PicoW_Access_Point + pico_stdlib + PicoW_WiFi_Operator + PicoW_UDP +) + +target_link_libraries(PicoW_Station pico_stdlib PicoW_WiFi_Operator PicoW_UDP ) # Stdio configuration -pico_enable_stdio_usb(PicoW_UDP_Tests 1) -pico_enable_stdio_uart(PicoW_UDP_Tests 1) +pico_enable_stdio_usb(PicoW_Access_Point 1) +pico_enable_stdio_uart(PicoW_Access_Point 1) + +pico_enable_stdio_usb(PicoW_Station 1) +pico_enable_stdio_uart(PicoW_Station 1) # Output -pico_add_extra_outputs(PicoW_UDP_Tests) +pico_add_extra_outputs(PicoW_Access_Point) +pico_add_extra_outputs(PicoW_Station) # Flash target -add_custom_target(Flash - DEPENDS PicoW_UDP_Tests - COMMAND picotool load -f ${PROJECT_BINARY_DIR}/PicoW_UDP_Tests.uf2 +add_custom_target(Flash_Access_Point + DEPENDS PicoW_Access_Point + COMMAND picotool load -f ${PROJECT_BINARY_DIR}/PicoW_Access_Point.uf2 +) + +add_custom_target(Flash_Station + DEPENDS PicoW_Station + COMMAND picotool load -f ${PROJECT_BINARY_DIR}/PicoW_Station.uf2 ) diff --git a/lib/PicoW_UDP b/lib/PicoW_UDP index be22ab1..66f06c7 160000 --- a/lib/PicoW_UDP +++ b/lib/PicoW_UDP @@ -1 +1 @@ -Subproject commit be22ab1cf48bd53b05e7380ab248f4a2749f2870 +Subproject commit 66f06c7ef5301235230d57fe066ddfb1d0fdc692 diff --git a/lib/PicoW_WiFi_Operator b/lib/PicoW_WiFi_Operator index db81c8e..64ba1dc 160000 --- a/lib/PicoW_WiFi_Operator +++ b/lib/PicoW_WiFi_Operator @@ -1 +1 @@ -Subproject commit db81c8ef1bba6bce966b779d1daf011af6c4d59c +Subproject commit 64ba1dcc72a3633eb93f071f438395526bea80e9 diff --git a/src/main_access_point.c b/src/main_access_point.c new file mode 100644 index 0000000..dfa460a --- /dev/null +++ b/src/main_access_point.c @@ -0,0 +1,58 @@ +#include +#include +#include "PicoW_WiFi_Operator.h" +#include "PicoW_UDP.h" + +static inline void udp_client_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) +{ + struct udp_client_t *udp_client = arg; + + printf("Received udp data with len %d :\n", p->len); + + for(uint16_t i = 0; i < p->len; i++) + { + printf("0x%02x ", ((uint8_t *)p->payload)[i]); + } + + putchar('\n'); + + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, ((uint8_t *)p->payload)[0]); + + pbuf_free(p); +} + +int main(void) +{ + stdio_init_all(); + + if(cyw43_arch_init_with_country(CYW43_COUNTRY_FRANCE)) return PICO_ERROR_GENERIC; + + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true); + + if(wifi_operator_init(WIFI_OPERATOR_MODE_ACCESS_POINT)) return PICO_ERROR_GENERIC; + + struct udp_client_t udp_client; + + if(udp_client_init(&udp_client, udp_client_callback)) return PICO_ERROR_GENERIC; + + for(int i = 0; i < 3; i++) + { + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, false); + sleep_ms(100); + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true); + sleep_ms(100); + } + + while(true) + { + cyw43_arch_poll(); + + tight_loop_contents(); + } + + if(wifi_operator_exit()) return PICO_ERROR_GENERIC; + + cyw43_arch_deinit(); + + return PICO_OK; +} \ No newline at end of file diff --git a/src/main.c b/src/main_station.c similarity index 81% rename from src/main.c rename to src/main_station.c index ba4ce0e..27a9b41 100644 --- a/src/main.c +++ b/src/main_station.c @@ -13,6 +13,10 @@ int main(void) if(wifi_operator_init(WIFI_OPERATOR_MODE_STATION)) return PICO_ERROR_GENERIC; + struct udp_server_t udp_server; + + if(udp_server_init(&udp_server)) return PICO_ERROR_GENERIC; + while(true) { static uint64_t last_time = 0; @@ -25,6 +29,8 @@ int main(void) led_state = !led_state; cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_state); + + if(udp_server_send(&udp_server, &led_state, sizeof(led_state))) return PICO_ERROR_GENERIC; } cyw43_arch_poll();