Skip to content

Commit 22aa1ae

Browse files
committed
feat: export adc/dac get channel functions
Fixes #1669 Signed-off-by: Frederic Pillon <[email protected]>
1 parent 0b749e5 commit 22aa1ae

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

cores/arduino/stm32/analog.h

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ extern "C" {
4949
#endif
5050

5151
/* Exported functions ------------------------------------------------------- */
52+
#if defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)
53+
uint32_t get_adc_channel(PinName pin, uint32_t *bank);
54+
uint32_t get_adc_internal_channel(PinName pin);
55+
#endif
56+
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)
57+
uint32_t get_dac_channel(PinName pin);
58+
#endif
5259
void dac_write_value(PinName pin, uint32_t value, uint8_t do_init);
5360
void dac_stop(PinName pin);
5461
uint16_t adc_read_value(PinName pin, uint32_t resolution);

libraries/SrcWrapper/src/stm32/analog.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ static PinName g_current_pin = NC;
101101
#define ADC_REGULAR_RANK_1 1
102102
#endif
103103

104-
/* Private Functions */
105-
static uint32_t get_adc_channel(PinName pin, uint32_t *bank)
104+
/* Exported Functions */
105+
/**
106+
* @brief Return ADC HAL channel linked to a PinName
107+
* @param pin: PinName
108+
* @param bank: pointer to get ADC channel bank if required
109+
* @retval HAL channel. return 0 if pin has no ADC
110+
*/
111+
uint32_t get_adc_channel(PinName pin, uint32_t *bank)
106112
{
107113
uint32_t function = pinmap_function(pin, PinMap_ADC);
108114
uint32_t channel = 0;
@@ -233,7 +239,14 @@ static uint32_t get_adc_channel(PinName pin, uint32_t *bank)
233239
return channel;
234240
}
235241

236-
static uint32_t get_adc_internal_channel(PinName pin)
242+
/**
243+
* @brief Return ADC HAL internal channel linked to a PinName
244+
* @param pin: specific PinName's for ADC internal. Value can be:
245+
* PADC_TEMP, PADC_TEMP_ADC5, PADC_VREF, PADC_VBAT
246+
* Note that not all of these values ​​may be available for all series.
247+
* @retval HAL internal channel. return 0 if pin has no ADC internal
248+
*/
249+
uint32_t get_adc_internal_channel(PinName pin)
237250
{
238251
uint32_t channel = 0;
239252
switch (pin) {
@@ -271,7 +284,12 @@ static uint32_t get_adc_internal_channel(PinName pin)
271284
#endif /* HAL_ADC_MODULE_ENABLED && !HAL_ADC_MODULE_ONLY */
272285

273286
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)
274-
static uint32_t get_dac_channel(PinName pin)
287+
/**
288+
* @brief Return DAC HAL channel linked to a PinName
289+
* @param pin: specific PinName's for ADC internal.
290+
* @retval HAL channel. return 0 if pin has no dac
291+
*/
292+
uint32_t get_dac_channel(PinName pin)
275293
{
276294
uint32_t function = pinmap_function(pin, PinMap_DAC);
277295
uint32_t channel = 0;

0 commit comments

Comments
 (0)