diff --git a/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h b/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h index a0fc954e5e8e419bbcccdd4db54ccec04b0e58cb..48a174fa205239f051e496e726ba63c52b1d45d6 100644 --- a/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h +++ b/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h @@ -54,12 +54,24 @@ typedef enum dac_function_sawtooth } dac_function_t; +typedef enum +{ + dac_polarity_decrement, + dac_polarity_increment +} dac_polarity_t; + +typedef enum +{ + hrtim_trig1, + hrtim_trig2 +} dac_trigger_t; + typedef struct { dac_function_t dac_function; - uint32_t trigger_source; - uint32_t step_trigger_source; - uint32_t polarity; + dac_trigger_t reset_trigger_source; + dac_trigger_t step_trigger_source; + dac_polarity_t polarity; uint32_t reset_data; uint32_t step_data; } dac_function_config_t; @@ -70,7 +82,6 @@ typedef enum dac_pin_external } dac_pin_config_t; - ///// // API diff --git a/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c b/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c index d6005cab40e282943b86c75c8efd5af796756a77..0786b941a8e364ffd1e13c06a12fb29d5cc81d73 100644 --- a/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c +++ b/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c @@ -109,12 +109,30 @@ static void dac_stm32_set_function(const struct device* dev, uint8_t channel, co { data->dac_config->function_config = *function_config; + uint32_t reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG1; + if (function_config->reset_trigger_source == hrtim_trig2) + { + reset_trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG2; + } + + uint32_t step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG1; + if (function_config->step_trigger_source == hrtim_trig2) + { + step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG2; + } + + uint32_t polarity = LL_DAC_SAWTOOTH_POLARITY_DECREMENT; + if (function_config->polarity == dac_polarity_increment) + { + polarity = LL_DAC_SAWTOOTH_POLARITY_INCREMENT; + } + LL_DAC_SetSignedFormat(dac_dev, dac_channel, LL_DAC_SIGNED_FORMAT_DISABLE); LL_DAC_SetWaveAutoGeneration(dac_dev, dac_channel, LL_DAC_WAVE_AUTO_GENERATION_SAWTOOTH); - LL_DAC_SetWaveSawtoothResetTriggerSource(dac_dev, dac_channel, function_config->trigger_source); - LL_DAC_SetWaveSawtoothStepTriggerSource(dac_dev, dac_channel, function_config->step_trigger_source); - LL_DAC_SetWaveSawtoothPolarity(dac_dev, dac_channel, function_config->polarity); + LL_DAC_SetWaveSawtoothResetTriggerSource(dac_dev, dac_channel, reset_trigger_source); + LL_DAC_SetWaveSawtoothStepTriggerSource(dac_dev, dac_channel, step_trigger_source); + LL_DAC_SetWaveSawtoothPolarity(dac_dev, dac_channel, polarity); LL_DAC_SetWaveSawtoothResetData(dac_dev, dac_channel, function_config->reset_data); LL_DAC_SetWaveSawtoothStepData(dac_dev, dac_channel, function_config->step_data); diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp index cf19771e85ebb9f9e0f4521d821ba5a2d91e0e7d..2b15ba9e4f07c50a2210deadc95b840812ce9aa5 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp @@ -19,6 +19,7 @@ /** * @date 2022 + * * @author Clément Foucher <clement.foucher@laas.fr> */ @@ -26,37 +27,33 @@ // Zephyr #include <zephyr.h> -// STM32LL -#include <stm32_ll_dac.h> - // Owntech driver #include "dac.h" - void dac_config_dac1_dac3_current_mode_init() { const struct device* dac1 = device_get_binding(DAC1_DEVICE); const struct device* dac3 = device_get_binding(DAC3_DEVICE); + // DAC 1 dac_function_config_t function_config = { .dac_function = dac_function_sawtooth, - .trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG1, - .step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG1, - .polarity = LL_DAC_SAWTOOTH_POLARITY_DECREMENT, + .reset_trigger_source = hrtim_trig1, + .step_trigger_source = hrtim_trig1, + .polarity = dac_polarity_decrement, .reset_data = 4000, .step_data = 200 }; - // DAC 1 dac_set_function(dac1, 1, &function_config); dac_pin_configure(dac1, 1, dac_pin_internal); dac_start(dac1, 1); // DAC 3 - function_config.trigger_source = LL_DAC_TRIG_EXT_HRTIM_RST_TRG2; - function_config.step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG2; + function_config.reset_trigger_source = hrtim_trig2; + function_config.step_trigger_source = hrtim_trig2; dac_set_function(dac3, 1, &function_config); dac_pin_configure(dac3, 1, dac_pin_internal);