bablokb / pico-st7735

Pico display library for the ST7735
23 stars 8 forks source link

How do I link to this library? #2

Closed playduck closed 1 year ago

playduck commented 1 year ago

I'm trying to use this library as a module for a project. I'm using it as a git submodule, thus the folder structure is identical to this repository.

The file structure looks something like this:

|- main.cpp
|- CMakeLists.txt
|- build/
|- pico-st7735/
     |- lib-st7735/
          |- CMakeLists.txt
          |- src/
          |- include/
     |- demo/

I've left out most files, I hope the idea is clear.

I'm trying to build and link the library from the topmost CMakeLists file.

Here I'm defining all parameters like SPI_TFT_PORT, SPI_TFT_CS and so on.

Then I'm including the subdirectory add_subdirectory(pico-st7735/lib-st7735). After that simple linking it target_link_libraries(${PROJECT_NAME} lib-st7735).

The library is built successfully at /build/pico/st7735/lib-st7735/liblib-st7735.a

The process fails however at the linker stage whereby numerous errors to undefined references are found (for example to TFT_BlackTab_Initialize(), this function and others are definitely included in the compilation).

Does the library support to be built this way or am I doing something wrong/is there a problem on my end?

The full top-level CMakeLists.txt file i'm using:

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
include(pico_sdk_import.cmake)
project(pico-test C CXX ASM)

pico_sdk_init()

set(SPI_TFT_PORT "spi1" CACHE STRING "TFT spi port-name")
set(SPI_TFT_CS   "9"    CACHE STRING "TFT CS  pin number")
set(SPI_TFT_DC   "10"   CACHE STRING "TFT DC  pin number")
set(SPI_TFT_RST  "11"   CACHE STRING "TFT RST pin number")
set(SPI_PORT "spi1" CACHE STRING "spi port-name")
set(SPI_RX   "12"   CACHE STRING "RX  pin number")
set(SPI_TX   "15"   CACHE STRING "TX  pin number")
set(SPI_SCK  "14"   CACHE STRING "SCK pin number")
add_compile_definitions(SPI_PORT=${SPI_PORT})
add_compile_definitions(SPI_RX=${SPI_RX})
add_compile_definitions(SPI_TX=${SPI_TX})
add_compile_definitions(SPI_SCK=${SPI_SCK})
add_compile_definitions(SPI_TFT_PORT=${SPI_TFT_PORT})
add_compile_definitions(SPI_TFT_CS=${SPI_TFT_CS})
add_compile_definitions(SPI_TFT_DC=${SPI_TFT_DC})
add_compile_definitions(SPI_TFT_RST=${SPI_TFT_RST})

set(TFT_OPTIONS TFT_ENABLE_BLACK TFT_ENABLE_RESET TFT_ENABLE_TEXT TFT_ENABLE_SHAPES
                TFT_ENABLE_ROTATE TFT_ENABLE_SCROLL
            CACHE STRING "TFT options/functions")

foreach(opt IN LISTS TFT_OPTIONS)
    message(">>> using: ${opt}")
    add_compile_definitions(${opt})
endforeach(opt)

add_subdirectory(pico-st7735/lib-st7735)

add_executable(${PROJECT_NAME} main.cpp )

pico_set_program_name(${PROJECT_NAME} "pico-test")
pico_set_program_version(${PROJECT_NAME} "0.1")

pico_enable_stdio_uart(${PROJECT_NAME} 0)
pico_enable_stdio_usb(${PROJECT_NAME} 1)

target_link_libraries(${PROJECT_NAME} pico_stdlib)
target_link_libraries(${PROJECT_NAME} lib-st7735)
target_link_libraries(${PROJECT_NAME} hardware_spi)

pico_add_extra_outputs(${PROJECT_NAME})
bablokb commented 1 year ago

I actually wanted to upload a project pico-st7735-demo, which was not done yet (well, the repo is there, but the content is still on my machine). I'll have to test if my version compiles and push the version. It basically moves the demo code from the lib to demonstrate the usage. But I think you are close already.

The only difference I see at first glance is that I use

add_subdirectory(pico-st7735)

instead of

add_subdirectory(pico-st7735/lib-st7735)

maybe you want to try this.

playduck commented 1 year ago

I just tried that (with clearing the cache). It unfortunately results in the same behavior.

bablokb commented 1 year ago

Hm, I will check tomorrow. (BTW: cool projects in your repos :-)

bablokb commented 1 year ago

I updated this library. Note that the library now has a tft-initialization-routine which you should call from your code.

Also, the demo-code is now in https://github.com/bablokb/pico-st7735-demo. This repo shows how to include the lib as a submodule.

Please check if this solves your problems.

playduck commented 1 year ago

Yes, the new repo worked as expected! Thank you.

I don't know why my solution didn't seem to work but i'll take it.