1 /****************************************************************************** 2 * 3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 4 * Analog Devices, Inc.), 5 * Copyright (C) 2023-2024 Analog Devices, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 ******************************************************************************/ 20 #ifndef LIBRARIES_PERIPHDRIVERS_SOURCE_ADC_ADC_REVA_H_ 21 #define LIBRARIES_PERIPHDRIVERS_SOURCE_ADC_ADC_REVA_H_ 22 23 #include <stdio.h> 24 #include "adc.h" 25 #include "adc_reva_regs.h" 26 #include "dma_reva_regs.h" 27 #include "dma_regs.h" 28 29 #include "mxc_device.h" 30 #include "mxc_errors.h" 31 #include "mxc_assert.h" 32 #include "mxc_sys.h" 33 #include "mxc_lock.h" 34 35 /***** MACROS *****/ 36 #define AIN0 0x0 37 #define AIN1 0x1 38 #define AIN2 0x2 39 #define AIN3 0x3 40 #define AIN4 0x4 41 #define AIN5 0x5 42 #define AIN6 0x6 43 #define AIN7 0x7 44 #define AIN8 0x8 45 #define AIN9 0x9 46 #define AIN10 0xA 47 #define AIN11 0xB 48 #define AIN12 0xC 49 #define AIN13 0xD 50 #define AIN14 0xE 51 #define AIN15 0xF 52 #define AIN16 0x10 53 54 /***** FUNCTIONS *****/ 55 int MXC_ADC_RevA_Init(mxc_adc_reva_regs_t *adc); 56 int MXC_ADC_RevA_Shutdown(mxc_adc_reva_regs_t *adc); 57 int MXC_ADC_RevA_Busy(mxc_adc_reva_regs_t *adc); 58 void MXC_ADC_RevA_EnableInt(mxc_adc_reva_regs_t *adc, uint32_t flags); 59 void MXC_ADC_RevA_DisableInt(mxc_adc_reva_regs_t *adc, uint32_t flags); 60 int MXC_ADC_RevA_GetFlags(mxc_adc_reva_regs_t *adc); 61 void MXC_ADC_RevA_ClearFlags(mxc_adc_reva_regs_t *adc, uint32_t flags); 62 int MXC_ADC_RevA_SetConversionSpeed(mxc_adc_reva_regs_t *adc, uint32_t hz); 63 int MXC_ADC_RevA_GetConversionSpeed(uint8_t divider); 64 void MXC_ADC_RevA_SetDataAlignment(mxc_adc_reva_regs_t *adc, int msbJustify); 65 void MXC_ADC_RevA_SetExtScale(mxc_adc_reva_regs_t *adc, mxc_adc_scale_t scale); 66 void MXC_ADC_RevA_EnableMonitor(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor); 67 void MXC_ADC_RevA_DisableMonitor(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor); 68 void MXC_ADC_RevA_SetMonitorHighThreshold(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor, 69 uint32_t threshold); 70 int MXC_ADC_RevA_GetMonitorHighThreshold(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor); 71 void MXC_ADC_RevA_SetMonitorLowThreshold(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor, 72 uint32_t threshold); 73 int MXC_ADC_RevA_GetMonitorLowThreshold(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor); 74 void MXC_ADC_RevA_SetMonitorChannel(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor, 75 mxc_adc_chsel_t channel); 76 int MXC_ADC_RevA_GetMonitorChannel(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_t monitor); 77 void MXC_ADC_RevA_EnableMonitorAsync(mxc_adc_monitor_t monitor, mxc_adc_monitor_cb_t callback); 78 void MXC_ADC_RevA_DisableMonitorAsync(mxc_adc_monitor_t monitor); 79 int MXC_ADC_RevA_StartConversion(mxc_adc_reva_regs_t *adc, mxc_adc_chsel_t channel); 80 int MXC_ADC_RevA_StartConversionAsync(mxc_adc_reva_regs_t *adc, mxc_adc_chsel_t channel, 81 mxc_adc_complete_cb_t callback); 82 int MXC_ADC_RevA_StartConversionDMA(mxc_adc_reva_regs_t *adc, mxc_adc_chsel_t channel, 83 mxc_dma_regs_t *dma, uint16_t *data, 84 void (*callback)(int, int)); 85 int MXC_ADC_RevA_Handler(mxc_adc_reva_regs_t *adc); 86 int MXC_ADC_RevA_Convert(mxc_adc_reva_regs_t *adc, mxc_adc_conversion_req_t *req); 87 int MXC_ADC_RevA_ConvertAsync(mxc_adc_reva_regs_t *adc, mxc_adc_conversion_req_t *req); 88 void MXC_ADC_RevA_Monitor(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_req_t req); 89 void MXC_ADC_RevA_MonitorAsync(mxc_adc_reva_regs_t *adc, mxc_adc_monitor_req_t req); 90 int MXC_ADC_RevA_GetData(mxc_adc_reva_regs_t *adc, uint16_t *outdata); 91 92 #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_ADC_ADC_REVA_H_ 93