Sync inav to Gitea
Make sure docs are updated / settings_md (push) Canceled after 0s
Build firmware / test (push) Canceled after 0s
Build firmware / build-SITL-Windows (push) Canceled after 0s
Build firmware / build-SITL-Mac (push) Canceled after 0s
Build firmware / build-SITL-Linux (push) Canceled after 0s
Build firmware / build-SITL-Linux-arm64 (push) Canceled after 0s
Build firmware / upload-artifacts (push) Canceled after 0s
Build firmware / build-single-target (push) Canceled after 0s
Build firmware / build (9) (push) Canceled after 0s
Build firmware / build (8) (push) Canceled after 0s
Build firmware / build (7) (push) Canceled after 0s
Build firmware / build (6) (push) Canceled after 0s
Build firmware / build (5) (push) Canceled after 0s
Build firmware / build (4) (push) Canceled after 0s
Build firmware / build (3) (push) Canceled after 0s
Build firmware / build (2) (push) Canceled after 0s
Build firmware / build (14) (push) Canceled after 0s
Build firmware / build (13) (push) Canceled after 0s
Build firmware / build (12) (push) Canceled after 0s
Build firmware / build (11) (push) Canceled after 0s
Build firmware / build (10) (push) Canceled after 0s
Build firmware / build (1) (push) Canceled after 0s
Build firmware / build (0) (push) Canceled after 0s
Build firmware / detect (push) Canceled after 0s
Build pre-release / build (push) Canceled after 0s
Build pre-release / Release (push) Canceled after 0s
Make sure docs are updated / settings_md (push) Canceled after 0s
Build firmware / test (push) Canceled after 0s
Build firmware / build-SITL-Windows (push) Canceled after 0s
Build firmware / build-SITL-Mac (push) Canceled after 0s
Build firmware / build-SITL-Linux (push) Canceled after 0s
Build firmware / build-SITL-Linux-arm64 (push) Canceled after 0s
Build firmware / upload-artifacts (push) Canceled after 0s
Build firmware / build-single-target (push) Canceled after 0s
Build firmware / build (9) (push) Canceled after 0s
Build firmware / build (8) (push) Canceled after 0s
Build firmware / build (7) (push) Canceled after 0s
Build firmware / build (6) (push) Canceled after 0s
Build firmware / build (5) (push) Canceled after 0s
Build firmware / build (4) (push) Canceled after 0s
Build firmware / build (3) (push) Canceled after 0s
Build firmware / build (2) (push) Canceled after 0s
Build firmware / build (14) (push) Canceled after 0s
Build firmware / build (13) (push) Canceled after 0s
Build firmware / build (12) (push) Canceled after 0s
Build firmware / build (11) (push) Canceled after 0s
Build firmware / build (10) (push) Canceled after 0s
Build firmware / build (1) (push) Canceled after 0s
Build firmware / build (0) (push) Canceled after 0s
Build firmware / detect (push) Canceled after 0s
Build pre-release / build (push) Canceled after 0s
Build pre-release / Release (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<!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 Driver</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-driver"><strong>Release Notes for CS42L51 Component Driver</strong></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>
|
||||
This software component is licensed by ST under BSD 3-Clause license, the “License”; You may not use this component except in compliance with the License. You may obtain a copy of the License at:
|
||||
<center>
|
||||
<a href="https://opensource.org/licenses/BSD-3-Clause">https://opensource.org/licenses/BSD-3-Clause</a>
|
||||
</center>
|
||||
<h1 id="purpose">Purpose</h1>
|
||||
<p>This driver provides a set of audio functions offered by CS42L51 codec component</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-section3" checked aria-hidden="true"> <label for="collapse-section3" aria-hidden="true"><strong>V2.0.1 / 30-October-2019</strong></label>
|
||||
<div>
|
||||
<h2 id="main-changes">Main Changes</h2>
|
||||
<ul>
|
||||
<li>Update st_logo.png inclusion path in Release notes.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse">
|
||||
<input type="checkbox" id="collapse-section2" checked aria-hidden="true"> <label for="collapse-section2" aria-hidden="true"><strong>V2.0.0 / 14-October-2019</strong></label>
|
||||
<div>
|
||||
<h2 id="main-changes-1">Main Changes</h2>
|
||||
<ul>
|
||||
<li>First Official release of CS42L51 BSP drivers in line with STM32Cube BSP drivers development guidelines (UM2298)</li>
|
||||
<li>The component drivers are composed of
|
||||
<ul>
|
||||
<li>component core drivers files: cs42l51.h/.c</li>
|
||||
<li>component register drivers files: cs42l51_regs.h/.c</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<h2 id="backward-compatibility">Backward Compatibility</h2>
|
||||
<ul>
|
||||
<li>This version breaks the compatibility with previous versions</li>
|
||||
</ul>
|
||||
<h2 id="dependencies">Dependencies</h2>
|
||||
<ul>
|
||||
<li><p>This software release is compatible with:</p>
|
||||
<ul>
|
||||
<li>BSP Common v6.0.1 or above</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse">
|
||||
<input type="checkbox" id="collapse-section1" checked aria-hidden="true"> <label for="collapse-section1" aria-hidden="true"><strong>V1.0.0 / 17-February-2017</strong></label>
|
||||
<div>
|
||||
<h2 id="main-changes-2">Main Changes</h2>
|
||||
<ul>
|
||||
<li>First official release of <strong>CS42L51</strong> Audio codec Component drivers</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="sticky">
|
||||
For complete documentation on <mark>STM32 Microcontrollers</mark> , visit: <span style="font-color: blue;"><a href="http://www.st.com/STM32">www.st.com</a></span>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,92 @@
|
||||
---
|
||||
pagetitle: Release Notes for CS42L51 Component Driver
|
||||
lang: en
|
||||
---
|
||||
|
||||
::: {.row}
|
||||
::: {.col-sm-12 .col-lg-4}
|
||||
|
||||
::: {.card .fluid}
|
||||
::: {.sectione .dark}
|
||||
<center>
|
||||
# **Release Notes for CS42L51 Component Driver**
|
||||
Copyright © 2017 STMicroelectronics\
|
||||
|
||||
[](https://www.st.com){.logo}
|
||||
</center>
|
||||
:::
|
||||
:::
|
||||
|
||||
# License
|
||||
|
||||
This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this component except in
|
||||
compliance with the License. You may obtain a copy of the License at:
|
||||
<center>
|
||||
[https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
|
||||
</center>
|
||||
|
||||
# Purpose
|
||||
|
||||
This driver provides a set of audio functions offered by CS42L51 codec component
|
||||
|
||||
:::
|
||||
|
||||
::: {.col-sm-12 .col-lg-8}
|
||||
# Update History
|
||||
|
||||
::: {.collapse}
|
||||
<input type="checkbox" id="collapse-section3" checked aria-hidden="true">
|
||||
<label for="collapse-section3" aria-hidden="true">__V2.0.1 / 30-October-2019__</label>
|
||||
<div>
|
||||
|
||||
## Main Changes
|
||||
|
||||
- Update st_logo.png inclusion path in Release notes.
|
||||
|
||||
</div>
|
||||
:::
|
||||
|
||||
::: {.collapse}
|
||||
<input type="checkbox" id="collapse-section2" checked aria-hidden="true">
|
||||
<label for="collapse-section2" aria-hidden="true">__V2.0.0 / 14-October-2019__</label>
|
||||
<div>
|
||||
|
||||
## Main Changes
|
||||
|
||||
- First Official release of CS42L51 BSP drivers in line with STM32Cube BSP drivers development guidelines (UM2298)
|
||||
- The component drivers are composed of
|
||||
- component core drivers files: cs42l51.h/.c
|
||||
- component register drivers files: cs42l51_regs.h/.c
|
||||
|
||||
## Backward Compatibility
|
||||
|
||||
- This version breaks the compatibility with previous versions
|
||||
|
||||
## Dependencies
|
||||
|
||||
- This software release is compatible with:
|
||||
|
||||
- BSP Common v6.0.1 or above
|
||||
|
||||
</div>
|
||||
:::
|
||||
|
||||
::: {.collapse}
|
||||
<input type="checkbox" id="collapse-section1" checked aria-hidden="true">
|
||||
<label for="collapse-section1" aria-hidden="true">__V1.0.0 / 17-February-2017__</label>
|
||||
<div>
|
||||
|
||||
## Main Changes
|
||||
|
||||
- First official release of **CS42L51** Audio codec Component drivers
|
||||
|
||||
</div>
|
||||
:::
|
||||
|
||||
:::
|
||||
:::
|
||||
|
||||
<footer class="sticky">
|
||||
For complete documentation on <mark>STM32 Microcontrollers</mark> ,
|
||||
visit: [[www.st.com](http://www.st.com/STM32)]{style="font-color: blue;"}
|
||||
</footer>
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,722 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs42l51.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the CS42L51 Audio Codec driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2018 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_Private_Types Private Types
|
||||
* @{
|
||||
*/
|
||||
/* Audio codec driver structure initialization */
|
||||
CS42L51_Drv_t CS42L51_Driver =
|
||||
{
|
||||
CS42L51_Init,
|
||||
CS42L51_DeInit,
|
||||
CS42L51_ReadID,
|
||||
CS42L51_Play,
|
||||
CS42L51_Pause,
|
||||
CS42L51_Resume,
|
||||
CS42L51_Stop,
|
||||
CS42L51_SetFrequency,
|
||||
CS42L51_GetFrequency,
|
||||
CS42L51_SetVolume,
|
||||
CS42L51_GetVolume,
|
||||
CS42L51_SetMute,
|
||||
CS42L51_SetOutputMode,
|
||||
CS42L51_SetResolution,
|
||||
CS42L51_GetResolution,
|
||||
CS42L51_SetProtocol,
|
||||
CS42L51_GetProtocol,
|
||||
CS42L51_Reset
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Variables Private Variables
|
||||
* @{
|
||||
*/
|
||||
static uint32_t CS42L51_CurrentDevices = CS42L51_OUT_NONE;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Function_Prototypes Function Prototypes
|
||||
* @{
|
||||
*/
|
||||
static int32_t CS42L51_ReadRegWrap(void *handle, uint16_t Reg, uint8_t* Data, uint16_t Length);
|
||||
static int32_t CS42L51_WriteRegWrap(void *handle, uint16_t Reg, uint8_t* Data, uint16_t Length);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Private_Functions Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the audio codec and the control interface.
|
||||
* @param pObj pointer to component object
|
||||
* @param pInit pointer de component init structure
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_Init(CS42L51_Object_t *pObj, CS42L51_Init_t *pInit)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
uint8_t tmp;
|
||||
|
||||
if(pObj->IsInitialized == 0U)
|
||||
{
|
||||
/* Set the device in standby mode */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp |= 0x01U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
|
||||
/* Set all power down bits to 1 */
|
||||
tmp = 0x7FU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp |= 0x0EU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
|
||||
pObj->IsInitialized = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set all power down bits to 1 exept PDN to mute ADCs and DACs*/
|
||||
tmp = 0x7EU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp |= 0x0EU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
|
||||
/* Disable zero cross and soft ramp */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_DAC_CTRL, &tmp, 1);
|
||||
tmp &= 0xFCU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_DAC_CTRL, &tmp, 1);
|
||||
|
||||
/* Power control : Enter standby (PDN = 1) */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp |= 0x01U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
}
|
||||
|
||||
|
||||
/* Mic Power and Speed Control : Auto detect on, Speed mode SSM, tri state off, MCLK divide by 2 off */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp = ((tmp & 0x0EU) | 0xA0U);
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
|
||||
/* Interface control : Loopback off, Slave, I2S (SDIN and SOUT), Digital mix off, Mic mix off */
|
||||
tmp = 0x0CU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_INTERFACE_CTRL, &tmp, 1);
|
||||
|
||||
/* Mic control : ADC single volume off, ADCB boost off, ADCA boost off, MicBias on AIN3B/MICIN2 pin, MicBias level 0.8xVA, MICB boost 32db, MICA boost 32dB */
|
||||
tmp = 0x03U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_CTRL, &tmp, 1);
|
||||
|
||||
/* ADC control : ADCB HPF on, ADCB HPF freeze off, ADCA HPF on, ADCA HPF freeze off, Soft ramp B on, Zero cross B on, Soft ramp A on, Zero cross A on */
|
||||
tmp = 0xAFU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADC_CTRL, &tmp, 1);
|
||||
|
||||
/* DAC output control : HP Gain to 1, Single volume control off, PCM invert signals polarity off, DAC channels mute on */
|
||||
tmp = 0xC3U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_DAC_OUTPUT_CTRL, &tmp, 1);
|
||||
|
||||
/* DAC control : Signal processing to DAC, Freeze off, De-emphasis off, Analog output auto mute off, DAC soft ramp */
|
||||
tmp = 0x42U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_DAC_CTRL, &tmp, 1);
|
||||
|
||||
/* ALCA and PGAA Control : ALCA soft ramp disable on, ALCA zero cross disable on, PGA A Gain +8dB */
|
||||
tmp = 0xD0U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ALCA_PGAA_CTRL, &tmp, 1);
|
||||
|
||||
/* ALCB and PGAB Control : ALCB soft ramp disable on, ALCB zero cross disable on, PGA B Gain +8dB */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ALCB_PGAB_CTRL, &tmp, 1);
|
||||
|
||||
/* ADCA Attenuator : 0dB */
|
||||
tmp = 0x00U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADCA_ATTENUATOR, &tmp, 1);
|
||||
|
||||
/* ADCB Attenuator : 0dB */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADCB_ATTENUATOR, &tmp, 1);
|
||||
|
||||
/* ADCA mixer volume control : ADCA mixer channel mute on, ADCA mixer volume 0dB */
|
||||
tmp = 0x80U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADCA_MIXER_VOL_CTRL, &tmp, 1);
|
||||
|
||||
/* ADCB mixer volume control : ADCB mixer channel mute on, ADCB mixer volume 0dB */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADCB_MIXER_VOL_CTRL, &tmp, 1);
|
||||
|
||||
/* PCMA mixer volume control : PCMA mixer channel mute off, PCMA mixer volume 0dB */
|
||||
tmp = 0x00U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PCMA_MIXER_VOL_CTRL, &tmp, 1);
|
||||
|
||||
/* PCMB mixer volume control : PCMB mixer channel mute off, PCMB mixer volume 0dB */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PCMB_MIXER_VOL_CTRL, &tmp, 1);
|
||||
|
||||
/* PCM channel mixer : AOUTA Left, AOUTB Right */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADC_PCM_CHANNEL_MIXER, &tmp, 1);
|
||||
|
||||
if((pInit->OutputDevice & CS42L51_OUT_HEADPHONE) == CS42L51_OUT_HEADPHONE)
|
||||
{
|
||||
tmp = VOLUME_CONVERT(pInit->Volume);
|
||||
/* AOUTA volume control : AOUTA volume */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_AOUTA_VOL_CTRL, &tmp, 1);
|
||||
/* AOUTB volume control : AOUTB volume */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_AOUTB_VOL_CTRL, &tmp, 1);
|
||||
}
|
||||
|
||||
/* ALC enable and attack rate : ALCB and ALCA enable, fastest attack */
|
||||
tmp = 0x40U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ALC_ENABLE_AND_ATTACK_RATE, &tmp, 1);
|
||||
|
||||
/* Store current devices */
|
||||
CS42L51_CurrentDevices = (pInit->OutputDevice | pInit->InputDevice);
|
||||
|
||||
if(ret != CS42L51_OK)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitializes the audio codec.
|
||||
* @param pObj pointer to component object
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_DeInit(CS42L51_Object_t *pObj)
|
||||
{
|
||||
if(pObj->IsInitialized == 1U)
|
||||
{
|
||||
pObj->IsInitialized = 0U;
|
||||
}
|
||||
|
||||
return CS42L51_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the CS42L51 ID.
|
||||
* @param pObj pointer to component object
|
||||
* @param Id component ID
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_ReadID(CS42L51_Object_t *pObj, uint32_t *Id)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t cs42l51_id;
|
||||
|
||||
/* Initialize the Control interface of the Audio Codec */
|
||||
pObj->IO.Init();
|
||||
|
||||
/* Get ID from component */
|
||||
ret = cs42l51_read_reg(&pObj->Ctx, CS42L51_CHIP_ID, &cs42l51_id, 1);
|
||||
|
||||
*Id = cs42l51_id;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start the audio Codec play feature.
|
||||
* @note For this codec no Play options are required.
|
||||
* @param pObj pointer to component object
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_Play(CS42L51_Object_t *pObj)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
uint8_t tmp;
|
||||
|
||||
if((CS42L51_CurrentDevices & CS42L51_OUT_HEADPHONE) == CS42L51_OUT_HEADPHONE)
|
||||
{
|
||||
/* Unmute the output first */
|
||||
ret += CS42L51_SetMute(pObj, CS42L51_MUTE_OFF);
|
||||
|
||||
/* DAC control : Signal processing to DAC, Freeze off, De-emphasis off, Analog output auto mute off, DAC soft ramp */
|
||||
tmp = 0x42U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_DAC_CTRL, &tmp, 1);
|
||||
|
||||
/* Power control 1 : PDN_DACA, PDN_DACB disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp &= 0x9FU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
}
|
||||
|
||||
if((CS42L51_CurrentDevices & CS42L51_IN_LINE1) == CS42L51_IN_LINE1)
|
||||
{
|
||||
/* ADC Input Select, Invert and Mute : AIN1B to PGAB, AIN1A to PGAA, ADCB invert off, ADCA invert off, ADCB mute off, ADCA mute off */
|
||||
tmp = 0x00U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADCX_INPUT_SELECT, &tmp, 1);
|
||||
|
||||
/* Power control 1 : PDN_PGAA, PDN_PGAA, PDN_ADCB, PDN_ADCA disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp &= 0xF9U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
|
||||
/* Mic Power and Speed Control : PDN_MICA, PDN_MICB, PDN_MIC_BIAS disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp &= 0xFFU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
}
|
||||
|
||||
if((CS42L51_CurrentDevices & CS42L51_IN_MIC1) == CS42L51_IN_MIC1)
|
||||
{
|
||||
/* 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 */
|
||||
tmp = 0x32U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_ADCX_INPUT_SELECT, &tmp, 1);
|
||||
|
||||
/* Power control 1 : PDN_PGAA, PDN_ADCA disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp &= 0xF5U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
|
||||
/* Mic Power and Speed Control : PDN_MICA, PDN_MIC_BIAS disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp &= 0xF9U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
}
|
||||
|
||||
if((CS42L51_CurrentDevices & CS42L51_IN_MIC2) == CS42L51_IN_MIC2)
|
||||
{
|
||||
/* Power control 1 : PDN_PGAB, PDN_ADCB disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp &= 0xEBU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
|
||||
/* Mic Power and Speed Control : PDN_MICB, PDN_MIC_BIAS disable. */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp &= 0xF5U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
}
|
||||
|
||||
/* Power control : Exit standby (PDN = 0) */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp &= 0xFEU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pauses playing on the audio codec.
|
||||
* @param pObj pointer to component object
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_Pause(CS42L51_Object_t *pObj)
|
||||
{
|
||||
/* Pause the audio file playing */
|
||||
if(CS42L51_SetMute(pObj, CS42L51_MUTE_ON) != CS42L51_OK)
|
||||
{
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
return CS42L51_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resumes playing on the audio codec.
|
||||
* @param pObj pointer to component object
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_Resume(CS42L51_Object_t *pObj)
|
||||
{
|
||||
/* Resumes the audio file playing */
|
||||
return CS42L51_SetMute(pObj, CS42L51_MUTE_OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops audio Codec playing. It powers down the codec.
|
||||
* @param pObj pointer to component object
|
||||
* @param CodecPdwnMode selects the power down mode.
|
||||
* - CS42L51_PDWN_SW: only mutes the audio codec. When resuming from this
|
||||
* mode the codec keeps the previous initialization
|
||||
* (no need to re-Initialize the codec registers).
|
||||
* - CS42L51_PDWN_HW: Physically power down the codec. When resuming from this
|
||||
* mode, the codec is set to default configuration
|
||||
* (user should re-Initialize the codec in order to
|
||||
* play again the audio stream).
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_Stop(CS42L51_Object_t *pObj, uint32_t CodecPdwnMode)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t tmp;
|
||||
|
||||
/* Mute the output first */
|
||||
ret = CS42L51_SetMute(pObj, CS42L51_MUTE_ON);
|
||||
|
||||
if (CodecPdwnMode == CS42L51_PDWN_SW)
|
||||
{
|
||||
/* Only output mute required*/
|
||||
}
|
||||
else /* CS42L51_PDWN_HW */
|
||||
{
|
||||
/* Set all power down bits to 1 exept PDN to mute ADCs and DACs*/
|
||||
tmp = 0x7EU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
tmp |= 0x0EU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_MIC_PWR_SPEED_CTRL, &tmp, 1);
|
||||
|
||||
/* Disable zero cross and soft ramp */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_DAC_CTRL, &tmp, 1);
|
||||
tmp &= 0xFCU;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_DAC_CTRL, &tmp, 1);
|
||||
|
||||
/* Power control : Enter standby (PDN = 1) */
|
||||
ret += cs42l51_read_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
tmp |= 0x01U;
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_PWR_CTRL_1, &tmp, 1);
|
||||
}
|
||||
|
||||
if(ret != CS42L51_OK)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set higher or lower the codec volume level.
|
||||
* @param pObj pointer to component object
|
||||
* @param InputOutput Input or Output volume
|
||||
* @param Volume a byte value from 0 to 255
|
||||
* (refer to codec registers description for more details).
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_SetVolume(CS42L51_Object_t *pObj, uint32_t InputOutput, uint8_t Volume)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t convertedvol;
|
||||
|
||||
if(InputOutput != VOLUME_OUTPUT)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedvol = VOLUME_CONVERT(Volume);
|
||||
|
||||
/* AOUTA volume control : AOUTA volume */
|
||||
ret = cs42l51_write_reg(&pObj->Ctx, CS42L51_AOUTA_VOL_CTRL, &convertedvol, 1);
|
||||
/* AOUTB volume control : AOUTB volume */
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_AOUTB_VOL_CTRL, &convertedvol, 1);
|
||||
}
|
||||
|
||||
if(ret != CS42L51_OK)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get higher or lower the codec volume level.
|
||||
* @param pObj pointer to component object
|
||||
* @param InputOutput Input or Output volume
|
||||
* @param Volume audio volume
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_GetVolume(CS42L51_Object_t *pObj, uint32_t InputOutput, uint8_t *Volume)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t tmp;
|
||||
|
||||
if(InputOutput != VOLUME_OUTPUT)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = cs42l51_read_reg(&pObj->Ctx, CS42L51_AOUTA_VOL_CTRL, &tmp, 1);
|
||||
*Volume = VOLUME_INVERT(tmp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables or disables the mute feature on the audio codec.
|
||||
* @param pObj pointer to component object
|
||||
* @param Cmd CS42L51_MUTE_ON to enable the mute or CS42L51_MUTE_OFF to disable the
|
||||
* mute mode.
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_SetMute(CS42L51_Object_t *pObj, uint32_t Cmd)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t tmp;
|
||||
|
||||
ret = cs42l51_read_reg(&pObj->Ctx, CS42L51_DAC_OUTPUT_CTRL, &tmp, 1);
|
||||
|
||||
/* Set the Mute mode */
|
||||
if(Cmd == CS42L51_MUTE_ON)
|
||||
{
|
||||
tmp |= 0x03U;
|
||||
}
|
||||
else /* CS42L51_MUTE_OFF Disable the Mute */
|
||||
{
|
||||
tmp &= 0xFCU;
|
||||
}
|
||||
|
||||
ret += cs42l51_write_reg(&pObj->Ctx, CS42L51_DAC_OUTPUT_CTRL, &tmp, 1);
|
||||
|
||||
if(ret != CS42L51_OK)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Switch dynamically (while audio file is played) the output target
|
||||
* (speaker or headphone).
|
||||
* @param pObj pointer to component object
|
||||
* @param Output Only CS42L51_OUT_HEADPHONE output is supported
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_SetOutputMode(CS42L51_Object_t *pObj, uint32_t Output)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(Output);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Audio resolution.
|
||||
* @param pObj pointer to component object
|
||||
* @param Resolution Audio resolution. Can be:
|
||||
* CS42L51_RESOLUTION_16b, CS42L51_RESOLUTION_18b,
|
||||
* CS42L51_RESOLUTION_20b or CS42L51_RESOLUTION_24b
|
||||
* @note This is applicable only for CS42L51_PROTOCOL_R_JUSTIFIED protocol
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_SetResolution(CS42L51_Object_t *pObj, uint32_t Resolution)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(Resolution);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Audio resolution.
|
||||
* @param pObj pointer to component object
|
||||
* @retval Audio resolution
|
||||
*/
|
||||
int32_t CS42L51_GetResolution(CS42L51_Object_t *pObj, uint32_t *Resolution)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(Resolution);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Audio Protocol.
|
||||
* @param pObj pointer to component object
|
||||
* @param Protocol Audio Protocol. Can be:
|
||||
* CS42L51_PROTOCOL_R_JUSTIFIED, CS42L51_PROTOCOL_L_JUSTIFIED
|
||||
* or CS42L51_PROTOCOL_I2S
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_SetProtocol(CS42L51_Object_t *pObj, uint32_t Protocol)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(Protocol);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Audio Protocol.
|
||||
* @param pObj pointer to component object
|
||||
* @param Protocol pointer to protocol value
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_GetProtocol(CS42L51_Object_t *pObj, uint32_t *Protocol)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(Protocol);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets new frequency.
|
||||
* @param pObj pointer to component object
|
||||
* @param AudioFreq Audio frequency
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_SetFrequency(CS42L51_Object_t *pObj, uint32_t AudioFreq)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(AudioFreq);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get frequency.
|
||||
* @param pObj pointer to component object
|
||||
* @param AudioFreq Audio frequency
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_GetFrequency(CS42L51_Object_t *pObj, uint32_t *AudioFreq)
|
||||
{
|
||||
(void)(pObj);
|
||||
(void)(AudioFreq);
|
||||
|
||||
/* This feature is not supported */
|
||||
return CS42L51_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resets cs42l51 registers.
|
||||
* @param pObj pointer to component object
|
||||
* @retval Component status
|
||||
*/
|
||||
int32_t CS42L51_Reset(CS42L51_Object_t *pObj)
|
||||
{
|
||||
/* De-Initialize Audio Codec interface */
|
||||
pObj->IO.DeInit();
|
||||
|
||||
/* Initialize Audio Codec interface */
|
||||
pObj->IO.Init();
|
||||
|
||||
return CS42L51_OK;
|
||||
}
|
||||
|
||||
/******************** Static functions ****************************************/
|
||||
/**
|
||||
* @brief Function
|
||||
* @param Component object pointer
|
||||
* @retval error status
|
||||
*/
|
||||
int32_t CS42L51_RegisterBusIO (CS42L51_Object_t *pObj, CS42L51_IO_t *pIO)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (pObj == NULL)
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
pObj->IO.Init = pIO->Init;
|
||||
pObj->IO.DeInit = pIO->DeInit;
|
||||
pObj->IO.Address = pIO->Address;
|
||||
pObj->IO.WriteReg = pIO->WriteReg;
|
||||
pObj->IO.ReadReg = pIO->ReadReg;
|
||||
pObj->IO.GetTick = pIO->GetTick;
|
||||
|
||||
pObj->Ctx.ReadReg = CS42L51_ReadRegWrap;
|
||||
pObj->Ctx.WriteReg = CS42L51_WriteRegWrap;
|
||||
pObj->Ctx.handle = pObj;
|
||||
|
||||
if(pObj->IO.Init != NULL)
|
||||
{
|
||||
ret = pObj->IO.Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = CS42L51_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function
|
||||
* @param handle Component object handle
|
||||
* @param Reg The target register address to write
|
||||
* @param pData The target register value to be written
|
||||
* @param Length buffer size to be written
|
||||
* @retval error status
|
||||
*/
|
||||
static int32_t CS42L51_ReadRegWrap(void *handle, uint16_t Reg, uint8_t* pData, uint16_t Length)
|
||||
{
|
||||
CS42L51_Object_t *pObj = (CS42L51_Object_t *)handle;
|
||||
|
||||
return pObj->IO.ReadReg(pObj->IO.Address, Reg, pData, Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function
|
||||
* @param handle Component object handle
|
||||
* @param Reg The target register address to write
|
||||
* @param pData The target register value to be written
|
||||
* @param Length buffer size to be written
|
||||
* @retval error status
|
||||
*/
|
||||
static int32_t CS42L51_WriteRegWrap(void *handle, uint16_t Reg, uint8_t* pData, uint16_t Length)
|
||||
{
|
||||
CS42L51_Object_t *pObj = (CS42L51_Object_t *)handle;
|
||||
|
||||
return pObj->IO.WriteReg(pObj->IO.Address, Reg, pData, Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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) 2018 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 "cs42l51_reg.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Component
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CS42L51
|
||||
* @{
|
||||
*/
|
||||
typedef int32_t (*CS42L51_Init_Func) (void);
|
||||
typedef int32_t (*CS42L51_DeInit_Func) (void);
|
||||
typedef int32_t (*CS42L51_GetTick_Func) (void);
|
||||
typedef int32_t (*CS42L51_Delay_Func) (uint32_t);
|
||||
typedef int32_t (*CS42L51_WriteReg_Func)(uint16_t, uint16_t, uint8_t*, uint16_t);
|
||||
typedef int32_t (*CS42L51_ReadReg_Func) (uint16_t, uint16_t, uint8_t*, uint16_t);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CS42L51_Init_Func Init;
|
||||
CS42L51_DeInit_Func DeInit;
|
||||
uint16_t Address;
|
||||
CS42L51_WriteReg_Func WriteReg;
|
||||
CS42L51_ReadReg_Func ReadReg;
|
||||
CS42L51_GetTick_Func GetTick;
|
||||
} CS42L51_IO_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CS42L51_IO_t IO;
|
||||
cs42l51_ctx_t Ctx;
|
||||
uint8_t IsInitialized;
|
||||
} CS42L51_Object_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t InputDevice;
|
||||
uint32_t OutputDevice;
|
||||
uint32_t Frequency;
|
||||
uint32_t Resolution;
|
||||
uint32_t Volume;
|
||||
} CS42L51_Init_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t ( *Init ) ( CS42L51_Object_t *, CS42L51_Init_t* );
|
||||
int32_t ( *DeInit ) ( CS42L51_Object_t * );
|
||||
int32_t ( *ReadID ) ( CS42L51_Object_t *, uint32_t * );
|
||||
int32_t ( *Play ) ( CS42L51_Object_t * );
|
||||
int32_t ( *Pause ) ( CS42L51_Object_t * );
|
||||
int32_t ( *Resume ) ( CS42L51_Object_t * );
|
||||
int32_t ( *Stop ) ( CS42L51_Object_t *, uint32_t );
|
||||
int32_t ( *SetFrequency ) ( CS42L51_Object_t *, uint32_t );
|
||||
int32_t ( *GetFrequency ) ( CS42L51_Object_t *, uint32_t*);
|
||||
int32_t ( *SetVolume ) ( CS42L51_Object_t *, uint32_t, uint8_t );
|
||||
int32_t ( *GetVolume ) ( CS42L51_Object_t *, uint32_t, uint8_t*);
|
||||
int32_t ( *SetMute ) ( CS42L51_Object_t *, uint32_t );
|
||||
int32_t ( *SetOutputMode ) ( CS42L51_Object_t *, uint32_t );
|
||||
int32_t ( *SetResolution ) ( CS42L51_Object_t *, uint32_t );
|
||||
int32_t ( *GetResolution ) ( CS42L51_Object_t *, uint32_t*);
|
||||
int32_t ( *SetProtocol ) ( CS42L51_Object_t *, uint32_t );
|
||||
int32_t ( *GetProtocol ) ( CS42L51_Object_t *, uint32_t*);
|
||||
int32_t ( *Reset ) ( CS42L51_Object_t * );
|
||||
} CS42L51_Drv_t;
|
||||
|
||||
|
||||
/** @defgroup CS42L51_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
#define CS42L51_OK (0)
|
||||
#define CS42L51_ERROR (-1)
|
||||
|
||||
/******************************************************************************/
|
||||
/*************************** Codec User defines ******************************/
|
||||
/******************************************************************************/
|
||||
/* Audio Input Device */
|
||||
#define CS42L51_IN_NONE 0x0000U
|
||||
#define CS42L51_IN_MIC1 0x0100U
|
||||
#define CS42L51_IN_MIC2 0x0200U
|
||||
#define CS42L51_IN_LINE1 0x0400U
|
||||
#define CS42L51_IN_LINE2 0x0800U
|
||||
#define CS42L51_IN_LINE3 0x1000U
|
||||
|
||||
/* Audio Output Device */
|
||||
#define CS42L51_OUT_NONE 0x0000U
|
||||
#define CS42L51_OUT_HEADPHONE 0x0001U
|
||||
|
||||
/* AUDIO FREQUENCY */
|
||||
#define CS42L51_FREQUENCY_192K 192000
|
||||
#define CS42L51_FREQUENCY_176K 176400
|
||||
#define CS42L51_FREQUENCY_96K 96000
|
||||
#define CS42L51_FREQUENCY_88K 88200
|
||||
#define CS42L51_FREQUENCY_48K 48000
|
||||
#define CS42L51_FREQUENCY_44K 44100
|
||||
#define CS42L51_FREQUENCY_32K 32000
|
||||
#define CS42L51_FREQUENCY_22K 22050
|
||||
#define CS42L51_FREQUENCY_16K 16000
|
||||
#define CS42L51_FREQUENCY_11K 11025
|
||||
#define CS42L51_FREQUENCY_8K 8000
|
||||
|
||||
/* AUDIO RESOLUTION */
|
||||
#define CS42L51_RESOLUTION_16b 0x05U
|
||||
#define CS42L51_RESOLUTION_18b 0x04U
|
||||
#define CS42L51_RESOLUTION_20b 0x03U
|
||||
#define CS42L51_RESOLUTION_24b 0x02U
|
||||
|
||||
/* Codec stop options */
|
||||
#define CS42L51_PDWN_HW 0x00U
|
||||
#define CS42L51_PDWN_SW 0x01U
|
||||
|
||||
/* Volume Input Output selection */
|
||||
#define VOLUME_INPUT 0U
|
||||
#define VOLUME_OUTPUT 1U
|
||||
|
||||
/* MUTE commands */
|
||||
#define CS42L51_MUTE_ON 1U
|
||||
#define CS42L51_MUTE_OFF 0U
|
||||
|
||||
/* AUDIO PROTOCOL */
|
||||
#define CS42L51_PROTOCOL_L_JUSTIFIED 0U
|
||||
#define CS42L51_PROTOCOL_I2S 1U
|
||||
#define CS42L51_PROTOCOL_R_JUSTIFIED 2U
|
||||
|
||||
#define VOLUME_CONVERT(Volume) (((Volume) >= 100U) ? 0U : ((uint8_t)((((Volume) * 2U) + 56U))))
|
||||
#define VOLUME_INVERT(Volume) (((Volume) == 0U) ? 100U : ((uint8_t)(((Volume) - 56U) / 2U)))
|
||||
|
||||
/**
|
||||
* @brief CS42L51 ID
|
||||
*/
|
||||
#define CS42L51_ID 0xD8U
|
||||
#define CS42L51_ID_MASK 0xF8U
|
||||
|
||||
/** @defgroup CS42L51_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CS42L51_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
Audio Codec functions
|
||||
------------------------------------------------------------------------------*/
|
||||
/* High Layer codec functions */
|
||||
int32_t CS42L51_RegisterBusIO (CS42L51_Object_t *pObj, CS42L51_IO_t *pIO);
|
||||
int32_t CS42L51_Init(CS42L51_Object_t *pObj, CS42L51_Init_t *pInit);
|
||||
int32_t CS42L51_DeInit(CS42L51_Object_t *pObj);
|
||||
int32_t CS42L51_ReadID(CS42L51_Object_t *pObj, uint32_t *Id);
|
||||
int32_t CS42L51_Play(CS42L51_Object_t *pObj);
|
||||
int32_t CS42L51_Pause(CS42L51_Object_t *pObj);
|
||||
int32_t CS42L51_Resume(CS42L51_Object_t *pObj);
|
||||
int32_t CS42L51_Stop(CS42L51_Object_t *pObj, uint32_t CodecPdwnMode);
|
||||
int32_t CS42L51_SetVolume(CS42L51_Object_t *pObj, uint32_t InputOutput, uint8_t Volume);
|
||||
int32_t CS42L51_GetVolume(CS42L51_Object_t *pObj, uint32_t InputOutput, uint8_t *Volume);
|
||||
int32_t CS42L51_SetMute(CS42L51_Object_t *pObj, uint32_t Cmd);
|
||||
int32_t CS42L51_SetOutputMode(CS42L51_Object_t *pObj, uint32_t Output);
|
||||
int32_t CS42L51_SetResolution(CS42L51_Object_t *pObj, uint32_t Resolution);
|
||||
int32_t CS42L51_GetResolution(CS42L51_Object_t *pObj, uint32_t *Resolution);
|
||||
int32_t CS42L51_SetProtocol(CS42L51_Object_t *pObj, uint32_t Protocol);
|
||||
int32_t CS42L51_GetProtocol(CS42L51_Object_t *pObj, uint32_t *Protocol);
|
||||
int32_t CS42L51_SetFrequency(CS42L51_Object_t *pObj, uint32_t AudioFreq);
|
||||
int32_t CS42L51_GetFrequency(CS42L51_Object_t *pObj, uint32_t *AudioFreq);
|
||||
int32_t CS42L51_Reset(CS42L51_Object_t *pObj);
|
||||
|
||||
/* Audio driver structure */
|
||||
extern CS42L51_Drv_t CS42L51_Driver;
|
||||
|
||||
#endif /* CS42L51_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs42l51_reg.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides unitary register function to control the CS42L51
|
||||
* Audio Codec driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2018 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_reg.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Components
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup cs42l51
|
||||
* @brief This file provides a set of functions needed to drive the
|
||||
* CS42L51 audio codec.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/************** Generic Function *******************/
|
||||
/*******************************************************************************
|
||||
* Function Name : cs42l51_read_reg
|
||||
* Description : Generic Reading function. It must be fullfilled with either
|
||||
* I2C or SPI reading functions
|
||||
* Input : Register Address, length of buffer
|
||||
* Output : data Read
|
||||
*******************************************************************************/
|
||||
int32_t cs42l51_read_reg(cs42l51_ctx_t *ctx, uint16_t reg, uint8_t* data, uint16_t length)
|
||||
{
|
||||
return ctx->ReadReg(ctx->handle, reg, data, length);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : cs42l51_write_reg
|
||||
* Description : Generic Writing function. It must be fullfilled with either
|
||||
* I2C or SPI writing function
|
||||
* Input : Register Address, data to be written, length of buffer
|
||||
* Output : None
|
||||
*******************************************************************************/
|
||||
int32_t cs42l51_write_reg(cs42l51_ctx_t *ctx, uint16_t reg, uint8_t *data, uint16_t length)
|
||||
{
|
||||
return ctx->WriteReg(ctx->handle, reg, data, length);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cs42l51_reg.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header of cs42l51_reg.c
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2018 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_REG_H
|
||||
#define CS42L51_REG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Component
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CS42L51
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup CS42L51_Exported_Constants CS42L51 Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/****************************** REGISTER MAPPING ******************************/
|
||||
/******************************************************************************/
|
||||
#define CS42L51_CHIP_ID 0x01U
|
||||
#define CS42L51_PWR_CTRL_1 0x02U
|
||||
#define CS42L51_MIC_PWR_SPEED_CTRL 0x03U
|
||||
#define CS42L51_INTERFACE_CTRL 0x04U
|
||||
#define CS42L51_MIC_CTRL 0x05U
|
||||
#define CS42L51_ADC_CTRL 0x06U
|
||||
#define CS42L51_ADCX_INPUT_SELECT 0x07U
|
||||
#define CS42L51_DAC_OUTPUT_CTRL 0x08U
|
||||
#define CS42L51_DAC_CTRL 0x09U
|
||||
#define CS42L51_ALCA_PGAA_CTRL 0x0AU
|
||||
#define CS42L51_ALCB_PGAB_CTRL 0x0BU
|
||||
#define CS42L51_ADCA_ATTENUATOR 0x0CU
|
||||
#define CS42L51_ADCB_ATTENUATOR 0x0DU
|
||||
#define CS42L51_ADCA_MIXER_VOL_CTRL 0x0EU
|
||||
#define CS42L51_ADCB_MIXER_VOL_CTRL 0x0FU
|
||||
#define CS42L51_PCMA_MIXER_VOL_CTRL 0x10U
|
||||
#define CS42L51_PCMB_MIXER_VOL_CTRL 0x11U
|
||||
#define CS42L51_BEEP_FREQ_AND_TIMING_CFG 0x12U
|
||||
#define CS42L51_BEEP_OFF_TIME_AND_VOL 0x13U
|
||||
#define CS42L51_BEEP_CFG_AND_TONE_CFG 0x14U
|
||||
#define CS42L51_TONE_CTRL 0x15U
|
||||
#define CS42L51_AOUTA_VOL_CTRL 0x16U
|
||||
#define CS42L51_AOUTB_VOL_CTRL 0x17U
|
||||
#define CS42L51_ADC_PCM_CHANNEL_MIXER 0x18U
|
||||
#define CS42L51_LIMITER_THR_SZC_DISABLE 0x19U
|
||||
#define CS42L51_LIMITER_RELEASE_RATE_REG 0x1AU
|
||||
#define CS42L51_LIMITER_ATTACK_RATE_REG 0x1BU
|
||||
#define CS42L51_ALC_ENABLE_AND_ATTACK_RATE 0x1CU
|
||||
#define CS42L51_ALC_RELEASE_RATE 0x1DU
|
||||
#define CS42L51_ALC_THR 0x1EU
|
||||
#define CS42L51_NOISE_GATE_CFG_AND_MISC 0x1FU
|
||||
#define CS42L51_STATUS 0x20U
|
||||
#define CS42L51_CHARGE_PUMP_FREQ 0x21U
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************** Generic Function *******************/
|
||||
|
||||
typedef int32_t (*CS42L51_Write_Func)(void *, uint16_t, uint8_t*, uint16_t);
|
||||
typedef int32_t (*CS42L51_Read_Func) (void *, uint16_t, uint8_t*, uint16_t);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CS42L51_Write_Func WriteReg;
|
||||
CS42L51_Read_Func ReadReg;
|
||||
void *handle;
|
||||
} cs42l51_ctx_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* Register : Generic - All
|
||||
* Address : Generic - All
|
||||
* Bit Group Name: None
|
||||
* Permission : W
|
||||
*******************************************************************************/
|
||||
int32_t cs42l51_write_reg(cs42l51_ctx_t *ctx, uint16_t reg, uint8_t *data, uint16_t length);
|
||||
int32_t cs42l51_read_reg(cs42l51_ctx_t *ctx, uint16_t reg, uint8_t* data, uint16_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CS42L51_REG_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user