2018-06-14 15:27:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 STMicroelectronics
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _STM32_I2S_H_
|
|
|
|
#define _STM32_I2S_H_
|
|
|
|
|
|
|
|
struct queue_item {
|
|
|
|
void *mem_block;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Minimal ring buffer implementation */
|
|
|
|
struct ring_buf {
|
|
|
|
struct queue_item *buf;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint16_t len;
|
|
|
|
uint16_t head;
|
|
|
|
uint16_t tail;
|
2018-06-14 15:27:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Device constant configuration parameters */
|
|
|
|
struct i2s_stm32_cfg {
|
|
|
|
SPI_TypeDef *i2s;
|
2023-03-02 21:43:58 +08:00
|
|
|
const struct stm32_pclken *pclken;
|
|
|
|
size_t pclk_len;
|
2021-11-08 18:14:22 +08:00
|
|
|
const struct pinctrl_dev_config *pcfg;
|
2020-05-01 02:33:38 +08:00
|
|
|
void (*irq_config)(const struct device *dev);
|
2023-02-16 04:02:02 +08:00
|
|
|
bool master_clk_sel;
|
2018-06-14 15:27:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stream {
|
2020-05-28 00:26:57 +08:00
|
|
|
int32_t state;
|
2018-06-14 15:27:46 +08:00
|
|
|
struct k_sem sem;
|
2019-10-24 15:57:17 +08:00
|
|
|
|
2021-02-27 00:19:37 +08:00
|
|
|
const struct device *dev_dma;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t dma_channel;
|
2018-06-14 15:27:46 +08:00
|
|
|
struct dma_config dma_cfg;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_t priority;
|
2019-10-24 15:50:24 +08:00
|
|
|
bool src_addr_increment;
|
|
|
|
bool dst_addr_increment;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_t fifo_threshold;
|
2024-04-23 20:33:09 +08:00
|
|
|
bool tx_stop_for_drain;
|
2019-10-24 15:50:24 +08:00
|
|
|
|
2018-06-14 15:27:46 +08:00
|
|
|
struct i2s_config cfg;
|
|
|
|
struct ring_buf mem_block_queue;
|
|
|
|
void *mem_block;
|
|
|
|
bool last_block;
|
|
|
|
bool master;
|
2020-05-01 02:33:38 +08:00
|
|
|
int (*stream_start)(struct stream *, const struct device *dev);
|
|
|
|
void (*stream_disable)(struct stream *, const struct device *dev);
|
2018-06-14 15:27:46 +08:00
|
|
|
void (*queue_drop)(struct stream *);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Device run time data */
|
|
|
|
struct i2s_stm32_data {
|
|
|
|
struct stream rx;
|
|
|
|
struct stream tx;
|
|
|
|
};
|
|
|
|
|
2024-05-23 23:25:32 +08:00
|
|
|
/* checks that DMA Tx packet is fully transmitted over the I2S */
|
|
|
|
static inline uint32_t ll_func_i2s_dma_busy(SPI_TypeDef *i2s)
|
|
|
|
{
|
|
|
|
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_i2s)
|
|
|
|
return LL_SPI_IsActiveFlag_TXC(i2s) == 0;
|
|
|
|
#else
|
|
|
|
/* the I2S Tx empty and busy flags are needed */
|
|
|
|
return (LL_SPI_IsActiveFlag_TXE(i2s) &&
|
|
|
|
!LL_SPI_IsActiveFlag_BSY(i2s));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-06-14 15:27:46 +08:00
|
|
|
#endif /* _STM32_I2S_H_ */
|