///////////////////////////////////////////////////////////////////////////////
//
// IAR C/C++ Compiler V2.10.4.157 for STM8                13/Jul/2020  10:55:02
// Copyright 2010-2015 IAR Systems AB.
//
//    Source file  =  F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\src\stm8l15x_adc.c
//    Command line =  
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\src\stm8l15x_adc.c -e -Ol
//        --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa
//        --no_cross_call --debug --code_model small --data_model medium -o
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\Obj\ --dlib_config
//        E:\IAR\stm8\LIB\dlstm8smf.h -lB
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\List\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\inc\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\src\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\radio\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\SX1278\ --vregs 16
//    List file    =  
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\List\stm8l15x_adc.s
//
///////////////////////////////////////////////////////////////////////////////

        EXTERN ?b0
        EXTERN ?b1
        EXTERN ?b2
        EXTERN ?b3
        EXTERN ?b4
        EXTERN ?sll8_a_a_5
        EXTERN ?w0
        EXTERN ?w1

        PUBLIC ADC_AnalogWatchdogChannelSelect
        PUBLIC ADC_AnalogWatchdogConfig
        PUBLIC ADC_AnalogWatchdogThresholdsConfig
        PUBLIC ADC_ChannelCmd
        PUBLIC ADC_ClearFlag
        PUBLIC ADC_ClearITPendingBit
        PUBLIC ADC_Cmd
        PUBLIC ADC_DMACmd
        PUBLIC ADC_DeInit
        PUBLIC ADC_ExternalTrigConfig
        PUBLIC ADC_GetConversionValue
        PUBLIC ADC_GetFlagStatus
        PUBLIC ADC_GetITStatus
        PUBLIC ADC_ITConfig
        PUBLIC ADC_Init
        PUBLIC ADC_SamplingTimeConfig
        PUBLIC ADC_SchmittTriggerConfig
        PUBLIC ADC_SoftwareStartConv
        PUBLIC ADC_TempSensorCmd
        PUBLIC ADC_VrefintCmd

// F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\src\stm8l15x_adc.c
//    1 /**
//    2   ******************************************************************************
//    3   * @file    stm8l15x_adc.c
//    4   * @author  MCD Application Team
//    5   * @version V1.6.0
//    6   * @date    28-June-2013
//    7   * @brief   This file provides firmware functions to manage the following 
//    8   *          functionalities of the Analog to Digital Convertor (ADC) peripheral:           
//    9   *           - Initialization and Configuration
//   10   *           - Power saving
//   11   *           - Analog Watchdog configuration              
//   12   *           - Temperature Sensor & Vrefint (Voltage Reference internal) management 
//   13   *           - Regular Channels Configuration
//   14   *           - Regular Channels DMA Configuration
//   15   *           - Injected channels Configuration      
//   16   *           - Interrupts and flags management       
//   17   *         
//   18   *  @verbatim
//   19   *                               
//   20   *          ===================================================================      
//   21   *                                   How to use this driver
//   22   *          ===================================================================      
//   23   *          1. Enable The ADC controller clock using CLK_PeripheralClockConfig() 
//   24   *            function : CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE).
//   25   *
//   26   *            2. Configure the ADC Prescaler, conversion resolution and data 
//   27   *              alignment using the ADC_Init() function.
//   28   * 
//   29   *            3. Activate the ADC peripheral using ADC_Cmd() function.  
//   30   *
//   31   *          Regular channels group configuration
//   32   *          ====================================    
//   33   *            - To configure the ADC regular channels group features, use 
//   34   *              ADC_Init() and ADC_RegularChannelConfig() functions.
//   35   *            - To activate the continuous mode, use the ADC_continuousModeCmd()
//   36   *              function.
//   37   *            - To configure and activate the Discontinuous mode, use the 
//   38   *              ADC_DiscModeChannelCountConfig() and ADC_DiscModeCmd() functions.        
//   39   *            - To read the ADC converted values, use the ADC_GetConversionValue()
//   40   *              function.
//   41   *
//   42   *          DMA for Regular channels group features configuration
//   43   *          ====================================================== 
//   44   *           - To enable the DMA mode for regular channels group, use the 
//   45   *             ADC_DMACmd() function.
//   46   *           - To enable the generation of DMA requests continuously at the end
//   47   *             of the last DMA transfer, use the ADC_DMARequestAfterLastTransferCmd() 
//   48   *             function.    
//   49              
//   50   *          Injected channels group configuration
//   51   *          =====================================    
//   52   *            - To configure the ADC Injected channels group features, use 
//   53   *              ADC_InjectedChannelConfig() and  ADC_InjectedSequencerLengthConfig()
//   54   *              functions.
//   55   *            - To activate the continuous mode, use the ADC_continuousModeCmd()
//   56   *              function.
//   57   *            - To activate the Injected Discontinuous mode, use the 
//   58   *              ADC_InjectedDiscModeCmd() function.  
//   59   *            - To activate the AutoInjected mode, use the ADC_AutoInjectedConvCmd() 
//   60   *              function.        
//   61   *            - To read the ADC converted values, use the ADC_GetInjectedConversionValue() 
//   62   *              function.
//   63   *              
//   64   *  @endverbatim
//   65   *         
//   66   ******************************************************************************
//   67   *
//   68   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
//   69   * You may not use this file except in compliance with the License.
//   70   * You may obtain a copy of the License at:
//   71   *
//   72   *        http://www.st.com/software_license_agreement_liberty_v2
//   73   *
//   74   * Unless required by applicable law or agreed to in writing, software 
//   75   * distributed under the License is distributed on an "AS IS" BASIS, 
//   76   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   77   * See the License for the specific language governing permissions and
//   78   * limitations under the License.
//   79   *
//   80   ****************************************************************************** 
//   81   */ 
//   82 
//   83 /* Includes ------------------------------------------------------------------*/
//   84 #include "stm8l15x_adc.h"
//   85 
//   86 /** @addtogroup STM8L15x_StdPeriph_Driver
//   87   * @{
//   88   */
//   89 
//   90 /** @defgroup ADC 
//   91   * @brief ADC driver modules
//   92   * @{
//   93   */ 
//   94   
//   95 /* Private typedef -----------------------------------------------------------*/
//   96 /* Private define ------------------------------------------------------------*/
//   97 /* Private macro -------------------------------------------------------------*/
//   98 /* Private variables ---------------------------------------------------------*/
//   99 /* Private function prototypes -----------------------------------------------*/
//  100 /* Private functions ---------------------------------------------------------*/
//  101 
//  102 /** @defgroup ADC_Private_Functions
//  103   * @{
//  104   */ 
//  105     
//  106     
//  107 /** @defgroup ADC_Group1 Initialization and Configuration functions
//  108  *  @brief   Initialization and Configuration functions 
//  109  *
//  110 @verbatim    
//  111  ===============================================================================
//  112                       Initialization and Configuration functions
//  113  ===============================================================================  
//  114   This section provides functions allowing to:
//  115    - Enable or disable the ADC peripheral,
//  116    - Initialize and configure the ADC Prescaler, ADC Conversion Resolution 
//  117      (12bit..6bit), ADC Continuous Conversion Mode (Continuous or Single 
//  118      conversion),
//  119    - Configure External trigger Sensitivity and source,
//  120    - Start ADC conversion, by software trigger.
//  121 
//  122 
//  123 @endverbatim
//  124   * @{
//  125   */
//  126 /**
//  127   * @brief  Deinitializes the ADC peripheral registers to their default reset 
//  128   *         values.
//  129   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  130   * @retval None
//  131   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  132 void ADC_DeInit(ADC_TypeDef* ADCx)
//  133 {
//  134   /*  Set the Configuration registers to their reset values */
//  135   ADCx->CR1 =  ADC_CR1_RESET_VALUE;
ADC_DeInit:
        CLR       A
        LD        (X), A
//  136   ADCx->CR2 =  ADC_CR2_RESET_VALUE;
        LDW       Y, X
        INCW      Y
        CLR       A
        LD        (Y), A
//  137   ADCx->CR3 =  ADC_CR3_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x2
        LD        A, #0x1f
        LD        (Y), A
//  138 
//  139   /*  Set the status registers to their reset values */
//  140   ADCx->SR =  (uint8_t)~ADC_SR_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x3
        LD        A, #0xff
        LD        (Y), A
//  141 
//  142   /*  Set the High threshold registers to their reset values */
//  143   ADCx->HTRH =  ADC_HTRH_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x6
        LD        A, #0xf
        LD        (Y), A
//  144   ADCx->HTRL =  ADC_HTRL_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x7
        LD        A, #0xff
        LD        (Y), A
//  145 
//  146   /*  Set the low threshold registers to their reset values */
//  147   ADCx->LTRH =  ADC_LTRH_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x8
        CLR       A
        LD        (Y), A
//  148   ADCx->LTRL =  ADC_LTRL_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x9
        CLR       A
        LD        (Y), A
//  149 
//  150   /*  Set the channels sequence registers to their reset values */
//  151   ADCx->SQR[0] =  ADC_SQR1_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0xa
        CLR       A
        LD        (Y), A
//  152   ADCx->SQR[1] =  ADC_SQR2_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0xb
        CLR       A
        LD        (Y), A
//  153   ADCx->SQR[2] =  ADC_SQR3_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0xc
        CLR       A
        LD        (Y), A
//  154   ADCx->SQR[3] =  ADC_SQR4_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0xd
        CLR       A
        LD        (Y), A
//  155 
//  156   /*  Set the channels Trigger registers to their reset values */
//  157   ADCx->TRIGR[0] =  ADC_TRIGR1_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0xe
        CLR       A
        LD        (Y), A
//  158   ADCx->TRIGR[1] =  ADC_TRIGR2_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0xf
        CLR       A
        LD        (Y), A
//  159   ADCx->TRIGR[2] =  ADC_TRIGR3_RESET_VALUE;
        LDW       Y, X
        ADDW      Y, #0x10
        CLR       A
        LD        (Y), A
//  160   ADCx->TRIGR[3] =  ADC_TRIGR4_RESET_VALUE;
        ADDW      X, #0x11
        CLR       A
        LD        (X), A
//  161 }
        RET
//  162 
//  163 /**
//  164   * @brief  Initializes the specified ADC peripheral according to the specified 
//  165   *         parameters.
//  166   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  167   * @param  ADC_ConversionMode : specifies the ADC conversion mode,
//  168   *          This parameter can be one of the following values:
//  169   *            @arg ADC_ConversionMode_Single: Single Conversion Mode
//  170   *            @arg ADC_ConversionMode_Continuous: Continuous Conversion Mode
//  171   * @param  ADC_Resolution : specifies the ADC Data resolution,
//  172   *          This parameter can be one of the following values:
//  173   *            @arg ADC_Resolution_12Bit: 12 bit resolution
//  174   *            @arg ADC_Resolution_10Bit: 10 bit resolution
//  175   *            @arg ADC_Resolution_8Bit: 8 bit resolution
//  176   *            @arg ADC_Resolution_6Bit: 6 bit resolution      
//  177   * @param  ADC_Prescaler : specifies the ADC Prescaler,
//  178   *          This parameter can be one of the following values:
//  179   *            @arg ADC_Prescaler_1: ADC Clock frequency is divided by 1
//  180   *            @arg ADC_Prescaler_2: ADC Clock frequency is divided by 2
//  181   * @retval None
//  182   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  183 void ADC_Init(ADC_TypeDef* ADCx,
//  184               ADC_ConversionMode_TypeDef ADC_ConversionMode,
//  185               ADC_Resolution_TypeDef ADC_Resolution,
//  186               ADC_Prescaler_TypeDef ADC_Prescaler)
//  187 {
ADC_Init:
        LD        S:?b2, A
//  188   /* Check the parameters */
//  189   assert_param(IS_ADC_CONVERSION_MODE(ADC_ConversionMode));
//  190   assert_param(IS_ADC_RESOLUTION(ADC_Resolution));
//  191   assert_param(IS_ADC_PRESCALER(ADC_Prescaler));
//  192 
//  193   /*clear CR1 register */
//  194   ADCx->CR1 &= (uint8_t)~(ADC_CR1_CONT | ADC_CR1_RES);
        LD        A, (X)
        AND       A, #0x9b
        LD        (X), A
//  195 
//  196   /* set the resolution and the conversion mode */
//  197   ADCx->CR1 |= (uint8_t)((uint8_t)ADC_ConversionMode | (uint8_t)ADC_Resolution);
        LD        A, S:?b0
        OR        A, S:?b2
        OR        A, (X)
        LD        (X), A
//  198 
//  199   /*clear CR2 register */
//  200   ADCx->CR2 &= (uint8_t)~(ADC_CR2_PRESC);
        LDW       Y, X
        INCW      Y
        LD        A, (Y)
        AND       A, #0x7f
        LDW       Y, X
        INCW      Y
        LD        (Y), A
//  201 
//  202   /* set the Prescaler */
//  203   ADCx->CR2 |= (uint8_t) ADC_Prescaler;
        LDW       Y, X
        INCW      Y
        LD        A, S:?b1
        OR        A, (Y)
        INCW      X
        LD        (X), A
//  204 }
        RET
//  205 
//  206 /**
//  207   * @brief  Enables or disables the selected ADC peripheral.
//  208   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  209   * @param  NewState : new state of the specified ADC peripheral.
//  210     *         This parameter can be: ENABLE or DISABLE.
//  211   * @retval None
//  212   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  213 void ADC_Cmd(ADC_TypeDef* ADCx,
//  214              FunctionalState NewState)
//  215 {
//  216   /* Check the parameters */
//  217   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  218 
//  219   if (NewState != DISABLE)
ADC_Cmd:
        TNZ       A
        JREQ      L:??ADC_Cmd_0
//  220   {
//  221     /* Set the ADON bit to wake up the specified ADC from power down mode */
//  222     ADCx->CR1 |= ADC_CR1_ADON;
        LD        A, (X)
        OR        A, #0x1
        LD        (X), A
        RET
//  223   }
//  224   else
//  225   {
//  226     /* Disable the selected ADC peripheral */
//  227     ADCx->CR1 &= (uint8_t)~ADC_CR1_ADON;
??ADC_Cmd_0:
        LD        A, (X)
        AND       A, #0xfe
        LD        (X), A
//  228   }
//  229 }
        RET
//  230 
//  231 /**
//  232   * @brief  Starts ADC conversion, by software trigger.
//  233   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  234   * @retval None
//  235   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  236 void ADC_SoftwareStartConv(ADC_TypeDef* ADCx)
//  237 {
//  238   /*  Start the ADC software conversion */
//  239   ADCx->CR1 |= ADC_CR1_START;
ADC_SoftwareStartConv:
        LD        A, (X)
        OR        A, #0x2
        LD        (X), A
//  240 }
        RET
//  241 
//  242 /**
//  243   * @brief  Configures the ADC conversion through external trigger.
//  244   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  245   * @param  ADC_ExtEventSelection : Specifies the external trigger.
//  246   *          This parameter can be one of the following values:
//  247   *            @arg ADC_ExtEventSelection_None: Conversion starts only by software start
//  248   *            @arg ADC_ExtEventSelection_Trigger1: Trigger 1  Enables conversion
//  249   *            @arg ADC_ExtEventSelection_Trigger2: Trigger 2  Enables conversion
//  250   *            @arg ADC_ExtEventSelection_Trigger3: Trigger 3  Enables conversion      
//  251   * @param  ADC_ExtTRGSensitivity : Specifies the external trigger sensitivity.
//  252   *          This parameter can be one of the following values:
//  253   *            @arg ADC_ExtTRGSensitivity_Rising: External Trigger Sensitivity is Rising Edge
//  254   *            @arg ADC_ExtTRGSensitivity_Falling: External Trigger Sensitivity is Falling Edge
//  255   *            @arg ADC_ExtTRGSensitivity_All: External Trigger Sensitivity is Falling and Rising Edge
//  256   * @retval None
//  257   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  258 void ADC_ExternalTrigConfig(ADC_TypeDef* ADCx,
//  259                             ADC_ExtEventSelection_TypeDef ADC_ExtEventSelection,
//  260                             ADC_ExtTRGSensitivity_TypeDef ADC_ExtTRGSensitivity)
//  261 {
ADC_ExternalTrigConfig:
        LD        S:?b1, A
//  262   /* Check the parameters */
//  263   assert_param(IS_ADC_EXT_EVENT_SELECTION(ADC_ExtEventSelection));
//  264   assert_param(IS_ADC_EXT_TRG_SENSITIVITY(ADC_ExtTRGSensitivity));
//  265 
//  266   /*clear old configuration of CR2 register */
//  267   ADCx->CR2 &= (uint8_t)~(ADC_CR2_TRIGEDGE | ADC_CR2_EXTSEL);
        LDW       Y, X
        INCW      Y
        LD        A, (Y)
        AND       A, #0x87
        LDW       Y, X
        INCW      Y
        LD        (Y), A
//  268 
//  269   /* set the External Trigger Edge Sensitivity  and the external event 
//  270      selection */
//  271   ADCx->CR2 |= (uint8_t)( (uint8_t)ADC_ExtTRGSensitivity | \ 
//  272                           (uint8_t)ADC_ExtEventSelection);
        LD        A, S:?b1
        OR        A, S:?b0
        LDW       Y, X
        INCW      Y
        OR        A, (Y)
        INCW      X
        LD        (X), A
//  273 }
        RET
//  274 
//  275  /**
//  276   * @}
//  277   */
//  278 
//  279 /** @defgroup ADC_Group2 Analog Watchdog configuration functions
//  280  *  @brief   Analog Watchdog configuration functions 
//  281  *
//  282 @verbatim   
//  283  ===============================================================================
//  284                     Analog Watchdog configuration functions
//  285  ===============================================================================  
//  286 
//  287   This section provides functions allowing to configure the Analog Watchdog
//  288   (AWD) feature in the ADC.
//  289   
//  290   A typical configuration Analog Watchdog is done following these steps :
//  291    1. the ADC guarded channel is selected using the 
//  292       ADC_AnalogWatchdogChannelSelect() function.
//  293    2. The Analog watchdog lower and higher threshold are configured using the  
//  294       ADC_AnalogWatchdogThresholdsConfig() function.
//  295    
//  296    Note : Both AWD selection and thresholds can be configured with one unique 
//  297           function ADC_AnalogWatchdogConfig(), which is kept for firmware 
//  298           compatibility reason.
//  299 
//  300 @endverbatim
//  301   * @{
//  302   */
//  303 /**
//  304   * @brief  Configures the channel to be checked by the Analog watchdog.
//  305   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  306   * @param  ADC_AnalogWatchdogSelection : Specifies the channel to be checked 
//  307   *         by the Analog watchdog.
//  308   *          This parameter can be one of the following values:
//  309   *            @arg ADC_AnalogWatchdogSelection_Channel0: AWD affected to Channel 0
//  310   *            @arg ADC_AnalogWatchdogSelection_Channel1: AWD affected to Channel 1
//  311   *            @arg ADC_AnalogWatchdogSelection_Channel2: AWD affected to Channel 2
//  312   *            @arg ADC_AnalogWatchdogSelection_Channel3: AWD affected to Channel 3
//  313   *            @arg ADC_AnalogWatchdogSelection_Channel4: AWD affected to Channel 4
//  314   *            @arg ADC_AnalogWatchdogSelection_Channel5: AWD affected to Channel 5
//  315   *            @arg ADC_AnalogWatchdogSelection_Channel6: AWD affected to Channel 6
//  316   *            @arg ADC_AnalogWatchdogSelection_Channel7: AWD affected to Channel 7
//  317   *            @arg ADC_AnalogWatchdogSelection_Channel8: AWD affected to Channel 8
//  318   *            @arg ADC_AnalogWatchdogSelection_Channel9: AWD affected to Channel 9
//  319   *            @arg ADC_AnalogWatchdogSelection_Channel10: AWD affected to Channel 10
//  320   *            @arg ADC_AnalogWatchdogSelection_Channel11: AWD affected to Channel 11
//  321   *            @arg ADC_AnalogWatchdogSelection_Channel12: AWD affected to Channel 12
//  322   *            @arg ADC_AnalogWatchdogSelection_Channel13: AWD affected to Channel 13
//  323   *            @arg ADC_AnalogWatchdogSelection_Channel14: AWD affected to Channel 14
//  324   *            @arg ADC_AnalogWatchdogSelection_Channel15: AWD affected to Channel 15
//  325   *            @arg ADC_AnalogWatchdogSelection_Channel16: AWD affected to Channel 16
//  326   *            @arg ADC_AnalogWatchdogSelection_Channel17: AWD affected to Channel 17
//  327   *            @arg ADC_AnalogWatchdogSelection_Channel18: AWD affected to Channel 18
//  328   *            @arg ADC_AnalogWatchdogSelection_Channel19: AWD affected to Channel 19
//  329   *            @arg ADC_AnalogWatchdogSelection_Channel20: AWD affected to Channel 20
//  330   *            @arg ADC_AnalogWatchdogSelection_Channel21: AWD affected to Channel 21
//  331   *            @arg ADC_AnalogWatchdogSelection_Channel22: AWD affected to Channel 22
//  332   *            @arg ADC_AnalogWatchdogSelection_Channel23: AWD affected to Channel 23
//  333   *         @ref ADC_AnalogWatchdogSelection_TypeDef enumeration.
//  334   * @retval None
//  335   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  336 void ADC_AnalogWatchdogChannelSelect(ADC_TypeDef* ADCx,
//  337                                      ADC_AnalogWatchdogSelection_TypeDef ADC_AnalogWatchdogSelection)
//  338 {
ADC_AnalogWatchdogChannelSelect:
        LD        S:?b0, A
//  339   /* Check the parameters */
//  340   assert_param(IS_ADC_ANALOGWATCHDOG_SELECTION(ADC_AnalogWatchdogSelection));
//  341 
//  342   /* Reset the CHSEL bits */
//  343   ADCx->CR3 &= ((uint8_t)~ADC_CR3_CHSEL);
        LDW       Y, X
        ADDW      Y, #0x2
        LD        A, (Y)
        AND       A, #0xe0
        LDW       Y, X
        ADDW      Y, #0x2
        LD        (Y), A
//  344 
//  345   /* Select the channel to be checked by the Analog watchdog */
//  346   ADCx->CR3 |= (uint8_t)ADC_AnalogWatchdogSelection;
        LDW       Y, X
        ADDW      Y, #0x2
        LD        A, S:?b0
        OR        A, (Y)
        ADDW      X, #0x2
        LD        (X), A
//  347 }
        RET
//  348 
//  349 /**
//  350   * @brief  Configures the high and low thresholds of the Analog watchdog.
//  351   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  352   * @param  HighThreshold: Analog watchdog High threshold value.
//  353     *       This parameter must be a 12bit value.
//  354   * @param  LowThreshold: Analog watchdog Low threshold value.
//  355     *       This parameter must be a 12bit value.
//  356   * @retval None
//  357   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  358 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold)
//  359 {
ADC_AnalogWatchdogThresholdsConfig:
        LDW       S:?w1, X
//  360   /* Check the parameters */
//  361   assert_param(IS_ADC_THRESHOLD(HighThreshold));
//  362   assert_param(IS_ADC_THRESHOLD(LowThreshold));
//  363 
//  364   /* Set the ADC high threshold */
//  365   ADCx->HTRH = (uint8_t)(HighThreshold >> 8);
        LDW       X, Y
        CLR       A
        RRWA      X, A
        LD        A, XL
        LDW       X, S:?w1
        ADDW      X, #0x6
        LD        (X), A
//  366   ADCx->HTRL = (uint8_t)(HighThreshold);
        LDW       X, S:?w1
        ADDW      X, #0x7
        LD        A, YL
        LD        (X), A
//  367 
//  368   /* Set the ADC low threshold */
//  369   ADCx->LTRH = (uint8_t)(LowThreshold >> 8);
        LDW       X, S:?w0
        CLR       A
        RRWA      X, A
        LD        A, XL
        LDW       X, S:?w1
        ADDW      X, #0x8
        LD        (X), A
//  370   ADCx->LTRL = (uint8_t)(LowThreshold);
        LDW       X, S:?w1
        ADDW      X, #0x9
        LD        A, S:?b1
        LD        (X), A
//  371 }
        RET
//  372 
//  373 /**
//  374   * @brief  Configures the Analog watchdog.
//  375   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  376   * @param  ADC_AnalogWatchdogSelection : Specifies the channel to be checked 
//  377   *         by the Analog watchdog.
//  378   *          This parameter can be one of the following values:
//  379   *            @arg ADC_AnalogWatchdogSelection_Channel0: AWD affected to Channel 0
//  380   *            @arg ADC_AnalogWatchdogSelection_Channel1: AWD affected to Channel 1
//  381   *            @arg ADC_AnalogWatchdogSelection_Channel2: AWD affected to Channel 2
//  382   *            @arg ADC_AnalogWatchdogSelection_Channel3: AWD affected to Channel 3
//  383   *            @arg ADC_AnalogWatchdogSelection_Channel4: AWD affected to Channel 4
//  384   *            @arg ADC_AnalogWatchdogSelection_Channel5: AWD affected to Channel 5
//  385   *            @arg ADC_AnalogWatchdogSelection_Channel6: AWD affected to Channel 6
//  386   *            @arg ADC_AnalogWatchdogSelection_Channel7: AWD affected to Channel 7
//  387   *            @arg ADC_AnalogWatchdogSelection_Channel8: AWD affected to Channel 8
//  388   *            @arg ADC_AnalogWatchdogSelection_Channel9: AWD affected to Channel 9
//  389   *            @arg ADC_AnalogWatchdogSelection_Channel10: AWD affected to Channel 10
//  390   *            @arg ADC_AnalogWatchdogSelection_Channel11: AWD affected to Channel 11
//  391   *            @arg ADC_AnalogWatchdogSelection_Channel12: AWD affected to Channel 12
//  392   *            @arg ADC_AnalogWatchdogSelection_Channel13: AWD affected to Channel 13
//  393   *            @arg ADC_AnalogWatchdogSelection_Channel14: AWD affected to Channel 14
//  394   *            @arg ADC_AnalogWatchdogSelection_Channel15: AWD affected to Channel 15
//  395   *            @arg ADC_AnalogWatchdogSelection_Channel16: AWD affected to Channel 16
//  396   *            @arg ADC_AnalogWatchdogSelection_Channel17: AWD affected to Channel 17
//  397   *            @arg ADC_AnalogWatchdogSelection_Channel18: AWD affected to Channel 18
//  398   *            @arg ADC_AnalogWatchdogSelection_Channel19: AWD affected to Channel 19
//  399   *            @arg ADC_AnalogWatchdogSelection_Channel20: AWD affected to Channel 20
//  400   *            @arg ADC_AnalogWatchdogSelection_Channel21: AWD affected to Channel 21
//  401   *            @arg ADC_AnalogWatchdogSelection_Channel22: AWD affected to Channel 22
//  402   *            @arg ADC_AnalogWatchdogSelection_Channel23: AWD affected to Channel 23  
//  403   * @param  HighThreshold: Analog watchdog High threshold value.
//  404     *       This parameter must be a 12bit value.
//  405   * @param  LowThreshold: Analog watchdog Low threshold value.
//  406     *       This parameter must be a 12bit value.
//  407   * @retval None
//  408   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  409 void ADC_AnalogWatchdogConfig(ADC_TypeDef* ADCx,
//  410                               ADC_AnalogWatchdogSelection_TypeDef ADC_AnalogWatchdogSelection,
//  411                               uint16_t HighThreshold,
//  412                               uint16_t LowThreshold)
//  413 {
ADC_AnalogWatchdogConfig:
        LDW       S:?w1, X
        LD        S:?b4, A
//  414   /* Check the parameters */
//  415   assert_param(IS_ADC_ANALOGWATCHDOG_SELECTION(ADC_AnalogWatchdogSelection));
//  416   assert_param(IS_ADC_THRESHOLD(HighThreshold));
//  417   assert_param(IS_ADC_THRESHOLD(LowThreshold));
//  418 
//  419   /*Reset the CHSEL bits */
//  420   ADCx->CR3 &= ((uint8_t)~ADC_CR3_CHSEL);
        LDW       X, S:?w1
        ADDW      X, #0x2
        LD        A, (X)
        AND       A, #0xe0
        LDW       X, S:?w1
        ADDW      X, #0x2
        LD        (X), A
//  421 
//  422   /* Select the channel to be checked by the Analog watchdog.*/
//  423   ADCx->CR3 |= (uint8_t)ADC_AnalogWatchdogSelection;
        LDW       X, S:?w1
        ADDW      X, #0x2
        LD        A, S:?b4
        OR        A, (X)
        LDW       X, S:?w1
        ADDW      X, #0x2
        LD        (X), A
//  424 
//  425   /* Set the ADC high threshold */
//  426   ADCx->HTRH = (uint8_t)(HighThreshold >> 8);
        LDW       X, Y
        CLR       A
        RRWA      X, A
        LD        A, XL
        LDW       X, S:?w1
        ADDW      X, #0x6
        LD        (X), A
//  427   ADCx->HTRL = (uint8_t)(HighThreshold);
        LDW       X, S:?w1
        ADDW      X, #0x7
        LD        A, YL
        LD        (X), A
//  428 
//  429   /* Set the ADC low threshold */
//  430   ADCx->LTRH = (uint8_t)(LowThreshold >> 8);
        LDW       X, S:?w0
        CLR       A
        RRWA      X, A
        LD        A, XL
        LDW       X, S:?w1
        ADDW      X, #0x8
        LD        (X), A
//  431   ADCx->LTRL = (uint8_t)LowThreshold;
        LDW       X, S:?w1
        ADDW      X, #0x9
        LD        A, S:?b1
        LD        (X), A
//  432 }
        RET
//  433 
//  434  /**
//  435   * @}
//  436   */
//  437 
//  438 /** @defgroup ADC_Group3 Temperature Sensor & Vrefint (Voltage Reference 
//  439  *            internal) management functions
//  440  *  @brief   Temperature Sensor & Vrefint (Voltage Reference internal) 
//  441  *            management functions 
//  442  *
//  443 @verbatim   
//  444  ===============================================================================
//  445   Temperature Sensor & Vrefint (Voltage Reference internal) management functions
//  446  ===============================================================================  
//  447 
//  448   This section provides functions allowing to enable/ disable the internal 
//  449   connections between the ADC and the Temperature Sensor and the Vrefint source.
//  450      
//  451   A typical configuration to get the Temperature sensor or/and Vrefint channels 
//  452   voltages is done following these steps :
//  453    1. Enable the internal connection of Temperature sensor or/and Vrefint sources 
//  454       with the ADC channels: 
//  455       - for the Temperature sensor using ADC_TempSensorCmd() function.
//  456       - for the Internal Voltage reference using ADC_VrefintCmd() function. 
//  457    2. Enable the ADC_Channel_TempSensor and/or ADC_Channel_Vrefint channels 
//  458       using ADC_ChannelCmd()function. 
//  459    3. Get the voltage values, using ADC_GetConversionValue().
//  460  
//  461 @endverbatim
//  462   * @{
//  463   */
//  464   
//  465 /**
//  466   * @brief  Enables or disables the Temperature sensor internal reference.
//  467   * @param  NewState : new state of the Temperature sensor internal reference.
//  468     *         This parameter can be: ENABLE or DISABLE.
//  469   * @retval None
//  470   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  471 void ADC_TempSensorCmd(FunctionalState NewState)
//  472 {
//  473   /* Check the parameters */
//  474   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  475 
//  476   if (NewState != DISABLE)
ADC_TempSensorCmd:
        TNZ       A
        JREQ      L:??ADC_TempSensorCmd_0
//  477   {
//  478     /*Enable the Temperature sensor internal reference.*/
//  479     ADC1->TRIGR[0] |= (uint8_t)(ADC_TRIGR1_TSON);
        BSET      L:0x534e, #0x5
        RET
//  480   }
//  481   else
//  482   {
//  483     /*Disable the Temperature sensor internal reference.*/
//  484     ADC1->TRIGR[0] &= (uint8_t)(~ADC_TRIGR1_TSON);
??ADC_TempSensorCmd_0:
        BRES      L:0x534e, #0x5
//  485   }
//  486 }
        RET
//  487 
//  488 /**
//  489   * @brief  Enables or disables the Internal Voltage reference.
//  490   * @param  NewState : new state of the Internal Voltage reference.
//  491     *         This parameter can be: ENABLE or DISABLE.
//  492   * @retval None
//  493   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  494 void ADC_VrefintCmd(FunctionalState NewState)
//  495 {
//  496   /* Check the parameters */
//  497   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  498 
//  499   if (NewState != DISABLE)
ADC_VrefintCmd:
        TNZ       A
        JREQ      L:??ADC_VrefintCmd_0
//  500   {
//  501     /* Enable the Internal Voltage reference.*/
//  502     ADC1->TRIGR[0] |= (uint8_t)(ADC_TRIGR1_VREFINTON);
        BSET      L:0x534e, #0x4
        RET
//  503   }
//  504   else
//  505   {
//  506     /* Disable the Internal Voltage reference.*/
//  507     ADC1->TRIGR[0] &= (uint8_t)(~ADC_TRIGR1_VREFINTON);
??ADC_VrefintCmd_0:
        BRES      L:0x534e, #0x4
//  508   }
//  509 }
        RET
//  510 
//  511  /**
//  512   * @}
//  513   */
//  514 /** @defgroup ADC_Group4 Channels Configuration functions
//  515  *  @brief   Channels Configuration functions
//  516  *
//  517 @verbatim    
//  518  ===============================================================================
//  519                       Channels Configuration functions
//  520  ===============================================================================  
//  521   This section provides functions allowing to:
//  522    - Enable or disable the ADC channel using ADC_ChannelCmd() function,
//  523    - Configure the channels sampling times using ADC_SamplingTimeConfig() 
//  524      function.
//  525      Note: there are 2 sampling times configuration values : 
//  526             - 1st Group value : for channels 0..23  
//  527             - 2nd Group value : for channels 24..27 (depending on the MCU 
//  528               package density) and Temperature Sensor and Vrefint channels. 
//  529    - Configure the channels Schmitt Trigger for each channel using 
//  530      ADC_SchmittTriggerConfig() function.
//  531    - Get the current ADC conversion value.
//  532    
//  533  @endverbatim
//  534   * @{
//  535   */
//  536     
//  537 /**
//  538   * @brief  Enables or disables the selected ADC channel(s).
//  539   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  540   * @param  ADC_Channels: specifies the ADC channels to be initialized
//  541   *          This parameter can be one of the following values:
//  542   *            @arg ADC_Channel_0: Channel 0
//  543   *            @arg ADC_Channel_1: Channel 1
//  544   *            @arg ADC_Channel_2: Channel 2
//  545   *            @arg ADC_Channel_3: Channel 3
//  546   *            @arg ADC_Channel_4: Channel 4
//  547   *            @arg ADC_Channel_5: Channel 5
//  548   *            @arg ADC_Channel_6: Channel 6
//  549   *            @arg ADC_Channel_7: Channel 7
//  550   *            @arg ADC_Channel_8: Channel 8
//  551   *            @arg ADC_Channel_9: Channel 9
//  552   *            @arg ADC_Channel_10: Channel 10
//  553   *            @arg ADC_Channel_11: Channel 11
//  554   *            @arg ADC_Channel_12: Channel 12
//  555   *            @arg ADC_Channel_13: Channel 13
//  556   *            @arg ADC_Channel_14: Channel 14
//  557   *            @arg ADC_Channel_15: Channel 15
//  558   *            @arg ADC_Channel_16: Channel 16
//  559   *            @arg ADC_Channel_17: Channel 17
//  560   *            @arg ADC_Channel_18: Channel 18
//  561   *            @arg ADC_Channel_19: Channel 19
//  562   *            @arg ADC_Channel_20: Channel 20
//  563   *            @arg ADC_Channel_21: Channel 21
//  564   *            @arg ADC_Channel_22: Channel 22
//  565   *            @arg ADC_Channel_23: Channel 23
//  566   *            @arg ADC_Channel_24: Channel 24
//  567   *            @arg ADC_Channel_25: Channel 25
//  568   *            @arg ADC_Channel_26: Channel 26
//  569   *            @arg ADC_Channel_27: Channel 27
//  570   *            @arg ADC_Channel_Vrefint: Vrefint Channel
//  571   *            @arg ADC_Channel_TempSensor: Temperature sensor Channel
//  572   *            @arg ADC_Channel_00To07: select from channel00 to channel07
//  573   *            @arg ADC_Channel_08To15: select from channel08 to channel15
//  574   *            @arg ADC_Channel_16To23: select from channel16 to channel23
//  575   *            @arg ADC_Channel_24To27: select from channel24 to channel27
//  576   * @param  NewState : new state of the specified ADC channel(s).
//  577     *         This parameter can be: ENABLE or DISABLE.
//  578   * @retval None
//  579   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  580 void ADC_ChannelCmd(ADC_TypeDef* ADCx, ADC_Channel_TypeDef ADC_Channels, FunctionalState NewState)
//  581 {
ADC_ChannelCmd:
        LDW       S:?w1, X
        LD        S:?b0, A
//  582   uint8_t regindex = 0;
        CLR       S:?b1
//  583   /* Check the parameters */
//  584   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  585 
//  586   regindex = (uint8_t)((uint16_t)ADC_Channels >> 8);
        LDW       X, Y
        CLR       A
        RRWA      X, A
        LD        A, XL
        LD        S:?b1, A
//  587 
//  588   if (NewState != DISABLE)
        TNZ       S:?b0
        JREQ      L:??ADC_ChannelCmd_0
//  589   {
//  590     /* Enable the selected ADC channel(s). */
//  591     ADCx->SQR[regindex] |= (uint8_t)(ADC_Channels);
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xa
        LD        A, YL
        OR        A, (X)
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xa
        LD        (X), A
        RET
//  592   }
//  593   else
//  594   {
//  595     /* Disable the selected ADC channel(s). */
//  596     ADCx->SQR[regindex] &= (uint8_t)(~(uint8_t)(ADC_Channels));
??ADC_ChannelCmd_0:
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xa
        LD        A, YL
        CPL       A
        AND       A, (X)
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xa
        LD        (X), A
//  597   }
//  598 }
        RET
//  599 
//  600 /**
//  601   * @brief  Configures the sampling time for the selected ADC channel group.
//  602   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  603   * @param  ADC_GroupChannels : ADC channel group to configure.
//  604   *          This parameter can be one of the following values:
//  605   *            @arg ADC_Group_SlowChannels: Slow Channels group
//  606   *            @arg ADC_Group_FastChannels: Fast Channels group  
//  607   * @note   The channels of 1st ADC Group can be channels 0..23  
//  608   * @note   The channels of 2nd ADC Group can be channels 24..27 (depending on the MCU 
//  609   *         package density) and Temperature Sensor and Vrefint channels.  
//  610   * @param  ADC_SamplingTime : Specifies the sample time value
//  611   *          This parameter can be one of the following values:
//  612   *            @arg ADC_SamplingTime_4Cycles: Sampling Time Cycles is 4
//  613   *            @arg ADC_SamplingTime_9Cycles: Sampling Time Cycles is 9
//  614   *            @arg ADC_SamplingTime_16Cycles: Sampling Time Cycles is 16
//  615   *            @arg ADC_SamplingTime_24Cycles: Sampling Time Cycles is 24
//  616   *            @arg ADC_SamplingTime_48Cycles: Sampling Time Cycles is 48
//  617   *            @arg ADC_SamplingTime_96Cycles: Sampling Time Cycles is 96
//  618   *            @arg ADC_SamplingTime_192Cycles: Sampling Time Cycles is 192
//  619   *            @arg ADC_SamplingTime_384Cycles: Sampling Time Cycles is 384
//  620   * @retval None
//  621   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  622 void ADC_SamplingTimeConfig(ADC_TypeDef* ADCx,
//  623                             ADC_Group_TypeDef ADC_GroupChannels,
//  624                             ADC_SamplingTime_TypeDef ADC_SamplingTime)
//  625 {
//  626   /* Check the parameters */
//  627   assert_param(IS_ADC_GROUP(ADC_GroupChannels));
//  628   assert_param(IS_ADC_SAMPLING_TIME_CYCLES(ADC_SamplingTime));
//  629 
//  630   if ( ADC_GroupChannels != ADC_Group_SlowChannels)
ADC_SamplingTimeConfig:
        TNZ       A
        JREQ      L:??ADC_SamplingTimeConfig_0
//  631   {
//  632     /* Configures the sampling time for the Fast ADC channel group. */
//  633     ADCx->CR3 &= (uint8_t)~ADC_CR3_SMPT2;
        LDW       Y, X
        ADDW      Y, #0x2
        LD        A, (Y)
        AND       A, #0x1f
        LDW       Y, X
        ADDW      Y, #0x2
        LD        (Y), A
//  634     ADCx->CR3 |= (uint8_t)(ADC_SamplingTime << 5);
        LDW       Y, X
        ADDW      Y, #0x2
        LD        A, S:?b0
        CALL      L:?sll8_a_a_5
        OR        A, (Y)
        ADDW      X, #0x2
        LD        (X), A
        RET
//  635   }
//  636   else
//  637   {
//  638     /* Configures the sampling time for the Slow ADC channel group. */
//  639     ADCx->CR2 &= (uint8_t)~ADC_CR2_SMPT1;
??ADC_SamplingTimeConfig_0:
        LDW       Y, X
        INCW      Y
        LD        A, (Y)
        AND       A, #0xf8
        LDW       Y, X
        INCW      Y
        LD        (Y), A
//  640     ADCx->CR2 |= (uint8_t)ADC_SamplingTime;
        LDW       Y, X
        INCW      Y
        LD        A, S:?b0
        OR        A, (Y)
        INCW      X
        LD        (X), A
//  641   }
//  642 }
        RET
//  643 
//  644 /**
//  645   * @brief  Configures the status of the Schmitt Trigger for the selected ADC 
//  646   *         channel(s).
//  647   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  648   * @param  ADC_Channels: specifies the ADC channels to be initialized,
//  649   *          This parameter can be one of the following values:
//  650   *            @arg ADC_Channel_0: Channel 0
//  651   *            @arg ADC_Channel_1: Channel 1
//  652   *            @arg ADC_Channel_2: Channel 2
//  653   *            @arg ADC_Channel_3: Channel 3
//  654   *            @arg ADC_Channel_4: Channel 4
//  655   *            @arg ADC_Channel_5: Channel 5
//  656   *            @arg ADC_Channel_6: Channel 6
//  657   *            @arg ADC_Channel_7: Channel 7
//  658   *            @arg ADC_Channel_8: Channel 8
//  659   *            @arg ADC_Channel_9: Channel 9
//  660   *            @arg ADC_Channel_10: Channel 10
//  661   *            @arg ADC_Channel_11: Channel 11
//  662   *            @arg ADC_Channel_12: Channel 12
//  663   *            @arg ADC_Channel_13: Channel 13
//  664   *            @arg ADC_Channel_14: Channel 14
//  665   *            @arg ADC_Channel_15: Channel 15
//  666   *            @arg ADC_Channel_16: Channel 16
//  667   *            @arg ADC_Channel_17: Channel 17
//  668   *            @arg ADC_Channel_18: Channel 18
//  669   *            @arg ADC_Channel_19: Channel 19
//  670   *            @arg ADC_Channel_20: Channel 20
//  671   *            @arg ADC_Channel_21: Channel 21
//  672   *            @arg ADC_Channel_22: Channel 22
//  673   *            @arg ADC_Channel_23: Channel 23
//  674   *            @arg ADC_Channel_24: Channel 24
//  675   *            @arg ADC_Channel_25: Channel 25
//  676   *            @arg ADC_Channel_26: Channel 26
//  677   *            @arg ADC_Channel_27: Channel 27
//  678   *            @arg ADC_Channel_Vrefint: Vrefint Channel
//  679   *            @arg ADC_Channel_TempSensor: Temperature sensor Channel
//  680   *            @arg ADC_Channel_00To07: select from channel00 to channel07
//  681   *            @arg ADC_Channel_08To15: select from channel08 to channel15
//  682   *            @arg ADC_Channel_16To23: select from channel16 to channel23
//  683   *            @arg ADC_Channel_24To27: select from channel24 to channel27
//  684   * @param  NewState : new state of the Schmitt Trigger
//  685     *         This parameter can be: ENABLE or DISABLE.
//  686   * @retval None
//  687   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  688 void ADC_SchmittTriggerConfig(ADC_TypeDef* ADCx, ADC_Channel_TypeDef ADC_Channels,
//  689                               FunctionalState NewState)
//  690 {
ADC_SchmittTriggerConfig:
        LDW       S:?w1, X
        LD        S:?b0, A
//  691   uint8_t regindex = 0;
        CLR       S:?b1
//  692   /* Check the parameters */
//  693   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  694 
//  695   regindex = (uint8_t)((uint16_t)ADC_Channels >> 8);
        LDW       X, Y
        CLR       A
        RRWA      X, A
        LD        A, XL
        LD        S:?b1, A
//  696 
//  697   if (NewState != DISABLE)
        TNZ       S:?b0
        JREQ      L:??ADC_SchmittTriggerConfig_0
//  698   {
//  699     /* Enable the Schmitt Trigger for the selected ADC channel(s).*/
//  700     ADCx->TRIGR[regindex] &= (uint8_t)(~(uint8_t)ADC_Channels);
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xe
        LD        A, YL
        CPL       A
        AND       A, (X)
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xe
        LD        (X), A
        RET
//  701   }
//  702   else
//  703   {
//  704     /* Disable the Schmitt Trigger for the selected ADC channel(s).*/
//  705     ADCx->TRIGR[regindex] |= (uint8_t)(ADC_Channels);
??ADC_SchmittTriggerConfig_0:
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xe
        LD        A, YL
        OR        A, (X)
        CLRW      X
        EXG       A, XL
        LD        A, S:?b1
        EXG       A, XL
        ADDW      X, S:?w1
        ADDW      X, #0xe
        LD        (X), A
//  706   }
//  707 }
        RET
//  708 
//  709 /**
//  710   * @brief  Returns the last ADC converted data.
//  711   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  712   * @retval The Data conversion value.
//  713   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  714 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
//  715 {
ADC_GetConversionValue:
        LDW       S:?w0, X
//  716   uint16_t tmpreg = 0;
        CLRW      X
//  717 
//  718   /* Get last ADC converted data.*/
//  719   tmpreg = (uint16_t)(ADCx->DRH);
        LDW       Y, S:?w0
        ADDW      Y, #0x4
        LD        A, (Y)
        CLRW      Y
        LD        YL, A
        LDW       X, Y
//  720   tmpreg = (uint16_t)((uint16_t)((uint16_t)tmpreg << 8) | ADCx->DRL);
        LDW       Y, S:?w0
        ADDW      Y, #0x5
        LD        A, (Y)
        CLRW      Y
        LD        YL, A
        CLR       A
        RLWA      X, A
        LDW       S:?w0, Y
        RRWA      X, A
        OR        A, S:?b1
        RRWA      X, A
        OR        A, S:?b0
        RRWA      X, A
//  721 
//  722   /* Return the selected ADC conversion value */
//  723   return (uint16_t)(tmpreg) ;
        RET
//  724 }
//  725 
//  726  /**
//  727   * @}
//  728   */
//  729 
//  730 /** @defgroup ADC_Group5 ADC Channels DMA Configuration function
//  731  *  @brief   ADC Channels DMA Configuration function 
//  732  *
//  733 @verbatim   
//  734  ===============================================================================
//  735                    ADC Channels DMA Configuration function
//  736  ===============================================================================  
//  737 
//  738   This section provides a function allowing to configure the DMA for ADC 
//  739   channel.
//  740   Since converted channel values are stored into a unique data register, 
//  741   it is useful to use DMA for conversion of more than one channel. This 
//  742   avoids the loss of the data already stored in the ADC Data register. 
//  743   
//  744   When the DMA mode is enabled (using the ADC_DMACmd() function), after each
//  745   conversion of a channel, a DMA request is generated.
//  746 
//  747 @endverbatim
//  748   * @{
//  749   */
//  750 /**
//  751   * @brief  Enables or disables the specified ADC DMA request.
//  752   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  753   * @param  NewState : new state of the specified ADC DMA transfer.
//  754     *         This parameter can be: ENABLE or DISABLE.
//  755   * @retval None
//  756   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  757 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
//  758 {
//  759   /* Check the parameters */
//  760   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  761 
//  762   if (NewState != DISABLE)
ADC_DMACmd:
        TNZ       A
        JREQ      L:??ADC_DMACmd_0
//  763   {
//  764     /* Enable the specified ADC DMA request */
//  765     ADCx->SQR[0] &= (uint8_t)~ADC_SQR1_DMAOFF;
        LDW       Y, X
        ADDW      Y, #0xa
        LD        A, (Y)
        AND       A, #0x7f
        ADDW      X, #0xa
        LD        (X), A
        RET
//  766   }
//  767   else
//  768   {
//  769     /* Disable the specified ADC DMA request */
//  770     ADCx->SQR[0] |= ADC_SQR1_DMAOFF;
??ADC_DMACmd_0:
        LDW       Y, X
        ADDW      Y, #0xa
        LD        A, (Y)
        OR        A, #0x80
        ADDW      X, #0xa
        LD        (X), A
//  771   }
//  772 }
        RET
//  773 
//  774 /**
//  775   * @}
//  776   */
//  777 
//  778 /** @defgroup ADC_Group6 Interrupts and flags management functions
//  779  *  @brief   Interrupts and flags management functions
//  780  *
//  781 @verbatim   
//  782  ===============================================================================
//  783                    Interrupts and flags management functions
//  784  ===============================================================================  
//  785 
//  786   This section provides functions allowing to configure the ADC Interrupts and 
//  787   get the status and clear flags and Interrupts pending bits.
//  788   
//  789   The ADC provides 3 Interrupt sources and 3 Flags:
//  790   
//  791   Flags :
//  792   ---------- 
//  793      1. ADC_FLAG_OVR : Overrun detection when ADC channel converted data is lost
//  794 
//  795      2. ADC_FLAG_EOC : End of conversion - to indicate the end of a regular 
//  796                   CHANNEL conversion or a GROUP conversions, depending of the 
//  797                   ADC Continuous Conversion Mode (Continuous or Single 
//  798                   conversion) and of the DMA usage.
//  799                   Note : if DMA is used, EOC occurs at the end of the sequence 
//  800                          conversion, else it occurs after each conversion
//  801      3. ADC_FLAG_AWD: to indicate if the converted voltage crosses the 
//  802                 programmed Analog watchdog thresholds values.
//  803 
//  804      
//  805   Interrupts :
//  806   ------------
//  807      1. ADC_IT_OVR : specifies the interrupt source for the Overrun detection event.
//  808      2. ADC_IT_EOC : specifies the interrupt source for the End of conversion event.
//  809      3. ADC_IT_AWD : specifies the interrupt source for the Analog watchdog event.
//  810 
//  811 @endverbatim
//  812   * @{
//  813   */ 
//  814 
//  815 /**
//  816   * @brief  Enables or disables the specified ADC interrupts.
//  817   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  818   * @param  ADC_IT : specifies the ADC interrupt sources to be enabled or 
//  819   *         disabled. 
//  820   *          This parameter can be one of the following values:
//  821   *            @arg ADC_IT_EOC: End of Conversion Interrupt
//  822   *            @arg ADC_IT_AWD: Analog WatchDog Interrupt
//  823   *            @arg ADC_IT_OVER: Over Run Interrupt
//  824   * @param  NewState : new state of the specified ADC interrupts.
//  825     *         This parameter can be: ENABLE or DISABLE.
//  826   * @retval None
//  827   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  828 void ADC_ITConfig(ADC_TypeDef* ADCx, ADC_IT_TypeDef ADC_IT, FunctionalState NewState)
//  829 {
//  830   /* Check the parameters */
//  831   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  832   assert_param(IS_ADC_IT(ADC_IT));
//  833 
//  834   if (NewState != DISABLE)
ADC_ITConfig:
        TNZ       S:?b0
        JREQ      L:??ADC_ITConfig_0
//  835   {
//  836     /* Enable the selected ADC interrupts */
//  837     ADCx->CR1 |= (uint8_t) ADC_IT;
        OR        A, (X)
        LD        (X), A
        RET
//  838   }
//  839   else
//  840   {
//  841     /* Disable the selected ADC interrupts */
//  842     ADCx->CR1 &= (uint8_t)(~ADC_IT);
??ADC_ITConfig_0:
        CPL       A
        AND       A, (X)
        LD        (X), A
//  843   }
//  844 }
        RET
//  845 
//  846 /**
//  847   * @brief  Checks whether the specified ADC flag is set or not.
//  848   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  849   * @param  ADC_FLAG: specifies the flag to check.
//  850   *          This parameter can be one of the following values:
//  851   *            @arg ADC_FLAG_EOC: End of Conversion flag
//  852   *            @arg ADC_FLAG_AWD: Analog WatchDog flag
//  853   *            @arg ADC_FLAG_OVER: Over Run flag    
//  854   * @retval The new state of ADC_FLAG (SET or RESET).
//  855   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  856 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, ADC_FLAG_TypeDef ADC_FLAG)
//  857 {
//  858   FlagStatus flagstatus = RESET;
ADC_GetFlagStatus:
        CLR       S:?b0
//  859 
//  860   /* Check the parameters */
//  861   assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
//  862 
//  863   /* Check the status of the specified ADC flag */
//  864   if ((ADCx->SR & ADC_FLAG) != (uint8_t)RESET)
        ADDW      X, #0x3
        AND       A, (X)
        CP        A, #0x0
        JREQ      L:??ADC_GetFlagStatus_0
//  865   {
//  866     /* ADC_FLAG is set */
//  867     flagstatus = SET;
        MOV       S:?b0, #0x1
        JRA       L:??ADC_GetFlagStatus_1
//  868   }
//  869   else
//  870   {
//  871     /* ADC_FLAG is reset */
//  872     flagstatus = RESET;
??ADC_GetFlagStatus_0:
        CLR       S:?b0
//  873   }
//  874 
//  875   /* Return the ADC_FLAG status */
//  876   return  flagstatus;
??ADC_GetFlagStatus_1:
        LD        A, S:?b0
        RET
//  877 }
//  878 
//  879 /**
//  880   * @brief  Clears the ADC's pending flags.
//  881   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  882   * @param  ADC_FLAG: specifies the flag to clear.
//  883   *          This parameter can be one of the following values:
//  884   *            @arg ADC_FLAG_EOC: End of Conversion flag
//  885   *            @arg ADC_FLAG_AWD: Analog WatchDog flag
//  886   *            @arg ADC_FLAG_OVER: Over Run flag 
//  887   * @retval None
//  888   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  889 void ADC_ClearFlag(ADC_TypeDef* ADCx,
//  890                    ADC_FLAG_TypeDef ADC_FLAG)
//  891 {
//  892   /* Check the parameters */
//  893   assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
//  894 
//  895   /* Clear the selected ADC flags */
//  896   ADCx->SR = (uint8_t)~ADC_FLAG;
ADC_ClearFlag:
        ADDW      X, #0x3
        CPL       A
        LD        (X), A
//  897 }
        RET
//  898 
//  899 /**
//  900   * @brief  Checks whether the specified ADC interrupt has occurred or not.
//  901   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  902   * @param  ADC_IT: specifies the ADC interrupt source to check.
//  903   *          This parameter can be one of the following values:
//  904   *            @arg ADC_IT_EOC: End of Conversion Interrupt
//  905   *            @arg ADC_IT_AWD: Analog WatchDog Interrupt
//  906   *            @arg ADC_IT_OVER: Over Run Interrupt
//  907   * @retval Status of ADC_IT (SET or RESET).
//  908   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  909 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx,
//  910                          ADC_IT_TypeDef ADC_IT)
//  911 {
ADC_GetITStatus:
        LD        S:?b3, A
//  912   ITStatus itstatus = RESET;
        CLR       S:?b0
//  913   uint8_t itmask = 0, enablestatus = 0;
        CLR       S:?b2
        CLR       S:?b1
//  914 
//  915   /* Check the parameters */
//  916   assert_param(IS_ADC_GET_IT(ADC_IT));
//  917 
//  918   /* Get the ADC IT index */
//  919   itmask = (uint8_t)(ADC_IT >> 3);
        LD        A, S:?b3
        SRL       A
        SRL       A
        SRL       A
        LD        S:?b2, A
//  920   itmask =  (uint8_t)((uint8_t)((uint8_t)(itmask & (uint8_t)0x10) >> 2) | \ 
//  921                                 (uint8_t)(itmask & (uint8_t)0x03));
        LD        A, S:?b2
        AND       A, #0x10
        SRL       A
        SRL       A
        LD        S:?b4, A
        LD        A, S:?b2
        AND       A, #0x3
        OR        A, S:?b4
        LD        S:?b2, A
//  922 
//  923   /* Get the ADC_IT enable bit status */
//  924   enablestatus = (uint8_t)(ADCx->CR1 & (uint8_t)ADC_IT) ;
        LD        A, S:?b3
        AND       A, (X)
        LD        S:?b1, A
//  925 
//  926   /* Check the status of the specified ADC interrupt */
//  927   if (((ADCx->SR & itmask) != (uint8_t)RESET) && enablestatus)
        ADDW      X, #0x3
        LD        A, S:?b2
        AND       A, (X)
        CP        A, #0x0
        JREQ      L:??ADC_GetITStatus_0
        TNZ       S:?b1
        JREQ      L:??ADC_GetITStatus_0
//  928   {
//  929     /* ADC_IT is set */
//  930     itstatus = SET;
        MOV       S:?b0, #0x1
        JRA       L:??ADC_GetITStatus_1
//  931   }
//  932   else
//  933   {
//  934     /* ADC_IT is reset */
//  935     itstatus = RESET;
??ADC_GetITStatus_0:
        CLR       S:?b0
//  936   }
//  937 
//  938   /* Return the ADC_IT status */
//  939   return  itstatus;
??ADC_GetITStatus_1:
        LD        A, S:?b0
        RET
//  940 }
//  941 
//  942 /**
//  943   * @brief  Clears the ADC’s interrupt pending bits.
//  944   * @param  ADCx where x can be 1 to select the specified ADC peripheral.
//  945   * @param  ADC_IT: specifies the ADC interrupt pending bit to clear.
//  946   *          This parameter can be one of the following values:
//  947   *            @arg ADC_IT_EOC: End of Conversion Interrupt
//  948   *            @arg ADC_IT_AWD: Analog WatchDog Interrupt
//  949   *            @arg ADC_IT_OVER: Over Run Interrupt
//  950   * @retval None
//  951   */

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  952 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx,
//  953                            ADC_IT_TypeDef ADC_IT)
//  954 {
//  955   uint8_t itmask = 0;
ADC_ClearITPendingBit:
        CLR       S:?b0
//  956 
//  957   /* Check the parameters */
//  958   assert_param(IS_ADC_IT(ADC_IT));
//  959 
//  960   /* Get the ADC IT index */
//  961   itmask = (uint8_t)(ADC_IT >> 3);
        SRL       A
        SRL       A
        SRL       A
        LD        S:?b0, A
//  962   itmask =  (uint8_t)((uint8_t)(((uint8_t)(itmask & (uint8_t)0x10)) >> 2) | \ 
//  963                                  (uint8_t)(itmask & (uint8_t)0x03));
        LD        A, S:?b0
        AND       A, #0x10
        SRL       A
        SRL       A
        LD        S:?b1, A
        LD        A, S:?b0
        AND       A, #0x3
        OR        A, S:?b1
        LD        S:?b0, A
//  964 
//  965   /* Clear the selected ADC interrupt pending bits */
//  966   ADCx->SR = (uint8_t)~itmask;
        ADDW      X, #0x3
        CPL       S:?b0
        LD        A, S:?b0
        LD        (X), A
//  967 }
        RET

        SECTION VREGS:DATA:REORDER:NOROOT(0)

        END
//  968 
//  969 /**
//  970   * @}
//  971   */ 
//  972 
//  973 /**
//  974   * @}
//  975   */
//  976 
//  977 /**
//  978   * @}
//  979   */ 
//  980 
//  981 /**
//  982   * @}
//  983   */ 
//  984 
//  985 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
// 
// 812 bytes in section .near_func.text
// 
// 812 bytes of CODE memory
//
//Errors: none
//Warnings: none
