Subversion Repositories DashDisplay

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 5
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_adc.c
3
  * @file    stm32f1xx_hal_adc.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.0.1
5
  * @version V1.0.4
6
  * @date    31-July-2015
6
  * @date    29-April-2016
7
  * @brief   This file provides firmware functions to manage the following
7
  * @brief   This file provides firmware functions to manage the following
8
  *          functionalities of the Analog to Digital Convertor (ADC)
8
  *          functionalities of the Analog to Digital Convertor (ADC)
9
  *          peripheral:
9
  *          peripheral:
10
  *           + Initialization and de-initialization functions
10
  *           + Initialization and de-initialization functions
11
  *             ++ Initialization and Configuration of ADC
11
  *             ++ Initialization and Configuration of ADC
Line 245... Line 245...
245
 
245
 
246
    @endverbatim
246
    @endverbatim
247
  ******************************************************************************
247
  ******************************************************************************
248
  * @attention
248
  * @attention
249
  *
249
  *
250
  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
250
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
251
  *
251
  *
252
  * Redistribution and use in source and binary forms, with or without modification,
252
  * Redistribution and use in source and binary forms, with or without modification,
253
  * are permitted provided that the following conditions are met:
253
  * are permitted provided that the following conditions are met:
254
  *   1. Redistributions of source code must retain the above copyright notice,
254
  *   1. Redistributions of source code must retain the above copyright notice,
255
  *      this list of conditions and the following disclaimer.
255
  *      this list of conditions and the following disclaimer.
Line 393... Line 393...
393
 
393
 
394
  if(hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
394
  if(hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
395
  {
395
  {
396
    assert_param(IS_ADC_REGULAR_NB_CONV(hadc->Init.NbrOfConversion));
396
    assert_param(IS_ADC_REGULAR_NB_CONV(hadc->Init.NbrOfConversion));
397
    assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DiscontinuousConvMode));
397
    assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DiscontinuousConvMode));
-
 
398
    if(hadc->Init.DiscontinuousConvMode != DISABLE)
-
 
399
    {
398
    assert_param(IS_ADC_REGULAR_DISCONT_NUMBER(hadc->Init.NbrOfDiscConversion));
400
      assert_param(IS_ADC_REGULAR_DISCONT_NUMBER(hadc->Init.NbrOfDiscConversion));
-
 
401
    }
399
  }
402
  }
400
 
403
 
401
  /* As prerequisite, into HAL_ADC_MspInit(), ADC clock must be configured    */
404
  /* As prerequisite, into HAL_ADC_MspInit(), ADC clock must be configured    */
402
  /* at RCC top level.                                                        */
405
  /* at RCC top level.                                                        */
403
  /* Refer to header of this file for more details on clock enabling          */
406
  /* Refer to header of this file for more details on clock enabling          */
Line 456... Line 459...
456
    /*  - discontinuous mode disable/enable                                   */
459
    /*  - discontinuous mode disable/enable                                   */
457
    /*  - discontinuous mode number of conversions                            */
460
    /*  - discontinuous mode number of conversions                            */
458
    tmp_cr1 |= (ADC_CR1_SCAN_SET(hadc->Init.ScanConvMode));
461
    tmp_cr1 |= (ADC_CR1_SCAN_SET(hadc->Init.ScanConvMode));
459
   
462
   
460
    /* Enable discontinuous mode only if continuous mode is disabled */
463
    /* Enable discontinuous mode only if continuous mode is disabled */
-
 
464
    /* Note: If parameter "Init.ScanConvMode" is set to disable, parameter    */
-
 
465
    /*       discontinuous is set anyway, but will have no effect on ADC HW.  */
461
    if (hadc->Init.DiscontinuousConvMode == ENABLE)
466
    if (hadc->Init.DiscontinuousConvMode == ENABLE)
462
    {
467
    {
463
      if (hadc->Init.ContinuousConvMode == DISABLE)
468
      if (hadc->Init.ContinuousConvMode == DISABLE)
464
      {
469
      {
465
        /* Enable the selected ADC regular discontinuous mode */
470
        /* Enable the selected ADC regular discontinuous mode */
Line 502... Line 507...
502
    /*   Note: Scan mode is present by hardware on this device and, if        */
507
    /*   Note: Scan mode is present by hardware on this device and, if        */
503
    /*   disabled, discards automatically nb of conversions. Anyway, nb of    */
508
    /*   disabled, discards automatically nb of conversions. Anyway, nb of    */
504
    /*   conversions is forced to 0x00 for alignment over all STM32 devices.  */
509
    /*   conversions is forced to 0x00 for alignment over all STM32 devices.  */
505
    /* - if scan mode is enabled, regular channels sequence length is set to  */
510
    /* - if scan mode is enabled, regular channels sequence length is set to  */
506
    /*   parameter "NbrOfConversion"                                          */
511
    /*   parameter "NbrOfConversion"                                          */
507
    if (hadc->Init.ScanConvMode == ADC_SCAN_ENABLE)
512
    if (ADC_CR1_SCAN_SET(hadc->Init.ScanConvMode) == ADC_SCAN_ENABLE)
508
    {
513
    {
509
      tmp_sqr1 = ADC_SQR1_L_SHIFT(hadc->Init.NbrOfConversion);
514
      tmp_sqr1 = ADC_SQR1_L_SHIFT(hadc->Init.NbrOfConversion);
510
    }
515
    }
511
     
516
     
512
    MODIFY_REG(hadc->Instance->SQR1,
517
    MODIFY_REG(hadc->Instance->SQR1,
Line 705... Line 710...
705
  * @param  hadc: ADC handle
710
  * @param  hadc: ADC handle
706
  * @retval None
711
  * @retval None
707
  */
712
  */
708
__weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
713
__weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
709
{
714
{
-
 
715
  /* Prevent unused argument(s) compilation warning */
-
 
716
  UNUSED(hadc);
710
  /* NOTE : This function should not be modified. When the callback is needed,
717
  /* NOTE : This function should not be modified. When the callback is needed,
711
            function HAL_ADC_MspInit must be implemented in the user file.
718
            function HAL_ADC_MspInit must be implemented in the user file.
712
   */
719
   */
713
}
720
}
714
 
721
 
Line 717... Line 724...
717
  * @param  hadc: ADC handle
724
  * @param  hadc: ADC handle
718
  * @retval None
725
  * @retval None
719
  */
726
  */
720
__weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
727
__weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
721
{
728
{
-
 
729
  /* Prevent unused argument(s) compilation warning */
-
 
730
  UNUSED(hadc);
722
  /* NOTE : This function should not be modified. When the callback is needed,
731
  /* NOTE : This function should not be modified. When the callback is needed,
723
            function HAL_ADC_MspDeInit must be implemented in the user file.
732
            function HAL_ADC_MspDeInit must be implemented in the user file.
724
   */
733
   */
725
}
734
}
726
 
735
 
Line 1052... Line 1061...
1052
  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1061
  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1053
  assert_param(IS_ADC_EVENT_TYPE(EventType));
1062
  assert_param(IS_ADC_EVENT_TYPE(EventType));
1054
 
1063
 
1055
  /* Get tick count */
1064
  /* Get tick count */
1056
  tickstart = HAL_GetTick();
1065
  tickstart = HAL_GetTick();
1057
     
1066
 
1058
  /* Check selected event flag */
1067
  /* Check selected event flag */
1059
  while(__HAL_ADC_GET_FLAG(hadc, EventType) == RESET)
1068
  while(__HAL_ADC_GET_FLAG(hadc, EventType) == RESET)
1060
  {
1069
  {
1061
    /* Check if timeout is disabled (set to infinite wait) */
1070
    /* Check if timeout is disabled (set to infinite wait) */
1062
    if(Timeout != HAL_MAX_DELAY)
1071
    if(Timeout != HAL_MAX_DELAY)
Line 1067... Line 1076...
1067
        SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
1076
        SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
1068
       
1077
       
1069
        /* Process unlocked */
1078
        /* Process unlocked */
1070
        __HAL_UNLOCK(hadc);
1079
        __HAL_UNLOCK(hadc);
1071
       
1080
       
1072
        return HAL_ERROR;
1081
        return HAL_TIMEOUT;
1073
      }
1082
      }
1074
    }
1083
    }
1075
  }
1084
  }
1076
 
1085
 
1077
  /* Analog watchdog (level out of window) event */
1086
  /* Analog watchdog (level out of window) event */
Line 1448... Line 1457...
1448
  return tmp_hal_status;
1457
  return tmp_hal_status;
1449
}
1458
}
1450
 
1459
 
1451
/**
1460
/**
1452
  * @brief  Get ADC regular group conversion result.
1461
  * @brief  Get ADC regular group conversion result.
1453
  * @note   Reading DR register automatically clears EOC (end of conversion of
1462
  * @note   Reading register DR automatically clears ADC flag EOC
-
 
1463
  *         (ADC group regular end of unitary conversion).
-
 
1464
  * @note   This function does not clear ADC flag EOS
-
 
1465
  *         (ADC group regular end of sequence conversion).
-
 
1466
  *         Occurrence of flag EOS rising:
-
 
1467
  *          - If sequencer is composed of 1 rank, flag EOS is equivalent
1454
  *         regular group) flag.
1468
  *            to flag EOC.
-
 
1469
  *          - If sequencer is composed of several ranks, during the scan
-
 
1470
  *            sequence flag EOC only is raised, at the end of the scan sequence
-
 
1471
  *            both flags EOC and EOS are raised.
-
 
1472
  *         To clear this flag, either use function:
-
 
1473
  *         in programming model IT: @ref HAL_ADC_IRQHandler(), in programming
-
 
1474
  *         model polling: @ref HAL_ADC_PollForConversion()
-
 
1475
  *         or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_EOS).
1455
  * @param  hadc: ADC handle
1476
  * @param  hadc: ADC handle
1456
  * @retval Converted value
1477
  * @retval ADC group regular conversion data
1457
  */
1478
  */
1458
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
1479
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
1459
{
1480
{
1460
  /* Check the parameters */
1481
  /* Check the parameters */
1461
  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1482
  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
Line 1587... Line 1608...
1587
  * @param  hadc: ADC handle
1608
  * @param  hadc: ADC handle
1588
  * @retval None
1609
  * @retval None
1589
  */
1610
  */
1590
__weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
1611
__weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
1591
{
1612
{
-
 
1613
  /* Prevent unused argument(s) compilation warning */
-
 
1614
  UNUSED(hadc);
1592
  /* NOTE : This function should not be modified. When the callback is needed,
1615
  /* NOTE : This function should not be modified. When the callback is needed,
1593
            function HAL_ADC_ConvCpltCallback must be implemented in the user file.
1616
            function HAL_ADC_ConvCpltCallback must be implemented in the user file.
1594
   */
1617
   */
1595
}
1618
}
1596
 
1619
 
Line 1599... Line 1622...
1599
  * @param  hadc: ADC handle
1622
  * @param  hadc: ADC handle
1600
  * @retval None
1623
  * @retval None
1601
  */
1624
  */
1602
__weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
1625
__weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
1603
{
1626
{
-
 
1627
  /* Prevent unused argument(s) compilation warning */
-
 
1628
  UNUSED(hadc);
1604
  /* NOTE : This function should not be modified. When the callback is needed,
1629
  /* NOTE : This function should not be modified. When the callback is needed,
1605
            function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
1630
            function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
1606
  */
1631
  */
1607
}
1632
}
1608
 
1633
 
Line 1611... Line 1636...
1611
  * @param  hadc: ADC handle
1636
  * @param  hadc: ADC handle
1612
  * @retval None
1637
  * @retval None
1613
  */
1638
  */
1614
__weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
1639
__weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
1615
{
1640
{
-
 
1641
  /* Prevent unused argument(s) compilation warning */
-
 
1642
  UNUSED(hadc);
1616
  /* NOTE : This function should not be modified. When the callback is needed,
1643
  /* NOTE : This function should not be modified. When the callback is needed,
1617
            function HAL_ADC_LevelOutOfWindowCallback must be implemented in the user file.
1644
            function HAL_ADC_LevelOutOfWindowCallback must be implemented in the user file.
1618
  */
1645
  */
1619
}
1646
}
1620
 
1647
 
Line 1624... Line 1651...
1624
  * @param  hadc: ADC handle
1651
  * @param  hadc: ADC handle
1625
  * @retval None
1652
  * @retval None
1626
  */
1653
  */
1627
__weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
1654
__weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
1628
{
1655
{
-
 
1656
  /* Prevent unused argument(s) compilation warning */
-
 
1657
  UNUSED(hadc);
1629
  /* NOTE : This function should not be modified. When the callback is needed,
1658
  /* NOTE : This function should not be modified. When the callback is needed,
1630
            function HAL_ADC_ErrorCallback must be implemented in the user file.
1659
            function HAL_ADC_ErrorCallback must be implemented in the user file.
1631
  */
1660
  */
1632
}
1661
}
1633
 
1662
 
Line 1766... Line 1795...
1766
  return tmp_hal_status;
1795
  return tmp_hal_status;
1767
}
1796
}
1768
 
1797
 
1769
/**
1798
/**
1770
  * @brief  Configures the analog watchdog.
1799
  * @brief  Configures the analog watchdog.
-
 
1800
  * @note   Analog watchdog thresholds can be modified while ADC conversion
-
 
1801
  *         is on going.
-
 
1802
  *         In this case, some constraints must be taken into account:
-
 
1803
  *         the programmed threshold values are effective from the next
-
 
1804
  *         ADC EOC (end of unitary conversion).
-
 
1805
  *         Considering that registers write delay may happen due to
-
 
1806
  *         bus activity, this might cause an uncertainty on the
-
 
1807
  *         effective timing of the new programmed threshold values.
1771
  * @param  hadc: ADC handle
1808
  * @param  hadc: ADC handle
1772
  * @param  AnalogWDGConfig: Structure of ADC analog watchdog configuration
1809
  * @param  AnalogWDGConfig: Structure of ADC analog watchdog configuration
1773
  * @retval HAL status
1810
  * @retval HAL status
1774
  */
1811
  */
1775
HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
1812
HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)