1 /* 2 * @brief LPC15xx ROM ADC API declarations and functions 3 * 4 * @note 5 * Copyright(C) NXP Semiconductors, 2014 6 * All rights reserved. 7 * 8 * @par 9 * Software that is described herein is for illustrative purposes only 10 * which provides customers with programming information regarding the 11 * LPC products. This software is supplied "AS IS" without any warranties of 12 * any kind, and NXP Semiconductors and its licensor disclaim any and 13 * all warranties, express or implied, including all implied warranties of 14 * merchantability, fitness for a particular purpose and non-infringement of 15 * intellectual property rights. NXP Semiconductors assumes no responsibility 16 * or liability for the use of the software, conveys no license or rights under any 17 * patent, copyright, mask work right, or any other intellectual property rights in 18 * or to any products. NXP Semiconductors reserves the right to make changes 19 * in the software without notification. NXP Semiconductors also makes no 20 * representation or warranty that such application will be suitable for the 21 * specified use without further testing or modification. 22 * 23 * @par 24 * Permission to use, copy, modify, and distribute this software and its 25 * documentation is hereby granted, under NXP Semiconductors' and its 26 * licensor's relevant copyrights in the software, without fee, provided that it 27 * is used in conjunction with NXP Semiconductors microcontrollers. This 28 * copyright, permission, and disclaimer notice must appear in all copies of 29 * this code. 30 */ 31 32 #ifndef __ROM_ADC_15XX_H_ 33 #define __ROM_ADC_15XX_H_ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** @defgroup ADCROM_15XX CHIP: LPC15xx ADC ROM API declarations and functions 40 * @ingroup ROMAPI_15XX 41 * @{ 42 */ 43 44 /** 45 * @brief ADC handle type 46 */ 47 typedef void *ADC_HANDLE_T; 48 49 typedef void (*ADC_SEQ_CALLBK_T)(ADC_HANDLE_T handle); 50 typedef void (*ADC_CALLBK_T)(ErrorCode_t error_code, uint32_t num_channel); 51 52 /* Typedef for structure pointed by the ADC_HANDLE */ 53 typedef struct { /* block of RAM allocated by the application program */ 54 uint32_t base_addr; /* adcr register base address */ 55 uint32_t *seqa_buffer; /* adc buffer */ 56 uint32_t *seqb_buffer; /* adc buffer */ 57 uint32_t seqa_channel_num; /* number of ADC channels */ 58 uint32_t seqb_channel_num; /* number of ADC channels */ 59 uint32_t seqa_hwtrig; 60 uint32_t seqb_hwtrig; 61 uint32_t comp_flags; 62 uint32_t overrun_flags; 63 uint32_t thcmp_flags; 64 uint32_t error_code; /* error code */ 65 ADC_SEQ_CALLBK_T seqa_callback; /* For interrupt, it's the end of the sequence A */ 66 ADC_SEQ_CALLBK_T seqb_callback; /* For interrupt, it's the end of the sequence B */ 67 ADC_CALLBK_T overrun_callback; /* For interrupt, it's the overrun */ 68 ADC_CALLBK_T thcmp_callback; /* For interrupt, it's over the threshold */ 69 uint32_t error_en; /* enable bits for error detection */ 70 uint32_t thcmp_en; /* enable bits for thcmp detection */ 71 } ADC_DRIVER_T; /* HEADER_TypeDef *********************************/ 72 73 typedef struct { 74 uint32_t system_clock; /* System clock */ 75 uint32_t adc_clock; /* ADC clock */ 76 uint32_t async_mode; 77 uint32_t tenbit_mode; 78 uint32_t lpwr_mode; 79 uint32_t input_sel; 80 uint32_t seqa_ctrl; 81 uint32_t seqb_ctrl; 82 uint32_t thrsel; 83 uint32_t thr0_low; 84 uint32_t thr0_high; 85 uint32_t thr1_low; 86 uint32_t thr1_high; 87 uint32_t error_en; 88 uint32_t thcmp_en; 89 uint32_t channel_num; 90 } ADC_CONFIG_T; 91 92 typedef struct { 93 uint32_t dma_adc_num; /* DMA channel used for ADC data peripheral to memory transfer */ 94 uint32_t dma_pinmux_num; /* H/W trigger number. */ 95 uint32_t dma_handle; /* DMA handle passed to ADC */ 96 ADC_CALLBK_T dma_done_callback_pt; /* DMA completion callback function */ 97 } ADC_DMA_CFG_T; 98 99 typedef ErrorCode_t (*ADC_DMA_SETUP_T)(ADC_HANDLE_T handle, ADC_DMA_CFG_T *dma_cfg); 100 101 typedef struct { /* params passed to adc driver function */ 102 uint32_t *buffer; /* Considering supporting DMA and non-DMA mode, 32-bit buffer is needed for DMA */ 103 uint32_t driver_mode; /* 0x00: Polling mode, function is blocked until transfer is finished. */ 104 /* 0x01: Interrupt mode, function exit immediately, callback function is invoked when transfer is finished. */ 105 /* 0x02: DMA mode, in case DMA block is available, data transferred by ADC is processed by DMA, 106 and max buffer size is the total number ADC channels, DMA req function is called for ADC DMA 107 channel setup, then SEQx completion also used as DMA callback function when that ADC conversion/DMA transfer 108 is finished. */ 109 uint32_t seqa_hwtrig; /* H/W trigger for sequence A */ 110 uint32_t seqb_hwtrig; /* H/W trigger for sequence B */ 111 ADC_CONFIG_T *adc_cfg; 112 uint32_t comp_flags; 113 uint32_t overrun_flags; 114 uint32_t thcmp_flags; 115 ADC_DMA_CFG_T *dma_cfg; 116 ADC_SEQ_CALLBK_T seqa_callback_pt; /* SEQA callback function/the same callback on DMA completion if DMA is used for ADCx. */ 117 ADC_SEQ_CALLBK_T seqb_callback_pt; /* SEQb callback function/the same callback on DMA completion if DMA is used for ADCx. */ 118 ADC_CALLBK_T overrun_callback_pt; /* Overrun callback function */ 119 ADC_CALLBK_T thcmp_callback_pt; /* THCMP callback function */ 120 ADC_DMA_SETUP_T dma_setup_func_pt; /* ADC DMA channel setup function */ 121 } ADC_PARAM_T; 122 123 /* Typedef Structure for ROM API's */ 124 typedef struct ADCD_API { 125 /* ADC Configuration functions */ 126 uint32_t (*adc_get_mem_size)(void); 127 ADC_HANDLE_T (*adc_setup)(uint32_t base_addr, uint8_t *ram); 128 void (*adc_calibration)(ADC_HANDLE_T handle, ADC_CONFIG_T *set); 129 void (*adc_init)(ADC_HANDLE_T handle, ADC_CONFIG_T *set); 130 131 /* ADC Conversion Functions */ 132 uint32_t (*adc_seqa_read)(ADC_HANDLE_T handle, ADC_PARAM_T *param); 133 uint32_t (*adc_seqb_read)(ADC_HANDLE_T handle, ADC_PARAM_T *param); 134 135 /* ADC Interrupt handlers */ 136 void (*adc_seqa_isr)(ADC_HANDLE_T handle); 137 void (*adc_seqb_isr)(ADC_HANDLE_T handle); 138 void (*adc_ovr_isr)(ADC_HANDLE_T handle); 139 void (*adc_thcmp_isr)(ADC_HANDLE_T handle); 140 141 uint32_t (*adc_get_firmware_version)(void); 142 } ADCD_API_T; 143 144 /** 145 * @} 146 */ 147 148 #ifdef __cplusplus 149 } 150 #endif 151 152 #endif /* __ROM_ADC_15XX_H_ */ 153