Commit 386e1983 authored by Clément Foucher's avatar Clément Foucher
Browse files

Make DAC driver public interface independent from LL headers.

parent a998efad
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment