1) How do you use the APORT to select a pin as an ADC input?
2) What is the correct way to configure a pin for an analog function?
1) Control of the APORT and associated pin connections for the ADC is accomplished through your selections in the ADC input selection bitfields in ADCn_SINGLECTRL (i.e. NEGSEL and POSSEL) for single conversions. This is true in a similar way for other analog peripherals in the sense that those peripherals have a mechanism within their registers for selecting a particular APORT bus and channel as inputs/outputs to the module. For each of these peripherals, the act of selecting an APORT channel as an input or output will cause that peripheral to exert control of the necessary switching and internal device routing necessary to connect the pin assigned to that channel to the peripheral. Because of this, multiple peripherals requesting access to the same APORT bus can create conflicts, which can be configured to generate interrupts to aid in debugging the issue. For more information about APORT conflicts and generating interrupts on this condition in the ADC module, please refer to section 126.96.36.199 on page 765 of the EFR32xG1 reference manual.
Please note that the MCU pins assigned to each APORT bus and channel are fixed and are defined in each device specific datasheet (see [Pin Definitions] > [Analog Port (APORT)]). The ADC positive input mux is connected only to APORT 'X' buses, while the negative input mux is connected only to APORT 'Y' buses, as shown in Figure 24.5 on page 760 of the EFR32xG1 reference manual. The easiest way to select the correct input mux setting to correspond to the pin you wish to use as input to the ADC is to consult the device datasheet and find which APORT (0, 1, 2, 3, or 4), Bus (X or Y), and channel (0-15) correspond to the pin you wish to use. You can easily find this information in Table 7.4: APORT Client Map on page 68 of the BGM12x datasheet (ADC0 APORT selections begin on page 71). Matching this information to the options given for the NEGSEL and POSSEL fields of the ADCn_SINGLECTRL register (see page 783 of EFR32xG1 reference manual). Writing to these bitfields will immediately cause the ADC to take control of the selected APORT bus.
Also, please note that emlib provides a relatively simple API for selecting the APORT channel for the positive and negative (if used) input to the ADC, using the ADC_InitSingle_TypeDef structure in combination with the ADC_InitSingle() function. For example:
ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;
singleInit.posSel = adcPosSelAPORT1XCH6; //select PC6 for BGM123
singleInit.negSel = adcNegSelVSS;
2) In the GPIO module, all you must do to use a GPIO pin as an analog input is to configure the pin mode to "disable" (to disable the input sense, output driver and pull resistors) and disable over-voltage tolerance for that pin (recommended for reduced distortion of analog signals):
GPIO_PinModeSet(gpioPortC, 6, gpioModeDisabled, 0); //set PC6 to DISABLE with no pull resistors
GPIO->P[gpioPortC].OVTDIS |= (0x01 << 6); //Disable over-voltage tolerance for PC6
As for the distinction between APORT A, B, C, D, etc... These correspond to APORT0 APORT1, etc. This can be a little confusing. Each APORT (0-4) has an X and a Y bus.
Finally, GPIO pin configuration follows the same guidelines whether the pin is being used as an analog input or output (i.e. set pin to DISABLE w/o pull and disable over-voltage tolerance). For more information on using GPIO pins for analog functions, please refer to section 188.8.131.52 of the EFR32xG1 reference manual on page 918. Note that Push-Pull mode should be used for digital outputs, and alternate port control can be used to apply different slew rate, drive strength, and data input disable settings to digital pins in the same port grouping, but this does not apply for analog functionality.