/* * @brief LPC13xx A/D conversion driver * * @note * Copyright(C) NXP Semiconductors, 2012 * All rights reserved. * * @par * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * LPC products. This software is supplied "AS IS" without any warranties of * any kind, and NXP Semiconductors and its licensor disclaim any and * all warranties, express or implied, including all implied warranties of * merchantability, fitness for a particular purpose and non-infringement of * intellectual property rights. NXP Semiconductors assumes no responsibility * or liability for the use of the software, conveys no license or rights under any * patent, copyright, mask work right, or any other intellectual property rights in * or to any products. NXP Semiconductors reserves the right to make changes * in the software without notification. NXP Semiconductors also makes no * representation or warranty that such application will be suitable for the * specified use without further testing or modification. * * @par * Permission to use, copy, modify, and distribute this software and its * documentation is hereby granted, under NXP Semiconductors' and its * licensor's relevant copyrights in the software, without fee, provided that it * is used in conjunction with NXP Semiconductors microcontrollers. This * copyright, permission, and disclaimer notice must appear in all copies of * this code. */ #ifndef __ADC_13XX_H_ #define __ADC_13XX_H_ #ifdef __cplusplus extern "C" { #endif /** @defgroup ADC_13XX CHIP: LPC13xx A/D conversion driver * @ingroup CHIP_13XX_Drivers * @{ */ #if defined(CHIP_LPC1347) #define ADC_ACC_12BITS #define ADC_TRIM_SUPPORT #else #define ADC_ACC_10BITS #endif #if defined(CHIP_LPC1347) #define ADC_MAX_SAMPLE_RATE 500000 #else #define ADC_MAX_SAMPLE_RATE 400000 #endif /** * @brief 10 or 12-bit ADC register block structure */ typedef struct { /*!< ADCn Structure */ __IO uint32_t CR; /*!< A/D Control Register. The AD0CR register must be written to select the operating mode before A/D conversion can occur. */ __I uint32_t GDR; /*!< A/D Global Data Register. Contains the result of the most recent A/D conversion. */ __I uint32_t RESERVED0; __IO uint32_t INTEN; /*!< A/D Interrupt Enable Register. This register contains enable bits that allow the DONE flag of each A/D channel to be included or excluded from contributing to the generation of an A/D interrupt. */ __I uint32_t DR[8]; /*!< A/D Channel Data Register. This register contains the result of the most recent conversion completed on channel n. */ __I uint32_t STAT; /*!< A/D Status Register. This register contains DONE and OVERRUN flags for all of the A/D channels, as well as the A/D interrupt flag. */ #if defined(ADC_TRIM_SUPPORT) __IO uint32_t ADTRM; #endif } LPC_ADC_T; /** * @brief ADC register support bitfields and mask */ #if defined(ADC_ACC_12BITS) #define ADC_DR_RESULT(n) ((((n) >> 4) & 0xFFF)) /*!< Mask for getting the 12 bits ADC data read value */ #else #define ADC_DR_RESULT(n) ((((n) >> 6) & 0x3FF)) /*!< Mask for getting the 10 bits ADC data read value */ #define ADC_CR_BITACC(n) ((((n) & 0x7) << 17)) /*!< Number of ADC accuracy bits */ #endif #define ADC_DR_DONE(n) (((n) >> 31)) /*!< Mask for reading the ADC done status */ #define ADC_DR_OVERRUN(n) ((((n) >> 30) & (1UL))) /*!< Mask for reading the ADC overrun status */ #define ADC_CR_CH_SEL(n) ((1UL << (n))) /*!< Selects which of the AD0.0:7 pins is (are) to be sampled and converted */ #define ADC_CR_CLKDIV(n) ((((n) & 0xFF) << 8)) /*!< The APB clock (PCLK) is divided by (this value plus one) to produce the clock for the A/D */ #define ADC_CR_BURST ((1UL << 16)) /*!< Repeated conversions A/D enable bit */ #if defined(CHIP_LPC1347) #define ADC_CR_LPWRMODE ((1UL << 22)) /*! ADC_3BITS * @return Nothing */ void Chip_ADC_SetResolution(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup, ADC_RESOLUTION_T resolution); /** * @brief Enable or disable the ADC channel on ADC peripheral * @param pADC : The base of ADC peripheral on the chip * @param channel : Channel to be enable or disable * @param NewState : New state, should be: * - ENABLE * - DISABLE * @return Nothing */ void Chip_ADC_EnableChannel(LPC_ADC_T *pADC, ADC_CHANNEL_T channel, FunctionalState NewState); /** * @brief Enable burst mode * @param pADC : The base of ADC peripheral on the chip * @param NewState : New state, should be: * - ENABLE * - DISABLE * @return Nothing */ void Chip_ADC_SetBurstCmd(LPC_ADC_T *pADC, FunctionalState NewState); /** * @} */ #ifdef __cplusplus } #endif #endif /* __ADC_13XX_H_ */