Skip to content

Commit

Permalink
add forgotten changes to cmake library
Browse files Browse the repository at this point in the history
  • Loading branch information
mjleehh committed Dec 16, 2024
1 parent c629a9f commit 0e302ad
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 115 deletions.
87 changes: 30 additions & 57 deletions tools/cmake/build_config/platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include(${TBD_CMAKE_DIR}/helpers.cmake)
include(${TBD_CMAKE_DIR}/indicators.cmake)
include(${TBD_CMAKE_DIR}/cv_inputs.cmake)
include(${TBD_CMAKE_DIR}/codecs.cmake)
include(${TBD_CMAKE_DIR}/displays.cmake)

set(TBD_PLATFORM_SYSTEMS esp32 desktop)
set(TBD_PLATFORM_APIS wifi serial shell)
Expand Down Expand Up @@ -110,7 +111,6 @@ macro(tbd_platform_attrs)
SYSTEM
ARCH
FILE_SYSTEM
DISPLAY
NETWORK
)
set(multi_attrs
Expand All @@ -119,6 +119,7 @@ macro(tbd_platform_attrs)
INDICATOR
AUDIO
APIS
DISPLAY
)
cmake_parse_arguments(arg "${bools}" "${attrs}" "${multi_attrs}" ${ARGV})
if (DEFINED arg_KEYWORDS_MISSING_VALUES)
Expand All @@ -138,7 +139,7 @@ endmacro()
# @arg AUDIO [class] audio chip config
# @arg INDICATOR [class] indicator light type
# @arg FILE_SYSTEM [enum] pick between stdlib filesystem and custom subset (std/wrapper)
# @arg DISPLAY [bool] enable display device
# @arg DISPLAY [class] configure connected display
# @arg NETWORK [bool] enable WIFI and WIFI control
#
function (tbd_platform var_name)
Expand All @@ -155,9 +156,12 @@ function (tbd_platform var_name)
endif()

tbd_indicator(CHECK "${arg_INDICATOR}")

if(NOT "${arg_DISPLAY}" STREQUAL no)
tbd_display(CHECK "${arg_DISPLAY}")
endif()
tbd_cv_input(CHECK "${arg_CV_INPUT}")
tbd_codec(CHECK "${arg_AUDIO}")
tbd_check_bool("${arg_DISPLAY}")
tbd_check_bool("${arg_NETWORK}")

if (NOT "${var_name}" STREQUAL "_")
Expand Down Expand Up @@ -239,51 +243,8 @@ endfunction()
#
function(tbd_platform_get_features platform)
tbd_platform_attrs(${platform})
tbd_cv_input_type("${arg_CV_INPUT}" VAR cv_input)

if ("${cv_input}" STREQUAL "adc")
set(cv_flags
TBD_CV_ADC=1
TBD_CV_MCP_3208=0
TBD_CV_STM32=0
TBD_CV_MIDI=0
TBD_CV_SIM=0
)
elseif ("${cv_input}" STREQUAL "mcp3208")
set(cv_flags
TBD_CV_ADC=0
TBD_CV_MCP_3208=1
TBD_CV_STM32=0
TBD_CV_MIDI=0
TBD_CV_SIM=0
)
elseif ("${cv_input}" STREQUAL "stm32")
set(cv_flags
TBD_CV_ADC=0
TBD_CV_MCP_3208=0
TBD_CV_STM32=1
TBD_CV_MIDI=0
TBD_CV_DYNAMIC=0
)
elseif ("${cv_input}" STREQUAL "midi")
set(cv_flags
TBD_CV_ADC=0
TBD_CV_MCP_3208=0
TBD_CV_STM32=0
TBD_CV_MIDI=1
TBD_CV_SIM=0
)
elseif ("${cv_input}" STREQUAL "sim_cv")
set(cv_flags
TBD_CV_ADC=0
TBD_CV_MCP_3208=0
TBD_CV_STM32=0
TBD_CV_MIDI=0
TBD_CV_SIM=1
)
else()
tbd_loge("failed to determine CV input, unknown input chip '${arg_CV_INPUT}'")
endif()

tbd_cv_input_type_flags("${arg_CV_INPUT}" VAR cv_flags)

# FIXME: this should be either be done in the input library or all inputs should
# allow calibration
Expand All @@ -294,14 +255,15 @@ function(tbd_platform_get_features platform)
set(calibration TBD_CALIBRATION=0)
endif()

if (arg_DISPLAY)
set(display TBD_DISPLAY=1)
else()
tbd_cv_input_n_cvs("${arg_CV_INPUT}" VAR n_cvs)
tbd_cv_input_n_triggers("${arg_CV_INPUT}" VAR n_triggers)

if("${arg_DISPLAY}" STREQUAL no)
set(display TBD_DISPLAY=0)
else()
set(display TBD_DISPLAY=1)
endif()

tbd_cv_input_n_cvs("${arg_CV_INPUT}" VAR n_cvs)
tbd_cv_input_n_triggers("${arg_CV_INPUT}" VAR n_triggers)
set(features
N_CVS=${n_cvs}
N_TRIGS=${n_triggers}
Expand All @@ -312,6 +274,7 @@ function(tbd_platform_get_features platform)
INDICATOR=${indicators}
${audio_mechanism}
)

tbd_store_or_return("${features}" ${ARGN})
endfunction()

Expand All @@ -332,6 +295,11 @@ function(tbd_platform_print_info platform)
tbd_cv_input_n_cvs("${arg_CV_INPUT}" VAR n_cvs)
tbd_cv_input_n_triggers("${arg_CV_INPUT}" VAR n_triggers)
tbd_codec_type("${arg_AUDIO}" VAR codec_type)
if(NOT "${arg_DISPLAY}" STREQUAL no)
tbd_display_type("${arg_DISPLAY}" VAR display_type)
else()
set(display_type -)
endif()

message("
TBD platform configuration
Expand All @@ -345,7 +313,7 @@ audio chip: ${codec_type}
indicators: ${indicator_type}
apis: ${arg_APIS}
file system: ${arg_FILE_SYSTEM}
display: ${arg_DISPLAY}
display: ${display_type}
netwrok: ${arg_NETWORK}
--------------------------
")
Expand All @@ -371,8 +339,13 @@ function(tbd_platform_load_preset file)
string(JSON apis_obj GET "${config_obj}" apis)
string(JSON file_system GET "${config_obj}" file_system)

string(JSON display GET "${config_obj}" display)
tbd_to_bool(display)
string(JSON display_type TYPE "${config_obj}" display)
if("${display_type}" STREQUAL NULL)
set(display no)
else()
string(JSON display_obj GET "${config_obj}" display)
tbd_display_load("${display_obj}" VAR display)
endif()

string(JSON network GET "${config_obj}" network)
tbd_to_bool(network)
Expand Down Expand Up @@ -403,7 +376,7 @@ function(tbd_platform_load_preset file)
INDICATOR ${indicator}
APIS ${apis}
FILE_SYSTEM ${file_system}
DISPLAY ${display}
DISPLAY "${display}"
NETWORK ${network}
)
tbd_store_or_return("${new_platform}" ${ARGN})
Expand Down
90 changes: 62 additions & 28 deletions tools/cmake/codecs/aic3254.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
## aic3254 codec class ##

set(TBD_AIC3254_PINS mclk bclk ws dout din)
set(TBD_AIC3254_I2C_PINS sda scl)
set(TBD_AIC3254_I2S_PINS mclk bclk ws dout din)

# helper for accessing aic3254 fields
#
#
macro(tbd_aic3254_attrs)
tbd_codec_attrs(${ARGV})

cmake_parse_arguments(arg "" "${TBD_CODEC_GENERAL_ATTRS}" "PINS" ${ARGV})
cmake_parse_arguments(arg "" "${TBD_CODEC_GENERAL_ATTRS}" "I2C;I2S" ${ARGV})
if (DEFINED arg_KEYWORDS_MISSING_VALUES)
tbd_loge("missing argument value for ${arg_KEYWORDS_MISSING_VALUES}")
endif()

if (NOT "${arg_TYPE}" STREQUAL "aic3254")
tbd_loge("aic3254 codec type has to be 'aic3254' got '${arg_TYPE}'")
endif()

tbd_pinout_check("${arg_I2C}" PINS ${TBD_AIC3254_I2C_PINS})
tbd_pinout_check("${arg_I2S}" PINS ${TBD_AIC3254_I2S_PINS})
endmacro()


# @brief constructor for aic3254
#
# @arg TYPE [enum] has to be 'aic3254'
# @arg PINS [map<str,int>] communication pins
# @arg SPI [map<str,int>] control communication pins
# @arg I2S [map<str,int>] audio communication pins
#
function (tbd_aic3254 var_name)
tbd_codec_attrs(${ARGN})
tbd_aic3254_attrs(${ARGN})
if (NOT "${arg_TYPE}" STREQUAL "aic3254")
tbd_loge("aic3254 codec type has to be 'aic3254' got '${arg_TYPE}'")
endif()

tbd_pinout_check("${arg_PINS}" PINS ${TBD_AIC3254_PINS})

if (NOT "${var_name}" STREQUAL "CHECK")
set(${var_name} ${ARGN} PARENT_SCOPE)
Expand All @@ -36,50 +38,82 @@ endfunction()

## properties ##

function(TBD_AIC3254_PINS aic3254)
# function(TBD_AIC3254_PINS aic3254)
# tbd_aic3254_attrs(${aic3254})
# tbd_store_or_return("${arg_PINS}" ${ARGN})
# endfunction()

function(tbd_aic3254_i2c_pins aic3254)
tbd_aic3254_attrs(${aic3254})
tbd_store_or_return("${arg_PINS}" ${ARGN})
tbd_store_or_return("${arg_SPI}" ${ARGN})
endfunction()

function(tbd_aic3254_i2s_pins aic3254)
tbd_aic3254_attrs(${aic3254})
tbd_store_or_return("${arg_I2S}" ${ARGN})
endfunction()

function(tbd_aic3254_pin_flags aic3254)
tbd_aic3254_attrs(${aic3254})
tbd_pinout_flags("${arg_PINS}"
PINS ${TBD_AIC3254_PINS}
NAMESPACE TBD_AIC3254_PIN_
tbd_pinout_flags("${arg_I2C}"
PINS ${TBD_AIC3254_I2C_PINS}
NAMESPACE TBD_AIC3254_I2C_PIN_
PREFIX GPIO_NUM_
VAR i2c
)
tbd_pinout_flags("${arg_I2S}"
PINS ${TBD_AIC3254_I2S_PINS}
NAMESPACE TBD_AIC3254_I2S_PIN_
PREFIX GPIO_NUM_
VAR flags
VAR i2s
)
tbd_store_or_return("${flags}" ${ARGN})
tbd_store_or_return("${i2c};${i2s}" ${ARGN})
endfunction()


## methods ##

function(tbd_aic3254_print_info aic3254)
tbd_aic3254_attrs(${aic3254})
tbd_pinout_info("${arg_PINS}"
PINS ${TBD_AIC3254_PINS}
VAR pins
tbd_pinout_info("${arg_I2C}"
PINS ${TBD_AIC3254_I2C_PINS}
VAR i2c
)
tbd_pinout_info("${arg_I2S}"
PINS ${TBD_AIC3254_I2S_PINS}
VAR i2s
)
message("
TBD codec configuration
---------------------------
type: aic3254
${pins}---------------------------
i2c pins
........
${i2c}
i2c pins
........
${i2s}---------------------------
")
endfunction()

function(_tbd_aic3254_load json_data)
string(JSON type GET "${json_data}" type)
string(JSON pin_obj GET "${json_data}" pins)

string(JSON i2c_data GET "${pin_obj}" i2c)
tbd_pinout_load("${i2c_data}"
PINS ${TBD_AIC3254_I2C_PINS}
VAR i2c
)

string(JSON pins_obj GET "${json_data}" pins)
tbd_pinout_load("${pins_obj}"
PINS ${TBD_AIC3254_PINS}
VAR pins
string(JSON i2s_data GET "${pin_obj}" i2s)
tbd_pinout_load("${i2s_data}"
PINS ${TBD_AIC3254_I2S_PINS}
VAR i2s
)

set(new_aic3254
PINS "${pins}"
I2C "${i2c}"
I2S "${i2s}"
WORK_TYPE pull
)
tbd_store_or_return("${new_aic3254}" ${ARGN})
Expand Down
Loading

0 comments on commit 0e302ad

Please sign in to comment.