MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
sgtl5000 Driver

Overview

The sgtl5000 driver provide codec control interface.

Modules

 sgtl5000 adapter
 

Data Structures

struct  sgtl_audio_format_t
 Audio format configuration. More...
 
struct  sgtl_config_t
 Initailize structure of sgtl5000. More...
 
struct  sgtl_handle_t
 SGTL codec handler. More...
 

Macros

#define CHIP_ID   0x0000
 Define the register address of sgtl5000. More...
 
#define SGTL5000_I2C_ADDR   0x0A
 SGTL5000 I2C address. More...
 
#define SGTL_I2C_HANDLER_SIZE   CODEC_I2C_MASTER_HANDLER_SIZE
 sgtl handle size
 
#define SGTL_I2C_BITRATE   100000U
 sgtl i2c baudrate
 

Enumerations

enum  sgtl_module_t {
  kSGTL_ModuleADC = 0x0,
  kSGTL_ModuleDAC,
  kSGTL_ModuleDAP,
  kSGTL_ModuleHP,
  kSGTL_ModuleI2SIN,
  kSGTL_ModuleI2SOUT,
  kSGTL_ModuleLineIn,
  kSGTL_ModuleLineOut,
  kSGTL_ModuleMicin
}
 Modules in Sgtl5000 board. More...
 
enum  sgtl_route_t {
  kSGTL_RouteBypass = 0x0,
  kSGTL_RoutePlayback,
  kSGTL_RoutePlaybackandRecord,
  kSGTL_RoutePlaybackwithDAP,
  kSGTL_RoutePlaybackwithDAPandRecord,
  kSGTL_RouteRecord
}
 Sgtl5000 data route. More...
 
enum  sgtl_protocol_t {
  kSGTL_BusI2S = 0x0,
  kSGTL_BusLeftJustified,
  kSGTL_BusRightJustified,
  kSGTL_BusPCMA,
  kSGTL_BusPCMB
}
 The audio data transfer protocol choice. More...
 
enum  _sgtl_play_channel {
  kSGTL_HeadphoneLeft = 0,
  kSGTL_HeadphoneRight = 1,
  kSGTL_LineoutLeft = 2,
  kSGTL_LineoutRight = 3
}
 sgtl play channel More...
 
enum  _sgtl_record_source {
  kSGTL_RecordSourceLineIn = 0U,
  kSGTL_RecordSourceMic = 1U
}
 sgtl record source More...
 
enum  _stgl_play_source {
  kSGTL_PlaySourceLineIn = 0U,
  kSGTL_PlaySourceDAC = 1U
}
 sgtl play source More...
 
enum  sgtl_sclk_edge_t {
  kSGTL_SclkValidEdgeRising = 0U,
  kSGTL_SclkValidEdgeFailling = 1U
}
 SGTL SCLK valid edge. More...
 

Functions

status_t SGTL_Init (sgtl_handle_t *handle, sgtl_config_t *config)
 sgtl5000 initialize function. More...
 
status_t SGTL_SetDataRoute (sgtl_handle_t *handle, sgtl_route_t route)
 Set audio data route in sgtl5000. More...
 
status_t SGTL_SetProtocol (sgtl_handle_t *handle, sgtl_protocol_t protocol)
 Set the audio transfer protocol. More...
 
void SGTL_SetMasterSlave (sgtl_handle_t *handle, bool master)
 Set sgtl5000 as master or slave. More...
 
status_t SGTL_SetVolume (sgtl_handle_t *handle, sgtl_module_t module, uint32_t volume)
 Set the volume of different modules in sgtl5000. More...
 
uint32_t SGTL_GetVolume (sgtl_handle_t *handle, sgtl_module_t module)
 Get the volume of different modules in sgtl5000. More...
 
status_t SGTL_SetMute (sgtl_handle_t *handle, sgtl_module_t module, bool mute)
 Mute/unmute modules in sgtl5000. More...
 
status_t SGTL_EnableModule (sgtl_handle_t *handle, sgtl_module_t module)
 Enable expected devices. More...
 
status_t SGTL_DisableModule (sgtl_handle_t *handle, sgtl_module_t module)
 Disable expected devices. More...
 
status_t SGTL_Deinit (sgtl_handle_t *handle)
 Deinit the sgtl5000 codec. More...
 
status_t SGTL_ConfigDataFormat (sgtl_handle_t *handle, uint32_t mclk, uint32_t sample_rate, uint32_t bits)
 Configure the data format of audio data. More...
 
status_t SGTL_SetPlay (sgtl_handle_t *handle, uint32_t playSource)
 select SGTL codec play source. More...
 
status_t SGTL_SetRecord (sgtl_handle_t *handle, uint32_t recordSource)
 select SGTL codec record source. More...
 
status_t SGTL_WriteReg (sgtl_handle_t *handle, uint16_t reg, uint16_t val)
 Write register to sgtl using I2C. More...
 
status_t SGTL_ReadReg (sgtl_handle_t *handle, uint16_t reg, uint16_t *val)
 Read register from sgtl using I2C. More...
 
status_t SGTL_ModifyReg (sgtl_handle_t *handle, uint16_t reg, uint16_t clr_mask, uint16_t val)
 Modify some bits in the register using I2C. More...
 

Driver version

#define FSL_SGTL5000_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))
 CLOCK driver version 2.1.0. More...
 

Data Structure Documentation

struct sgtl_audio_format_t

Data Fields

uint32_t mclk_HZ
 master clock
 
uint32_t sampleRate
 Sample rate.
 
uint32_t bitWidth
 Bit width.
 
sgtl_sclk_edge_t sclkEdge
 sclk valid edge
 
struct sgtl_config_t

Data Fields

sgtl_route_t route
 Audio data route. More...
 
sgtl_protocol_t bus
 Audio transfer protocol.
 
bool master_slave
 Master or slave. More...
 
sgtl_audio_format_t format
 audio format
 
uint8_t slaveAddress
 code device slave address
 
codec_i2c_config_t i2cConfig
 i2c bus configuration
 

Field Documentation

sgtl_route_t sgtl_config_t::route
bool sgtl_config_t::master_slave

True means master, false means slave.

struct sgtl_handle_t

Data Fields

sgtl_config_tconfig
 sgtl config pointer
 
uint8_t i2cHandle [SGTL_I2C_HANDLER_SIZE]
 i2c handle
 

Macro Definition Documentation

#define FSL_SGTL5000_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))
#define CHIP_ID   0x0000
#define SGTL5000_I2C_ADDR   0x0A

Enumeration Type Documentation

Enumerator
kSGTL_ModuleADC 

ADC module in SGTL5000.

kSGTL_ModuleDAC 

DAC module in SGTL5000.

kSGTL_ModuleDAP 

DAP module in SGTL5000.

kSGTL_ModuleHP 

Headphone module in SGTL5000.

kSGTL_ModuleI2SIN 

I2S-IN module in SGTL5000.

kSGTL_ModuleI2SOUT 

I2S-OUT module in SGTL5000.

kSGTL_ModuleLineIn 

Line-in moudle in SGTL5000.

kSGTL_ModuleLineOut 

Line-out module in SGTL5000.

kSGTL_ModuleMicin 

Micphone module in SGTL5000.

Note
Only provide some typical data route, not all route listed. Users cannot combine any routes, once a new route is set, the precios one would be replaced.
Enumerator
kSGTL_RouteBypass 

LINEIN->Headphone.

kSGTL_RoutePlayback 

I2SIN->DAC->Headphone.

kSGTL_RoutePlaybackandRecord 

I2SIN->DAC->Headphone, LINEIN->ADC->I2SOUT.

kSGTL_RoutePlaybackwithDAP 

I2SIN->DAP->DAC->Headphone.

kSGTL_RoutePlaybackwithDAPandRecord 

I2SIN->DAP->DAC->HP, LINEIN->ADC->I2SOUT.

kSGTL_RouteRecord 

LINEIN->ADC->I2SOUT.

Sgtl5000 only supports I2S format and PCM format.

Enumerator
kSGTL_BusI2S 

I2S Type.

kSGTL_BusLeftJustified 

Left justified.

kSGTL_BusRightJustified 

Right Justified.

kSGTL_BusPCMA 

PCMA.

kSGTL_BusPCMB 

PCMB.

Enumerator
kSGTL_HeadphoneLeft 

headphone left channel

kSGTL_HeadphoneRight 

headphone right channel

kSGTL_LineoutLeft 

lineout left channel

kSGTL_LineoutRight 

lineout right channel

Enumerator
kSGTL_RecordSourceLineIn 

record source line in

kSGTL_RecordSourceMic 

record source single end

Enumerator
kSGTL_PlaySourceLineIn 

play source line in

kSGTL_PlaySourceDAC 

play source line in

Enumerator
kSGTL_SclkValidEdgeRising 

SCLK valid edge.

kSGTL_SclkValidEdgeFailling 

SCLK failling edge.

Function Documentation

status_t SGTL_Init ( sgtl_handle_t handle,
sgtl_config_t config 
)

This function calls SGTL_I2CInit(), and in this function, some configurations are fixed. The second parameter can be NULL. If users want to change the SGTL5000 settings, a configure structure should be prepared.

Note
If the codec_config is NULL, it would initialize sgtl5000 using default settings. The default setting:
* sgtl_init_t codec_config
* codec_config.route = kSGTL_RoutePlaybackandRecord
* codec_config.bus = kSGTL_BusI2S
* codec_config.master = slave
*
Parameters
handleSgtl5000 handle structure.
configsgtl5000 configuration structure. If this pointer equals to NULL, it means using the default configuration.
Returns
Initialization status
status_t SGTL_SetDataRoute ( sgtl_handle_t handle,
sgtl_route_t  route 
)

This function would set the data route according to route. The route cannot be combined, as all route would enable different modules.

Note
If a new route is set, the previous route would not work.
Parameters
handleSgtl5000 handle structure.
routeAudio data route in sgtl5000.
status_t SGTL_SetProtocol ( sgtl_handle_t handle,
sgtl_protocol_t  protocol 
)

Sgtl5000 only supports I2S, I2S left, I2S right, PCM A, PCM B format.

Parameters
handleSgtl5000 handle structure.
protocolAudio data transfer protocol.
void SGTL_SetMasterSlave ( sgtl_handle_t handle,
bool  master 
)
Parameters
handleSgtl5000 handle structure.
master1 represent master, 0 represent slave.
status_t SGTL_SetVolume ( sgtl_handle_t handle,
sgtl_module_t  module,
uint32_t  volume 
)

This function would set the volume of sgtl5000 modules. This interface set module volume. The function assume that left channel and right channel has the same volume.

Parameters
handleSgtl5000 handle structure.
moduleSgtl5000 module, such as DAC, ADC and etc.
volumeVolume value need to be set. The value is the exact value in register.
uint32_t SGTL_GetVolume ( sgtl_handle_t handle,
sgtl_module_t  module 
)

This function gets the volume of sgtl5000 modules. This interface get DAC module volume. The function assume that left channel and right channel has the same volume.

Parameters
handleSgtl5000 handle structure.
moduleSgtl5000 module, such as DAC, ADC and etc.
Returns
Module value, the value is exact value in register.
status_t SGTL_SetMute ( sgtl_handle_t handle,
sgtl_module_t  module,
bool  mute 
)
Parameters
handleSgtl5000 handle structure.
moduleSgtl5000 module, such as DAC, ADC and etc.
muteTrue means mute, and false means unmute.
status_t SGTL_EnableModule ( sgtl_handle_t handle,
sgtl_module_t  module 
)
Parameters
handleSgtl5000 handle structure.
moduleModule expected to enable.
status_t SGTL_DisableModule ( sgtl_handle_t handle,
sgtl_module_t  module 
)
Parameters
handleSgtl5000 handle structure.
moduleModule expected to enable.
status_t SGTL_Deinit ( sgtl_handle_t handle)

Shut down Sgtl5000 modules.

Parameters
handleSgtl5000 handle structure pointer.
status_t SGTL_ConfigDataFormat ( sgtl_handle_t handle,
uint32_t  mclk,
uint32_t  sample_rate,
uint32_t  bits 
)

This function would configure the registers about the sample rate, bit depths.

Parameters
handleSgtl5000 handle structure pointer.
mclkMaster clock frequency of I2S.
sample_rateSample rate of audio file running in sgtl5000. Sgtl5000 now supports 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, 44.1k, 48k and 96k sample rate.
bitsBit depth of audio file (Sgtl5000 only supports 16bit, 20bit, 24bit and 32 bit in HW).
status_t SGTL_SetPlay ( sgtl_handle_t handle,
uint32_t  playSource 
)
Parameters
handleSgtl5000 handle structure pointer.
playSourceplay source value, reference _sgtl_play_source.
Returns
kStatus_Success, else failed.
status_t SGTL_SetRecord ( sgtl_handle_t handle,
uint32_t  recordSource 
)
Parameters
handleSgtl5000 handle structure pointer.
recordSourcerecord source value, reference _sgtl_record_source.
Returns
kStatus_Success, else failed.
status_t SGTL_WriteReg ( sgtl_handle_t handle,
uint16_t  reg,
uint16_t  val 
)
Parameters
handleSgtl5000 handle structure.
regThe register address in sgtl.
valValue needs to write into the register.
status_t SGTL_ReadReg ( sgtl_handle_t handle,
uint16_t  reg,
uint16_t *  val 
)
Parameters
handleSgtl5000 handle structure.
regThe register address in sgtl.
valValue written to.
status_t SGTL_ModifyReg ( sgtl_handle_t handle,
uint16_t  reg,
uint16_t  clr_mask,
uint16_t  val 
)
Parameters
handleSgtl5000 handle structure.
regThe register address in sgtl.
clr_maskThe mask code for the bits want to write. The bit you want to write should be 0.
valValue needs to write into the register.