Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
i2s.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Piotr Mienkowski
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_I2S_H_
13#define ZEPHYR_INCLUDE_DRIVERS_I2S_H_
14
28#include <zephyr/types.h>
29#include <zephyr/device.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/*
36 * The following #defines are used to configure the I2S controller.
37 */
38
41
43#define I2S_FMT_DATA_FORMAT_SHIFT 0
45#define I2S_FMT_DATA_FORMAT_MASK (0x7 << I2S_FMT_DATA_FORMAT_SHIFT)
46
64#define I2S_FMT_DATA_FORMAT_I2S (0 << I2S_FMT_DATA_FORMAT_SHIFT)
65
83#define I2S_FMT_DATA_FORMAT_PCM_SHORT (1 << I2S_FMT_DATA_FORMAT_SHIFT)
84
103#define I2S_FMT_DATA_FORMAT_PCM_LONG (2 << I2S_FMT_DATA_FORMAT_SHIFT)
104
124#define I2S_FMT_DATA_FORMAT_LEFT_JUSTIFIED (3 << I2S_FMT_DATA_FORMAT_SHIFT)
125
145#define I2S_FMT_DATA_FORMAT_RIGHT_JUSTIFIED (4 << I2S_FMT_DATA_FORMAT_SHIFT)
146
148#define I2S_FMT_DATA_ORDER_MSB (0 << 3)
150#define I2S_FMT_DATA_ORDER_LSB BIT(3)
152#define I2S_FMT_DATA_ORDER_INV I2S_FMT_DATA_ORDER_LSB
153
155#define I2S_FMT_CLK_FORMAT_SHIFT 4
157#define I2S_FMT_CLK_FORMAT_MASK (0x3 << I2S_FMT_CLK_FORMAT_SHIFT)
158
160#define I2S_FMT_BIT_CLK_INV BIT(4)
162#define I2S_FMT_FRAME_CLK_INV BIT(5)
163
165#define I2S_FMT_CLK_NF_NB (0 << I2S_FMT_CLK_FORMAT_SHIFT)
167#define I2S_FMT_CLK_NF_IB (1 << I2S_FMT_CLK_FORMAT_SHIFT)
169#define I2S_FMT_CLK_IF_NB (2 << I2S_FMT_CLK_FORMAT_SHIFT)
171#define I2S_FMT_CLK_IF_IB (3 << I2S_FMT_CLK_FORMAT_SHIFT)
172
175
177#define I2S_OPT_BIT_CLK_CONT (0 << 0)
179#define I2S_OPT_BIT_CLK_GATED BIT(0)
181#define I2S_OPT_BIT_CLK_MASTER (0 << 1)
183#define I2S_OPT_BIT_CLK_SLAVE BIT(1)
185#define I2S_OPT_FRAME_CLK_MASTER (0 << 2)
187#define I2S_OPT_FRAME_CLK_SLAVE BIT(2)
188
194#define I2S_OPT_LOOPBACK BIT(7)
195
204#define I2S_OPT_PINGPONG BIT(6)
205
217
236
279
315
321__subsystem struct i2s_driver_api {
322 int (*configure)(const struct device *dev, enum i2s_dir dir,
323 const struct i2s_config *cfg);
324 const struct i2s_config *(*config_get)(const struct device *dev,
325 enum i2s_dir dir);
326 int (*read)(const struct device *dev, void **mem_block, size_t *size);
327 int (*write)(const struct device *dev, void *mem_block, size_t size);
328 int (*trigger)(const struct device *dev, enum i2s_dir dir,
329 enum i2s_trigger_cmd cmd);
330};
357__syscall int i2s_configure(const struct device *dev, enum i2s_dir dir,
358 const struct i2s_config *cfg);
359
360static inline int z_impl_i2s_configure(const struct device *dev,
361 enum i2s_dir dir,
362 const struct i2s_config *cfg)
363{
364 const struct i2s_driver_api *api =
365 (const struct i2s_driver_api *)dev->api;
366
367 return api->configure(dev, dir, cfg);
368}
369
378static inline const struct i2s_config *i2s_config_get(const struct device *dev,
379 enum i2s_dir dir)
380{
381 const struct i2s_driver_api *api =
382 (const struct i2s_driver_api *)dev->api;
383
384 return api->config_get(dev, dir);
385}
386
418static inline int i2s_read(const struct device *dev, void **mem_block,
419 size_t *size)
420{
421 const struct i2s_driver_api *api =
422 (const struct i2s_driver_api *)dev->api;
423
424 return api->read(dev, mem_block, size);
425}
426
451__syscall int i2s_buf_read(const struct device *dev, void *buf, size_t *size);
452
479static inline int i2s_write(const struct device *dev, void *mem_block,
480 size_t size)
481{
482 const struct i2s_driver_api *api =
483 (const struct i2s_driver_api *)dev->api;
484
485 return api->write(dev, mem_block, size);
486}
487
507__syscall int i2s_buf_write(const struct device *dev, void *buf, size_t size);
508
526__syscall int i2s_trigger(const struct device *dev, enum i2s_dir dir,
527 enum i2s_trigger_cmd cmd);
528
529static inline int z_impl_i2s_trigger(const struct device *dev,
530 enum i2s_dir dir,
531 enum i2s_trigger_cmd cmd)
532{
533 const struct i2s_driver_api *api =
534 (const struct i2s_driver_api *)dev->api;
535
536 return api->trigger(dev, dir, cmd);
537}
538
543#ifdef __cplusplus
544}
545#endif
546
547#include <zephyr/syscalls/i2s.h>
548
549#endif /* ZEPHYR_INCLUDE_DRIVERS_I2S_H_ */
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
static int i2s_write(const struct device *dev, void *mem_block, size_t size)
Write data to the TX queue.
Definition i2s.h:479
uint8_t i2s_fmt_t
I2S data stream format options.
Definition i2s.h:40
int i2s_configure(const struct device *dev, enum i2s_dir dir, const struct i2s_config *cfg)
Configure operation of a host I2S controller.
int i2s_buf_read(const struct device *dev, void *buf, size_t *size)
Read data from the RX queue into a provided buffer.
static int i2s_read(const struct device *dev, void **mem_block, size_t *size)
Read data from the RX queue.
Definition i2s.h:418
i2s_dir
I2C Direction.
Definition i2s.h:209
i2s_state
Interface state.
Definition i2s.h:219
int i2s_buf_write(const struct device *dev, void *buf, size_t size)
Write data to the TX queue from a provided buffer.
int i2s_trigger(const struct device *dev, enum i2s_dir dir, enum i2s_trigger_cmd cmd)
Send a trigger command.
i2s_trigger_cmd
Trigger command.
Definition i2s.h:238
static const struct i2s_config * i2s_config_get(const struct device *dev, enum i2s_dir dir)
Fetch configuration information of a host I2S controller.
Definition i2s.h:378
uint8_t i2s_opt_t
I2S configuration options.
Definition i2s.h:174
@ I2S_DIR_BOTH
Both receive and transmit data.
Definition i2s.h:215
@ I2S_DIR_TX
Transmit data.
Definition i2s.h:213
@ I2S_DIR_RX
Receive data.
Definition i2s.h:211
@ I2S_STATE_ERROR
TX buffer underrun or RX buffer overrun has occurred.
Definition i2s.h:234
@ I2S_STATE_NOT_READY
The interface is not ready.
Definition i2s.h:226
@ I2S_STATE_STOPPING
The interface is draining its transmit queue.
Definition i2s.h:232
@ I2S_STATE_RUNNING
The interface is receiving / transmitting data.
Definition i2s.h:230
@ I2S_STATE_READY
The interface is ready to receive / transmit data.
Definition i2s.h:228
@ I2S_TRIGGER_STOP
Stop the transmission / reception of data.
Definition i2s.h:255
@ I2S_TRIGGER_PREPARE
Prepare the queues after underrun/overrun error has occurred.
Definition i2s.h:277
@ I2S_TRIGGER_START
Start the transmission / reception of data.
Definition i2s.h:245
@ I2S_TRIGGER_DRAIN
Empty the transmit queue.
Definition i2s.h:264
@ I2S_TRIGGER_DROP
Discard the transmit / receive queue.
Definition i2s.h:271
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
Interface configuration options.
Definition i2s.h:295
struct k_mem_slab * mem_slab
Memory slab to store RX/TX data.
Definition i2s.h:307
i2s_opt_t options
Configuration options as defined by I2S_OPT_* constants.
Definition i2s.h:303
uint8_t word_size
Number of bits representing one data word.
Definition i2s.h:297
size_t block_size
Size of one RX/TX memory block (buffer) in bytes.
Definition i2s.h:309
i2s_fmt_t format
Data stream format as defined by I2S_FMT_* constants.
Definition i2s.h:301
int32_t timeout
Read/Write timeout.
Definition i2s.h:313
uint32_t frame_clk_freq
Frame clock (WS) frequency, this is sampling rate.
Definition i2s.h:305
uint8_t channels
Number of words per frame.
Definition i2s.h:299