1 /*
2  * Copyright 2017-2020 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "fsl_wm8524.h"
9 
10 /*******************************************************************************
11  * Definitions
12  ******************************************************************************/
13 
14 /*******************************************************************************
15  * Prototypes
16  ******************************************************************************/
17 
18 /*******************************************************************************
19  * Variables
20  ******************************************************************************/
21 
22 /*******************************************************************************
23  * Code
24  ******************************************************************************/
25 
26 /*!
27  * brief Initializes WM8524.
28  *
29  * param handle WM8524 handle structure.
30  * param config WM8524 configure structure.
31  * return kStatus_Success.
32  */
WM8524_Init(wm8524_handle_t * handle,wm8524_config_t * config)33 status_t WM8524_Init(wm8524_handle_t *handle, wm8524_config_t *config)
34 {
35     assert(config != NULL);
36     wm8524_config_t *wm8524Config = (wm8524_config_t *)config;
37 
38     handle->config = config;
39 
40     if ((wm8524Config->setProtocol) != NULL)
41     {
42         /* set format */
43         WM8524_ConfigFormat(handle, wm8524Config->protocol);
44     }
45 
46     /* Unmute codec */
47     wm8524Config->setMute(kWM8524_Unmute);
48 
49     return kStatus_Success;
50 }
51 
52 /*!
53  * brief Configure WM8524 audio protocol.
54  *
55  * param handle WM8524 handle structure.
56  * param protocol WM8524 configuration structure.
57  */
WM8524_ConfigFormat(wm8524_handle_t * handle,wm8524_protocol_t protocol)58 void WM8524_ConfigFormat(wm8524_handle_t *handle, wm8524_protocol_t protocol)
59 {
60     assert(handle->config != NULL);
61     assert(handle->config->setProtocol != NULL);
62 
63     wm8524_config_t *wm8524Config = (wm8524_config_t *)handle->config;
64 
65     if (protocol != kWM8524_ProtocolRightJustified)
66     {
67         wm8524Config->setProtocol((uint32_t)protocol);
68     }
69 }
70 
71 /*!
72  * brief Sets the codec mute state.
73  *
74  * param handle WM8524 handle structure.
75  * param isMute true means mute, false means normal.
76  */
WM8524_SetMute(wm8524_handle_t * handle,bool isMute)77 void WM8524_SetMute(wm8524_handle_t *handle, bool isMute)
78 {
79     assert(handle->config != NULL);
80     assert(handle->config->setMute != NULL);
81 
82     wm8524_config_t *wm8524Config = (wm8524_config_t *)handle->config;
83 
84     wm8524Config->setMute(!isMute);
85 }
86