Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
tlv320aic33.c File Reference

Driver for codec TLV320AIC33. More...

`#include "tlv320aic33.h"`
`#include <stdio.h>`
`#include "print_funcs.h"`

## Macros
#define | TLV320AIC33_MAX_CMD_ID 8
| Maximum command ID (is defined by last command) More...

## Functions
GD_RES_CODE | tlv320aic33_find_raw_volume_value (float f_value, uint8_t *p_raw_volume)
| Find raw volume value to input float value. More...
GD_RES_CODE | tlv320aic33_find_float_volume_value (uint8_t i_raw_volume, float *p_float)
| Find input float value raw volume value. More...
GD_RES_CODE | tlv320aic33_init (void)
| Initialize TLV320AIC33. More...
GD_RES_CODE | tlv320aic33_set_DAC_play_input_data (uint8_t i_play_stereo)
| Set DAC data path to input data. More...
GD_RES_CODE | tlv320aic33_set_digital_interface_as_master (uint8_t i_master)
| Set digital interface as master or slave. More...
GD_RES_CODE | tlv320aic33_set_data_interface_mode (e_AudioSerialDataInterfaceTransferMode e_mode)
| Set data interface mode. More...
GD_RES_CODE | tlv320aic33_set_word_length (uint8_t i_word_length)
| Set word length. More...
GD_RES_CODE | tlv320aic33_set_DAC_power (uint8_t enable_DACs)
| Enable or disable DACs. More...
GD_RES_CODE | tlv320aic33_set_headphones_single_ended (uint8_t i_single_ended)
| Set headphone COM pins as single ended or differential. More...
GD_RES_CODE | tlv320aic33_set_DAC_mute (uint8_t i_mute_flag)
| Enable or disable mute flag on DAC. More...
GD_RES_CODE | tlv320aic33_set_DAC_volume_dB (float f_volume)
| Set DAC volume. Volume is in dB. More...
GD_RES_CODE | tlv320aic33_set_CLKDIV_IN_source (e_CLKDIV_INSourceSelection e_source)
| Set CLKDIV_IN source. More...
GD_RES_CODE | tlv320aic33_set_PLLCLK_IN_source (e_PLLCLK_INSourceSelection e_source)
| Set PLLCLK_IN source. More...
GD_RES_CODE | tlv320aic33_set_headphones_volume_dB (float f_volume)
| Set headphones volume. Volume is in dB. More...
GD_RES_CODE | tlv320aic33_get_headphones_volume_db (float *p_f_volume)
| Get real headphones volume. More...
GD_RES_CODE | tlv320aic33_reset (void)
| Set page to 0 and restart codec. More...
GD_RES_CODE | tlv320aic33_set_output_driver_power_on_delay (e_OutputDriverPowerOnDelayControl e_delay)
| Set output driver power on delay. More...
GD_RES_CODE | tlv320aic33_set_driver_ramp_up_step_time (e_DriverRampUpStepTimingControl e_time)
| Set driver ramp-up step time. More...
GD_RES_CODE | tlv320aic33_set_DAC_volume (uint8_t i_volume)
| Set DAC volume in raw format. More...
GD_RES_CODE | tlv320aic33_set_headphones_volume (uint8_t i_volume)
| Set headphone volume in raw format. More...
GD_RES_CODE | tlv320aic33_write_data (const uint8_t i_register_number, const uint8_t i_value)
| Write data on TWI (I2C) bus. More...
GD_RES_CODE | tlv320aic33_read_data (uint8_t i_register_number, uint8_t *p_data)
| Read data on TWI (I2C) bus. More...

## Variables
const float | TLV320AIC33_volume_table_float []
| todo REMOVE More...
static tlv320aic33_virtual_reg_img_t | s_virtual_reg_img
| Virtual register image. More...
const gd_config_struct | TLV320AIC33_config_table []
| Configure table for device. More...
const gd_metadata | TLV320AIC33_metadata
portBASE_TYPE | xStatus
xSemaphoreHandle | mutexI2C

## Detailed Description

Driver for codec TLV320AIC33.

Created: 02.04.2014
Modified: 15.05.2014

Version
  0.1a

Author
  Martin Stejskal

## Macro Definition Documentation

#define TLV320AIC33_MAX_CMD_ID 8

Maximum command ID (is defined by last command)

## Function Documentation

GD_RES_CODE tlv320aic33_find_float_volume_value | ( | uint8_t | i_raw_volume,
|  | float * | p_float
| ) |  |

Find input float value raw volume value.

Parameters

  i_raw_volume | Input raw volume value
  p_float | Pointer to float value. To this address will be written result.

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE tlv320aic33_find_raw_volume_value | ( | float | f_value,
|  | uint8_t * | p_raw_volume
| ) |  |

Find raw volume value to input float value.

Parameters

  f_value | Input float value
  p_raw_volume | Pointer to raw variable. Address where result will be written.

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_get_headphones_volume_db | ( | float * | p_f_volume) |  |

Get real headphones volume.

Parameters

  p_f_volume | Pointer to address where result will be written

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE tlv320aic33_init | ( | void | ) |  |

Initialize TLV320AIC33.

Must be called before any other function from this library!

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE tlv320aic33_read_data | ( | uint8_t | i_register_number,
|  | uint8_t * | p_data
| ) |  |
| inline

Read data on TWI (I2C) bus.

MCU is in master mode. Send TLV320AIC33 address and register value. Stop
condition. Send address and then receive data (1B). This function also
check if TWI module is available (when RTOS support is enabled).

Parameters

  p_data | Data are saved thru this pointer
  i_register_number | Register number

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_reset | ( | void | ) |  |
| inline

Set page to 0 and restart codec.

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_CLKDIV_IN_source | ( | e_CLKDIV_INSourceSelection | e_source) |  |

Set CLKDIV_IN source.

Parameters

  e_source | Options are defined in e_CLKDIV_INSourceSelection

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_DAC_mute | ( | uint8_t | i_mute_flag) |  |

Enable or disable mute flag on DAC.

Parameters

  i_mute_flag | 0 - disable mute ; 1 - enable mute

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_DAC_play_input_data | ( | uint8_t | i_play_stereo) |  |

Set DAC data path to input data.

Parameters

  i_play_stereo | Options: 0 - mix left and right input data channel ; 1 - input data are send directly to DAC

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE tlv320aic33_set_DAC_power | ( | uint8_t | enable_DACs) |  |

Enable or disable DACs.

Parameters

  enable_DACs | Options: 0 - disable DACs ; 1 - enable DACs

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_DAC_volume | ( | uint8_t | i_volume) |  |

Set DAC volume in raw format.

Volume is in binary representation in codec register, so it is up to user
to recalculate it to dB.

Parameters

  i_volume | Volume value (7 bit number) in binary representation for register

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_DAC_volume_dB | ( | float | f_volume) |  |

Set DAC volume. Volume is in dB.

Because codec have 0.5 dB step, function convergence input parameter to
closest result.

Parameters

  f_volume | Volume in dB. Range is from 0 to -63.5 dB. Step is 0.5 dB.

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE tlv320aic33_set_data_interface_mode | ( | e_AudioSerialDataInterfaceTransferMode | e_mode) |  |

Set data interface mode.

Parameters

  i_mode | Options are defined in e_AudioSerialDataInterfaceTransferMode

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_digital_interface_as_master | ( | uint8_t | i_master) |  |

Set digital interface as master or slave.

When set as master BCLK and WCLK are configured as output. Else BCLK and
WCLK is configured as input.

Parameters

  i_master | Options: 0 - configure as slave ; 1 - configure as master

Returns
  GD_SUCCESS (0) if all OKs

GD_RES_CODE tlv320aic33_set_driver_ramp_up_step_time | ( | e_DriverRampUpStepTimingControl | e_time) |  |

Set driver ramp-up step time.

Parameters

  e_time | Options are defined in e_DriverRampUpStepTimingControl

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_headphones_single_ended | ( | uint8_t | i_single_ended) |  |

Set headphone COM pins as single ended or differential.

Parameters

  single_ended | 0 - HPxCOM as differential ; 1 - HPxCOM as single ended

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_headphones_volume | ( | uint8_t | i_volume) |  |

Set headphone volume in raw format.

Volume is in binary representation in codec register, so it is up to user
to recalculate it to dB.

Parameters

  i_volume | Volume value (7 bit number) in binary representation for register

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_headphones_volume_dB | ( | float | f_volume) |  |

Set headphones volume. Volume is in dB.

Because codec approximately 0.5 dB step, function convergence input
parameter to closest result.

Parameters

  f_volume | Volume in dB. Range is from 0 to -78.3 dB. Step is approximately 0.5 dB.

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE tlv320aic33_set_output_driver_power_on_delay | ( | e_OutputDriverPowerOnDelayControl | e_delay) |  |

Set output driver power on delay.

Parameters

  e_delay | Options are defined in e_OutputDriverPowerOnDelayControl

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_PLLCLK_IN_source | ( | e_PLLCLK_INSourceSelection | e_source) |  |

Set PLLCLK_IN source.

Parameters

  e_source | Options are defined in e_PLLCLK_INSourceSelection

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_set_word_length | ( | uint8_t | i_word_length) |  |

Set word length.

Parameters

  i_word_length | Options: 16, 20, 24, 32

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE tlv320aic33_write_data | ( | const uint8_t | i_register_number,
|  | const uint8_t | i_value
| ) |  |
| inline

Write data on TWI (I2C) bus.

MCU is in master mode. Send TLV320AIC33 address, then register number and
data. This function also check if TWI module is available (when RTOS
support is enabled).

Parameters

  i_register_number | Register number
  i_value | Register value

Returns
  GD_SUCCESS (0) if all OK

## Variable Documentation

xSemaphoreHandle mutexI2C

tlv320aic33_virtual_reg_img_t s_virtual_reg_img
| static

Virtual register image.

This values codec directly do not have in memory. However, there are in
more human readable format. Also some values can use generic driver (need
to point to result variables and so on).
It is static, so it is "global" only for this file.

Note
  This structure have meaning only if generic driver is enable

const gd_config_struct TLV320AIC33_config_table[]

Configure table for device.

const gd_metadata TLV320AIC33_metadata

Initial value:
=
{
TLV320AIC33_MAX_CMD_ID,
"Audio codec TLV320AIC33 v0.1a",
(gd_config_struct*)&TLV320AIC33_config_table[0],
0x66
}

const float TLV320AIC33_volume_table_float[]

Initial value:
=
{ 0, -0.5, -1, -1.5, -2, -2.5, -3, -3.5, -4, -4.5,
-5, -5.5, -6, -6.5, -7, -7.5, -8, -8.5, -9, -9.5,
-10, -10.5, -11, -11.5, -12, -12.5, -13, -13.5, -14, -14.5,
-15, -15.5, -16, -16.5, -17, -17.5, -18, -18.6, -19.1, -19.6,
-20.1, -20.6, -21.1, -21.6, -22.1, -22.6, -23.1, -23.6, -24.1, -24.6,
-25.1, -25.6, -26.1, -26.6, -27.1, -27.6, -28.1, -28.6, -29.1, -29.6,
-30.1, -30.6, -31.1, -31.6, -32.1, -32.6, -33.1, -33.6, -34.1, -34.6,
-35.1, -35.7, -36.1, -36.7, -37.1, -37.7, -38.2, -38.7, -39.2, -39.7,
-40.2, -40.7, -41.2, -41.7, -42.2, -42.7, -43.2, -43.8, -44.3, -44.8,
-45.2, -45.8, -46.2, -46.7, -47.4, -47.9, -48.2, -48.7, -49.3, -50,
-50.3, -51, -51.4, -51.8, -52.2, -52.7, -53.7, -54.2, -55.3, -56.7,
-58.3, -60.2, -62.7, -64.3, -66.2, -68.7, -72.2, -78.3
}

todo REMOVE

Table with volume values in float type

This table is used to find float value to raw volume value. Index is raw
volume value and content is float value, so it is easy to find float
number or raw value equal to float value.

portBASE_TYPE xStatus