I am starting with the raspberry pi pico and the visual studio code in windows. I am practising with the pico examples coming in the SDK V1.5. What I want to try in this example is to add a new level of folder with an .C and .h files in it. The purpose of this is I want to try a sensor mcp for that the folders structure is something like.
/pico-example
-CMakeLists.txt
/i2c
-CMakeList.txt
- i2c.c
/Sensor9600
-mcp9600.c
-mcp9600.h
/spi
/gpio
I tried to have a executable from i2c that call main and include the sensor as well.
The Cmakelist from the pico-example is
cmake_minimum_required(VERSION 3.12)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
include(pico_extras_import_optional.cmake)
project(pico_examples C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})
# Initialize the SDK
pico_sdk_init()
include(example_auto_set_url.cmake)
# Add blink example
add_subdirectory(blink)
# Add hello world example
add_subdirectory(hello_world)
add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-Wno-maybe-uninitialized
)
# Hardware-specific examples in subdirectories:
add_subdirectory(adc)
add_subdirectory(clocks)
add_subdirectory(cmake)
add_subdirectory(divider)
add_subdirectory(dma)
add_subdirectory(flash)
add_subdirectory(gpio)
add_subdirectory(i2c)
add_subdirectory(interp)
add_subdirectory(multicore)
add_subdirectory(picoboard)
add_subdirectory(pico_w)
add_subdirectory(pio)
add_subdirectory(pwm)
add_subdirectory(reset)
add_subdirectory(rtc)
add_subdirectory(spi)
add_subdirectory(system)
add_subdirectory(timer)
add_subdirectory(uart)
add_subdirectory(usb)
add_subdirectory(watchdog)
add_subdirectory(betagecko)
I tried to create One Cmakefile.txt for the i2c folder
add_executable(i2c
i2c.c
)
# pull in common dependencies and additional i2c hardware support
target_link_libraries(i2c pico_stdlib hardware_i2c
mcp9600)
# enable usb output, disable uart output
pico_enable_stdio_usb(i2c 1)
pico_enable_stdio_uart(i2c 0)
# create map/bin/hex file etc.
pico_add_extra_outputs(i2c)
# add url via pico_set_program_url
example_auto_set_url(i2c)
add_subdirectory(Sensor9600)
Then the file inside the Sensor9600 folder CMakeList.txt
I tried
add_library(mcp9600 mcp9600.c)
target_sources(mcp9600PUBLIC mcp9600.h)
target_include_directories(mcp9600 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
I tried modified the I2c.c and it works the probles is when I tried to add other level of folder. I read some solution and it did not works for me so I am doing something really wrong.
Could you help me with this?
Edit: The compiler can not find the file mcp9600.h, so I think I am doing something wrong with Cmake