Workflow

  1. 1.
    Create a module software instance structure for the ADC module to store the ADC driver state while in use.
    struct adc_module adc_instance;
    
    Note: This should never go out of scope as long as the module is in use. In most cases, this should be global.
  2. 2.
    Configure the ADC module.
    1. 2.1.
      Create an ADC module configuration struct, which can be filled out to adjust the configuration of a physical ADC peripheral.
      struct adc_config config_adc;
      
    2. 2.2.
      Initialize the ADC configuration struct with the module's default values.
      adc_get_config_defaults(&config_adc);
      
      Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. 2.3.
      Set ADC configurations.
      #if (SAMC21)
          adc_init(&adc_instance, ADC1, &config_adc);
      #else
          adc_init(&adc_instance, ADC, &config_adc);
      #endif
      
    4. 2.4.
      Enable the ADC module so that conversions can be made.
      adc_enable(&adc_instance);