p3 fin
This commit is contained in:
65
P3_SETR2/Components/cs42l51/Release_Notes.html
Normal file
65
P3_SETR2/Components/cs42l51/Release_Notes.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
||||
<title>Release Notes for CS42L51 Component Drivers</title>
|
||||
<style type="text/css">
|
||||
code{white-space: pre-wrap;}
|
||||
span.smallcaps{font-variant: small-caps;}
|
||||
span.underline{text-decoration: underline;}
|
||||
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
||||
</style>
|
||||
<link rel="stylesheet" href="../../../../_htmresc/mini-st.css" />
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-lg-4">
|
||||
<div class="card fluid">
|
||||
<div class="sectione dark">
|
||||
<center>
|
||||
<h1 id="release-notes-for-cs42l51-component-drivers"><small>Release Notes for</small> <mark>CS42L51 Component Drivers</mark></h1>
|
||||
<p>Copyright © 2017 STMicroelectronics<br />
|
||||
</p>
|
||||
<a href="https://www.st.com" class="logo"><img src="../../../../_htmresc/st_logo.png" alt="ST logo" /></a>
|
||||
</center>
|
||||
</div>
|
||||
</div>
|
||||
<h1 id="license">License</h1>
|
||||
<p>Licensed by ST under BSD 3-Clause license (the "License"). You may not use this package except in compliance with the License. You may obtain a copy of the License at:</p>
|
||||
<p><a href="https://opensource.org/licenses/BSD-3-Clause">https://opensource.org/licenses/BSD-3-Clause</a></p>
|
||||
<h1 id="purpose">Purpose</h1>
|
||||
<p>This directory contains the CS42L51 component drivers.</p>
|
||||
</div>
|
||||
<div class="col-sm-12 col-lg-8">
|
||||
<h1 id="update-history">Update History</h1>
|
||||
<div class="collapse">
|
||||
<input type="checkbox" id="collapse-section22" checked aria-hidden="true"> <label for="collapse-section22" aria-hidden="true">V1.0.1 / 03-April-2019</label>
|
||||
<div>
|
||||
<h2 id="main-changes">Main Changes</h2>
|
||||
<ul>
|
||||
<li>Update release notes format</li>
|
||||
<li>Reformat the BSD 3-Clause license declaration in the files header (replace license terms by a web reference to OSI website where those terms lie)</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse">
|
||||
<input type="checkbox" id="collapse-section20" aria-hidden="true"> <label for="collapse-section20" aria-hidden="true">V1.0.0 / 17-February-2017</label>
|
||||
<div>
|
||||
<h2 id="main-changes-1">Main Changes</h2>
|
||||
<ul>
|
||||
<li>First official release of CS42L51 Audio codec Component driver</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="sticky">
|
||||
For complete documentation on <mark>STM32 Microcontrollers</mark> , visit: <a href="http://www.st.com/STM32">http://www.st.com/STM32</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
504
P3_SETR2/Components/cs42l51/cs42l51.c
Normal file
504
P3_SETR2/Components/cs42l51/cs42l51.c
Normal file
@@ -0,0 +1,504 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs42l51.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the CS42L51 Audio Codec driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "cs42l51.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Components
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CS42L51
|
||||
* @brief This file provides a set of functions needed to drive the
|
||||
* CS42L51 audio codec.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Audio codec driver structure initialization */
|
||||
AUDIO_DrvTypeDef cs42l51_drv =
|
||||
{
|
||||
cs42l51_Init,
|
||||
cs42l51_DeInit,
|
||||
cs42l51_ReadID,
|
||||
|
||||
cs42l51_Play,
|
||||
cs42l51_Pause,
|
||||
cs42l51_Resume,
|
||||
cs42l51_Stop,
|
||||
|
||||
cs42l51_SetFrequency,
|
||||
cs42l51_SetVolume,
|
||||
cs42l51_SetMute,
|
||||
cs42l51_SetOutputMode,
|
||||
cs42l51_Reset,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/* Uncomment this line to enable verifying data sent to codec after each write
|
||||
operation (for debug purpose) */
|
||||
#if !defined (VERIFY_WRITTENDATA)
|
||||
#define VERIFY_WRITTENDATA
|
||||
#endif /* VERIFY_WRITTENDATA */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t Is_CS42L51_Initialized = 0;
|
||||
static uint8_t Is_CS42L51_Stop = 1;
|
||||
|
||||
static uint16_t CS42L51_Device = OUTPUT_DEVICE_HEADPHONE;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup CS42L51_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the audio codec and the control interface.
|
||||
* @param DeviceAddr: Device address on communication bus.
|
||||
* @param Device: Can be combination values of OUTPUT_DEVICE_HEADPHONE and
|
||||
* INPUT_DEVICE_MIC1.
|
||||
* @param Volume: Initial output volume level (from 0 (-100dB) to 100 (0dB)).
|
||||
* @param AudioFreq: Initial audio frequency (currently not used).
|
||||
* @retval 0 if correct communication, else wrong communication.
|
||||
*/
|
||||
uint32_t cs42l51_Init(uint16_t DeviceAddr, uint16_t Device, uint8_t Volume, uint32_t AudioFreq)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
uint8_t Value;
|
||||
|
||||
/* Check if codec is already initialized */
|
||||
if(Is_CS42L51_Initialized == 0)
|
||||
{
|
||||
/* Initialize the Control interface of the Audio Codec */
|
||||
AUDIO_IO_Init();
|
||||
|
||||
Is_CS42L51_Initialized = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set all power down bits to 1 exept PDN to mute ADCs and DACs*/
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x7E);
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x03, (Value | 0x0E));
|
||||
|
||||
/* Disable zero cross and soft ramp */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x09);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x09, (Value & 0xFC));
|
||||
|
||||
/* Power control : Enter standby (PDN = 1) */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value | 0x01));
|
||||
}
|
||||
|
||||
/* Mic Power and Speed Control : Auto detect on, Speed mode SSM, tri state off, MCLK divide by 2 off */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x03, ((Value & 0x0E) | 0xA0));
|
||||
|
||||
/* Interface control : Loopback off, Slave, I2S (SDIN and SOUT), Digital mix off, Mic mix off */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0C);
|
||||
|
||||
/* Mic control : ADC single volume off, ADCB boost off, ADCA boost off, MicBias on AIN3B/MICIN2 pin, MicBias level 0.8xVA, MICB boost 16db, MICA boost 16dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x00);
|
||||
|
||||
/* ADC control : ADCB HPF off, ADCB HPF freeze off, ADCA HPF off, ADCA HPF freeze off, Soft ramp B off, Zero cross B off, Soft ramp A off, Zero cross A off */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x06, 0x00);
|
||||
|
||||
/* ADC Input Select, Invert and Mute : AIN1B to PGAB, AIN3A to PreAmp to PGAA, ADCB invert off, ADCA invert off, ADCB mute on, ADCA mute off */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x07, 0x32);
|
||||
|
||||
/* DAC output control : HP Gain to 1, Single volume control off, PCM invert signals polarity off, DAC channels mute on */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x08, 0xC3);
|
||||
|
||||
/* DAC control : Signal processing to DAC, Freeze off, De-emphasis off, Analog output auto mute off, DAC soft ramp */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x09, 0x42);
|
||||
|
||||
/* ALCA and PGAA Control : ALCA soft ramp disable on, ALCA zero cross disable on, PGA A Gain 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x0A, 0xC0);
|
||||
|
||||
/* ALCB and PGAB Control : ALCB soft ramp disable on, ALCB zero cross disable on, PGA B Gain 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x0B, 0xC0);
|
||||
|
||||
/* ADCA Attenuator : 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x0C, 0x00);
|
||||
|
||||
/* ADCB Attenuator : 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x0D, 0x00);
|
||||
|
||||
/* ADCA mixer volume control : ADCA mixer channel mute on, ADCA mixer volume 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x0E, 0x80);
|
||||
|
||||
/* ADCB mixer volume control : ADCB mixer channel mute on, ADCB mixer volume 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x0F, 0x80);
|
||||
|
||||
/* PCMA mixer volume control : PCMA mixer channel mute off, PCMA mixer volume 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x10, 0x00);
|
||||
|
||||
/* PCMB mixer volume control : PCMB mixer channel mute off, PCMB mixer volume 0dB */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x11, 0x00);
|
||||
|
||||
/* PCM channel mixer : AOUTA Left, AOUTB Right */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x18, 0x00);
|
||||
|
||||
if(Device & OUTPUT_DEVICE_HEADPHONE)
|
||||
{
|
||||
Value = VOLUME_CONVERT(Volume);
|
||||
/* AOUTA volume control : AOUTA volume */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x16, Value);
|
||||
/* AOUTB volume control : AOUTB volume */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x17, Value);
|
||||
}
|
||||
|
||||
/* Store device */
|
||||
CS42L51_Device = Device;
|
||||
|
||||
/* Return communication control value */
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the audio codec.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void cs42l51_DeInit(void)
|
||||
{
|
||||
/* Deinitialize Audio Codec interface */
|
||||
AUDIO_IO_DeInit();
|
||||
|
||||
Is_CS42L51_Initialized = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the CS42L51 ID.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval The CS42L51 ID
|
||||
*/
|
||||
uint32_t cs42l51_ReadID(uint16_t DeviceAddr)
|
||||
{
|
||||
uint8_t Value;
|
||||
|
||||
if(Is_CS42L51_Initialized == 0)
|
||||
{
|
||||
/* Initialize the Control interface of the Audio Codec */
|
||||
AUDIO_IO_Init();
|
||||
|
||||
Value = AUDIO_IO_Read(DeviceAddr, CS42L51_CHIPID_ADDR);
|
||||
Value = (Value & CS42L51_ID_MASK);
|
||||
|
||||
/* Deinitialize Audio Codec interface */
|
||||
AUDIO_IO_DeInit();
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = AUDIO_IO_Read(DeviceAddr, CS42L51_CHIPID_ADDR);
|
||||
Value = (Value & CS42L51_ID_MASK);
|
||||
}
|
||||
|
||||
return((uint32_t) Value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start the audio Codec play feature.
|
||||
* @note For this codec no Play options are required.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
uint8_t Value;
|
||||
|
||||
if(Is_CS42L51_Stop == 1)
|
||||
{
|
||||
/* Unmute output device */
|
||||
counter += cs42l51_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
||||
|
||||
if(CS42L51_Device & OUTPUT_DEVICE_HEADPHONE)
|
||||
{
|
||||
/* DAC control : Signal processing to DAC, Freeze off, De-emphasis off, Analog output auto mute off, DAC soft ramp */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x09, 0x42);
|
||||
|
||||
/* Power control 1 : PDN_DACA, PDN_DACB disable. */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value & 0x9F));
|
||||
}
|
||||
|
||||
if(CS42L51_Device & INPUT_DEVICE_MIC1)
|
||||
{
|
||||
/* Power control 1 : PDN_PGAA, PDN_ADCA disable. */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value & 0xF5));
|
||||
|
||||
/* Mic Power and Speed Control : PDN_MICA, PDN_MIC_BIAS disable. */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x03, (Value & 0xF9));
|
||||
}
|
||||
|
||||
/* Power control : Exit standby (PDN = 0) */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value & 0xFE));
|
||||
|
||||
Is_CS42L51_Stop = 0;
|
||||
}
|
||||
|
||||
/* Return communication control value */
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pause playing on the audio codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_Pause(uint16_t DeviceAddr)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
/* Pause the audio file playing */
|
||||
/* Mute the output first */
|
||||
counter += cs42l51_SetMute(DeviceAddr, AUDIO_MUTE_ON);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume playing on the audio codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_Resume(uint16_t DeviceAddr)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
|
||||
/* Unmute the output */
|
||||
counter += cs42l51_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop audio Codec playing. It powers down the codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param CodecPdwnMode: selects the power down mode (currently not used).
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
uint8_t Value;
|
||||
|
||||
/* Set all power down bits to 1 exept PDN to mute ADCs and DACs*/
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x7E);
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x03, (Value | 0x0E));
|
||||
|
||||
/* Disable zero cross and soft ramp */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x09);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x09, (Value & 0xFC));
|
||||
|
||||
/* Power control : Enter standby (PDN = 1) */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value | 0x01));
|
||||
|
||||
Is_CS42L51_Stop = 1;
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set higher or lower the codec volume level.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param Volume: output volume level (from 0 (-100dB) to 100 (0dB)).
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
uint8_t convertedvol = VOLUME_CONVERT(Volume);
|
||||
|
||||
/* AOUTA volume control : AOUTA volume */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x16, convertedvol);
|
||||
/* AOUTB volume control : AOUTB volume */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x17, convertedvol);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set new frequency.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param AudioFreq: Audio frequency used to play the audio stream.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable the mute feature on the audio codec.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
|
||||
* mute mode.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_SetMute(uint16_t DeviceAddr, uint32_t Cmd)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
uint8_t Value;
|
||||
|
||||
/* Read DAC output control register */
|
||||
Value = AUDIO_IO_Read(DeviceAddr, 0x08);
|
||||
|
||||
/* Set the Mute mode */
|
||||
if(Cmd == AUDIO_MUTE_ON)
|
||||
{
|
||||
/* Mute DAC channels */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x08, (Value | 0x03));
|
||||
}
|
||||
else /* AUDIO_MUTE_OFF Disable the Mute */
|
||||
{
|
||||
/* Unmute DAC channels */
|
||||
counter += CODEC_IO_Write(DeviceAddr, 0x08, (Value & 0xFC));
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Switch dynamically (while audio file is played) the output target
|
||||
* (speaker, headphone, etc).
|
||||
* @note This function is currently not used (only headphone output device).
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param Output: specifies the audio output device target.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_SetOutputMode(uint16_t DeviceAddr, uint8_t Output)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset CS42L51 registers.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval 0 if correct communication, else wrong communication
|
||||
*/
|
||||
uint32_t cs42l51_Reset(uint16_t DeviceAddr)
|
||||
{
|
||||
if(Is_CS42L51_Initialized == 1)
|
||||
{
|
||||
/* Deinitialize Audio Codec interface */
|
||||
AUDIO_IO_DeInit();
|
||||
|
||||
/* Initialize the Control interface of the Audio Codec */
|
||||
AUDIO_IO_Init();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup CS42L51_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Write and optionally read back a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param Value: Data to be written
|
||||
* @retval None
|
||||
*/
|
||||
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
AUDIO_IO_Write(Addr, Reg, Value);
|
||||
|
||||
#ifdef VERIFY_WRITTENDATA
|
||||
/* Verify that the data has been correctly written */
|
||||
result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1;
|
||||
#endif /* VERIFY_WRITTENDATA */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
171
P3_SETR2/Components/cs42l51/cs42l51.h
Normal file
171
P3_SETR2/Components/cs42l51/cs42l51.h
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs42l51.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the cs42l51.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CS42L51_H
|
||||
#define __CS42L51_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../Common/audio.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Component
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CS42L51
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
/*************************** Codec User defines ******************************/
|
||||
/******************************************************************************/
|
||||
/* Codec output devices */
|
||||
#define OUTPUT_DEVICE_HEADPHONE 0x01
|
||||
|
||||
/* Codec input devices */
|
||||
#define INPUT_DEVICE_MIC1 0x10
|
||||
|
||||
/* Volume Levels values */
|
||||
#define DEFAULT_VOLMIN 0x00
|
||||
#define DEFAULT_VOLMAX 0xFF
|
||||
#define DEFAULT_VOLSTEP 0x04
|
||||
|
||||
#define AUDIO_PAUSE 0
|
||||
#define AUDIO_RESUME 1
|
||||
|
||||
/* Codec POWER DOWN modes */
|
||||
#define CODEC_PDWN_HW 1
|
||||
#define CODEC_PDWN_SW 2
|
||||
|
||||
/* MUTE commands */
|
||||
#define AUDIO_MUTE_ON 1
|
||||
#define AUDIO_MUTE_OFF 0
|
||||
|
||||
/* AUDIO FREQUENCY */
|
||||
#define AUDIO_FREQUENCY_192K ((uint32_t)192000)
|
||||
#define AUDIO_FREQUENCY_96K ((uint32_t)96000)
|
||||
#define AUDIO_FREQUENCY_48K ((uint32_t)48000)
|
||||
#define AUDIO_FREQUENCY_44K ((uint32_t)44100)
|
||||
#define AUDIO_FREQUENCY_32K ((uint32_t)32000)
|
||||
#define AUDIO_FREQUENCY_22K ((uint32_t)22050)
|
||||
#define AUDIO_FREQUENCY_16K ((uint32_t)16000)
|
||||
#define AUDIO_FREQUENCY_11K ((uint32_t)11025)
|
||||
#define AUDIO_FREQUENCY_8K ((uint32_t)8000)
|
||||
|
||||
/******************************************************************************/
|
||||
/****************************** REGISTER MAPPING ******************************/
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief CS42L51 ID
|
||||
*/
|
||||
#define CS42L51_ID 0xD8
|
||||
#define CS42L51_ID_MASK 0xF8
|
||||
/**
|
||||
* @brief Chip ID Register: Chip I.D. and Revision Register
|
||||
* Read only register
|
||||
* Default value: 0x01
|
||||
* [7:3] CHIPID[4:0]: I.D. code for the CS42L51.
|
||||
* Default value: 11100b
|
||||
* [2:0] REVID[2:0]: CS42L51 revision level.
|
||||
* Default value:
|
||||
* 000 - Rev A0
|
||||
* 001 - Rev A1
|
||||
* 010 - Rev B0
|
||||
* 011 - Rev B1
|
||||
*/
|
||||
#define CS42L51_CHIPID_ADDR 0x01
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
#define VOLUME_CONVERT(Volume) ((Volume >= 100) ? 0 : ((uint8_t)(((Volume * 2) + 56))))
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
Audio Codec functions
|
||||
------------------------------------------------------------------------------*/
|
||||
/* High Layer codec functions */
|
||||
uint32_t cs42l51_Init(uint16_t DeviceAddr, uint16_t Device, uint8_t Volume, uint32_t AudioFreq);
|
||||
void cs42l51_DeInit(void);
|
||||
uint32_t cs42l51_ReadID(uint16_t DeviceAddr);
|
||||
uint32_t cs42l51_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
|
||||
uint32_t cs42l51_Pause(uint16_t DeviceAddr);
|
||||
uint32_t cs42l51_Resume(uint16_t DeviceAddr);
|
||||
uint32_t cs42l51_Stop(uint16_t DeviceAddr, uint32_t Cmd);
|
||||
uint32_t cs42l51_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
|
||||
uint32_t cs42l51_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
|
||||
uint32_t cs42l51_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
|
||||
uint32_t cs42l51_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
|
||||
uint32_t cs42l51_Reset(uint16_t DeviceAddr);
|
||||
|
||||
/* AUDIO IO functions */
|
||||
void AUDIO_IO_Init(void);
|
||||
void AUDIO_IO_DeInit(void);
|
||||
void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
|
||||
void AUDIO_IO_Delay(uint32_t Delay);
|
||||
|
||||
/* Audio driver structure */
|
||||
extern AUDIO_DrvTypeDef cs42l51_drv;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __CS42L51_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user