Microchip® Advanced Software Framework

i2s.h File Reference

SAM I2S - Inter-IC Sound Controller.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <system.h>
#include <system_interrupt.h>

Data Structures

struct  i2s_clock_config
 Configure for I2S clock (SCK). More...
 
struct  i2s_clock_unit_config
 Configure for I2S clock unit. More...
 
struct  i2s_frame_config
 Configure for I2S frame. More...
 
struct  i2s_frame_sync_config
 Configure for I2S frame sync (FS). More...
 
struct  i2s_module
 I2S Software Module instance struct. More...
 
struct  i2s_pin_config
 Configure for I2S pin. More...
 
struct  i2s_serializer_config
 Configure for I2S Serializer. More...
 
struct  i2s_serializer_module
 I2S Serializer instance struct. More...
 

Macros

Module Status Flags

I2S status flags, returned by i2s_get_status() and cleared by i2s_clear_status().

#define I2S_STATUS_TRANSMIT_UNDERRUN(x)   (1u << ((x)+0))
 Module Serializer x (0~1) Transmit Underrun. More...
 
#define I2S_STATUS_TRANSMIT_READY(x)   (1u << ((x)+2))
 Module Serializer x (0~1) is ready to accept new data to be transmitted. More...
 
#define I2S_STATUS_RECEIVE_OVERRUN(x)   (1u << ((x)+4))
 Module Serializer x (0~1) Receive Overrun. More...
 
#define I2S_STATUS_RECEIVE_READY(x)   (1u << ((x)+6))
 Module Serializer x (0~1) has received a new data. More...
 
#define I2S_STATUS_SYNC_BUSY   (1u << 8)
 Module is busy on synchronization. More...
 

Typedefs

typedef void(* i2s_serializer_callback_t )(struct i2s_module *const module)
 Type of the callback functions. More...
 

Enumerations

enum  i2s_bit_order {
  I2S_BIT_ORDER_MSB_FIRST,
  I2S_BIT_ORDER_LSB_FIRST
}
 I2S data bit order. More...
 
enum  i2s_bit_padding {
  I2S_BIT_PADDING_0,
  I2S_BIT_PADDING_1,
  I2S_BIT_PADDING_MSB,
  I2S_BIT_PADDING_LSB
}
 I2S data bit padding. More...
 
enum  i2s_clock_unit {
  I2S_CLOCK_UNIT_0,
  I2S_CLOCK_UNIT_1,
  I2S_CLOCK_UNIT_N
}
 I2S clock unit selection. More...
 
enum  i2s_data_adjust {
  I2S_DATA_ADJUST_RIGHT,
  I2S_DATA_ADJUST_LEFT
}
 I2S data word adjust. More...
 
enum  i2s_data_delay {
  I2S_DATA_DELAY_0,
  I2S_DATA_DELAY_1,
  I2S_DATA_DELAY_LEFT_JUSTIFIED = I2S_DATA_DELAY_0,
  I2S_DATA_DELAY_I2S = I2S_DATA_DELAY_1
}
 Data delay from Frame Sync (FS). More...
 
enum  i2s_data_format {
  I2S_DATA_FORMAT_STEREO,
  I2S_DATA_FORMAT_MONO
}
 I2S data format, to extend mono data to two channels. More...
 
enum  i2s_data_padding {
  I2S_DATA_PADDING_0,
  I2S_DATA_PADDING_SAME_AS_LAST,
  I2S_DATA_PADDING_LAST = I2S_DATA_PADDING_SAME_AS_LAST,
  I2S_DATA_PADDING_SAME = I2S_DATA_PADDING_SAME_AS_LAST
}
 I2S data padding. More...
 
enum  i2s_data_size {
  I2S_DATA_SIZE_32BIT,
  I2S_DATA_SIZE_24BIT,
  I2S_DATA_SIZE_20BIT,
  I2S_DATA_SIZE_18BIT,
  I2S_DATA_SIZE_16BIT,
  I2S_DATA_SIZE_16BIT_COMPACT,
  I2S_DATA_SIZE_8BIT,
  I2S_DATA_SIZE_8BIT_COMPACT
}
 I2S data word size. More...
 
enum  i2s_dma_usage {
  I2S_DMA_USE_SINGLE_CHANNEL_FOR_ALL,
  I2S_DMA_USE_ONE_CHANNEL_PER_DATA_CHANNEL
}
 DMA channels usage for I2S. More...
 
enum  i2s_frame_sync_source {
  I2S_FRAME_SYNC_SOURCE_SCKDIV,
  I2S_FRAME_SYNC_SOURCE_FSPIN
}
 Frame Sync (FS) source. More...
 
enum  i2s_frame_sync_width {
  I2S_FRAME_SYNC_WIDTH_SLOT,
  I2S_FRAME_SYNC_WIDTH_HALF_FRAME,
  I2S_FRAME_SYNC_WIDTH_BIT,
  I2S_FRAME_SYNC_WIDTH_BURST
}
 Frame Sync (FS) output pulse width. More...
 
enum  i2s_line_default_state {
  I2S_LINE_DEFAULT_0,
  I2S_LINE_DEFAULT_1,
  I2S_LINE_DEFAULT_HIGH_IMPEDANCE = 3,
  I2S_LINE_DEFAULT_HIZ = I2S_LINE_DEFAULT_HIGH_IMPEDANCE
}
 I2S line default value when slot disabled. More...
 
enum  i2s_master_clock_source {
  I2S_MASTER_CLOCK_SOURCE_GCLK,
  I2S_MASTER_CLOCK_SOURCE_MCKPIN
}
 Master Clock (MCK) source selection. More...
 
enum  i2s_serial_clock_source {
  I2S_SERIAL_CLOCK_SOURCE_MCKDIV,
  I2S_SERIAL_CLOCK_SOURCE_SCKPIN
}
 Serial Clock (SCK) source selection. More...
 
enum  i2s_serializer {
  I2S_SERIALIZER_0,
  I2S_SERIALIZER_1,
  I2S_SERIALIZER_N
}
 I2S Serializer selection. More...
 
enum  i2s_serializer_callback {
  I2S_SERIALIZER_CALLBACK_BUFFER_DONE,
  I2S_SERIALIZER_CALLBACK_OVER_UNDER_RUN
}
 I2S Serializer Callback enum. More...
 
enum  i2s_serializer_mode {
  I2S_SERIALIZER_RECEIVE,
  I2S_SERIALIZER_TRANSMIT,
  I2S_SERIALIZER_PDM2
}
 I2S Serializer mode. More...
 
enum  i2s_slot_adjust {
  I2S_SLOT_ADJUST_RIGHT,
  I2S_SLOT_ADJUST_LEFT
}
 I2S data slot adjust. More...
 
enum  i2s_slot_size {
  I2S_SLOT_SIZE_8_BIT,
  I2S_SLOT_SIZE_16_BIT,
  I2S_SLOT_SIZE_24_BIT,
  I2S_SLOT_SIZE_32_BIT
}
 Time Slot Size in number of I2S serial clocks (bits). More...
 

Functions

static bool i2s_is_syncing (const struct i2s_module *const module_inst)
 Determines if the hardware module(s) are currently synchronizing to the bus. More...
 
Driver Initialization
enum status_code i2s_init (struct i2s_module *const module_inst, I2s *hw)
 Initializes a hardware I2S module instance. More...
 
Enable/Disable/Reset
static void i2s_enable (const struct i2s_module *const module_inst)
 Enable the I2S module. More...
 
static void i2s_disable (const struct i2s_module *const module_inst)
 Disables the I2S module. More...
 
static void i2s_reset (const struct i2s_module *const module_inst)
 Resets the I2S module. More...
 
Clock Unit Initialization and Configuration
static void i2s_clock_unit_get_config_defaults (struct i2s_clock_unit_config *const config)
 Initializes config with predefined default values for I2S clock unit. More...
 
enum status_code i2s_clock_unit_set_config (struct i2s_module *const module_inst, const enum i2s_clock_unit clock_unit, const struct i2s_clock_unit_config *config)
 Configure specified I2S clock unit. More...
 
Clock Unit Enable/Disable
static void i2s_clock_unit_enable (const struct i2s_module *const module_inst, const enum i2s_clock_unit clock_unit)
 Enable the Specified Clock Unit of I2S module. More...
 
static void i2s_clock_unit_disable (const struct i2s_module *const module_inst, const enum i2s_clock_unit clock_unit)
 Disable the Specified Clock Unit of I2S module. More...
 
Serializer Initialization and Configuration
static void i2s_serializer_get_config_defaults (struct i2s_serializer_config *const config)
 Initializes config with predefined default values for I2S Serializer. More...
 
enum status_code i2s_serializer_set_config (struct i2s_module *const module_inst, const enum i2s_serializer serializer, const struct i2s_serializer_config *config)
 Configure specified I2S serializer. More...
 
Serializer Enable/Disable
static void i2s_serializer_enable (const struct i2s_module *const module_inst, const enum i2s_serializer serializer)
 Enable the Specified Serializer of I2S module. More...
 
static void i2s_serializer_disable (const struct i2s_module *const module_inst, const enum i2s_serializer serializer)
 Disable the Specified Serializer of I2S module. More...
 
Status Management
uint32_t i2s_get_status (const struct i2s_module *const module_inst)
 Retrieves the current module status. More...
 
void i2s_clear_status (const struct i2s_module *const module_inst, uint32_t status)
 Clears a module status flags. More...
 
enum status_code i2s_enable_status_interrupt (struct i2s_module *const module_inst, uint32_t status)
 Enable interrupts on status set. More...
 
void i2s_disable_status_interrupt (struct i2s_module *const module_inst, uint32_t status)
 Disable interrupts on status set. More...
 
Data Read/Write
static void i2s_serializer_write_wait (const struct i2s_module *const module_inst, enum i2s_serializer serializer, uint32_t data)
 Write a data word to the specified Serializer of I2S module. More...
 
static uint32_t i2s_serializer_read_wait (const struct i2s_module *const module_inst, enum i2s_serializer serializer)
 Read a data word from the specified Serializer of I2S module. More...
 
enum status_code i2s_serializer_write_buffer_wait (const struct i2s_module *const module_inst, enum i2s_serializer serializer, void *buffer, uint32_t size)
 Write buffer to the specified Serializer of I2S module. More...
 
enum status_code i2s_serializer_read_buffer_wait (const struct i2s_module *const module_inst, enum i2s_serializer serializer, void *buffer, uint32_t size)
 Read from the specified Serializer of I2S module to a buffer. More...