Skip to content

Commit

Permalink
fix spi SS pin and refactor it
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Nov 17, 2024
1 parent c36bdad commit 5b3bf25
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Src/peripheral/spi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2023-2024 Dmitry Ponomarev <[email protected]>
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.

# Include guard
if(PERIPHERAL_SPI_CMAKE)
return()
endif()
set(PERIPHERAL_SPI_CMAKE ${CMAKE_CURRENT_LIST_DIR})

if(NOT APP_PLATFORM)
message(SEND_ERROR "APP_PLATFORM is not specified or unsupported! Options: stm32f103, stm32g0b1, ubuntu.")
endif()

if(APP_PLATFORM STREQUAL "stm32f103" OR APP_PLATFORM STREQUAL "stm32g0b1")
list(APPEND PERIPHERAL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/spi_stm32.cpp)
elseif(APP_PLATFORM STREQUAL "ubuntu")
list(APPEND PERIPHERAL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/spi_ubuntu.cpp)
else()
message(SEND_ERROR "APP_PLATFORM is unknown.")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ static void spi_set_nss(bool nss_state) {
#ifdef SPI2_NSS_GPIO_Port
auto state = nss_state ? GPIO_PIN_SET : GPIO_PIN_RESET;
HAL_GPIO_WritePin(SPI2_NSS_GPIO_Port, SPI2_NSS_Pin, state);
#elif defined(SPI_SS_GPIO_Port)
auto state = nss_state ? GPIO_PIN_SET : GPIO_PIN_RESET;
HAL_GPIO_WritePin(SPI_SS_GPIO_Port, SPI_SS_Pin, state);
#endif
}

Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion Src/platform/stm32g0b1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cmake_path(GET CMAKE_CURRENT_LIST_DIR PARENT_PATH PLATFORM_DIR)
cmake_path(GET PLATFORM_DIR PARENT_PATH SRC_DIR)
cmake_path(GET SRC_DIR PARENT_PATH ROOT_DIR)

include(${ROOT_DIR}/Src/peripheral/spi/CMakeLists.txt)

set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE}
${APPLICATION_SOURCES}
Expand All @@ -21,7 +23,6 @@ add_executable(${EXECUTABLE}
${PLATFORM_DIR}/stm32f103/adc.cpp
${CMAKE_CURRENT_LIST_DIR}/gpio.cpp
${PLATFORM_DIR}/stm32g0b1/pwm.cpp
${PLATFORM_DIR}/stm32g0b1/spi.cpp
${ROOT_DIR}/Src/platform/stm32/iwdg/iwdg.cpp
${PLATFORM_DIR}/stm32f103/temperature_sensor.cpp
${ROOT_DIR}/Src/platform/stm32/platform_specific.cpp
Expand Down

0 comments on commit 5b3bf25

Please sign in to comment.