MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_hw_adc_unit_init

Function rt_hw_adc_unit_init

bsp/efm32/drv_adc.c:732–793  ·  view source on GitHub ↗

/ * @brief * Initialize the specified ADC unit * * @details * * @note * * @param[in] device * Pointer to device descriptor * * @param[in] unitNumber * Unit number * * @return * Pointer to ADC device ******************************************************************************/

Source from the content-addressed store, hash-verified

730 * Pointer to ADC device
731 ******************************************************************************/
732static struct efm32_adc_device_t *rt_hw_adc_unit_init(
733 rt_device_t device,
734 rt_uint8_t unitNumber)
735{
736 struct efm32_adc_device_t *adc;
737 CMU_Clock_TypeDef adcClock;
738 ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
739
740 do
741 {
742 /* Allocate device and set default value */
743 adc = rt_malloc(sizeof(struct efm32_adc_device_t));
744 if (adc == RT_NULL)
745 {
746 adc_debug("no memory for ADC%d driver\n", unitNumber);
747 break;
748 }
749 adc->mode = 0;
750 adc->singleCount = 0;
751 adc->singleDmaChannel = (rt_uint8_t)EFM32_NO_DMA;
752 adc->scanCount = 0;
753 adc->scanDmaChannel = (rt_uint8_t)EFM32_NO_DMA;
754
755 /* Initialization */
756 if (unitNumber >= ADC_COUNT)
757 {
758 break;
759 }
760 switch (unitNumber)
761 {
762 case 0:
763 adc->adc_device = ADC0;
764 adcClock = (CMU_Clock_TypeDef)cmuClock_ADC0;
765 break;
766
767 default:
768 break;
769 }
770
771 /* Enable ADC clock */
772 CMU_ClockEnable(adcClock, true);
773
774 /* Reset */
775 ADC_Reset(adc->adc_device);
776
777 /* Configure ADC */
778 // TODO: Fixed oversampling rate?
779 init.ovsRateSel = adcOvsRateSel4096;
780 init.timebase = ADC_TimebaseCalc(0);
781 init.prescale = ADC_PrescaleCalc(ADC_CONVERT_FREQUENCY, 0);
782 ADC_Init(adc->adc_device, &init);
783
784 return adc;
785 } while(0);
786
787 if (adc)
788 {
789 rt_free(adc);

Callers 1

rt_hw_adc_initFunction · 0.85

Calls 8

rt_mallocFunction · 0.85
CMU_ClockEnableFunction · 0.85
ADC_TimebaseCalcFunction · 0.85
ADC_PrescaleCalcFunction · 0.85
rt_freeFunction · 0.85
rt_kprintfFunction · 0.85
ADC_ResetFunction · 0.50
ADC_InitFunction · 0.50

Tested by

no test coverage detected