Giter Site home page Giter Site logo

wm8940-stm32-c's Introduction

WM8940 audio codec library for STM32

Useful links:

How to use

Write your implementation to write/read register from the device. For example:

// --- main.c ---

void MyI2C_Write(I2C_HandleTypeDef* i2c_handle, uint8_t i2c_address, uint8_t register, uint16_t value)
{
    // TODO
}

uint16_t MyI2C_Read(I2C_HandleTypeDef* i2c_handle, uint8_t i2c_address, uint8_t register)
{
    // TODO
}
// --- main.h ---

void MyI2C_Write(I2C_HandleTypeDef* i2c_handle, uint8_t i2c_address, uint8_t register, uint16_t value);
uint16_t MyI2C_Read(I2C_HandleTypeDef* i2c_handle, uint8_t i2c_address, uint8_t register);

Edit the wm8940.h to call your implementation

// --- wm8940.h ---

#include "main.h"    // The location of the function prototype for the implementation

#define WM8940_REG_WRITE(handle, reg, val) MyI2C_Write(handle, WM8940_I2C_ADDRESS, reg, val)
#define WM8940_REG_READ(handle, reg) MyI2C_Read(handle, WM8940_I2C_ADDRESS, reg)

Now you can initialize the audio codec, configure the Digital Audio Interface to transmit/receive audio data, and follow the Audio Signal Path from the datasheet.

// --- main.c ---

#include "wm8940.h"

WM8940_t wm8940;

int main(void)
{
    // ...

    wm8940.comm_handle = &hi2c1;
    WM8940_Init(&wm8940);

    // STM32 as I2S Master
    WM8940_Set_Clock(&wm8940, 0, WM8940_BCLKDIV_1, WM8940_MCLKDIV_1, WM8940_CLKSEL_MCLK);
    WM8940_Set_AudioInterfaceFormat(&wm8940, WM8940_AUDIO_IFACE_FMT_I2S, WM8940_AUDIO_IFACE_WL_16BITS);
    WM8940_Set_SampleRate(&wm8940, WM8940_SAMPLERATE_8KHZ);

    // Audio bypass from MICN to Speaker (BTL) and Mono
    WM8940_Set_PGA_Input(&wm8940, WM8940_INPUT_MICN);
    WM8940_Set_PGA_Mute(&wm8940, 1);
    WM8940_Set_PGA_Enable(&wm8940, 1);
    WM8940_Set_Boost_Enable(&wm8940, 1);
    WM8940_Set_MicBias_Enable(&wm8940, 1);
    WM8940_Set_Speaker_Source(&wm8940, WM8940_OUTPUT_FROM_BYPASS);
    WM8940_Set_Speaker_Mute(&wm8940, 0);
    WM8940_Set_Mono_Source(&wm8940, WM8940_OUTPUT_FROM_BYPASS);
    WM8940_Set_Mono_Mute(&wm8940, 0);
    WM8940_Set_Output_Enable(&wm8940, WM8940_OUTPUT_SPK | WM8940_OUTPUT_MONO);

    // ...
}

Implemented (based on device description):

  • Input signal path
    • Microphone inputs
    • Input PGA volume control
    • Auxiliary input
    • Input boost
    • Microphone biasing
  • Analogue to Digital Converter (ADC)
    • High pass filter
    • Notch filter
    • Digital ADC volume control
  • Input limiter/Automatic Level Control (ALC)
    • Operation mode (Normal/Limiter)
    • Attack and decay times
    • Minimum and maximum gain
    • Hold time and ALC level
    • Noise gate
    • ALC zero cross
  • Output signal path
    • Hi-Fi DAC volume control
    • Hi-Fi Digital to Analogue Converter (DAC)
    • Automute
    • DAC output limiter
    • Volume boost
  • Analogue outputs
    • SPKOUTP/SPKOUTN outputs
    • Zero cross timeout
    • Enabling the outputs
    • Unused analogue inputs/outputs (VREF to analogue output resistance/VROI)
  • Output switch
    • Thermal shutdown
  • Digital audio interfaces
    • Set audio format
    • Set word length
    • Set frame clock and BCLK polarity
    • Set LOUTR
    • (ADC & DAC) data L&R swap
    • Clock generation control
  • Audio sample rates
  • Master clock and Phase Locked Loop (PLL)
    • Enable PLL
    • Set PLL power
    • Set PLL frequency
  • Companding
    • (ADC & DAC) Loopback
    • (ADC & DAC) Companding
    • Enable 8-bit word length
  • General Purpose Input/Output
  • Control interface
    • Selection of control mode
    • Auto-incremental write setting
    • Readback
  • Resetting the chip
  • Power management
    • VMID control
    • BIASEN control
  • POP minimisation
    • Power on Bias control (configured on init)
    • VMID soft start (configured on init)
    • Fast VMID discharge

wm8940-stm32-c's People

Contributors

muhammadrefa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dmarman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.