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
tlv320aic33_HAL_AVR32_UC3A3_HW_interface.h File Reference

Hardware Abstraction Layer for codec TLV320AIC33 running on AVR32
UC3A3 architecture. More...

`#include <avr32/io.h>`
`#include <inttypes.h>`
`#include "gpio.h"`

Go to the source code of this file.

## Macros
Basic settings for TWI
Todo: Try to remove this dependency
#define | TLV320AIC33_TWI_DEVICE (&AVR32_TWIM0)
| TWI interface. More...
#define | TLV320AIC33_TWI_CLK_SOURCE 33000000UL
| Clock speed in Hz. More...
#define | TLV320AIC33_TWI_ADDRESS 0b0011000
| TWI address of TLV320AIC33. More...
#define | TLV320AIC33_TWI_SDA_PIN AVR32_TWIMS0_TWD_0_0_PIN
| Definition of TWI (I2C) pins. More...
#define | TLV320AIC33_TWI_SDA_FUNCTION AVR32_TWIMS0_TWD_0_0_FUNCTION
| Function for TWI data signal. More...
#define | TLV320AIC33_TWI_SCL_PIN AVR32_TWIMS0_TWCK_0_0_PIN
| Pin for TWI clock signal. More...
#define | TLV320AIC33_TWI_SCL_FUNCTION AVR32_TWIMS0_TWCK_0_0_FUNCTION
| Function for TWI clock signal. More...

## Advanced settings TWI interface
#define | TLV320AIC33_TWI_BAUDRATE 0
| Baudrate in Hz - in real should not exceed 100 kb/s. More...
#define | TLV320AIC33_TWI_BAUDRATE 100000UL
| Baudrate in Hz - in real should not exceed 100 kb/s. More...
#define | TLV320AIC33_TWI_CKDIV 0
#define | TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/2)
enum | TLV320AIC33_status_t { TLV320AIC33_ERROR = -1, TLV320AIC33_OK = 0, TLV320AIC33_ERROR_TWI_TIMEOUT = 1, TLV320AIC33_ERROR_TWI_INVALID_PARAMETER = 2, TLV320AIC33_ERROR_TWI_NACK = 3 }
| Enumeration of states, which can function returns. More...
TLV320AIC33_status_t | tlv320aic33_HAL_init (void)
| Initialize TWI module on chip. More...
TLV320AIC33_status_t | tlv320aic33_HAL_write_data (uint8_t i_register_number, uint8_t i_data)
| Write data on TWI (I2C) bus. More...
TLV320AIC33_status_t | tlv320aic33_HAL_read_data (uint8_t i_register_number, uint8_t *p_data)
| Read data on TWI (I2C) bus. More...

## Detailed Description

Hardware Abstraction Layer for codec TLV320AIC33 running on AVR32
UC3A3 architecture.

Contains basic low level functions which depend on user architecture and
hardware. Thanks to this layer is possible use common higher level driver
and apply it thru many architectures and devices. Also this allow easy
updates independent to higher layer (new features and so on).

Created: 02.04.2014
Modified: 23.04.2014

Version
  0.1

Author
  Martin Stejskal

## Macro Definition Documentation

#define TLV320AIC33_TWI_ADDRESS 0b0011000

TWI address of TLV320AIC33.

Because this depend on hardware settings, it is up to user to set correct
address.

Note
  Depend on...

Todo:
  Complete doc

#define TLV320AIC33_TWI_BAUDRATE 0

Baudrate in Hz - in real should not exceed 100 kb/s.

Too low speed decrease whole application performance.
For maximum performance is recommended to set this value to 0. Library itself will try to set maximum possible baudrate.
However it can not be ideal solution. When any other devices are connected
to this TWI bus, they may not support this speed! So please check maximum
baudrate at other devices connected to bus. Example: TLV320AIC33_SPI_BAUDRATE 100000UL

Todo:
  Check device address (1 of 4)

#define TLV320AIC33_TWI_BAUDRATE 100000UL

Baudrate in Hz - in real should not exceed 100 kb/s.

Too low speed decrease whole application performance.
For maximum performance is recommended to set this value to 0. Library itself will try to set maximum possible baudrate.
However it can not be ideal solution. When any other devices are connected
to this TWI bus, they may not support this speed! So please check maximum
baudrate at other devices connected to bus. Example: TLV320AIC33_SPI_BAUDRATE 100000UL

Todo:
  Check device address (1 of 4)

#define TLV320AIC33_TWI_CKDIV 0

#define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/2)

#define TLV320AIC33_TWI_CLK_SOURCE 33000000UL

Clock speed in Hz.

User should define at least approximately speed of clock on which is TWI
module connected. This value is used to calculate correct values in
registers. After reset, MCU use slow oscillator, which in case UC3A3256
runs at 115 kHz. If your clock source is variable, then is recommended
set this constant to maximum used frequency. Anyway, if you want use
maximum possible speed, just set TLV320AIC33_TWI_BAUDRATE to 0 and
preprocessor do the rest :)
Example: TLV320AIC33_TWI_CLK_SOURCE 115000UL

#define TLV320AIC33_TWI_DEVICE (&AVR32_TWIM0)

TWI interface.

Aka (*((volatile avr32_twi_t*)AVR32_TWIM0_ADDRESS)) or (&AVR32_TWIM0)
Example: TLV320AIC33_TWI_DEVICE (&AVR32_TWIM0)

#define TLV320AIC33_TWI_SCL_FUNCTION AVR32_TWIMS0_TWCK_0_0_FUNCTION

Function for TWI clock signal.

Example: TLV320AIC33_TWI_SCL_FUNCTION AVR32_TWIMS0_TWCK_0_0_FUNCTION

#define TLV320AIC33_TWI_SCL_PIN AVR32_TWIMS0_TWCK_0_0_PIN

Pin for TWI clock signal.

Example: TLV320AIC33_TWI_SCL_PIN AVR32_TWIMS0_TWCK_0_0_PIN

#define TLV320AIC33_TWI_SDA_FUNCTION AVR32_TWIMS0_TWD_0_0_FUNCTION

Function for TWI data signal.

Example: TLV320AIC33_TWI_SDA_FUNCTION AVR32_TWIMS0_TWD_0_0_FUNCTION

#define TLV320AIC33_TWI_SDA_PIN AVR32_TWIMS0_TWD_0_0_PIN

Definition of TWI (I2C) pins.

There are defined pins and their functions Pin for TWI data signal

Example: TLV320AIC33_TWI_SDA_PIN AVR32_TWIMS0_TWD_0_0_PIN

## Enumeration Type Documentation

enum TLV320AIC33_status_t

Enumeration of states, which can function returns.

Generally if function return non-zero value then no problem occurs. This
enum also use TLV320AIC33 driver (higher layer of this driver).

Enumerator
TLV320AIC33_ERROR | Unspecified error.
TLV320AIC33_OK | All OK.
TLV320AIC33_ERROR_TWI_TIMEOUT |
TLV320AIC33_ERROR_TWI_INVALID_PARAMETER | !< Timeout occurs - when waiting for complete TX data
TLV320AIC33_ERROR_TWI_NACK | When NACK occurs. !< Invalid parameter when configure TWI interface

## Function Documentation

TLV320AIC33_status_t tlv320aic33_HAL_init | ( | void | ) |  |

Initialize TWI module on chip.

Set TWI module as master. Set I/O, enable clock to module and so on

Returns
  TLV320AIC33_OK (0) if all OK

TLV320AIC33_status_t tlv320aic33_HAL_read_data | ( | uint8_t | i_register_number,
|  | uint8_t * | p_data
| ) |  |

Read data on TWI (I2C) bus.

MCU is in master mode. Send TLV320AIC33 address, register value, repeated
start condition, TLV320AIC33 address and then receive data.

Parameters

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

Returns
  TLV320AIC33_OK (0) if all OK

TLV320AIC33_status_t tlv320aic33_HAL_write_data | ( | uint8_t | i_register_number,
|  | uint8_t | i_data
| ) |  |

Write data on TWI (I2C) bus.

MCU is in master mode. Send TLV320AIC33 address and then data (argument).

Parameters

  i_register_number | Register number
  i_data | Data which will be send to codec

Returns
  TLV320AIC33_OK (0) if all OK