Commit 52cf5ace authored by Clément Foucher's avatar Clément Foucher
Browse files

Move ADC source event enum to ADC Driver.

parent 386e1983
......@@ -62,12 +62,36 @@ void adc_set_dual_mode(uint8_t dual_mode)
adc_core_set_dual_mode(dual_mode);
}
void adc_configure_trigger_source(uint8_t adc_number, uint32_t trigger_source)
void adc_configure_trigger_source(uint8_t adc_number, adc_ev_src_t trigger_source)
{
/////
// Convert to LL constants
uint32_t trig;
switch (trigger_source)
{
case hrtim_ev1:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG1;
break;
case hrtim_ev2:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG2;
break;
case hrtim_ev3:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG3;
break;
case hrtim_ev4:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG4;
break;
case software:
default:
trig = LL_ADC_REG_TRIG_SOFTWARE;
break;
}
// Only store configuration: it must be applied after ADC enable
if ( (adc_number > 0) && (adc_number <= NUMBER_OF_ADCS) )
{
adc_trigger_sources[adc_number-1] = trigger_source;
adc_trigger_sources[adc_number-1] = trig;
}
}
......
......@@ -47,6 +47,22 @@ extern "C" {
#endif
/////
// Public enums
typedef enum
{
hrtim_ev1,
hrtim_ev2,
hrtim_ev3,
hrtim_ev4,
software
} adc_ev_src_t;
/////
// Public API
/**
* @brief Initializes the ADCs. It must be
* called *before* any configuration is made.
......@@ -67,17 +83,16 @@ void adc_set_dual_mode(uint8_t dual_mode);
* Registers the triger source for an ADC.
* It will be applied when ADC is started.
*
* @param adc_number Number of the ADC to configure
* @param triggger_source Source of the trigger as defined
* in stm32gxx_ll_adc.h (LL_ADC_REG_TRIG_***)
* @param adc_number Number of the ADC to configure.
* @param triggger_source Source of the trigger.
*/
void adc_configure_trigger_source(uint8_t adc_number, uint32_t trigger_source);
void adc_configure_trigger_source(uint8_t adc_number, adc_ev_src_t trigger_source);
/**
* Registers the discontinuous count for an ADC.
* It will be applied when ADC is started.
*
* @param adc_number Number of the ADC to configure
* @param adc_number Number of the ADC to configure.
* @param dicontinuous_count Number of channels to acquire on each
* trigger event. 0 to disable discontinuous mode (default).
*/
......@@ -103,7 +118,8 @@ int8_t adc_configure_adc_channels(uint8_t adc_number, const char* channel_list[]
/**
* Get the number of enabled channels for an ADC.
* @param adc_num Number of the ADC
*
* @param adc_num Number of the ADC.
* @return Number of enabled channels in this ADC.
*/
uint8_t adc_get_enabled_channels_count(uint8_t adc_num);
......@@ -116,10 +132,10 @@ void adc_start();
/**
* This function returns the name of an enabled channel.
*
* This function must onle be called after
* This function must only be called after
* adc_configure_adc_channels has been called.
*
* @param adc_number Number of the ADC
* @param adc_number Number of the ADC.
* @param channel_rank Rank of the ADC channel to query.
* Rank ranges from 0 to (number of enabled channels)-1
* @return Name of the channel as defined in the device tree, or
......
......@@ -19,6 +19,7 @@
/**
* @date 2022
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
......@@ -241,7 +242,7 @@ int8_t HardwareConfiguration::configureAdcChannels(uint8_t adc_number, const cha
return configure_adc_channels(adc_number, channel_list, channel_count);
}
void HardwareConfiguration::configureAdcTriggerSource(uint8_t adc_number, adc_src_t trigger_source)
void HardwareConfiguration::configureAdcTriggerSource(uint8_t adc_number, adc_ev_src_t trigger_source)
{
configure_adc_trigger_source(adc_number, trigger_source);
}
......
......@@ -19,6 +19,7 @@
/**
* @date 2022
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
......@@ -104,7 +105,7 @@ public:
// ADC
static void configureAdc12DualMode(uint8_t dual_mode);
static int8_t configureAdcChannels(uint8_t adc_number, const char* channel_list[], uint8_t channel_count);
static void configureAdcTriggerSource(uint8_t adc_number, adc_src_t trigger_source);
static void configureAdcTriggerSource(uint8_t adc_number, adc_ev_src_t trigger_source);
static void configureAdcDefaultAllMeasurements();
};
......
......@@ -19,13 +19,11 @@
/**
* @date 2022
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
// STM32 LL
#include <stm32_ll_adc.h>
// OwnTech Power API
#include "adc.h"
......@@ -94,7 +92,7 @@ int8_t configure_adc_channels(uint8_t adc_number, const char* channel_list[], ui
return NOERROR;
}
void configure_adc_trigger_source(uint8_t adc_number, adc_src_t trigger_source)
void configure_adc_trigger_source(uint8_t adc_number, adc_ev_src_t trigger_source)
{
/////
// Make sure module is initialized
......@@ -106,28 +104,8 @@ void configure_adc_trigger_source(uint8_t adc_number, adc_src_t trigger_source)
/////
// Proceed
uint32_t trig;
switch (trigger_source)
{
case hrtim_ev1:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG1;
break;
case hrtim_ev2:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG2;
break;
case hrtim_ev3:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG3;
break;
case hrtim_ev4:
trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG4;
break;
case software:
default:
trig = LL_ADC_REG_TRIG_SOFTWARE;
break;
}
adc_configure_trigger_source(adc_number, trig);
adc_configure_trigger_source(adc_number, trigger_source);
}
void configure_adc_default_all_measurements()
......
......@@ -19,6 +19,7 @@
/**
* @date 2022
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
......@@ -30,17 +31,8 @@
// Stdlib
#include <stdint.h>
/////
// Public enums
typedef enum
{
hrtim_ev1,
hrtim_ev2,
hrtim_ev3,
hrtim_ev4,
software
} adc_src_t;
// OwnTech API
#include "adc.h"
/////
......@@ -88,7 +80,7 @@ int8_t configure_adc_channels(uint8_t adc_number, const char* channel_list[], ui
* @param adc_number Number of the ADC to configure
* @param trigger_source Source of the trigger
*/
void configure_adc_trigger_source(uint8_t adc_number, adc_src_t trigger_source);
void configure_adc_trigger_source(uint8_t adc_number, adc_ev_src_t trigger_source);
/**
* This function is used to configure all ADC channels in default configuration.
......
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