00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is confidential property of Nordic 00004 * Semiconductor ASA.Terms and conditions of usage are described in detail 00005 * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 * $LastChangedRevision: 224 $ 00012 */ 00013 00018 #include <stdint.h> 00019 #include <stdbool.h> 00020 00021 #include "nrf24le1.h" 00022 #include "nordic_common.h" 00023 #include "hal_adc.h" 00024 00025 00026 void hal_adc_set_input_channel(hal_adc_input_channel_t chsel) 00027 { // Update "chsel" bits 00028 ADCCON1 = ((ADCCON1 & 0xC3) | (((uint8_t)(chsel) << 2) & ~0xC3)); 00029 } 00030 00031 00032 void hal_adc_set_reference(hal_adc_reference_t refsel) 00033 { // Update "refsel" bits 00034 ADCCON1 = ((ADCCON1 & 0xFC) | (((uint8_t)(refsel)) & ~0xFC)); 00035 } 00036 00037 00038 void hal_adc_set_input_mode(hal_adc_input_mode_t input_mode) 00039 { // Update "diffm" bits 00040 ADCCON2 = ((ADCCON2 & 0x3F) | ((uint8_t)(input_mode) << 6)); 00041 } 00042 00043 00044 void hal_adc_set_conversion_mode(hal_adc_conversion_mode_t conv_mode) 00045 { // Update "cont" bit 00046 ADCCON2 = ((ADCCON2 & 0xDF) | (((uint8_t)(conv_mode) << 5) & ~0xDF)); 00047 } 00048 00049 00050 void hal_adc_set_sampling_rate(hal_adc_sampling_rate_t rate) 00051 { // Update "rate" bits 00052 ADCCON2 = ((ADCCON2 & 0xE3) | (((uint8_t)(rate) << 2) & ~0xE3)); 00053 } 00054 00055 00056 void hal_adc_set_power_down_delay(hal_adc_power_down_delay_t pdd) 00057 { // Update "rate" bits 00058 ADCCON2 = ((ADCCON2 & 0xE3) | (((uint8_t)(pdd) << 2) & ~0xE3)); 00059 } 00060 00061 00062 void hal_adc_set_acq_window(hal_adc_acq_window_t tacq) 00063 { // Update "tacq" bits 00064 ADCCON2 = ((ADCCON2 & 0xFC) | (((uint8_t)(tacq)) & ~0xFC)); 00065 } 00066 00067 00068 void hal_adc_set_resolution(hal_adc_resolution_t res) 00069 { // Update "resol" bits 00070 ADCCON3 = ((ADCCON3 & 0x3F) | ((uint8_t)(res) << 6)); 00071 } 00072 00073 00074 void hal_adc_set_data_just(hal_adc_data_just_t just) 00075 { // Update "rljust" bit 00076 ADCCON3 = ((ADCCON3 & 0xDF) | (((uint8_t)(just) << 5) & ~0xDF)); 00077 } 00078 00079 00080 void hal_adc_start(void) 00081 { 00082 uint8_t cnt = ADC_STARTUP_CNT; // Get the counter value 00083 ADCCON1 = ADCCON1 | BIT_7; // Set "pwrup" bit 00084 00085 while(cnt--){} // Wait for busy bit to stabilize 00086 } 00087 00088 00089 uint8_t hal_adc_read_LSB(void) 00090 { 00091 return ADCDATL; // Return value stored in ADCDATL 00092 } 00093 00094 uint8_t hal_adc_read_MSB(void) 00095 { 00096 return ADCDATH; // Return value stored in ADCDATH 00097 } 00098 00099 bool hal_adc_busy(void) 00100 { 00101 return ((ADCCON1 & BIT_6)); // Return status of "busy" bit 00102 } 00103 00104 hal_adc_overflow_t hal_adc_get_overflow_status(void) 00105 { 00106 return (hal_adc_overflow_t)((ADCCON3 & (BIT_3 | BIT_4)) >> 3); 00107 } 00108 // Return status bits from ADCCON3