sd + skpeaker
Dependencies: ST_I2S X_NUCLEO_COMMON
Fork of X_NUCLEO_CCA01M1 by
Diff: Components/sta350bw/sta350bw.h
- Revision:
- 3:c688a4acb4bf
- Parent:
- 0:542c79e7e0ef
diff -r edc4558a75b7 -r c688a4acb4bf Components/sta350bw/sta350bw.h --- a/Components/sta350bw/sta350bw.h Mon Apr 10 13:14:40 2017 +0000 +++ b/Components/sta350bw/sta350bw.h Fri Apr 21 10:07:28 2017 +0200 @@ -4,8 +4,7 @@ * @author Central Labs * @version V1.0.0 * @date 18-August-2015 -* @brief This file contains definitions for STA350BW.c -* firmware driver. +* @brief This file provides the STA350BW SOUND TERMINAL audio driver. ****************************************************************************** * @attention * @@ -37,969 +36,458 @@ */ +/* Generated with STM32CubeTOO -----------------------------------------------*/ + + +/* Revision ------------------------------------------------------------------*/ +/* + Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev + Branch/Trunk/Tag: trunk + Based on: X-CUBE-SOUNDTER1/trunk/Drivers/BSP/Components/STA350BW/STA350BW.h + Revision: 0 +*/ + + /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STA350BW_H -#define __STA350BW_H +#ifndef __STA350BW_CLASS_H +#define __STA350BW_CLASS_H -#ifdef __cplusplus -extern "C" { -#endif - /* Includes ------------------------------------------------------------------*/ -#include "../Common/sound_terminal.h" - - /** @addtogroup BSP - * @{ - */ - - /** @addtogroup Components - * @{ - */ - - /** @addtogroup STA350BW - * @{ - */ - - - /** @defgroup STA350BW_Exported_Constants - * @{ - */ - - /** @defgroup STA350BW_Registers_Mapping - * @brief STA350BW register mapping - * @{ - */ - -#define STA350BW_MAX_REGISTERS ((uint8_t)0x56) - - /** - * @brief Configuration Register A - * \code - * Read/Write - * Default value: 0x63 - * 7 FAULT detect recovery bypass - * 6 TWAB Thermal warning adjustable bypass - * 5 TWRB Thermal warning recovery bypass - * 4,3 IR Interpolatio ratio - * [2:0] MCS Master clock selection - * \endcode - */ -#define STA350BW_CONF_REGA ((uint8_t)0x00) /*Configuration Register A*/ - - /** - * @brief Configuration Register B - * \code - * Read/Write - * Default value: 0x80 - * 7 C2IM channel 2 input mapping - * 6 C2IM channel 1 input mapping - * 5 DSCKE Delay serial clock enable - * 4 SAIFB Serial data first bit - * [3:0] Serial Input interface format - * \endcode - */ -#define STA350BW_CONF_REGB ((uint8_t)0x01) /*Configuration Register B*/ - - - /** - * @brief Configuration Register C - * \code - * Read/write - * Default value: 0x09F - * 7 OCRB Overcurrent warning adjustment bypass - * [5:2] CSZx: FFX compensating pulse size - * [1:0] OMx: FFX Output mode - * 0 Clk_Out: Enable HSE on MCO. 0: MCO disable. 1: MCO enable - * \endcode - */ -#define STA350BW_CONF_REGC ((uint8_t)0x02) /*Configuration Register C*/ - - /** - * @brief I2C address Configuration Register D - * \code - * Read/write - * Default value: 0x40 - * 7 SME soft mute enable - * 6 ZDE zero detect enable - * 5 DRC DRC or anti-clipping mode - * 4 BQL Biquad Link - * 3 PSL Post scale Link - * 2 DSPB DSP bypass - * 1 DEMP De-Emphasys filter - * 0 HPB High pass filter bypass - * \endcode - */ -#define STA350BW_CONF_REGD ((uint8_t)0x03) /*Configuration Register D*/ - - /** - * @brief I2C address Configuration Register E - * \code - * Read/write - * Default value: 0xC2 - * 7 SVE soft volume enable - * 6 ZCE zero crossing enable - * 5 DCCV variable distorsion compensation - * 4 PWMS PWM speed - * 3 AME AM noise reduction enable - * 2 NSBW Noise shaper bandwidth - * 1 MPC Max Power correction - * 0 MPCV Variable ax power correction - * \endcode - */ -#define STA350BW_CONF_REGE ((uint8_t)0x04) /*Configuration Register E*/ - - /** - * @brief I2C address Configuration Register F - * \code - * Read/write - * Default value: 0x5C - * 7 EAPD External Amplifier Power Down - * 6 PWDN device power down - * 5 ECLE Auto EAPD on clock loss - * 4 LDTE LRCK double trigger protection - * 3 BCLE Binary out mode clock loss detection - * 2 IDE Invalid Input Detect - * 1,0 OCFG Output configuration - * \endcode - */ -#define STA350BW_CONF_REGF ((uint8_t)0x05) /*Configuration Register F*/ - - /** - * @brief I2C address MUTE/Line Out configuration - * \code - * Read/write - * Default value: 0x10 - * [7:6] LOC line out configuration - * [5:4] RESERVED - * 3 C3M Channel 3 MUTE - * 2 C2M Channel 2 MUTE - * 1 C1M Channel 1 MUTE - * 0 MMUTE Master Mute - * \endcode - */ -#define STA350BW_MUTE ((uint8_t)0x06) /* MUTE / Lineout configuration */ - - /** - * @brief I2C address Master Volume - * \code - * Read/write - * Default value: 0xFF - * [7:0] Master volume (default -127.5dB) - * \endcode - */ -#define STA350BW_MVOL ((uint8_t)0x07) /* Master Volume */ - - /** - * @brief I2C address Channel 1 Volume - * \code - * Read/write - * Default value: 0x60 - * [7:0] Master volume (default 0.0dB) - * \endcode - */ -#define STA350BW_C1VOL ((uint8_t)0x08) /* Channel 1 volume */ - - /** - * @brief I2C address Channel 2 Volume - * \code - * Read/write - * Default value: 0x60 - * [7:0] Master volume (default 0.0dB) - * \endcode - */ -#define STA350BW_C2VOL ((uint8_t)0x09) /* Channel 2 volume */ - - /** - * @brief I2C address Channel 3 Volume - * \code - * Read/write - * Default value: 0x60 - * [7:0] Master volume (default 0.0dB) - * \endcode - */ -#define STA350BW_C3VOL ((uint8_t)0x0A) /* Channel 3 volume */ - - /** - * @brief I2C address AUTO MODE 1 - * \code - * Read/write - * Default value: 0x80 - * [7:6] RESERVED - * [5:4] AMGC Audio Preset Gain compression - * [3:0] RESERVED - * \endcode - */ -#define STA350BW_AUTO1 ((uint8_t)0x0B) /* Audio Preset 1 register */ - - /** - * @brief I2C address AUTO MODE 2 - * \code - * Read/write - * Default value: 0x00 - * [7:4] XO preset crossover filter - * [3:1] AMAMx AM atomode settings - * 0 AMAME AM automode enable - * \endcode - */ -#define STA350BW_AUTO2 ((uint8_t)0x0C) /* Audio Preset 2 register */ - - /** - * @brief I2C address Channel 1 configuration register - * \code - * Read/write - * Default value: 0x00 - * 7,6 C1OM Channel 1 output mapping - * 5,4 C1LS Channel 1 limiter mapping - * 3 C1BO Channel 1 Binary output - * 2 C1VPB Channel 1 volume bypass - * 1 C1EQBP Channel 1 Equalization Bypass - * 0 C1TCB Channel 1 Tone/Control Bypass - * \endcode - */ -#define STA350BW_C1CFG ((uint8_t)0x0E) /* Channel 1 configuration register */ - - /** - * @brief I2C address Channel 2 configuration register - * \code - * Read/write - * Default value: 0x40 - * 7,6 C2OM Channel 2 output mapping - * 5,4 C2LS Channel 2 limiter mapping - * 3 C2BO Channel 2 Binary output - * 2 C2VPB Channel 2 volume bypass - * 1 C2EQBP Channel 2 Equalization Bypass - * 0 C2TCB Channel 2 Tone/Control Bypass - * \endcode - */ -#define STA350BW_C2CFG ((uint8_t)0x0F) /* Channel 2 configuration register */ - - /** - * @brief I2C address Channel 3 configuration register - * \code - * Read/write - * Default value: 0x80 - * 7,6 C2OM Channel 3 output mapping - * 5,4 C2LS Channel 3 limiter mapping - * 3 C2BO Channel 3 Binary output - * 2 C2VPB Channel 3 volume bypass - * 1,0 RESERVED - * \endcode - */ -#define STA350BW_C3CFG ((uint8_t)0x10) /* Channel 3 configuration register */ - - /** - * @brief I2C address Tone control register - * \code - * Read/write - * Default value: 0x77 - * [7:4] Treble - * [3:0] Bass - * \endcode - */ -#define STA350BW_TONE ((uint8_t)0x11) /* Tone control register */ - - /** - * @brief I2C address Limiter 1 Attack/Release rate register - * \code - * Read/write - * Default value: 0x6A - * [7:4] Limiter 1 Attack rate - * [3:0] Limiter 1 release rate - * \endcode - */ -#define STA350BW_L1AR ((uint8_t)0x12) /* Limiter 1 Attack/Release rate register */ - - /** - * @brief I2C address Limiter 1 Attack/Release threshold register - * \code - * Read/write - * Default value: 0x69 - * [7:4] Limiter 1 Attack threshold - * [3:0] Limiter 1 release threshold - * \endcode - */ -#define STA350BW_L1ATR ((uint8_t)0x13) /* Limiter 1 Attack/Release threshold register */ - - /** - * @brief I2C address Limiter 2 Attack/Release rate register - * \code - * Read/write - * Default value: 0x6A - * [7:4] Limiter 2 Attack rate - * [3:0] Limiter 2 Release rate - * \endcode - */ -#define STA350BW_L2AR ((uint8_t)0x14) /* Limiter 2 Attack/Release rate register */ - - /** - * @brief I2C address Limiter 2 Attack/Release threshold register - * \code - * Read/write - * Default value: 0x69 - * [7:4] Limiter 2 Attack threshold - * [3:0] Limiter 2 release threshold - * \endcode - */ -#define STA350BW_L2ATR ((uint8_t)0x15) /* Limiter 2 Attack/Release threshold register */ - - /* RAM download*/ - - /** - * @brief I2C address Coefficient address register - * \code - * Read/write - * Default value: 0x00 - * [7:6] RESERVED - * [5:0] RAM address - * \endcode - */ -#define STA350BW_CFADDR ((uint8_t)0x16) /* Coefficient address register */ - - /** - * @brief I2C address Coefficient b1 data register bits 23:16 - * \code - * Read/write - * Default value: 0x00 - * [7:0] coefficient b1 bits 23:16 - * \endcode - */ -#define STA350BW_B1CF1 ((uint8_t)0x17) /* Coefficient b1 data register bits 23:16 */ - - /** - * @brief I2C address Coefficient b1 data register bits 15:8 - * \code - * Read/write - * Default value: 0x00 - * [7:0] coefficient b1 bits 15:8 - * \endcode - */ -#define STA350BW_B1CF2 ((uint8_t)0x18) /* Coefficient b1 data register bits 15:8 */ - - /** - * @brief I2C address Coefficient b1 data register bits 7:0 - * \code - * Read/write - * Default value: 0x00 - * [7:0] coefficient b1 bits 7:0 - * \endcode - */ -#define STA350BW_B1CF3 ((uint8_t)0x19) /* Coefficient b1 data register bits 7:0 */ - - /** - * @brief I2C address Coefficient b2 data register bits 23:16 - * \code - * Read/write - * Default value: 0x00 - * [7:0] coefficient b2 bits 23:16 - * \endcode - */ -#define STA350BW_B2CF1 ((uint8_t)0x1A) /* Coefficient b2 data register bits 23:16 */ - - /** - * @brief I2C address Coefficient b2 data register bits 15:8 - * \code - * Read/write - * Default value: 0x00 - * [7:0] coefficient b2 bits 15:8 - * \endcode - */ -#define STA350BW_B2CF2 ((uint8_t)0x1B) /* Coefficient b2 data register bits 15:8 */ - - /** - * @brief I2C address Coefficient b2 data register bits 7:0 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient b2 data bits 7:0 - * \endcode - */ -#define STA350BW_B2CF3 ((uint8_t)0x1C) /* Coefficient b2 data register bits 7:0 */ - - /** - * @brief I2C address Coefficient a1 data register bits 23:16 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient a1 data bits 23:16 - * \endcode - */ -#define STA350BW_A1CF1 ((uint8_t)0x1D) /* Coefficient a1 data register bits 23:16 */ - - /** - * @brief I2C address Coefficient a1 data register bits 15:8 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient a1 data bits 15:8 - * \endcode - */ -#define STA350BW_A1CF2 ((uint8_t)0x1E) /* Coefficient a1 data register bits 15:8 */ - - /** - * @brief I2C address Coefficient a1 data register bits 7:0 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient a1 data bits 7:0 - * \endcode - */ -#define STA350BW_A1CF3 ((uint8_t)0x1F) /* Coefficient a1 data register bits 7:0 */ - - /** - * @brief I2C address Coefficient a2 data register bits 23:16 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient a2 data bits 23:16 - * \endcode - */ -#define STA350BW_A2CF1 ((uint8_t)0x20) /* Coefficient a2 data register bits 23:16 */ - - /** - * @brief I2C address Coefficient a2 data register bits 15:8 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient a2 data bits 15:8 - * \endcode - */ -#define STA350BW_A2CF2 ((uint8_t)0x21) /* Coefficient a2 data register bits 15:8 */ - - /** - * @brief I2C address Coefficient a2 data register bits 7:0 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient a2 data bits 7:0 - * \endcode - */ -#define STA350BW_A2CF3 ((uint8_t)0x22) /* Coefficient a2 data register bits 7:0 */ - - /** - * @brief I2C address Coefficient b0 data register bits 23:16 - * \code - * Read/write - * Default value: 0x00 - * [7:0] coefficient b0 bits 23:16 - * \endcode - */ -#define STA350BW_B0CF1 ((uint8_t)0x23) /* Coefficient b0 data register bits 23:16 */ - - /** - * @brief I2C address Coefficient b0 data register bits 15:8 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient b0 data bits 15:8 - * \endcode - */ -#define STA350BW_B0CF2 ((uint8_t)0x24) /* Coefficient b0 data register bits 15:8 */ - - /** - * @brief I2C address Coefficient b0 data register bits 7:0 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Coefficient b0 data bits 7:0 - * \endcode - */ -#define STA350BW_B0CF3 ((uint8_t)0x25) /* Coefficient b0 data register bits 7:0 */ - - /** - * @brief I2C address Coefficient write/read control register - * \code - * Read/write - * Default value: 0x00 - * [7:4] RESERVED - * 3 RA read a complete set of coefficient - * 2 R1 read only one coefficient - * 1 WA write a complete set of coefficient - * 0 W1 write only one coefficient - * \endcode - */ -#define STA350BW_CFUD ((uint8_t)0x26) /* Coefficient write/read control register */ - - - /** - * @brief I2C address Variable max power correction 15:8 - * \code - * Read/write - * Default value: 0x1A - * [7:0] Coefficient for Variable max power correction 15:8 - * \endcode - */ -#define STA350BW_MPCC1 ((uint8_t)0x27) /* Variable max power correction 15:8 register*/ - - /** - * @brief I2C address Variable max power correction 7:0 - * \code - * Read/write - * Default value: 0x30 - * [7:0] Coefficient for Variable max power correction 7:0 - * \endcode - */ -#define STA350BW_MPCC2 ((uint8_t)0x28) /* Variable max power correction 7:0 register*/ - - /** - * @brief I2C address Variable distortion compensation 15:8 - * \code - * Read/write - * Default value: 0xF3 - * [7:0] Coefficient for Variable distortion compensation 15:8 - * \endcode - */ -#define STA350BW_DCC1 ((uint8_t)0x29) /* Variable distortion compensation 15:8 */ - - /** - * @brief I2C address Variable distortion compensation 7:0 - * \code - * Read/write - * Default value: 0x33 - * [7:0] Coefficient for Variable distortion compensation 7:0 - * \endcode - */ -#define STA350BW_DCC2 ((uint8_t)0x2A) /* Variable distortion compensation 7:0 */ - - /** - * @brief I2C address Fault detect recovery constant register 15:8 - * \code - * Read/write - * Default value: 0x00 - * [7:0] Fault detect recovery constant 15:8 - * \endcode - */ -#define STA350BW_FDRC1 ((uint8_t)0x2B) /* Fault detect recovery constant register 15:8 */ - - /** - * @brief I2C address Fault detect recovery constant register 7:0 - * \code - * Read/write - * Default value: 0xC0 - * [7:0] Fault detect recovery constant 7:0 - * \endcode - */ -#define STA350BW_FDRC2 ((uint8_t)0x2C) /* Fault detect recovery constant register 7:0 */ - - /** - * @brief I2C address Status Register - * \code - * Read - * Default value: 0x7F - * 7 PLLUL PLL unlock - * 6 FAULT Fault detected on bridge - * 5 UVFAULT undervoltage fault - * 4 OVFAULT overvoltage fault - * 3 OCFAULT overcurrent fault - * 2 OCWARN overcurrent warning - * 1 TFAULT Thermal fault - * 0 TWARN thermal warning - * \endcode - */ -#define STA350BW_STATUS ((uint8_t)0x2D) /* Status Register */ - - /** - * @brief I2C address EQ coefficients and DRC configuration register - * \code - * Read/write - * Default value: 0x00 - * 7 XOB Crossover filter bypass - * [6:5] RESERVED - * [4:3] AMGC Anti-clipping and DRC preset - * 2 RESERVED - * [1:0] EQ RAM bank selector - * \endcode - */ -#define STA350BW_EQCFG ((uint8_t)0x31) /* EQ coefficients and DRC configuration register */ - - /** - * @brief I2C address Limiter 1 extended attack threshold register - * \code - * Read/write - * Default value: 0x30 - * 7 EATHEN1 Limiter 1 Extended Attack threshold enable - * [6:0] EATH1 Limiter 1 Extended Attack threshold - * \endcode - */ -#define STA350BW_EATH1 ((uint8_t)0x32) /* Limiter 1 extended attack threshold register */ - - /** - * @brief I2C address Limiter 1 extended release threshold register - * \code - * Read/write - * Default value: 0x30 - * 7 ERTHEN1 Limiter 1 Extended Release threshold enable - * [6:0] ERTH1 Limiter 1 Extended Release threshold - * \endcode - */ -#define STA350BW_ERTH1 ((uint8_t)0x33) /* Limiter 1 extended release threshold register */ - - /** - * @brief I2C address Limiter 2 extended attack threshold register - * \code - * Read/write - * Default value: 0x30 - * 7 EATHEN2 Limiter 2 Extended Attack threshold enable - * [6:0] EATH2 Limiter 2 Extended Attack threshold - * \endcode - */ -#define STA350BW_EATH2 ((uint8_t)0x34) /* Limiter 2 extended attack threshold register */ - - /** - * @brief I2C address Limiter 2 extended release threshold register - * \code - * Read/write - * Default value: 0x30 - * 7 ERTHEN2 Limiter 2 Extended Release threshold enable - * [6:0] ERTH2 Limiter 2 Extended Release threshold - * \endcode - */ -#define STA350BW_ERTH2 ((uint8_t)0x35) /* Limiter 2 extended release threshold register */ - - /** - * @brief I2C address Extended configuration register - * \code - * Read/write - * Default value: 0x00 - * [7:6] MDRC MDRC or EQ DRC selector - * 5 PS48DB Extended post-scale range - * 4 Extended attack rate Limiter 1 - * 3 Extended attack rate Limiter 2 - * 2 Biquad 5 enable - * 1 Biquad 6 enable - * 0 Biquad 7 enable - * \endcode - */ -#define STA350BW_CONFX ((uint8_t)0x36) /* Extended configuration register */ - - /** - * @brief I2C address soft-volume up configuration register - * \code - * Read/write - * Default value: 0x00 - * [7:6] RESERVED - * 5 SVUPE Soft volume up enable - * [4:0] SVUP Soft volume up coefficient - * \endcode - */ -#define STA350BW_SVCA ((uint8_t)0x37) /* soft-volume up configuration register */ - - /** - * @brief I2C address soft-volume down configuration register - * \code - * Read/write - * Default value: 0x00 - * [7:6] RESERVED - * 5 SVDWE Soft volume down enable - * [4:0] SVDW Soft volume down coefficient - * \endcode - */ -#define STA350BW_SVCB ((uint8_t)0x38) /* soft-volume down configuration register */ - - - /** - * @brief I2C address DRC RMS filter coefficient c0 23:16 register - * \code - * Read/write - * Default value: 0x01 - * [7:0] R_C0 DRC RMS filter coefficient c0 23:16 - * \endcode - */ -#define STA350BW_RMS0A ((uint8_t)0x39) /* DRC RMS filter coefficient c0 23:16 register */ - - /** - * @brief I2C address DRC RMS filter coefficient c0 15:8 register - * \code - * Read/write - * Default value: 0xEE - * [7:0] R_C0 DRC RMS filter coefficient c0 15:8 - * \endcode - */ -#define STA350BW_RMS0B ((uint8_t)0x3A) /* DRC RMS filter coefficient c0 15:8 register */ - - /** - * @brief I2C address DRC RMS filter coefficient c0 7:0 register - * \code - * Read/write - * Default value: 0xFF - * [7:0] R_C0 DRC RMS filter coefficient c0 7:0 - * \endcode - */ -#define STA350BW_RMS0C ((uint8_t)0x3B) /* DRC RMS filter coefficient c0 7:0 register */ - - /** - * @brief I2C address DRC RMS filter coefficient c1 23:16 register - * \code - * Read/write - * Default value: 0x7E - * [7:0] R_C1 DRC RMS filter coefficient c0 23:16 - * \endcode - */ -#define STA350BW_RMS1A ((uint8_t)0x3C) /* DRC RMS filter coefficient c1 23:16 register */ - - /** - * @brief I2C address DRC RMS filter coefficient c1 15:8 register - * \code - * Read/write - * Default value: 0xC0 - * [7:0] R_C1 DRC RMS filter coefficient c1 15:8 - * \endcode - */ -#define STA350BW_RMS1B ((uint8_t)0x3D) /* DRC RMS filter coefficient c1 15:8 register */ - - /** - * @brief I2C address DRC RMS filter coefficient c1 7:0 register - * \code - * Read/write - * Default value: 0x26 - * [7:0] R_C0 DRC RMS filter coefficient c1 7:0 - * \endcode - */ -#define STA350BW_RMS1C ((uint8_t)0x3E) /* DRC RMS filter coefficient c1 7:0 register */ - - /** - * @brief I2C address Extra volume resolution configuration register - * \code - * Read/write - * Default value: 0x00 - * 7 VRESEN Extra volume resolution enable - * 6 VRESTG Extra volume resolution update - * [5:4] C3VR Channel 3 extra volume value - * [3:2] C2VR Channel 2 extra volume value - * [1:0] C1VR Channel 1 extra volume value - * \endcode - */ -#define STA350BW_EVOLRES ((uint8_t)0x3F) /* Extra volume resolution configuration register */ - - /** - * @brief I2C address Quantization error noise correction register - * \code - * Read/write - * Default value: 0x00 - * 7 Quntization Noise shaping enable - * 6 Quntization Noise shaping on biquad 7 - * 5 Quntization Noise shaping on biquad 6 - * 4 Quntization Noise shaping on biquad 5 - * 3 Quntization Noise shaping on biquad 4 - * 2 Quntization Noise shaping on biquad 3 - * 1 Quntization Noise shaping on biquad 2 - * 0 Quntization Noise shaping on biquad 1 - * \endcode - */ -#define STA350BW_NSHAPE ((uint8_t)0x48) /* Quantization error noise correction register */ - - /** - * @brief I2C address Extended coefficient range up to -4...4 biquad 1-4 register - * \code - * Read/write - * Default value: 0x00 - * [7:6] CXTB4 Extended coefficient on biquad 4 - * [5:4] CXTB3 Extended coefficient on biquad 3 - * [3:2] CXTB2 Extended coefficient on biquad 2 - * [1:0] CXTB1 Extended coefficient on biquad 1 - * \endcode - */ -#define STA350BW_CXT_B4B1 ((uint8_t)0x49) /* Extended coefficient range up to -4...4 biquad 1-4 register */ - - /** - * @brief I2C address Extended coefficient range up to -4...4 biquad 5-7 register - * \code - * Read/write - * Default value: 0x00 - * [7:6] RESERVED - * [5:4] CXTB7 Extended coefficient on biquad 7 - * [3:2] CXTB6 Extended coefficient on biquad 6 - * [1:0] CXTB5 Extended coefficient on biquad 5 - * \endcode - */ -#define STA350BW_CXT_B7B5 ((uint8_t)0x4A) /* Extended coefficient range up to -4...4 biquad 5-7 register */ - - /** - * @brief I2C address Miscellaneous register 1 - * \code - * Read/write - * Default value: 0x04 - * 7 RPDNEN Rate powerdown enable - * 6 NSHHPEN Noise shaping feature enable - * 5 BRIDGOFF Bridge immediate OFF - * [4:3] RESERVED - * 2 CPWMEN Channel PWM enable - * [1:0] RESERVED - * \endcode - */ -#define STA350BW_MISC1 ((uint8_t)0x4B) /* Miscellaneous register 1 */ - - /** - * @brief I2C address Miscellaneous register 2 - * \code - * Read/write - * Default value: 0x00 - * [7:5] RESERVED - * [4:2] PNDLSL Power-down delay selector - * [1:0] RESERVED - * \endcode - */ -#define STA350BW_MISC2 ((uint8_t)0x4C) /* Miscellaneous register 2 */ - - /** - * @} - */ - - - - /** @defgroup STA350BW_Main_parameter - * @{ - */ -#define STA350BW_EAPD_ON ((uint8_t)0x80) -#define STA350BW_EAPD_OFF ((uint8_t)0x00) -#define STA350BW_PWDN_OFF ((uint8_t)0x40) -#define STA350BW_PWDN_ON ((uint8_t)0x00) /* low power consumption */ - -#define STA350BW_MVOL_0dB ((uint8_t)0x00) -#define STA350BW_MVOL_MUTE ((uint8_t)0xFF) - /** - * @} - */ - - - /** @defgroup STA350BW_Input_frequency_selection - * @{ - */ -#define STA350BW_Fs_32000 ((uint32_t)32000) -#define STA350BW_Fs_44100 ((uint32_t)44100) -#define STA350BW_Fs_48000 ((uint32_t)48000) -#define STA350BW_Fs_88200 ((uint32_t)88200) -#define STA350BW_Fs_96000 ((uint32_t)96000) - -#define STA350BW_MCLK_256_LR_48K ((uint8_t)0x03) -#define STA350BW_MCLK_128_LR_48K ((uint8_t)0x04) -#define STA350BW_MCLK_256_LR_96K ((uint8_t)0x09) -#define STA350BW_MCLK_128_LR_96K ((uint8_t)0x0B) - /** - * @} - */ - - - - - - /** @defgroup STA350BW_mode_selection - * @brief STA350BW mode configuration constants - * @{ - */ -#define STA350BW_STEREO_CONF ((uint8_t)0x00) -#define STA350BW_2SE_1BTL_CONF ((uint8_t)0x01) -#define STA350BW_STEREO_EXT_BRIDGE_CONF ((uint8_t)0x00) -#define STA350BW_MONOBTL_CONF ((uint8_t)0x11) -#define STA350BW_BINARY_CONF ((uint8_t)0x80) /* on registers 0E, 0F, 10 */ - /** - * @} - */ - - /** @defgroup STA350BW_DSP_option_selection - * @brief STA350BW constants related to data path management - * @{ - */ -#define STA350BW_DSPB ((uint8_t)0x00) -#define STA350BW_C1EQBP ((uint8_t)0x01) -#define STA350BW_C2EQBP ((uint8_t)0x02) -#define STA350BW_C1TCB ((uint8_t)0x03) -#define STA350BW_C2TCB ((uint8_t)0x04) -#define STA350BW_C1VBP ((uint8_t)0x05) -#define STA350BW_C2VBP ((uint8_t)0x06) -#define STA350BW_HPB ((uint8_t)0x07) -#define STA350BW_DEMP ((uint8_t)0x08) -#define STA350BW_BQL ((uint8_t)0x09) -#define STA350BW_BQ5 ((uint8_t)0x0A) -#define STA350BW_BQ6 ((uint8_t)0x0B) -#define STA350BW_BQ7 ((uint8_t)0x0C) -#define STA350BW_EXT_RANGE_BQ1 ((uint8_t)0x0D) -#define STA350BW_EXT_RANGE_BQ2 ((uint8_t)0x0E) -#define STA350BW_EXT_RANGE_BQ3 ((uint8_t)0x0F) -#define STA350BW_EXT_RANGE_BQ4 ((uint8_t)0x10) -#define STA350BW_EXT_RANGE_BQ5 ((uint8_t)0x11) -#define STA350BW_EXT_RANGE_BQ6 ((uint8_t)0x12) -#define STA350BW_EXT_RANGE_BQ7 ((uint8_t)0x13) -#define STA350BW_RAM_BANK_SELECT ((uint8_t)0x14) - /** - * @} - */ - - - -#define STA350BW_ERROR ((int32_t)-1) -#define STA350BW_OK ((int32_t)0) - - - /** @defgroup STA350BW_state_define STA350BW state define - * @brief STA350BW state definitions - * @{ - */ -#define STA350BW_ENABLE ((uint8_t)0x01) -#define STA350BW_DISABLE ((uint8_t)0x00) -#define STA350BW_RANGE_ONE ((uint8_t)0x01) -#define STA350BW_RANGE_TWO ((uint8_t)0x02) -#define STA350BW_RANGE_FOUR ((uint8_t)0x04) - /** - * @} - */ - - /** @defgroup STA350BW_channel_define STA350BW channel define - * @brief STA350BW channels definitions - * @{ - */ -#define STA350BW_CHANNEL_MASTER ((uint8_t)0x00) -#define STA350BW_CHANNEL_1 ((uint8_t)0x01) -#define STA350BW_CHANNEL_2 ((uint8_t)0x02) -#define STA350BW_CHANNEL_3 ((uint8_t)0x03) - /** - * @} - */ - - /** @defgroup STA350BW_channel_define STA350BW Biq define - * @brief STA350BW Biq definitions - * @{ - */ -#define STA350BW_RAM_BANK_FIRST ((uint8_t)0x00) -#define STA350BW_RAM_BANK_SECOND ((uint8_t)0x01) -#define STA350BW_RAM_BANK_THIRD ((uint8_t)0x02) -#define STA350BW_CH1_BQ1 ((uint8_t)0x00) -#define STA350BW_CH1_BQ2 ((uint8_t)0x01) -#define STA350BW_CH1_BQ3 ((uint8_t)0x02) -#define STA350BW_CH1_BQ4 ((uint8_t)0x03) -#define STA350BW_CH2_BQ1 ((uint8_t)0x04) -#define STA350BW_CH2_BQ2 ((uint8_t)0x05) -#define STA350BW_CH2_BQ3 ((uint8_t)0x06) -#define STA350BW_CH2_BQ4 ((uint8_t)0x07) +/* ACTION 1 ------------------------------------------------------------------* + * Include here platform specific header files. * + *----------------------------------------------------------------------------*/ +#include "mbed.h" +#include "I2S.h" +#include "DevI2C.h" +/* ACTION 2 ------------------------------------------------------------------* + * Include here component specific header files. * + *----------------------------------------------------------------------------*/ +#include "STA350BW_def.h" +/* ACTION 3 ------------------------------------------------------------------* + * Include here interface specific header files. * + * * + * Example: * + * #include "Humidity_class.h" * + * #include "Temperature_class.h" * + *----------------------------------------------------------------------------*/ +#include "SoundTerminal.h" + + +/* Definitions ---------------------------------------------------------------*/ + +#define MIN_VOLUME 0 +#define MAX_VOLUME 128 + + +/* Classes -------------------------------------------------------------------*/ + +/** + * @brief Class representing a STA350BW component. + */ +class STA350BW : public SoundTerminal +{ +public: + + /*** Constructor and Destructor Methods ***/ + + /** + * @brief Constructor. + * @param reset pin name of the RESET pin of the component. + * @param address I2C address of the component. + * @param i2c I2C device to be used for communication. + * @param dpin pin name of the DPIN pin of the I2S device to be used for audio transmission. + * @param clk pin name of the CLK pin of the I2S device to be used for audio transmission. + * @param wsel pin name of the WSEL pin of the I2S device to be used for audio transmission. + * @param fdpin pin name of the FDPIN pin of the I2S device to be used for audio transmission. + * @param mck pin name of the MCK pin of the I2S device to be used for audio transmission. + * @note Initialization depends on the I2S interface you wish to use: + * I2S1) address = STA350BW_ADDRESS_1, dpin = PB_15, clk = PB_13, wsel = PB_12, fdpin = NC, mck = PC_6; + * I2S2) address = STA350BW_ADDRESS_2, dpin = PC_12, clk = PC_10, wsel = PA_4, fdpin = NC, mck = PC_7. + */ + STA350BW(PinName reset, uint8_t address, DevI2C &i2c, PinName dpin, PinName clk, PinName wsel, PinName fdpin = NC, PinName mck = NC) : + SoundTerminal(), + _reset(reset), + _address(address), + _dev_i2c(i2c), + dev_i2s(dpin, clk, wsel, fdpin, mck), + _PCM_buffer(NULL), + _PCM_buffer_bytes(0), + _loop(false) +#ifdef X_NUCLEO_CCA01M1_DEBUG + , _i2s_signal(D11) +#endif + { + /* ACTION 4 ----------------------------------------------------------* + * Initialize here the component's member variables, one variable per * + * line. * + * * + * Example: * + * measure = 0; * + * instance_id = number_of_instances++; * + *--------------------------------------------------------------------*/ + } + + /** + * @brief Destructor. + */ + virtual ~STA350BW(void) {} + + + /*** Public Component Related Methods ***/ + + /* ACTION 5 --------------------------------------------------------------* + * Implement here the component's public methods, as wrappers of the C * + * component's functions. * + * They should be: * + * + Methods with the same name of the C component's virtual table's * + * functions (1); * + * + Methods with the same name of the C component's extended virtual * + * table's functions, if any (2). * + * * + * Example: * + * virtual int GetValue(float *f) //(1) * + * { * + * return COMPONENT_GetValue(float *f); * + * } * + * * + * virtual int EnableFeature(void) //(2) * + * { * + * return COMPONENT_EnableFeature(); * + * } * + *------------------------------------------------------------------------*/ + /** + * @brief Initializing the STA350BW component. + * @param init Pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int init(void *init = NULL) + { + if (STA350BW_Init((void *) init) != COMPONENT_OK) + return COMPONENT_ERROR; + + /* Setting I2S parameters. */ + dev_i2s.mode(MASTER_TX, true); + + return COMPONENT_OK; + } + + /** + * @brief Getting the ID of the component. + * @param id Pointer to an allocated variable to store the ID into. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int read_id(uint8_t *id = NULL) + { + return (int) STA350BW_ReadID((uint8_t *) id); + } + + /** + * @brief De-initializing the STA350BW component. + * @param None. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int32_t de_init(void) + { + return (int32_t) STA350BW_DeInit(); + } + + /* + * @brief Start playing audio. + * @param PCM_buffer The buffer of data to be played. + * @param PCM_buffer_bytes The size in bytes of the buffer of data to be played. + * @param loop Loops indefinitely if true, just once otherwise. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int32_t play(int16_t *PCM_buffer, uint16_t PCM_buffer_bytes, bool loop = false) + { + /* Storing data. */ + _PCM_buffer = PCM_buffer; + _PCM_buffer_bytes = PCM_buffer_bytes; + _loop = loop; + + /* Sending data to the speakers via I2S. */ + int res = dev_i2s.transfer( + (void *) _PCM_buffer, _PCM_buffer_bytes, + (void *) NULL, 0, + event_callback_t(this, &STA350BW::i2s_callback), + I2S_EVENT_ALL + ); + if (res != 0) + return COMPONENT_ERROR; + + return COMPONENT_OK; + } + + /* + * @brief Stop playing audio. + * @param None. + * @retval None. + */ + virtual int32_t stop(void) + { + dev_i2s.abort_all_transfers(); + return (int32_t) STA350BW_Stop(); + } + + /* + * @brief Set the volume of the audio. + * @param channel The channel on which to set the volume of the audio. + * @param value The value of the volume in the range [MIN_VOLUME..MAX_VOLUME]. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int32_t set_volume(uint8_t channel, uint8_t value) + { + if (!(value >= MIN_VOLUME && value <= MAX_VOLUME)) + return COMPONENT_ERROR; + + return (int32_t) STA350BW_SetVolume((uint8_t) channel, (uint8_t) MAX_VOLUME - value); + } + + /* + * @brief Set the frequency of the audio. + * @param audio_freq The frequency of the audio. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int32_t set_frequency(uint32_t audio_freq) + { + return (int32_t) STA350BW_SetFrequency((uint32_t) audio_freq); + } + + + /*** Public Interrupt Related Methods ***/ - /** @defgroup STA350BW_adsress_define STA350BW address define - * @brief STA350BW address definitions - * @{ - */ -#define STA350BW_ADDRESS_1 ((uint8_t)0x38) /* To be used when using I2S1. */ -#define STA350BW_ADDRESS_2 ((uint8_t)0x3A) /* To be used when using I2S2. */ + /* ACTION 6 --------------------------------------------------------------* + * Implement here interrupt related methods, if any. * + * Note that interrupt handling is platform dependent, e.g.: * + * + mbed: * + * InterruptIn feature_irq(pin); //Interrupt object. * + * feature_irq.fall(callback); //Attach a callback. * + * feature_irq.mode(PullNone); //Set interrupt mode. * + * feature_irq.enable_irq(); //Enable interrupt. * + * feature_irq.disable_irq(); //Disable interrupt. * + * + Arduino: * + * attachInterrupt(pin, callback, RISING); //Attach a callback. * + * detachInterrupt(pin); //Detach a callback. * + * * + * Example (mbed): * + * void AttachFeatureIRQ(void (*fptr) (void)) * + * { * + * feature_irq.fall(fptr); * + * } * + * * + * void EnableFeatureIRQ(void) * + * { * + * feature_irq.enable_irq(); * + * } * + * * + * void DisableFeatureIRQ(void) * + * { * + * feature_irq.disable_irq(); * + * } * + *------------------------------------------------------------------------*/ + + +protected: + + /*** Protected Component Related Methods ***/ -/* Audio processor initialization structure. */ -typedef struct -{ - uint32_t frequency; /* Allowed frequency: 32000, 44100, 48000, 88200, 96000. */ - uint16_t volume; /* Allowed volume: [0..128]. */ -} STA350BW_Init_t; + /* ACTION 7 --------------------------------------------------------------* + * Declare here the component's specific methods. * + * They should be: * + * + Methods with the same name of the C component's virtual table's * + * functions (1); * + * + Methods with the same name of the C component's extended virtual * + * table's functions, if any (2); * + * + Helper methods, if any, like functions declared in the component's * + * source files but not pointed by the component's virtual table (3). * + * * + * Example: * + * status_t COMPONENT_GetValue(float *f); //(1) * + * status_t COMPONENT_EnableFeature(void); //(2) * + * status_t COMPONENT_ComputeAverage(void); //(3) * + *------------------------------------------------------------------------*/ + int32_t STA350BW_Init(void *init); + int32_t STA350BW_ReadID(uint8_t *id); + int32_t STA350BW_DeInit(void); + int32_t STA350BW_Play(int16_t *pData, uint16_t Size); + int32_t STA350BW_Stop(void); + int32_t STA350BW_Pause(void); + int32_t STA350BW_Resume(void); + int32_t STA350BW_SetVolume(uint8_t channel, uint8_t value); + int32_t STA350BW_SetFrequency(uint32_t audio_freq); + int32_t STA350BW_PowerOn(void); + int32_t STA350BW_PowerOff(void); + int32_t STA350BW_Reset(void); + int32_t STA350BW_SetEq(uint8_t ram_block, uint8_t filter_number, uint32_t * filter_values); + int32_t STA350BW_SetTone(uint8_t tone_gain); + int32_t STA350BW_SetMute(uint8_t channel, uint8_t state); + int32_t STA350BW_SetDSPOption(uint8_t option, uint8_t state); + int32_t STA350BW_WriteRAMSet(uint8_t RAM_block, uint8_t RAM_address, uint8_t * pIn); + + /** + * @brief I2S callback. + * @param narg Narg flag. + * @retval None. + */ + void i2s_callback(int narg) + { + if (!(narg & (I2S_EVENT_TX_COMPLETE | I2S_EVENT_TX_HALF_COMPLETE))) + error("Unexpected transmission event.\r\n"); + else if ((narg & I2S_EVENT_TX_COMPLETE) && !_loop) + stop(); + +#ifdef X_NUCLEO_CCA01M1_DEBUG + _i2s_signal = !_i2s_signal; +#endif + } + + + /*** Component's I/O Methods ***/ -/* Audio processor extern functions. */ -extern uint8_t STA350BW_IO_Init(void); -extern uint8_t STA350BW_IO_Read(uint8_t reg, uint8_t *value); -extern uint8_t STA350BW_IO_Write(uint8_t reg, uint8_t value); -extern uint8_t STA350BW_IO_ReadMulti(uint8_t *pBuffer, uint8_t reg, uint16_t length); -extern uint8_t STA350BW_IO_WriteMulti(uint8_t *pBuffer, uint8_t reg, uint16_t length); -extern uint8_t STA350BW_IO_Delay(uint32_t delay_ms); + /** + * @brief Utility function to read data from STA350BW. + * @param[out] pBuffer pointer to the buffer to read data into. + * @param[in] RegisterAddr specifies the internal address register to read from. + * @param[in] NumBytesToRead number of bytes to read. + * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. + */ + status_t read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumBytesToRead) + { + if (_dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumBytesToRead) != 0) + return COMPONENT_ERROR; + return COMPONENT_OK; + } + + /** + * @brief Utility function to write data to STA350BW. + * @param[in] pBuffer pointer to the buffer of data to send. + * @param[in] RegisterAddr specifies the internal address register to write to. + * @param[in] NumBytesToWrite number of bytes to write. + * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. + */ + status_t write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumBytesToWrite) + { + if (_dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumBytesToWrite) != 0) + return COMPONENT_ERROR; + return COMPONENT_OK; + } + + /* ACTION 8 --------------------------------------------------------------* + * Implement here other I/O methods beyond those already implemented * + * above, which are declared extern within the component's header file. * + *------------------------------------------------------------------------*/ + uint8_t STA350BW_IO_Init(void) + { + /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ + return (uint8_t) 0; + } + + uint8_t STA350BW_IO_Read(uint8_t reg, uint8_t *value) + { + /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ + return (uint8_t) read(value, reg, 1); + } + + uint8_t STA350BW_IO_Write(uint8_t reg, uint8_t value) + { + /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ + return (uint8_t) write(&value, reg, 1); + } + + uint8_t STA350BW_IO_ReadMulti(uint8_t *pBuffer, uint8_t reg, uint16_t length) + { + /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ + return (uint8_t) read(pBuffer, reg, length); + } + + uint8_t STA350BW_IO_WriteMulti(uint8_t *pBuffer, uint8_t reg, uint16_t length) + { + /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ + return (uint8_t) write(pBuffer, reg, length); + } + + uint8_t STA350BW_IO_Delay(uint32_t delay_ms) + { + /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ + wait_ms(delay_ms); + return (uint8_t) 0; + } + -#ifdef __cplusplus -} + /*** Component's Instance Variables ***/ + + /* ACTION 9 --------------------------------------------------------------* + * Declare here interrupt related variables, if needed. * + * Note that interrupt handling is platform dependent, see * + * "Interrupt Related Methods" above. * + * * + * Example: * + * + mbed: * + * InterruptIn feature_irq; * + *------------------------------------------------------------------------*/ + + /* ACTION 10 -------------------------------------------------------------* + * Declare here other pin related variables, if needed. * + * * + * Example: * + * + mbed: * + * DigitalOut standby_reset; * + *------------------------------------------------------------------------*/ + DigitalOut _reset; + + /* ACTION 11 -------------------------------------------------------------* + * Declare here communication related variables, if needed. * + * * + * Example: * + * + mbed: * + * DigitalOut address; * + * DevI2C &dev_i2c; * + *------------------------------------------------------------------------*/ + /* Configuration. */ + uint8_t _address; + + /* IO Device. */ + DevI2C &_dev_i2c; + +public: + + /* I2S Audio Device (exclusive). */ + I2S dev_i2s; + + +protected: + + /* ACTION 12 -------------------------------------------------------------* + * Declare here identity related variables, if needed. * + * Note that there should be only a unique identifier for each component, * + * which should be the "who_am_i" parameter. * + *------------------------------------------------------------------------*/ + + /* ACTION 13 -------------------------------------------------------------* + * Declare here the component's static and non-static data, one variable * + * per line. * + * * + * Example: * + * float measure; * + * int instance_id; * + * static int number_of_instances; * + *------------------------------------------------------------------------*/ + /* Buffer of data to be played. */ + int16_t *_PCM_buffer; + /* The size in bytes of the buffer of data to be played. */ + uint16_t _PCM_buffer_bytes; + /* Loops indefinitely if true, just once otherwise. */ + bool _loop; + +#ifdef X_NUCLEO_CCA01M1_DEBUG + /* Signals for debugging purposes. */ + DigitalOut _i2s_signal; #endif +}; -#endif /*__STA350BW_H*/ +#endif /* __STA350BW_CLASS_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/