<commit_before>/*
 * This file is a part of the open source stm32plus library.
 * Copyright (c) 2011,2012,2013 <NAME> <www.andybrown.me.uk>
 * Please see website for licensing terms.
 */

#include "config/stm32plus.h"
#include "config/timing.h"
#include "config/adc.h"
#include "config/usart.h"
#include "config/string.h"


using namespace stm32plus;


/**
 * This example shows how to use two ADC peripherals simultaneously. ADC1 and ADC2 are used
 * to convert channels 0,1 (ADC1) and 2,3 (ADC2) simultaneously. That is, channels 0 and 2
 * are converted at the same time followed by channels 1 and 3. The order of the values in
 * the 4-value output buffer will be channel [0,2,1,3].
 *
 * USART3 remap1 is configured with protocol settings of 57600/8/N/1. The ADC channels are read
 * from PA[0], PA[1], PA[2], PA[3]. You will need to connect these GPIO inputs to valid levels
 * between GND and VREF to see conversion values.
 *
 * Compatible MCU:
 *   STM32F1
 *   STM32F4
 *
 * Tested on devices:
 *   STM32F103ZET6
 *   STM32F407VGT6
 */


class AdcMultiDmaMultiChan {

  private:
    volatile bool _ready;

  public:

    void run() {

      uint16_t dmaTransfers;

      _ready=false;

      /*
       * We're converting 4 channels in circular buffer mode so we need exactly 4 16-bit words
       * for that circular buffer
       */

      volatile uint16_t readBuffer[4];

      /*
       * Declare the ADC DMA channel. The default is circular mode for the MultiAdcDmaMode1Feature
       * which means that it wil automatically refill our buffer on each conversion because
       * one conversion exactly matches the size of the memory buffer that we will give
       * to the DMA peripheral.
       */

      Adc1DmaChannel<AdcMultiDmaFeature<Adc1PeripheralTraits>,Adc1DmaChannelInterruptFeature> dma;

      /*
       * Unfortunately the ADC is quite different across the MCU series so we have to
       * be MCU-specific when declaring this instance
       */

#if defined(STM32PLUS_F1)

      Adc1<
        AdcClockPrescalerFeature<6>,                    // PCLK2/6
        Adc1Cycle55RegularChannelFeature<0,1>,          // using channels 0,1 on ADC1 with 55.5-cycle latency
        AdcScanModeFeature,                             // scan mode
        AdcContinuousModeFeature,
        AdcDualRegularSimultaneousFeature<              // regular simultaneous multi mode
          Adc2<                                         // the second ADC
            Adc2Cycle55RegularChannelFeature<2,3>,      // using channels 2,3 on ADC2 with 55.5-cycle latency
            AdcScanModeFeature,                         // scan mode
            AdcContinuousModeFeature
          >
        >
      > adc;

      // word transfers

      dmaTransfers=2;

#elif defined(STM32PLUS_F4)<commit_msg>fix regression on f4. #21<commit_after>/*
 * This file is a part of the open source stm32plus library.
 * Copyright (c) 2011,2012,2013 <NAME> <www.andybrown.me.uk>
 * Please see website for licensing terms.
 */

#include "config/stm32plus.h"
#include "config/timing.h"
#include "config/adc.h"
#include "config/usart.h"
#include "config/string.h"


using namespace stm32plus;


/**
 * This example shows how to use two ADC peripherals simultaneously. ADC1 and ADC2 are used
 * to convert channels 0,1 (ADC1) and 2,3 (ADC2) simultaneously. That is, channels 0 and 2
 * are converted at the same time followed by channels 1 and 3. The order of the values in
 * the 4-value output buffer will be channel [0,2,1,3].
 *
 * USART3 remap1 is configured with protocol settings of 57600/8/N/1. The ADC channels are read
 * from PA[0], PA[1], PA[2], PA[3]. You will need to connect these GPIO inputs to valid levels
 * between GND and VREF to see conversion values.
 *
 * Compatible MCU:
 *   STM32F1
 *   STM32F4
 *
 * Tested on devices:
 *   STM32F103ZET6
 *   STM32F407VGT6
 */


class AdcMultiDmaMultiChan {

  private:
    volatile bool _ready;

  public:

    void run() {

      uint16_t dmaTransfers;

      _ready=false;

      /*
       * We're converting 4 channels in circular buffer mode so we need exactly 4 16-bit words
       * for that circular buffer
       */

      volatile uint16_t readBuffer[4];

      /*
       * Unfortunately the ADC is quite different across the MCU series so we have to
       * be MCU-specific when declaring this instance
       */

#if defined(STM32PLUS_F1)

      /*
       * Declare the ADC DMA channel. The default is circular mode for the MultiAdcDmaMode1Feature
       * which means that it wil automatically refill our buffer on each conversion because
       * one conversion exactly matches the size of the memory buffer that we will give
       * to the DMA peripheral.
       */

      Adc1DmaChannel<AdcMultiDmaFeature<Adc1PeripheralTraits>,Adc1DmaChannelInterruptFeature> dma;

      Adc1<
        AdcClockPrescalerFeature<6>,                    // PCLK2/6
        Adc1Cycle55RegularChannelFeature<0,1>,          // using channels 0,1 on ADC1 with 55.5-cycle latency
        AdcScanModeFeature,                             // scan mode
        AdcContinuousModeFeature,
        AdcDualRegularSimultaneousFeature<              // regular simultaneous multi mode
          Adc2<                                         // the second ADC
            Adc2Cycle55RegularChannelFeature<2,3>,      // using channels 2,3 on ADC2 with 55.5-cycle latency
            AdcScanModeFeature,                         // scan mode
            AdcContinuousModeFeature
          >
        >
      > adc;

      // word transfers

      dmaTransfers=2;

#elif defined(STM32PLUS_F4)

      /*
       * Declare the ADC DMA channel. The default is circular mode for the MultiAdcDmaMode1Feature
       * which means that it wil automatically refill our buffer on each conversion because
       * one conversion exactly matches the size of the memory buffer that we will give
       * to the DMA peripheral.
       */

      Adc1DmaChannel<AdcMultiDmaMode1Feature<Adc1PeripheralTraits>,Adc1DmaChannelInterruptFeature> dma;
{'fraction_non_alphanumeric': 0.06979821369500497, 'fraction_numerical': 0.0387032748924909, 'mean_word_length': 2.3688022284122563, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2766985', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1726, 'n_words': 619}