disable claim pin for debug

This commit is contained in:
Hierophect 2019-09-11 17:26:33 -04:00
parent 7f54630224
commit 57ce381bcd
1 changed files with 43 additions and 43 deletions

View File

@ -46,9 +46,9 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
} }
//TODO: add ADC traits to structure? //TODO: add ADC traits to structure?
LL_GPIO_SetPinMode(pin_port(pin->number), pin_mask(pin->number), LL_GPIO_MODE_ANALOG); LL_GPIO_SetPinMode(pin_port(pin->port), pin_mask(pin->number), LL_GPIO_MODE_ANALOG);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); //TODO: conditional on ADC unit LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); //TODO: conditional on ADC unit
claim_pin(pin); //claim_pin(pin);
self->pin = pin; self->pin = pin;
} }
@ -69,54 +69,54 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
// so we completely re-initialize it. // so we completely re-initialize it.
//HAL Implementation //HAL Implementation
ADC_HandleTypeDef AdcHandle; // ADC_HandleTypeDef AdcHandle;
ADC_ChannelConfTypeDef sConfig; // ADC_ChannelConfTypeDef sConfig;
AdcHandle.Instance = ADC1; // AdcHandle.Instance = ADC1;
AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; // AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; // AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle.Init.ScanConvMode = DISABLE; // AdcHandle.Init.ScanConvMode = DISABLE;
AdcHandle.Init.ContinuousConvMode = ENABLE; // AdcHandle.Init.ContinuousConvMode = ENABLE;
AdcHandle.Init.DiscontinuousConvMode = DISABLE; // AdcHandle.Init.DiscontinuousConvMode = DISABLE;
AdcHandle.Init.NbrOfDiscConversion = 0; // AdcHandle.Init.NbrOfDiscConversion = 0;
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; // AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; // AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; // AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.NbrOfConversion = 1; // AdcHandle.Init.NbrOfConversion = 1;
AdcHandle.Init.DMAContinuousRequests = ENABLE; // AdcHandle.Init.DMAContinuousRequests = ENABLE;
AdcHandle.Init.EOCSelection = DISABLE; // AdcHandle.Init.EOCSelection = DISABLE;
sConfig.Channel = self->pin->adc_channel; // sConfig.Channel = self->pin->adc_channel;
sConfig.Rank = 1; // sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; // sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
sConfig.Offset = 0; // sConfig.Offset = 0;
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); // HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle); // HAL_ADC_Start(&AdcHandle);
HAL_ADC_PollForConversion(&AdcHandle,1); //timeout in ms // HAL_ADC_PollForConversion(&AdcHandle,1); //timeout in ms
uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle); // uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
HAL_ADC_Stop(&AdcHandle); // HAL_ADC_Stop(&AdcHandle);
//LL Implementation //LL Implementation
// if (LL_ADC_IsEnabled(ADC1) == 0) if (LL_ADC_IsEnabled(ADC1) == 0)
// { {
// LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_SOFTWARE); LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_SOFTWARE);
// LL_ADC_REG_SetContinuousMode(ADC1, LL_ADC_REG_CONV_SINGLE); LL_ADC_REG_SetContinuousMode(ADC1, LL_ADC_REG_CONV_SINGLE);
// LL_ADC_REG_SetSequencerLength(ADC1, LL_ADC_REG_SEQ_SCAN_DISABLE); LL_ADC_REG_SetSequencerLength(ADC1, LL_ADC_REG_SEQ_SCAN_DISABLE);
// LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, stm32_adc_channel(self->pin->adc)); LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, self->pin->adc_channel);
// //LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_4); //LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_4);
// LL_ADC_SetChannelSamplingTime(ADC1, stm32_adc_channel(self->pin->adc), LL_ADC_SAMPLINGTIME_56CYCLES); LL_ADC_SetChannelSamplingTime(ADC1, self->pin->adc_channel, LL_ADC_SAMPLINGTIME_56CYCLES);
// LL_ADC_EnableIT_OVR(ADC1); LL_ADC_EnableIT_OVR(ADC1);
// } }
// LL_ADC_Enable(ADC1); LL_ADC_Enable(ADC1);
// uint16_t uhADCxConvertedData = (__LL_ADC_DIGITAL_SCALE(LL_ADC_RESOLUTION_12B) + 1); uint16_t uhADCxConvertedData = (__LL_ADC_DIGITAL_SCALE(LL_ADC_RESOLUTION_12B) + 1);
// LL_ADC_REG_StartConversionSWStart(ADC1); LL_ADC_REG_StartConversionSWStart(ADC1);
// while (LL_ADC_IsActiveFlag_EOCS(ADC1) == 0) {} while (LL_ADC_IsActiveFlag_EOCS(ADC1) == 0) {}
// /* Retrieve ADC conversion data */ /* Retrieve ADC conversion data */
// /* (data scale corresponds to ADC resolution: 12 bits) */ /* (data scale corresponds to ADC resolution: 12 bits) */
// uhADCxConvertedData = LL_ADC_REG_ReadConversionData12(ADC1); uhADCxConvertedData = LL_ADC_REG_ReadConversionData12(ADC1);
// // Shift the value to be 16 bit. // // Shift the value to be 16 bit.
return uhADCxConvertedData << 4; return uhADCxConvertedData << 4;