Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Initialize each ADC only once in Analogread#2133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Candas1 wants to merge13 commits intostm32duino:main
base:main
Choose a base branch
Loading
fromCandas1:analogread
Draft
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletionslibraries/SrcWrapper/src/stm32/analog.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -850,7 +850,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
#ifdef ADC_SCAN_SEQ_FIXED
AdcHandle.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
#else
AdcHandle.Init.ScanConvMode =DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
AdcHandle.Init.ScanConvMode =ENABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
#endif
#ifdef ADC_EOC_SINGLE_CONV
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
Expand DownExpand Up@@ -927,13 +927,22 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
AdcHandle.Init.VrefProtection = ADC_VREF_PPROT_NONE;
#endif

AdcHandle.State = HAL_ADC_STATE_RESET;
AdcHandle.DMA_Handle = NULL;
AdcHandle.Lock = HAL_UNLOCKED;
/* Some other ADC_HandleTypeDef fields exists but not required */

g_current_pin = pin; /* Needed for HAL_ADC_MspInit*/

if (!LL_ADC_IsEnabled(AdcHandle.Instance)) {
AdcHandle.State = HAL_ADC_STATE_RESET;
} else {
AdcHandle.State = HAL_ADC_STATE_READY;
/* Configure ADC GPIO pin */
if (!(g_current_pin & PADC_BASE)) {
pinmap_pinout(g_current_pin, PinMap_ADC);
}
}

if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {
return 0;
}
Expand DownExpand Up@@ -981,20 +990,22 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
return 0;
}

if (!LL_ADC_IsEnabled(AdcHandle.Instance)) {
#if defined(ADC_CR_ADCAL) || defined(ADC_CR2_RSTCAL)
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
#if defined(ADC_CALIB_OFFSET)
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
#elif defined(ADC_SINGLE_ENDED) && !defined(ADC1_V2_5)
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
#else
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
#endif
{
/* ADC Calibration Error */
return 0;
}
{
/* ADC Calibration Error */
return 0;
}
#endif
}

/*##-3- Start the conversion process ####################*/
if (HAL_ADC_Start(&AdcHandle) != HAL_OK) {
Expand All@@ -1017,18 +1028,6 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);
}

if (HAL_ADC_Stop(&AdcHandle) != HAL_OK) {
/* Stop Conversation Error */
return 0;
}

if (HAL_ADC_DeInit(&AdcHandle) != HAL_OK) {
return 0;
}

if (__LL_ADC_COMMON_INSTANCE(AdcHandle.Instance) != 0U) {
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(AdcHandle.Instance), LL_ADC_PATH_INTERNAL_NONE);
}
return uhADCxConvertedValue;
}
#endif /* HAL_ADC_MODULE_ENABLED && !HAL_ADC_MODULE_ONLY*/
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp