diff --git a/CMakeLists.txt b/CMakeLists.txt index 29cd7a5..67096b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,29 @@ -# User configuration section starts here +if (NOT PICO_PROGRAM_MAIN_ENTRY) + # User configuration for HyperSerialPico section starts here -# Some boards, such as the first Adafruit revisions, may have trouble booting properly -# due to bad componets used in the design. -# Turn this setting to ON if your rp2040 is not detected after firmware upload and reset -set(BOOT_WORKAROUND OFF) + # Some boards, such as the first Adafruit revisions, may have trouble booting properly + # due to bad componets used in the design. + # Turn this setting to ON if your rp2040 is not detected after firmware upload and reset + set(BOOT_WORKAROUND OFF) -# Default output data pin for the non-SPI LED strips (only for sk6812/ws2812b) -set(OUTPUT_DATA_PIN 2) + # Default output data pin for the non-SPI LED strips (only for sk6812/ws2812b) + set(OUTPUT_DATA_PIN 2) -# Default output data/clocks pin for the SPI LED strips (only for apa102, not for sk6812/ws2812b) -# only certain pairs of pins are allowed for selected SPI interface (refer to "readme.md") -set(OUTPUT_SPI_DATA_PIN 3) -set(OUTPUT_SPI_CLOCK_PIN 2) -set(OUTPUT_SPI_INTERFACE spi0) + # Default output data/clocks pin for the SPI LED strips (only for apa102, not for sk6812/ws2812b) + # only certain pairs of pins are allowed for selected SPI interface (refer to "readme.md") + set(OUTPUT_SPI_DATA_PIN 3) + set(OUTPUT_SPI_CLOCK_PIN 2) + set(OUTPUT_SPI_INTERFACE spi0) -# Use multi-segment, starting index of second led strip or OFF to disable -set(SECOND_SEGMENT_INDEX OFF) + # Use multi-segment, starting index of second led strip or OFF to disable + set(SECOND_SEGMENT_INDEX OFF) -# If multi-segment is used and it's reversed, set this option to ON to enable reversing -set(SECOND_SEGMENT_REVERSED OFF) + # If multi-segment is used and it's reversed, set this option to ON to enable reversing + set(SECOND_SEGMENT_REVERSED OFF) -# User configuration section ends here -# Usually you don't need to change anything below this section + # User configuration section ends here + # Usually you don't need to change anything below this section +endif() cmake_minimum_required(VERSION 3.13) @@ -30,8 +32,8 @@ add_definitions ( -DPICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=0 ) # initialize the SDK based on PICO_SDK_PATH # note: this must happen before project() -set(PICO_SDK_PATH ${CMAKE_SOURCE_DIR}/sdk/pico) -set(FREERTOS_KERNEL_PATH ${CMAKE_SOURCE_DIR}/sdk/freertos) +set(PICO_SDK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/sdk/pico) +set(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/sdk/freertos) include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake) include(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) @@ -52,9 +54,9 @@ pico_sdk_init() # generic HyperSerialPico settings set(HyperSerialPicoCompanionLibs FreeRTOS-Kernel FreeRTOS-Kernel-Heap1 pico_stdlib pico_multicore hardware_pio hardware_dma hardware_spi) -set(HyperSerialPicoCompanionIncludes ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/sdk/config) -file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/generated) -file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/firmware) +set(HyperSerialPicoCompanionIncludes ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/sdk/config) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/generated) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/firmware) if(NOT CMAKE_HOST_WIN32) string(ASCII 27 EscChar) @@ -92,6 +94,11 @@ message( STATUS "---------------------------") message( STATUS "Neopixel Data GPIO: ${GreenColor}${OUTPUT_DATA_PIN}${ColorReset}") message( STATUS "SPI Data GPIO: ${GreenColor}${OUTPUT_SPI_DATA_PIN}${ColorReset}") message( STATUS "SPI Clock GPIO: ${GreenColor}${OUTPUT_SPI_CLOCK_PIN}${ColorReset}") + +if (OUTPUT_SPI_CHIP_SELECT) + message( STATUS "SPI Select GPIO: ${GreenColor}${OUTPUT_SPI_CHIP_SELECT}${ColorReset}") +endif() + message( STATUS "SPI Interface: ${GreenColor}${OUTPUT_SPI_INTERFACE}${ColorReset}") message( STATUS "Boot workaround: ${GreenColor}${BOOT_WORKAROUND}${ColorReset}") message( STATUS "---------------------------") @@ -99,7 +106,11 @@ message( STATUS "---------------------------") add_compile_options(-ftrack-macro-expansion=0 -fno-diagnostics-show-caret -fdiagnostics-color=auto) macro(HyperSerialPicoTarget HyperSerialPicoTargetName) - add_executable(${HyperSerialPicoTargetName} ${CMAKE_SOURCE_DIR}/source/main.cpp) + if (PICO_PROGRAM_MAIN_ENTRY) + add_executable(${HyperSerialPicoTargetName} ${PICO_PROGRAM_MAIN_ENTRY}) + else() + add_executable(${HyperSerialPicoTargetName} ${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp) + endif() if (BOOT_WORKAROUND) target_compile_definitions(${HyperSerialPicoTargetName} PUBLIC -DBOOT_WORKAROUND -DPICO_XOSC_STARTUP_DELAY_MULTIPLIER=64) endif() @@ -108,15 +119,17 @@ macro(HyperSerialPicoTarget HyperSerialPicoTargetName) pico_add_extra_outputs(${HyperSerialPicoTargetName}) pico_enable_stdio_usb(${HyperSerialPicoTargetName} 1) pico_enable_stdio_uart(${HyperSerialPicoTargetName} 0) - pico_generate_pio_header(${HyperSerialPicoTargetName} ${CMAKE_SOURCE_DIR}/pio/neopixel.pio OUTPUT_DIR ${CMAKE_SOURCE_DIR}/generated) - pico_generate_pio_header(${HyperSerialPicoTargetName} ${CMAKE_SOURCE_DIR}/pio/neopixel_ws2812b.pio OUTPUT_DIR ${CMAKE_SOURCE_DIR}/generated) - add_custom_command(TARGET ${HyperSerialPicoTargetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${HyperSerialPicoTargetName}.uf2 ${CMAKE_SOURCE_DIR}/firmware) + pico_generate_pio_header(${HyperSerialPicoTargetName} ${CMAKE_CURRENT_SOURCE_DIR}/pio/neopixel.pio OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/generated) + pico_generate_pio_header(${HyperSerialPicoTargetName} ${CMAKE_CURRENT_SOURCE_DIR}/pio/neopixel_ws2812b.pio OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/generated) + add_custom_command(TARGET ${HyperSerialPicoTargetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${HyperSerialPicoTargetName}.uf2 ${CMAKE_CURRENT_SOURCE_DIR}/firmware) endmacro() # targets for different LED strips IF(NOT SECOND_SEGMENT_INDEX) - HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_Spi") - target_compile_definitions("${CMAKE_PROJECT_NAME}_Spi" PRIVATE -DSPILED_APA102 -DSPI_INTERFACE=${OUTPUT_SPI_INTERFACE} -DDATA_PIN=${OUTPUT_SPI_DATA_PIN} -DCLOCK_PIN=${OUTPUT_SPI_CLOCK_PIN}) + IF(NOT DISABLE_SPI_LEDS) + HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_Spi") + target_compile_definitions("${CMAKE_PROJECT_NAME}_Spi" PRIVATE -DSPILED_APA102 -DSPI_INTERFACE=${OUTPUT_SPI_INTERFACE} -DDATA_PIN=${OUTPUT_SPI_DATA_PIN} -DCLOCK_PIN=${OUTPUT_SPI_CLOCK_PIN}) + endif() HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_sk6812Cold") target_compile_definitions("${CMAKE_PROJECT_NAME}_sk6812Cold" PRIVATE -DNEOPIXEL_RGBW -DCOLD_WHITE -DDATA_PIN=${OUTPUT_DATA_PIN}) HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_sk6812Neutral") diff --git a/include/framestate.h b/include/framestate.h index ba8d514..fba9343 100644 --- a/include/framestate.h +++ b/include/framestate.h @@ -67,6 +67,7 @@ class uint16_t fletcher2 = 0; uint16_t fletcherExt = 0; uint8_t position = 0; + bool regroup = false; public: ColorDefinition color; @@ -212,6 +213,16 @@ class fletcherExt = (fletcherExt + (input ^ (position++))) % 255; } + void setRegroup(bool newValue) + { + regroup = newValue; + } + + bool getRegroup() + { + return regroup; + } + /** * @brief Check if the calibration data was updated and calculate new one * diff --git a/include/main.h b/include/main.h index f114808..375fa28 100644 --- a/include/main.h +++ b/include/main.h @@ -140,6 +140,9 @@ void processData() if (input == 0x15) printf(HELLO_MESSAGE); + + frameState.setRegroup(true); + delay(10); currentTime = millis();