Skip to content

Commit

Permalink
wip(cmake): compile hw tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glencoe committed Oct 29, 2024
1 parent 47ec78f commit bef97d0
Show file tree
Hide file tree
Showing 31 changed files with 649 additions and 383 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.20...3.24)

include(cmake/set_build_target.cmake)


include(cmake/third_party_deps.cmake)

add_pico_sdk("2.0.0")
add_unity()
add_cexception()
add_freertos()
add_runtime_c()


Expand Down Expand Up @@ -48,10 +48,17 @@ include(cmake/custom_targets.cmake)

pico_sdk_init()

add_freertos()

include(cmake/pico_targets.cmake)
add_subdirectory(src)
add_subdirectory(test/unit)
add_subdirectory(test/hardware/Helper)
add_subdirectory(test/hardware/Sensors)

if(BUILDING_FOR_ELASTIC_NODE AND NOT TARGET tinyusb_device)
message(WARNING "not building project, because tinyusb not initialized")
endif ()
# if (TARGET tinyusb_device)
# # include required libraries
# add_basic_functionality()
Expand Down
12 changes: 10 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
"generator": "Ninja",
"binaryDir": "build/host/",
"cacheVariables": {
"ELASTIC_AI_TARGET": "HOST",
"REVISION": "1"
"ELASTIC_AI_TARGET": "HOST"
}
},
{
"name": "env5_rev2",
"displayName": "EnV5 Rev2",
"generator": "Ninja",
"binaryDir": "build/env5_rev2",
"cacheVariables": {
"ELASTIC_AI_TARGET": "ENV5_REV2"
}
}
],
Expand Down
25 changes: 24 additions & 1 deletion cmake/custom_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function(__add_elastic_ai_implementation)
cmake_parse_arguments(PARSE_ARGV 0 arg
"${options}" "${oneValueArgs}" "${multiValueArgs}"
)
add_library(${arg_NAME} ${arg_SOURCES})
add_library(${arg_NAME})
target_sources(${arg_NAME} PRIVATE ${arg_SOURCES})
target_include_directories(${arg_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
endfunction()

Expand Down Expand Up @@ -71,6 +72,12 @@ function(add_elastic_ai_lib)
"${options}" "${oneValueArgs}" "${multiValueArgs}"
)
set(BUILD_IMPLEMENTATION (arg_SRCS AND ((NOT ${arg_HW_ONLY}) OR BUILDING_FOR_ELASTIC_NODE)))

foreach (file ${arg_SRCS})
if(NOT ((NOT IS_ABSOLUTE ${file} AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/${file}) OR EXISTS ${file}))
message(FATAL_ERROR "${file} does not exist")
endif ()
endforeach ()
if(${BUILD_IMPLEMENTATION})
__add_elastic_ai_implementation(NAME ${arg_NAME}__impl SOURCES ${arg_SRCS})
__target_use_interfaces(${arg_NAME}__impl ${arg_DEPS})
Expand Down Expand Up @@ -119,4 +126,20 @@ function(add_elastic_ai_unit_test)
add_test(${NAME} ${NAME})
set_property(TEST ${NAME} PROPERTY LABELS unit)
target_link_libraries(${NAME} ${arg_MORE_LIBS})
endfunction()


function(create_enV5_executable target)
# enable usb output
pico_enable_stdio_usb(${target} 1)
# disable uart output
pico_enable_stdio_uart(${target} 0)
# create map/bin/hex/uf2 file etc.
pico_add_uf2_output(${target})
# # copy u2f files after build to out directory
# file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
# add_custom_command(TARGET ${target} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_BINARY_DIR}/${relative_path}/${target}.uf2
# ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}-Rev${REVISION}/${relative_path}/${target}.uf2)
endfunction()
8 changes: 7 additions & 1 deletion cmake/env5.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
message("Building for env5")
set(BUILDING_FOR_ELASTIC_NODE ON CACHE INTERNAL "we're building for elastic node")
set(PICO_BOARD none CACHE STRING "")
set(PICO_PLATFORM rp2040 CACHE STRING "")
set(PICO_PLATFORM rp2040 CACHE STRING "")

if(${ELASTIC_AI_TARGET} EQUAL ENV5_REV1)
set(REVISION "1" CACHE INTERNAL "")
else()
set(REVISION "2" CACHE INTERNAL "")
endif ()
1 change: 1 addition & 0 deletions cmake/host.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ message("building for native host platform")
set(BUILDING_FOR_ELASTIC_NODE OFF CACHE INTERNAL "we're building for elastic node")
set(PICO_BOARD none CACHE STRING "")
set(PICO_PLATFORM host CACHE STRING "")
set(REVISION "1" CACHE INTERNAL "")
6 changes: 3 additions & 3 deletions cmake/pico_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ endfunction()


foreach (arg
pico_runtime hardware_gpio
hardware_sleep
pico_time hardware_timer
pico_runtime hardware_gpio pico_stdlib pico_stdio_usb pico_bootrom
hardware_i2c hardware_spi pico_util pico_platform pico_clib_interface
pico_time hardware_timer hardware_rtc
hardware_uart hardware_irq
)
__add_pico_lib(${arg})
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_subdirectory(common)
add_subdirectory(hal)
add_subdirectory(flash)
add_subdirectory(network)

add_subdirectory(rtos)
add_subdirectory(fpga)

add_subdirectory(filesystem)
Expand Down
2 changes: 1 addition & 1 deletion src/hal/enV5HwController/EnV5HwController.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include "Common.h"
#include "EnV5HwConfiguration.h"
#include "EnV5HwController.h"
#include "Gpio.h"
#include "Sleep.h"
#include "include/EnV5HwController.h"

void env5HwControllerInit() {
env5HwControllerLedsInit();
Expand Down
2 changes: 1 addition & 1 deletion src/hal/gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ add_elastic_ai_lib(
HW_ONLY
NAME Gpio
SRCS Gpio.c
DEPS Common Pico::gpio_hardware
DEPS Common Pico::hardware_gpio
)
4 changes: 2 additions & 2 deletions src/hal/gpio/Gpio.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#define SOURCE_FILE "GPIO-LIB"

#include "Gpio.h"
#include "include/Gpio.h"

#include <hardware/gpio.h>
#include "hardware/gpio.h"

gpioErrorCode_t gpioInitPin(gpioPin_t pin, gpioDirection_t direction) {
gpio_init(pin);
Expand Down
2 changes: 1 addition & 1 deletion src/hal/i2c/I2c.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "I2c.h"
#include "include/I2c.h"
#include "Common.h"
#include "Gpio.h"
#include "I2cInternal.h"
Expand Down
14 changes: 11 additions & 3 deletions src/network/broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ add_elastic_ai_lib(
NAME MqttBroker
SRCS MqttBroker.c
DEPS
Protocol
Common
Uart
AtCommands
Expand All @@ -13,5 +12,14 @@ add_elastic_ai_lib(

target_include_directories(
MqttBroker__impl
PRIVATE
$<TARGET_PROPERTY:topicMatcher,INTERFACE_INCLUDE_DIRECTORIES>)
INTERFACE
$<TARGET_PROPERTY:topicMatcher,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:protocol,INTERFACE_INCLUDE_DIRECTORIES>
)

target_include_directories(
MqttBroker__hdrs
INTERFACE
$<TARGET_PROPERTY:protocol,INTERFACE_INCLUDE_DIRECTORIES>

)
2 changes: 1 addition & 1 deletion src/network/broker/MqttBroker.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "CException.h"
#include "Common.h"
#include "Esp.h"
#include "MqttBroker.h"
#include "MqttBrokerInternal.h"
#include "include/MqttBroker.h"

// header from elastic-ai.runtime.c
#include "CommunicationEndpoint.h"
Expand Down
2 changes: 1 addition & 1 deletion src/network/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ endif ()

add_elastic_ai_lib(
NAME NetworkConfig
SOURCES NetworkConfig.c
SRCS ${CMAKE_SOURCE_DIR}/NetworkConfig.c
DEPS MqttBroker Network
)
2 changes: 1 addition & 1 deletion src/network/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_elastic_ai_lib(
NAME Http
SOURCES HTTP.c
SRCS HTTP.c
DEPS
Common
CException
Expand Down
2 changes: 1 addition & 1 deletion src/network/http/HTTP.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "AtCommands.h"
#include "Common.h"
#include "Esp.h"
#include "HTTP.h"
#include "include/HTTP.h"

HttpResponse_t *HTTPResponse = NULL;
volatile uint32_t httpCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/network/wifi/Network.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Esp.h"
#include "FreeRtosTaskWrapper.h"
#include "HTTP.h"
#include "Network.h"
#include "include/Network.h"

extern networkCredentials_t networkCredentials;

Expand Down
13 changes: 0 additions & 13 deletions src/rtos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
add_library(freeRtosUtils INTERFACE)
target_include_directories(freeRtosUtils INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_sources(freeRtosUtils INTERFACE
${CMAKE_CURRENT_LIST_DIR}/FreeRtosSMP.c
${CMAKE_CURRENT_LIST_DIR}/FreeRtosTaskWrapper.c
${CMAKE_CURRENT_LIST_DIR}/FreeRtosQueueWrapper.c
${CMAKE_CURRENT_LIST_DIR}/FreeRtosMutexWrapper.c)
target_link_libraries(freeRtosUtils INTERFACE
FreeRTOS-Kernel
FreeRTOS-Kernel-Heap3
common_lib
sleep_interface)

add_elastic_ai_lib(
HW_ONLY
NAME freeRtosUtils
Expand Down
4 changes: 2 additions & 2 deletions src/sensor/adxl345b/Adxl345b.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#define SOURCE_FILE "ADXL345B-LIB"

#include "Adxl345b.h"
#include "include/Adxl345b.h"
#include "Adxl345bInternal.h"
#include "Adxl345bTypedefs.h"
#include "Common.h"
#include "I2c.h"
#include "Sleep.h"
#include "Time.h"
#include "include/Adxl345bTypedefs.h"

/* region CONSTANTS */

Expand Down
2 changes: 1 addition & 1 deletion src/sensor/adxl345b/Adxl345bInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Activity \b detection -> Can not be used due to unconnected interrupt pins\n
*/

#include "Adxl345bTypedefs.h"
#include "include/Adxl345bTypedefs.h"
#include <stdint.h>

typedef struct adxl345bRangeSetting {
Expand Down
12 changes: 1 addition & 11 deletions src/sensor/pac193x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
add_library(sensor_lib_pac193x INTERFACE)
target_include_directories(sensor_lib_pac193x INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_sources(sensor_lib_pac193x INTERFACE
${CMAKE_CURRENT_LIST_DIR}/Pac193x.c)
target_link_libraries(sensor_lib_pac193x INTERFACE
common_lib
sleep_interface
gpio_interface
i2c_interface)

add_elastic_ai_lib(
NAME Pac193
NAME Pac193x
SRCS Pac193x.c
DEPS
Common
Expand Down
23 changes: 11 additions & 12 deletions test/hardware/Helper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
################## hardwareTestHelper ##################
add_library(hardware-testHelper INTERFACE)
target_sources(hardware-testHelper INTERFACE
${CMAKE_CURRENT_LIST_DIR}/HardwaretestHelper.c)
target_include_directories(hardware-testHelper INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(hardware-testHelper INTERFACE
common_lib
pico_stdlib
espBroker_lib
network_lib
freeRtosUtils)

add_elastic_ai_lib(
NAME HardwaretestHelper
SRCS HardwaretestHelper.c
DEPS
Common
Pico::pico_stdlib
MqttBroker
Network
Network
freeRtosUtils
)
Loading

0 comments on commit bef97d0

Please sign in to comment.