dernasherbrezon / sx127x

Library to work with Semtech chips SX1276/SX1277/SX1278/SX1279.
Apache License 2.0
34 stars 4 forks source link

[REQUEST] Weak functions for SPI hal implementation #3

Closed liliumjsn closed 1 year ago

liliumjsn commented 1 year ago

Hello,

Is it possible to make the sx127x_esp_spi.c functions __weak so we can override them with our own SPI implementation?

Thank you, Dimitris

dernasherbrezon commented 1 year ago

Hi,

sx127x.c doesn't depend on any SPI implementations. You can implement functions defined at https://github.com/dernasherbrezon/sx127x/blob/main/include/sx127x_spi.h and link them accordingly to the sx127x.o.

Here is how you can link different SPI implementations:

set(srcs
    "${CMAKE_CURRENT_SOURCE_DIR}/src/sx127x.c"
)
if (CUSTOM_ARCHITECTURE)
list(APPEND srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/sx127x_mycustom_spi.c")
    add_library(sx127x STATIC ${srcs})
endif()
liliumjsn commented 1 year ago

The point was to use this repo as a submodule as it is so we can follow its updates. If we edit your CMakeLists.txt that's not the case. That's why I suggested the __weak functions. Another suggestion would be to make an if statement in the cmakelists that checks for a SX127X_CUSTOM_SPI definition (or something like this) and if it does not exist then proceed to https://github.com/dernasherbrezon/sx127x/blob/7740da9e945ac2aa801b7ab6477796dc684f6d41/CMakeLists.txt#L5

dernasherbrezon commented 1 year ago

I see. I think in that case you can completely ignore cmakelists.txt and reference source and includes from the outside.

for example in the top level cmakelists:

list(APPEND srcs "${CMAKE_CURRENT_SOURCE_DIR}/sx127x/src/sx127x.c")

and also your own implementation of spi:

list(APPEND srcs "${CMAKE_CURRENT_SOURCE_DIR}/sx127x_mycustom_spi.c")

will it work for you?