From e0e624f6590361ef403674c8e0561d5e84923e7d Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Sun, 27 Sep 2026 13:02:22 +0200 Subject: [PATCH] Initial Commit. --- .gitignore | 2 + .gitmodules | 3 + .vscode/c_cpp_properties.json | 26 ++++++++ .vscode/tasks.json | 114 ++++++++++++++++++++++++++++++++++ CMakeLists.txt | 60 ++++++++++++++++++ README.md | 3 + lib/Pico_I2C | 1 + src/main_master.c | 41 ++++++++++++ src/main_slave.c | 21 +++++++ 9 files changed, 271 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 160000 lib/Pico_I2C create mode 100644 src/main_master.c create mode 100644 src/main_slave.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c264f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ccls-cache +build \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..89bfe2a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/Pico_I2C"] + path = lib/Pico_I2C + url = https://gitea.skadubpc.net/ulysse/Pico_I2C_Lib diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..5d9ccf7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,26 @@ +{ + "configurations": [ + { + "name": "Linux", + "intelliSenseMode": "linux-gcc-arm", + "includePath": [ + "${env:PICO_SDK_PATH}/src/**/include/", + "${env:PICO_SDK_PATH}/lib/**/include/", + "${env:PICO_SDK_PATH}/lib/**/src/", + "${workspaceFolder}/build/generated/pico_base/", + "${workspaceFolder}/src/", + "${workspaceFolder}/lib/**/" + ], + "compilerPath": "/usr/bin/arm-none-eabi-gcc", + "cStandard": "c17", + "browse": { + "path": [ + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + } + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d5b419e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,114 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Configure", + "detail": "configure project", + "type": "shell", + "command": "cmake", + "args": [ + "-H.", + "-Bbuild" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Build", + "detail": "Build project", + "dependsOn": [ + "Configure" + ], + "type": "shell", + "command": "make", + "args": [ + "-C", + "build", + "-j$(nproc)" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Flash Master", + "detail": "Build and flash master", + "type": "shell", + "dependsOn": [ + "Configure" + ], + "command": "make", + "args": [ + "-C", + "build", + "-j$(nproc)", + "Flash_Master" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Flash Slave", + "detail": "Build and flash slave", + "type": "shell", + "dependsOn": [ + "Configure" + ], + "command": "make", + "args": [ + "-C", + "build", + "-j$(nproc)", + "Flash_Slave" + ], + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + }, + { + "label": "Clean", + "detail": "Clean build directory and executable", + "type": "shell", + "command": "rm", + "args": [ + "-rf", + "build" + ], + "group": "build", + "presentation": { + "echo": false, + "reveal": "never", + "focus": false, + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3f63e2c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.13) + +# Explicitely define board +set(PICO_BOARD pico_w) +if(NOT DEFINED PICO_BOARD) + add_definitions(-DPICO_BOARD=${PICO_BOARD}) +endif() + +# Include pico-sdk cmake support +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) + +project(Pico_I2C_Tests C CXX ASM) +set(CMAKE_C_STANDARD 17) +set(CMAKE_CXX_STANDARD 17) + +pico_sdk_init() + +# Executables and sources +add_executable(Pico_Master + src/main_master.c +) + +add_executable(Pico_Slave + src/main_slave.c +) + +# Libs +add_subdirectory(lib/Pico_I2C) + +target_link_libraries(Pico_Master + pico_stdlib + Pico_I2C +) + +target_link_libraries(Pico_Slave + pico_stdlib + Pico_I2C +) + +# Stdio configuration +pico_enable_stdio_usb(Pico_Master 1) +pico_enable_stdio_uart(Pico_Master 1) + +pico_enable_stdio_usb(Pico_Slave 1) +pico_enable_stdio_uart(Pico_Slave 1) + +# Output +pico_add_extra_outputs(Pico_Master) +pico_add_extra_outputs(Pico_Slave) + +# Flash target +add_custom_target(Flash_Master + DEPENDS Pico_Master + COMMAND picotool load -f ${PROJECT_BINARY_DIR}/Pico_Master.uf2 +) + +add_custom_target(Flash_Slave + DEPENDS Pico_Slave + COMMAND picotool load -f ${PROJECT_BINARY_DIR}/Pico_Slave.uf2 +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..95cc531 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# PicoW_UDP_Tests + +Test of the library PicoW_UDP_Lib. \ No newline at end of file diff --git a/lib/Pico_I2C b/lib/Pico_I2C new file mode 160000 index 0000000..2ec3b68 --- /dev/null +++ b/lib/Pico_I2C @@ -0,0 +1 @@ +Subproject commit 2ec3b6816b2c863b03d3dceb4bb247dd48781ec5 diff --git a/src/main_master.c b/src/main_master.c new file mode 100644 index 0000000..131e892 --- /dev/null +++ b/src/main_master.c @@ -0,0 +1,41 @@ +#include +#include +#include "Pico_I2C.h" + +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); + + 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) + { + static uint64_t last_time = 0; + uint64_t time = time_us_64(); + if(time - last_time > 1000 * 1000) + { + last_time = time; + + static bool led_state = true; + led_state = !led_state; + + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_state); + } + + tight_loop_contents(); + } + + cyw43_arch_deinit(); + + return PICO_OK; +} \ No newline at end of file diff --git a/src/main_slave.c b/src/main_slave.c new file mode 100644 index 0000000..ff3898b --- /dev/null +++ b/src/main_slave.c @@ -0,0 +1,21 @@ +#include +#include +#include "Pico_I2C.h" + +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); + + while(true) + { + tight_loop_contents(); + } + + cyw43_arch_deinit(); + + return PICO_OK; +} \ No newline at end of file