⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc_wm8951.c

📁 nrf24z1 代码
💻 C
字号:
/*= adc_wm8951.c ===============================================================
 *
 * Copyright (C) 2005 Nordic Semiconductor
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * WARRANTY OF ANY KIND.
 *
 * Author(s): Borge Strand
 *
 * Description:
 *
 *    ADC specific code for Wolfson WM8951
 *    This file must be ported to any other ADC to be used. 
 *    It must implement all functions in adc.h
 *    All defines specific to WM8951 reside in this file
 *
 * Compiler: Tested with WinAVR, avr-gcc (GCC) 3.4.3
 *
 * Revision: 2.0 
 *
 *==============================================================================
 */


#include "adc.h"


// Write a single byte to ADC's slave interface
void adc_singlewrite(char adr, char data) {
    // Local address in WM8951 is 7 bits long. Data field is 9 bits long! That means only single writes are possible. 
    // The upper bits (2-wire local address) are comprised by the 7-bit WM8951 local address and data bit 8. The lower
    // bits (2-wire data) are data bits 7:0 Because WM8951L has to be reset when powered down, the wakeup sequence has 
    // to do a complete init. 
    
    #define ADC2WDEVADR     0b00011010              // 7-bit ADC slave device address with CSB = 0
    mcu_2w_write(ADC2WDEVADR, adr, data);           // ADC accepts both SPI and 2-wire. Only 2-wire in program
}


// Set up the ADC
void adc_init(void) {
    #ifdef ATXDEVBOARD                              // ATX is development board, don't do any ADC stuff
    #else                                           // ATX is Headphone reference design, wake up ADC
        adc_wake();
    #endif
}


// Put the ADC into sleep mode to save current in ATX. First mute, then disable stuff. Check details with Wolfson support
void adc_sleep(void) {
    #ifdef ATXDEVBOARD                              // ATX is development board, don't do any ADC stuff
    #else                                           // ATX is Headphone reference design, wake up ADC
        mcu_wait_ms(10);                            // Add some delay in case the watchdog was on our tail
    
        // Include next line and sleep current is 27uA. Comment it out and sleep current is either 2uA or 3mA
        adc_singlewrite(0b00011110, 0b00000000);    // Resetting ADC before going to sleep. This means that full init must be done, page 20
        adc_singlewrite(0b00001110, 0b00000010);    // Non-inverted BCLK, Slave mode, 16 bit I2S see page 24 of datasheet, vs. pin TP2 == GND
        adc_singlewrite(0b00010000, 0b00100000);    // 44.1 256x, 256x normal mode see page 26 of datasheet
//      adc_singlewrite(0b00010000, 0b00000000);    // 32 256x, 256x normal mode see page 26 of datasheet
        adc_singlewrite(0b00000001, 0b10011011);    // Left and right volume control, mute, 6dB volume see page 15 of datasheet 
        adc_singlewrite(0b00001100, 0b11111111);    // Disable VMID, CLKOUT, oscillator, ADC, microphone, linein. Page 32
        mcu_wait_ms(10);                             // Add some delay in case the watchdog was on our tail
    #endif
}                                                   


// Wake the ADC up after sleep mode. First wake, then demute. Check details with Wolfson support
void adc_wake(void) {
    #ifdef ATXDEVBOARD                              // ATX is development board, don't do any ADC stuff
    #else                                           // ATX is Headphone reference design, wake up ADC
        mcu_wait_ms(2);                             // Add some delay in case the watchdog was on our tail
        adc_singlewrite(0b00001110, 0b00000010);    // Non-inverted BCLK, Slave mode, 16 bit I2S see page 24 of datasheet, vs. pin TP2 == GND
        adc_singlewrite(0b00010000, 0b00100000);    // 44.1 256x, 256x normal mode see page 26 of datasheet
//      adc_singlewrite(0b00010000, 0b00000000);    // 32 256x, 256x normal mode see page 26 of datasheet
        adc_singlewrite(0b00000001, 0b00011011);    // Left and right volume control, no mute, 6dB volume page 15
        adc_singlewrite(0b00001100, 0b01111010);    // Disable CLKOUT, oscillator, and microphone. Enable VMID, ADC and linein
        adc_singlewrite(0b00010010, 0b00000001);    // Activate digital audio interface
        mcu_wait_ms(2);                             // Add some delay in case the watchdog was on our tail
    #endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -