summaryrefslogtreecommitdiff
path: root/bsp/imxrt/libraries/drivers/drv_sai.h
blob: 6033fd66848fdf199a75eae8d5d38a155ad6f752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-4-30     misonyo     the first version.
 */

#ifndef __DRV_SOUND_H_
#define __DRV_SOUND_H_

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <rtdef.h>

#include <rthw.h>
#include "fsl_sai.h"
#include "fsl_dmamux.h"
#include "fsl_sai_edma.h"

#define AUD_DMA_FIFO_SIZE (2048)
#define CODEC_I2C_NAME ("i2c1")
/* Select Audio/Video PLL (786.48 MHz) as sai1 clock source */
#define DEMO_SAI1_CLOCK_SOURCE_SELECT (2U)
/* Clock pre divider for sai1 clock source */
#define DEMO_SAI1_CLOCK_SOURCE_PRE_DIVIDER (0U)
/* Clock divider for sai1 clock source */
#define DEMO_SAI1_CLOCK_SOURCE_DIVIDER (63U)
/* Get frequency of sai1 clock */
#define AUD_BLOCK_CNT   2
#define AUD_BLOCK_SIZE  1024
#define AUD_FIFO_SIZE   (AUD_BLOCK_SIZE * AUD_BLOCK_CNT)
#define DEMO_SAI_CLK_FREQ                                                        \
    (CLOCK_GetFreq(kCLOCK_AudioPllClk) / (DEMO_SAI1_CLOCK_SOURCE_DIVIDER + 1U) / \
     (DEMO_SAI1_CLOCK_SOURCE_PRE_DIVIDER + 1U))


#define AUD_DMA_FIFO_SIZE (2048)
struct saidma_tx_config
{
    edma_handle_t edma;
    rt_uint8_t channel;
    dma_request_source_t request;
    sai_edma_handle_t txHandle;
};
struct saidma_rx_config
{
    edma_handle_t edma;
    rt_uint8_t channel;
    dma_request_source_t request;
    sai_edma_handle_t rxHandle;
};

struct drv_sai {
    I2S_Type *base;
    IRQn_Type irqn;
    struct saidma_tx_config *dma_tx;
    struct saidma_rx_config *dma_rx;
    rt_uint8_t dma_flag;
    int txBlockIndex;
    int rxBlockIndex;
};

void sai_init(void);
int rt_hw_sound_init(void);

#endif