### Pico SDK CMakeLists Setup Source: https://github.com/pstolarz/onewireng/blob/master/examples/pico-sdk/DS2431/CMakeLists.txt Initializes the Pico SDK and sets up the project. This is a standard setup for Pico SDK projects. ```cmake cmake_minimum_required(VERSION 3.13) include(pico_sdk_import.cmake) project(DS2431) pico_sdk_init() ``` -------------------------------- ### Create Multiple RP2040 PIO OneWire Buses Source: https://github.com/pstolarz/onewireng/blob/master/README.md Demonstrates how to dynamically allocate and initialize multiple OneWire buses using the `OneWireNg_PicoRP2040PIO` driver. This example shows how subsequent drivers can reuse the PIO program from a base driver, reducing resource usage. Ensure the base driver outlives any dependent drivers. ```cpp constexpr bool INT_PULLUP = false; // the driver is handled by PIO0/SM0 OneWireNg *ow1 = new OneWireNg_PicoRP2040PIO(PIN1, INT_PULLUP, 0); // create more drivers handled by PIO0/SM1..3 // the drivers reuse PIO0 program loaded by driver ow1 OneWireNg *ow2 = new OneWireNg_PicoRP2040PIO(PIN2, INT_PULLUP, (OneWireNg_PicoRP2040PIO&)*ow1); #if CONFIG_RP2040_PIOSM_NUM_USED <= 1 OneWireNg *ow3 = new OneWireNg_PicoRP2040PIO(PIN3, INT_PULLUP, (OneWireNg_PicoRP2040PIO&)*ow1); OneWireNg *ow4 = new OneWireNg_PicoRP2040PIO(PIN4, INT_PULLUP, (OneWireNg_PicoRP2040PIO&)*ow1); #endif // the driver is handled by PIO1/SM0 OneWireNg *ow5 = new OneWireNg_PicoRP2040PIO(PIN5, INT_PULLUP, 1); // create more drivers handled by PIO1/SM1..3 // the drivers reuse PIO1 program loaded by driver ow5 OneWireNg *ow6 = new OneWireNg_PicoRP2040PIO(PIN6, INT_PULLUP, (OneWireNg_PicoRP2040PIO&)*ow5); #if CONFIG_RP2040_PIOSM_NUM_USED <= 1 OneWireNg *ow7 = new OneWireNg_PicoRP2040PIO(PIN7, INT_PULLUP, (OneWireNg_PicoRP2040PIO&)*ow5); OneWireNg *ow8 = new OneWireNg_PicoRP2040PIO(PIN8, INT_PULLUP, (OneWireNg_PicoRP2040PIO&)*ow5); #endif ``` -------------------------------- ### Pico SDK I/O Configuration Source: https://github.com/pstolarz/onewireng/blob/master/examples/pico-sdk/DS2431/CMakeLists.txt Enables or disables standard I/O for USB and UART. This snippet configures USB for the DS2431 example. ```cmake pico_enable_stdio_usb(DS2431 1) pico_enable_stdio_uart(DS2431 0) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/pstolarz/onewireng/blob/master/examples/esp-idf/DS2431/CMakeLists.txt Sets the minimum CMake version and includes the ESP-IDF project setup script. Defines the project name. ```cmake cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(DS2431) ``` -------------------------------- ### DS2431 Executable and Linking Source: https://github.com/pstolarz/onewireng/blob/master/examples/pico-sdk/DS2431/CMakeLists.txt Defines the main executable for the DS2431 example and links it with the OneWireNg library. It also sets compile definitions for overdrive mode, CRC16, and USB connection timeout. ```cmake add_executable(DS2431 DS2431.cpp) add_subdirectory(OneWireNg) target_link_libraries(DS2431 PRIVATE OneWireNg) target_compile_definitions(DS2431 PRIVATE USE_OD_MODE) target_compile_definitions(DS2431 PRIVATE CONFIG_OVERDRIVE_ENABLED) target_compile_definitions(DS2431 PRIVATE CONFIG_CRC16_ENABLED) target_compile_definitions(DS2431 PRIVATE PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=-1) ``` -------------------------------- ### Configure Parasite Powering with OneWireNg Source: https://github.com/pstolarz/onewireng/blob/master/README.md Demonstrates how to initialize the OneWireNg library for parasite powering. Choose between GPIO bit-banging or switching transistor modes based on platform capabilities and configuration. ```cpp #include "OneWireNg_CurrentPlatform.h" static OneWireNg *ow = NULL; void setup() { /* * Macro-defines used: * * OW_PIN: GPIO pin number used for bit-banging 1-wire bus. * PWR_CTRL_PIN: power-control-GPIO pin number (optional). */ #ifdef PWR_CTRL_PIN # if CONFIG_PWR_CTRL_ENABLED # error "CONFIG_PWR_CTRL_ENABLED needs to be configured" # endif // switching transistor powering ow = new OneWireNg_CurrentPlatform(OW_PIN, PWR_CTRL_PIN); #else // GPIO bit-bang powering ow = new OneWireNg_CurrentPlatform(OW_PIN); #endif // ... // write array of bytes and power the bus subsequently; // the bus is powered until explicit unpowering or next 1-wire bus activity ow->writeBytes(bytes, bytes_len, true); // wait for connected slaves to fulfill their task requiring extra powering delay(750); // unpower the bus explicitly ow->powerBus(false); } ``` -------------------------------- ### Initialize and Search 1-Wire Bus with Range Loop Source: https://github.com/pstolarz/onewireng/blob/master/README.md Shows how to initialize the OneWireNg service and iterate through connected slave devices using a C++11 range-based for loop. This provides a more modern way to detect slaves on the bus. ```cpp #include "OneWireNg_CurrentPlatform.h" static OneWireNg *ow = NULL; void setup() { ow = new OneWireNg_CurrentPlatform(10); for (const auto& id: *ow) { // 'id' contains 1-wire address of a connected slave } } ``` -------------------------------- ### Pico SDK Library Creation Source: https://github.com/pstolarz/onewireng/blob/master/CMakeLists.txt Creates a static library for OneWireNg using source files found in the src and src/platform directories. It also links against pico_stdlib and hardware_pio. ```cmake file(GLOB target_src src/*.cpp src/platform/*.cpp src/drivers/*.cpp ) add_library(OneWireNg STATIC ${target_src}) target_include_directories(OneWireNg PUBLIC src) target_link_libraries(OneWireNg PUBLIC pico_stdlib hardware_pio ) target_optimize_size(OneWireNg) ``` -------------------------------- ### Configure OneWireNg in Pico SDK CMakeLists.txt Source: https://github.com/pstolarz/onewireng/blob/master/README.md Link the OneWireNg library to your Pico SDK project by adding it as a subdirectory and linking it in your CMakeLists.txt file. ```cmake cmake_minimum_required(VERSION 3.13) include(pico_sdk_import.cmake) project(some_project) pico_sdk_init() add_executable(some_project) ... add_subdirectory(OneWireNg) target_link_libraries(some_project PRIVATE OneWireNg) pico_add_extra_outputs(some_project) ``` -------------------------------- ### Initialize and Search 1-Wire Bus Source: https://github.com/pstolarz/onewireng/blob/master/README.md Demonstrates how to initialize the OneWireNg service for the current platform and perform a search for connected slave devices using the traditional search method. The bus is controlled by a specified MCU pin. ```cpp #include "OneWireNg_CurrentPlatform.h" static OneWireNg *ow = NULL; void setup() { OneWireNg::Id id; ow = new OneWireNg_CurrentPlatform(10); ow->searchReset(); while (ow->search(id) == OneWireNg::EC_MORE) { // 'id' contains 1-wire address of a connected slave } } ``` -------------------------------- ### Using Placeholder for In-place OneWireNg Allocation Source: https://github.com/pstolarz/onewireng/blob/master/README.md Demonstrates using the Placeholder utility template to store a OneWireNg_CurrentPlatform object, initializing it with in-place new. This is an alternative to direct buffer allocation for managing OneWireNg objects without heap allocation. ```cpp #include "OneWireNg_CurrentPlatform.h" #include "utils/Placeholder.h" static Placeholder ow; void setup() { // initialize the placeholded object by in-place new new (&ow) OneWireNg_CurrentPlatform(10); // ... } ``` -------------------------------- ### Add Executable and Link Libraries Source: https://github.com/pstolarz/onewireng/blob/master/examples/pico-sdk/DallasTemperature/CMakeLists.txt Defines the main executable for the project and links it with the OneWireNg library. It also configures standard output streams. ```cmake add_executable(DallasTemperature DallasTemperature.cpp) add_subdirectory(OneWireNg) target_link_libraries(DallasTemperature PRIVATE OneWireNg) pico_enable_stdio_usb(DallasTemperature 1) pico_enable_stdio_uart(DallasTemperature 0) pico_add_extra_outputs(DallasTemperature) ``` -------------------------------- ### In-place Memory Allocation for OneWireNg Source: https://github.com/pstolarz/onewireng/blob/master/README.md Illustrates how to use the in-place 'new' operator to allocate memory for a OneWireNg_CurrentPlatform object directly from a pre-allocated buffer, avoiding heap allocation. This is useful when heap allocation is not desired. ```cpp #include "OneWireNg_CurrentPlatform.h" ALLOC_ALIGNED static uint8_t OneWireNg_buf[sizeof(OneWireNg_CurrentPlatform)]; static OneWireNg *ow = NULL; void setup() { ow = new (OneWireNg_buf) OneWireNg_CurrentPlatform(10); // ... } ``` -------------------------------- ### Add OneWireNg as Pico SDK Git Submodule Source: https://github.com/pstolarz/onewireng/blob/master/README.md Incorporate OneWireNg into a Raspberry Pi Pico SDK project by adding it as a git submodule. After adding, checkout a specific version. ```bash git submodule add -- https://github.com/pstolarz/OneWireNg OneWireNg cd OneWireNg git checkout VERSION ``` -------------------------------- ### Add OneWireNg as ESP-IDF Git Submodule Source: https://github.com/pstolarz/onewireng/blob/master/README.md Integrate OneWireNg into an ESP-IDF project by adding it as a git submodule in the components directory. Ensure to checkout a specific version after adding. ```bash git submodule add -- https://github.com/pstolarz/OneWireNg components/OneWireNg cd components/OneWireNg git checkout VERSION ``` -------------------------------- ### Add OneWireNg for Mbed OS Source: https://github.com/pstolarz/onewireng/blob/master/README.md Include OneWireNg in an Mbed OS project using the 'mbed add' command, specifying the desired version with a tag or branch. ```bash mbed add https://github.com/pstolarz/OneWireNg#VERSION ``` -------------------------------- ### ESP-IDF Component Registration (v5+) Source: https://github.com/pstolarz/onewireng/blob/master/CMakeLists.txt Registers the OneWireNg component for ESP-IDF version 5 and above. It specifies include directories, source directories, and required components. ```cmake idf_component_register( INCLUDE_DIRS src SRC_DIRS src src/platform src/drivers PRIV_REQUIRES driver esp_driver_gpio esp_timer soc ) ``` -------------------------------- ### ESP-IDF Component Registration (pre-v5) Source: https://github.com/pstolarz/onewireng/blob/master/CMakeLists.txt Registers the OneWireNg component for ESP-IDF versions prior to 5. It specifies include and source directories. ```cmake idf_component_register( INCLUDE_DIRS src SRC_DIRS src src/platform src/drivers ) ``` -------------------------------- ### Pico SDK Extra Outputs Source: https://github.com/pstolarz/onewireng/blob/master/examples/pico-sdk/DS2431/CMakeLists.txt Adds extra outputs for the specified target, typically used for debugging or additional build artifacts. ```cmake pico_add_extra_outputs(DS2431) ``` -------------------------------- ### Optimize Target Size for GNU/Clang Source: https://github.com/pstolarz/onewireng/blob/master/CMakeLists.txt Applies the -Os optimization flag to targets compiled with GCC or Clang to reduce binary size. This is useful for embedded systems with limited flash memory. ```cmake function(target_optimize_size target) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_options(${target} PRIVATE -Os) endif() endfunction() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.