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
Data Structures | Macros | Enumerations | Functions | Variables
brd_driver_hw_03.h File Reference

Board driver for "Sonochan mkII" HW version 03. More...

`#include <avr32/io.h>`
`#include <inttypes.h>`
`#include <stdio.h>`
`#include "cs2200.h"`
`#include "tlv320aic33.h"`
`#include "LCD_5110.h"`
`#include "board.h"`
`#include "print_funcs.h"`
`#include "gpio.h"`
`#include "FreeRTOS.h"`
`#include "task.h"`
`#include "generic_driver.h"`

Go to the source code of this file.

## Data Structures
struct | s_brd_drv_mute_t
| Mute structure. More...
struct | s_brd_drv_rst_i2s_t
| Reset I2S structure. More...
struct | s_brd_drv_pure_i2s_dir_t
| Directions for pure I2S signals. More...

## Macros
#define | BRD_DRV_DEFAULT_HEADPHONES_VOLUME_IN_DB -45
| Set default headphones volume in dB. More...
#define | BRD_DRV_SUPPORT_GENERIC_DRIVER 1
| Option for generic driver support. More...
#define | BRD_DRV_SUPPORT_RTOS 1
| Option for FreeRTOS support. More...
#define | BRD_DRV_RTOS_CREATE_MUTEX 1
| Option allow create ADCmutex when brd_drv_init() is called. More...
#define | BDR_DRV_ADC_ADDRESS AVR32_ADC_ADDRESS
| Address to memory where are ADC registers. More...
#define | BRD_DRV_ADC_CLK_SOURCE 33000000UL
| Clock speed for ADC module in Hz. More...
#define | BRD_DRV_ADC_PRESCALLED_CLK 0
| Wanted clock speed for ADC module in Hz. More...
#define | BRD_DRV_ADC_SAMPLE_HOLD_TIME 5
| Define sample and hold time in ADC CLK cycles. More...
#define | BRD_DRV_ADC_START_UP_TIME 10
| Define minimal ADC start up time in ADC CLK cycles. More...
#define | BRD_DRV_LOCK_ADC_MODULE_IF_RTOS xSemaphoreTake( mutexADC, portMAX_DELAY );
| Define lock function when support for RTOS is enabled. More...
#define | BRD_DRV_UNLOCK_ADC_MODULE_IF_RTOS xSemaphoreGive( mutexADC );
#define | BRD_DRV_EN_ADC_CHANNEL_simple(CH) p_adc->CHER.ch##CH = 1
| Macro allow enabled needed channel. More...
#define | BRD_DRV_EN_ADC_CHANNEL(CH) BRD_DRV_EN_ADC_CHANNEL_simple(CH)
| Macro allow enabled needed channel. More...
#define | BRD_DRV_IS_ADC_DONE_simple(CH) p_adc->SR.eoc##CH
| Test if selected channel done conversion. More...
#define | BRD_DRV_IS_ADC_DONE(CH) BRD_DRV_IS_ADC_DONE_simple(CH)
| Test if selected cannel done conversion. More...
#define | BRD_DRV_ADC_DATA_simple(CH) p_adc->cdr##CH
| Read data from selected ADC channel. More...
#define | BRD_DRV_ADC_DATA(CH) BRD_DRV_ADC_DATA_simple(CH)
| Read data from selected ADC channel. More...
#define | BRD_DRV_IO_AS_INPUT_simple(PIN)
#define | BRD_DRV_IO_AS_INPUT(PIN) BRD_DRV_IO_AS_INPUT_simple(PIN)
#define | BRD_DRV_IO_LOW_simple(PIN)
#define | BRD_DRV_IO_LOW(PIN) BRD_DRV_IO_LOW_simple(PIN)
#define | BRD_DRV_IO_HIGH_simple(PIN)
#define | BRD_DRV_IO_HIGH(PIN) BRD_DRV_IO_HIGH_simple(PIN)
#define | BRD_DRV_IO_READ_simple(VAR, PIN)
#define | BRD_DRV_IO_READ(VAR, PIN) BRD_DRV_IO_READ_simple(VAR,PIN)
#define | BRD_DRV_ADC_PRESCAL ((BRD_DRV_ADC_CLK_SOURCE/(200000UL*2)) -1)
Pin mapping for BRD_DRV driver
#define | BRD_DRV_ADC_VOLUME_CONTROL_PIN AVR32_ADC_AD_5_PIN
| ADC volume signal pin. More...
#define | BRD_DRV_ADC_VOLUME_CONTROL_FUNCTION AVR32_ADC_AD_5_FUNCTION
| ADC volume signal pin function. More...
#define | BRD_DRV_ADC_VOLUME_CONTROL_CHANNEL 5
| Used ADC channel by volume signal. More...
#define | BRD_DRV_ADC_CON_VOLTAGE_PIN AVR32_ADC_AD_0_PIN
| ADC con voltage signal pin. More...
#define | BRD_DRV_ADC_CON_VOLTAGE_FUNCTION AVR32_ADC_AD_0_FUNCTION
| ADC con voltage signal pin function. More...
#define | BRD_DRV_ADC_CON_VOLTAGE_CHANNEL 0
| Used ADC channel by con voltage signal. More...
#define | BRD_DRV_MUTE_EN_A_PIN AVR32_PIN_PB02
| Mute enable on MCU side. More...
#define | BRD_DRV_RST_EN_A_PIN AVR32_PIN_PA27
| Reset enable on MCU side. More...
#define | BRD_DRV_BCLK_EN_A_PIN AVR32_PIN_PX42
| Bit clock enable on MCU side. More...
#define | BRD_DRV_FS_EN_A_PIN AVR32_PIN_PX03
| brief Frame sync enable on MCU side More...
#define | BRD_DRV_MCLK_EN_A_PIN AVR32_PIN_PX34
| Master clock enable on MCU side. More...
#define | BRD_DRV_MUTE_EN_B_PIN AVR32_PIN_PB01
| Mute enable on CON side. More...
#define | BRD_DRV_RST_EN_B_PIN AVR32_PIN_PB03
| Reset enable on CON side. More...
#define | BRD_DRV_TX_EN_B_PIN AVR32_PIN_PX58
| TX enable on CON side. More...
#define | BRD_DRV_RX_EN_B_PIN AVR32_PIN_PX00
| RX enable on MCU side. More...
#define | BRD_DRV_MCLK_EN_B_PIN AVR32_PIN_PX41
| Master clock enable on CON side. More...
#define | BRD_DRV_BCLK_EN_B_PIN AVR32_PIN_PX22
| Bit clock enable on CON side. More...
#define | BRD_DRV_FS_EN_B_PIN AVR32_PIN_PX45
| Frame sync enable on CON side. More...
#define | BRD_DRV_MUTE_BTN_PIN AVR32_PIN_PX10
| Mute button. More...
#define | BRD_DRV_RESET_I2S_BTN_PIN AVR32_PIN_PA28
| Reset I2S button. More...
#define | BRD_DRV_RESET_I2S_PIN AVR32_PIN_PX07
| Reset I2S signal. More...
#define | BRD_DRV_MUTE_PIN AVR32_PIN_PX38
| Mute signal. More...
#define | BRD_DRV_ERROR_SIG_PIN AVR32_PIN_PC00
| Error indication. More...
#define | BRD_DRV_ADC_UPDATE_THRESHOLD 3
| Define when volume is updated (how much must be value on ADC different from previous value on ADC) More...
#define | BRD_DRV_BUTTON_REFRESH_PERIOD 4
| Define "period" in which will be input buttons, ADC and so on scanned. More...
#define | BRD_DRV_SHORT_PRESS 5
| Define "period" in which will be button press evaluated as short. More...
#define | BRD_DRV_RESET_I2S_PERIOD 1
| When RESET_I2S is output, this define period in high level. More...
Display configuration
#define | BRD_DRV_LCD_LOGO_LINE 0
| Define on which line begin write logo. More...
#define | BRD_DRV_LCD_WARN_MSG_LINE 0
| Define on which line begin write warning message. More...
#define | BRD_DRV_LCD_INFO_MSG_LINE 2
| Define on which line begin write info message. More...
#define | BRD_DRV_LCD_HP_VOLUME_LINE 5
| Define on which line will be displayed headphone volume. More...
Error messages
This is set of error messages, which will be written to debug UART or LCD
#define | BRD_DRV_MSG_LCD_INIT_FAIL {"LCD initialization failed!\n"}
| Can not initialize LCD display. More...
#define | BRD_DRV_MSG_SONOCHAN_MK_II {"Sonochan mk II\n > v0.1\n"}
| Sonochan mk II. More...
#define | BRD_DRV_MSG_DRAW_LOGO_FAIL {"Write logo failed\n"}
| Can not draw logo. More...
#define | BRD_DRV_MSG_ADC_INIT_FAIL {"Can not initialize internal ADC\n"}
| Can not initialize ADC. More...
#define | BRD_DRV_MSG_CODEC_INIT_FAIL {"Can not initialize codec\n"}
| Can not initialize codec. More...
#define | BRD_DRV_MSG_PLL_SET_SAVE_FLAG_FAIL {"Can not set save flag at PLL\n"}
| Can not set save flag. More...
#define | BRD_DRV_TLV_FAILED_SET_HEADPHONE_VOL_DB {"Can not set headphone volume in DB\n"}
| Can not set headphone volume in dB. More...
#define | BRD_DRV_LCD_WRITE_FAIL {"Can not write to LCD\n"}
| Can not write to LCD. More...
#define | BRD_DRV_CON_VOL_LOW {"Con: low voltage\n"}
| Voltage on connector side is too low or powered off. More...
#define | BRD_DRV_CON_VOL_SAVE {"Con: save voltage\n"}
| Voltage on connector side in save range. More...
#define | BRD_DRV_CON_VOL_HIGH {"Con: high voltage!\n"}
| Voltage on connector side is too high. More...
#define | BRD_DRV_MUTE_IN_MUTE_OFF {"MUTE (IN): OFF\n"}
| Mute direction IN ; Mute off. More...
#define | BRD_DRV_MUTE_IN_MUTE_ON {"MUTE (IN): ON\n"}
| Mute direction IN ; Mute on. More...
#define | BRD_DRV_MUTE_OUT_MUTE_OFF {"MUTE (OUT): OFF\n"}
| Mute direction OUT ; Mute off. More...
#define | BRD_DRV_MUTE_OUT_MUTE_ON {"MUTE (OUT): ON\n"}
| Mute direction OUT ; Mute on. More...
#define | BRD_DRV_MSG_MUTE_BTN_PRESSED {"MUTE_BTN pressed\n"}
| Mute direction IN ; Button pressed ; Mute on. More...
#define | BRD_DRV_MSG_MUTE_BTN_RELEASED {"MUTE_BTN released\n"}
| Mute direction IN ; Button released ; Mute off. More...
#define | BRD_DRV_MSG_MUTE_RISING_EDGE {"MUTE: rising edge\n"}
| Signal MUTE - rising edge. More...
#define | BRD_DRV_MSG_MUTE_FALLING_EDGE {"MUTE: falling edge\n"}
| Signal MUTE - falling edge. More...
#define | BRD_DRV_CON_NOT_POWERED {"Connector side is not powered\n"}
| Info that connector is not powered so can not react for buttons. More...
#define | BRD_DRV_MSG_ERR_MSG_CLEARED {"Error message cleared\n"}
| Error message was cleaned from LCD. More...
#define | BRD_DRV_MSG_RESET_I2S_DONE {"Reset I2S done\n"}
| Info that restart I2S was occurred. More...
#define | BRD_DRV_MSG_RESET_I2S_SET_TO_HIGH {"Reset I2S (OUT) set to HIGH\n"}
| Info that RESET_I2S_PIN was set to HIGH. More...
#define | BRD_DRV_MSG_RESET_I2S_SET_TO_LOW {"Reset I2S (OUT) set to LOW\n"}
| Info that RESET_I2S_PIN was set to LOW. More...
#define | BRD_DRV_MSG_RESET_I2S_INPUT_OFF {"Reset I2S (IN) off\n"}
| RESET_I2S_PIN is input and there is require to turn off reset I2S. More...
#define | BRD_DRV_MSG_RESET_I2S_INPUT_ON {"Reset I2S (IN) on\n"}
| RESET_I2S_PIN is input and there is require to turn on reset I2S. More...
#define | BRD_DRV_MSG_RST_I2S_RISING_EDGE {"RESET_I2S: rising edge\n"}
| Info that rising edge was detected on RESET_I2S_PIN. More...
#define | BRD_DRV_MSG_RST_I2S_FALLING_EDGE {"RESET_I2S: falling edge\n"}
| Info that falling edge was detected on RESET_I2S_PIN. More...
#define | BRD_DRV_MSG_RST_I2S_BTN_PRESSED {"RESET_I2S_BTN pressed\n"}
| RESET_I2S_BTN was pressed. More...
#define | BRD_DRV_MSG_RST_I2S_BTN_RELEASED {"RESET_I2S_BTN released\n"}
| RESET_I2S_BTN was released. More...
#define | BRD_DRV_MSG_ERROR_CLEANED {"ERROR message deleted\n\n\n"}
| Error message was removed. More...

## Enumerations
enum | e_brd_drv_con_state { brd_drv_con_low_vol = 0, brd_drv_con_save_vol = 1, brd_drv_con_high_vol = 2, brd_drv_con_undefined = 3 }
| Connector voltage states. More...
enum | e_brd_drv_dir_t { brd_drv_dir_in = 0, brd_drv_dir_out = 1, brd_drv_dir_hiz = 2 }
| Pin directions. More...

## Functions
GD_RES_CODE | brd_drv_pre_init (void)
| Initialization that MUST be done as soon as possible. More...
GD_RES_CODE | brd_drv_init (void)
| Basic initialization of board components. More...
void | brd_drv_task (void)
| Board driver task. Watch ADC and buttons. More...
GD_RES_CODE | brd_drv_reset_i2s (void)
| Preset I2S connector to default state. Also reset codec. More...
GD_RES_CODE | brd_drv_show_volume (void)
| Show volume value on LCD. More...
GD_RES_CODE | brd_drv_draw_logo (void)
| Draw Sonochan mk II logo on display. More...
void | brd_drv_send_msg (const char *p_msg, uint8_t i_write_to_DBG, uint8_t i_write_to_LCD, uint8_t i_LCD_line)
| Write message to selected outputs. More...
void | brd_drv_send_warning_msg (const char *p_msg, uint8_t i_write_to_DBG, uint8_t i_write_to_LCD)
| Write warning message. More...
void | brd_drv_send_error_msg (const char *p_msg, uint8_t i_write_to_DBG, uint8_t i_write_to_LCD)
| Write error message and turn on ERROR LED. More...
GD_RES_CODE | brd_drv_set_isolators_to_HiZ (void)
| Set pins, that control signal direction at digital isolators, to low. More...
GD_RES_CODE | brd_drv_set_mclk_dir (e_brd_drv_dir_t e_mclk_dir)
| Set direction of MCLK. More...
GD_RES_CODE | brd_drv_set_bclk_dir (e_brd_drv_dir_t e_bclk_dir)
| Set BCLK direction. More...
GD_RES_CODE | brd_drv_set_frame_sync_dir (e_brd_drv_dir_t e_frame_sync_dir)
| Set direction of FRAME_SYNC. More...
GD_RES_CODE | brd_drv_set_tx_data_dir (e_brd_drv_dir_t e_tx_data_dir)
| Set TX_DATA direction (OUT/Hi-Z) More...
GD_RES_CODE | brd_drv_set_rx_data_dir (e_brd_drv_dir_t e_rx_data_dir)
| Set RX_DATA direction (IN/Hi-Z) More...
GD_RES_CODE | brd_drv_set_mute_dir (e_brd_drv_dir_t e_mute_dir)
| Allow set MUTE pin direction. More...
GD_RES_CODE | brd_drv_set_mute (uint8_t i_mute_flag)
| Set mute flag. More...
GD_RES_CODE | brd_drv_set_rst_i2s_dir (e_brd_drv_dir_t e_rst_i2s_dir)
| Allow set RESET_I2S pin direction. More...
GD_RES_CODE | brd_drv_set_rst_i2s (uint8_t i_reset_i2s_flag)
| Set RESET_I2S pin if configured as output. More...

## Variables
const gd_config_struct | BRD_DRV_config_table_flash []
const gd_metadata | BRD_DRV_metadata

## Detailed Description

Board driver for "Sonochan mkII" HW version 03.

Allow set basic settings on board. Also support "generic driver"

Created: 23.04.2014
Modified: 07.05.2014

Version
  0.1

Author
  Martin Stejskal

## Macro Definition Documentation

#define BDR_DRV_ADC_ADDRESS AVR32_ADC_ADDRESS

Address to memory where are ADC registers.

Example: AVR32_ADC_ADDRESS or (&AVR32_ADC) - it is the same

#define BRD_DRV_ADC_CLK_SOURCE 33000000UL

Clock speed for ADC module in Hz.

User should define at least approximately speed of clock on which is ADC
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.
Example:

#define BRD_DRV_ADC_CLK_SOURCE 115000UL

#define BRD_DRV_ADC_CON_VOLTAGE_CHANNEL 0

Used ADC channel by con voltage signal.

#define BRD_DRV_ADC_CON_VOLTAGE_FUNCTION AVR32_ADC_AD_0_FUNCTION

ADC con voltage signal pin function.

#define BRD_DRV_ADC_CON_VOLTAGE_PIN AVR32_ADC_AD_0_PIN

ADC con voltage signal pin.

#define BRD_DRV_ADC_DATA | ( |  | CH) |  | BRD_DRV_ADC_DATA_simple(CH)

Read data from selected ADC channel.

Example:

#define USED_CH 0
...
my_variable = BRD_DRV_ADC_DATA(USED_CH);

#define BRD_DRV_ADC_DATA_simple | ( |  | CH) |  | p_adc->cdr##CH

Read data from selected ADC channel.

Example:

my_variable = BRD_DRV_ADC_DATA_simple(6);

Note
  Argument must be number. If you want use symbolic name (through
  define you should use BRD_DRV_ADC_DATA() macro

#define BRD_DRV_ADC_PRESCAL ((BRD_DRV_ADC_CLK_SOURCE/(200000UL*2)) -1)

#define BRD_DRV_ADC_PRESCALLED_CLK 0

Wanted clock speed for ADC module in Hz.

Because ADC module have own prescaller, it is possible set lower frequency
for ADC and other components can run on high speed bus. Also for 10 bit
resolution prescalled CLK should not exceed 5 MHz and for 8 bit resolution
should not exceed 8 MHz.
If you unsure, just set this value to 0 and preprocessor do the rest.
Example:

#define BRD_DRV_ADC_PRESCALLED_CLK 0UL

#define BRD_DRV_ADC_SAMPLE_HOLD_TIME 5

Define sample and hold time in ADC CLK cycles.

Due to capacitance, there should be some time to sample input value and
hold it. Higher value means more accurate results, but it takes more time.
Sample and hold time (in cycles) can be calculated as:
tsh = (BRD_DRV_ADC_SAMPLE_HOLD_TIME + 3)
If you are unsure, set this value to 5. Example:

#define BRD_DRV_ADC_SAMPLE_HOLD_TIME 5

#define BRD_DRV_ADC_START_UP_TIME 10

Define minimal ADC start up time in ADC CLK cycles.

Start up time can be calculated as:
tsup = (BRD_DRV_ADC_START_UP_TIME+1)*8
If you are unsure, set this value to 5. Example:

#define BRD_DRV_ADC_START_UP_TIME 5

#define BRD_DRV_ADC_UPDATE_THRESHOLD 3

Define when volume is updated (how much must be value on ADC
different from previous value on ADC)

Because of noise on ADC it is recommended to set value 3. Enough for
user, no I2C bandwidth wasting because of ADC noise. But it depends on
board and environs. For 8 bit ADC resolution is recommended 1 or 2.

#define BRD_DRV_ADC_VOLUME_CONTROL_CHANNEL 5

Used ADC channel by volume signal.

#define BRD_DRV_ADC_VOLUME_CONTROL_FUNCTION AVR32_ADC_AD_5_FUNCTION

ADC volume signal pin function.

#define BRD_DRV_ADC_VOLUME_CONTROL_PIN AVR32_ADC_AD_5_PIN

ADC volume signal pin.

#define BRD_DRV_BCLK_EN_A_PIN AVR32_PIN_PX42

Bit clock enable on MCU side.

#define BRD_DRV_BCLK_EN_B_PIN AVR32_PIN_PX22

Bit clock enable on CON side.

#define BRD_DRV_BUTTON_REFRESH_PERIOD 4

Define "period" in which will be input buttons, ADC and so on scanned.

Period is set by experimental. It depends on system load, if used RTOS, RTOS priority and many other stuff.
Scan "mute", "reset I2S", ADC volume control, ADC con voltage and so on.

#define BRD_DRV_CON_NOT_POWERED {"Connector side is not powered\n"}

Info that connector is not powered so can not react for buttons.

#define BRD_DRV_CON_VOL_HIGH {"Con: high voltage!\n"}

Voltage on connector side is too high.

#define BRD_DRV_CON_VOL_LOW {"Con: low voltage\n"}

Voltage on connector side is too low or powered off.

#define BRD_DRV_CON_VOL_SAVE {"Con: save voltage\n"}

Voltage on connector side in save range.

#define BRD_DRV_DEFAULT_HEADPHONES_VOLUME_IN_DB -45

Set default headphones volume in dB.

Recommended value is about -40, but it is up to you if you want destroy
your ears or headphones...

#define BRD_DRV_EN_ADC_CHANNEL | ( |  | CH) |  | BRD_DRV_EN_ADC_CHANNEL_simple(CH)

Macro allow enabled needed channel.

Example:

#define USED_CH 3
...
BRD_DRV_EN_ADC_CHANNEL(USED_CH); // Enable channel 3

#define BRD_DRV_EN_ADC_CHANNEL_simple | ( |  | CH) |  | p_adc->CHER.ch##CH = 1

Macro allow enabled needed channel.

Example:

BRD_DRV_EN_ADC_CHANNEL_simple(3); // Enable channel 3

Note
  Argument must be number. If you want use symbolic name (through
  define you should use BRD_DRV_EN_ADC_CHANNEL() macro.

#define BRD_DRV_ERROR_SIG_PIN AVR32_PIN_PC00

Error indication.

#define BRD_DRV_FS_EN_A_PIN AVR32_PIN_PX03

brief Frame sync enable on MCU side

#define BRD_DRV_FS_EN_B_PIN AVR32_PIN_PX45

Frame sync enable on CON side.

#define BRD_DRV_IO_AS_INPUT | ( |  | PIN) |  | BRD_DRV_IO_AS_INPUT_simple(PIN)

#define BRD_DRV_IO_AS_INPUT_simple | ( |  | PIN) |  |

Value:
gpio_port = \
&AVR32_GPIO.port[PIN >> 5]; \
gpio_port->oderc = 1 << (PIN & 0x1F); \
gpio_port->gpers = 1 << (PIN & 0x1F)

#define BRD_DRV_IO_HIGH | ( |  | PIN) |  | BRD_DRV_IO_HIGH_simple(PIN)

#define BRD_DRV_IO_HIGH_simple | ( |  | PIN) |  |

Value:
gpio_port = \
&AVR32_GPIO.port[PIN >> 5]; \
gpio_port->ovrs = 1 << (PIN & 0x1F); \
gpio_port->oders = 1 << (PIN & 0x1F); \
gpio_port->gpers = 1 << (PIN & 0x1F)

#define BRD_DRV_IO_LOW | ( |  | PIN) |  | BRD_DRV_IO_LOW_simple(PIN)

#define BRD_DRV_IO_LOW_simple | ( |  | PIN) |  |

Value:
gpio_port = \
&AVR32_GPIO.port[PIN >> 5]; \
gpio_port->ovrc = 1 << (PIN & 0x1F); \
gpio_port->oders = 1 << (PIN & 0x1F); \
gpio_port->gpers = 1 << (PIN & 0x1F)

#define BRD_DRV_IO_READ | ( |  | VAR,
|  |  | PIN
| ) |  | BRD_DRV_IO_READ_simple(VAR,PIN)

#define BRD_DRV_IO_READ_simple | ( |  | VAR,
|  |  | PIN
| ) |  |

Value:
gpio_port = \
&AVR32_GPIO.port[PIN >> 5]; \
VAR = (gpio_port->pvr >> (PIN & 0x1F)) & 1

#define BRD_DRV_IS_ADC_DONE | ( |  | CH) |  | BRD_DRV_IS_ADC_DONE_simple(CH)

Test if selected cannel done conversion.

Example:

#define USED_CH 1
...
if(BRD_DRV_IS_ADC_DONE(USED_CH))
{ // If ADC conversion is done, continue here
...
}

#define BRD_DRV_IS_ADC_DONE_simple | ( |  | CH) |  | p_adc->SR.eoc##CH

Test if selected channel done conversion.

Example:

if(BRD_DRV_IS_ADC_DONE_simple(1))
{ // If ADC conversion done, continue here
...
}

Note
  Argument must be number. If you want use symbolic name (through
  define you should use BRD_DRV_IS_ADC_DONE() macro

#define BRD_DRV_LCD_HP_VOLUME_LINE 5

Define on which line will be displayed headphone volume.

#define BRD_DRV_LCD_INFO_MSG_LINE 2

Define on which line begin write info message.

It is recommended to leave BRD_DRV_LCD_WARN_MSG_LINE 2 lines and rest
for info message. This value define where info message start

#define BRD_DRV_LCD_LOGO_LINE 0

Define on which line begin write logo.

This should be set to 0 or at least same as BRD_DRV_LCD_WARN_MSG_LINE

#define BRD_DRV_LCD_WARN_MSG_LINE 0

Define on which line begin write warning message.

This should be set to 0, because when warning message disappear logo is
written on these lines.

#define BRD_DRV_LCD_WRITE_FAIL {"Can not write to LCD\n"}

Can not write to LCD.

#define BRD_DRV_LOCK_ADC_MODULE_IF_RTOS xSemaphoreTake( mutexADC, portMAX_DELAY );

Define lock function when support for RTOS is enabled.

If BRD_DRV_SUPPORT_RTOS is enabled, then there is defined function, that
"lock" ADC device, so any other device can not use it.
If BRD_DRV_SUPPORT_RTOS is disabled, there is defined just void macro.

#define BRD_DRV_MCLK_EN_A_PIN AVR32_PIN_PX34

Master clock enable on MCU side.

#define BRD_DRV_MCLK_EN_B_PIN AVR32_PIN_PX41

Master clock enable on CON side.

#define BRD_DRV_MSG_ADC_INIT_FAIL {"Can not initialize internal ADC\n"}

Can not initialize ADC.

#define BRD_DRV_MSG_CODEC_INIT_FAIL {"Can not initialize codec\n"}

Can not initialize codec.

#define BRD_DRV_MSG_DRAW_LOGO_FAIL {"Write logo failed\n"}

Can not draw logo.

#define BRD_DRV_MSG_ERR_MSG_CLEARED {"Error message cleared\n"}

Error message was cleaned from LCD.

#define BRD_DRV_MSG_ERROR_CLEANED {"ERROR message deleted\n\n\n"}

Error message was removed.

#define BRD_DRV_MSG_LCD_INIT_FAIL {"LCD initialization failed!\n"}

Can not initialize LCD display.

#define BRD_DRV_MSG_MUTE_BTN_PRESSED {"MUTE_BTN pressed\n"}

Mute direction IN ; Button pressed ; Mute on.

#define BRD_DRV_MSG_MUTE_BTN_RELEASED {"MUTE_BTN released\n"}

Mute direction IN ; Button released ; Mute off.

#define BRD_DRV_MSG_MUTE_FALLING_EDGE {"MUTE: falling edge\n"}

Signal MUTE - falling edge.

#define BRD_DRV_MSG_MUTE_RISING_EDGE {"MUTE: rising edge\n"}

Signal MUTE - rising edge.

#define BRD_DRV_MSG_PLL_SET_SAVE_FLAG_FAIL {"Can not set save flag at PLL\n"}

Can not set save flag.

#define BRD_DRV_MSG_RESET_I2S_DONE {"Reset I2S done\n"}

Info that restart I2S was occurred.

#define BRD_DRV_MSG_RESET_I2S_INPUT_OFF {"Reset I2S (IN) off\n"}

RESET_I2S_PIN is input and there is require to turn off reset I2S.

#define BRD_DRV_MSG_RESET_I2S_INPUT_ON {"Reset I2S (IN) on\n"}

RESET_I2S_PIN is input and there is require to turn on reset I2S.

#define BRD_DRV_MSG_RESET_I2S_SET_TO_HIGH {"Reset I2S (OUT) set to HIGH\n"}

Info that RESET_I2S_PIN was set to HIGH.

#define BRD_DRV_MSG_RESET_I2S_SET_TO_LOW {"Reset I2S (OUT) set to LOW\n"}

Info that RESET_I2S_PIN was set to LOW.

#define BRD_DRV_MSG_RST_I2S_BTN_PRESSED {"RESET_I2S_BTN pressed\n"}

RESET_I2S_BTN was pressed.

#define BRD_DRV_MSG_RST_I2S_BTN_RELEASED {"RESET_I2S_BTN released\n"}

RESET_I2S_BTN was released.

#define BRD_DRV_MSG_RST_I2S_FALLING_EDGE {"RESET_I2S: falling edge\n"}

Info that falling edge was detected on RESET_I2S_PIN.

#define BRD_DRV_MSG_RST_I2S_RISING_EDGE {"RESET_I2S: rising edge\n"}

Info that rising edge was detected on RESET_I2S_PIN.

#define BRD_DRV_MSG_SONOCHAN_MK_II {"Sonochan mk II\n > v0.1\n"}

Sonochan mk II.

#define BRD_DRV_MUTE_BTN_PIN AVR32_PIN_PX10

Mute button.

#define BRD_DRV_MUTE_EN_A_PIN AVR32_PIN_PB02

Mute enable on MCU side.

#define BRD_DRV_MUTE_EN_B_PIN AVR32_PIN_PB01

Mute enable on CON side.

#define BRD_DRV_MUTE_IN_MUTE_OFF {"MUTE (IN): OFF\n"}

Mute direction IN ; Mute off.

#define BRD_DRV_MUTE_IN_MUTE_ON {"MUTE (IN): ON\n"}

Mute direction IN ; Mute on.

#define BRD_DRV_MUTE_OUT_MUTE_OFF {"MUTE (OUT): OFF\n"}

Mute direction OUT ; Mute off.

#define BRD_DRV_MUTE_OUT_MUTE_ON {"MUTE (OUT): ON\n"}

Mute direction OUT ; Mute on.

#define BRD_DRV_MUTE_PIN AVR32_PIN_PX38

Mute signal.

#define BRD_DRV_RESET_I2S_BTN_PIN AVR32_PIN_PA28

Reset I2S button.

#define BRD_DRV_RESET_I2S_PERIOD 1

When RESET_I2S is output, this define period in high level.

#define BRD_DRV_RESET_I2S_PIN AVR32_PIN_PX07

Reset I2S signal.

#define BRD_DRV_RST_EN_A_PIN AVR32_PIN_PA27

Reset enable on MCU side.

#define BRD_DRV_RST_EN_B_PIN AVR32_PIN_PB03

Reset enable on CON side.

#define BRD_DRV_RTOS_CREATE_MUTEX 1

Option allow create ADCmutex when brd_drv_init() is called.

Mutexes is needed when in RTOS two functions share same hardware. This
option allow create mutex mutexADC, so any other functions just can use
xSemaphoreTake and xSemaphoreGive functions.
Options: 0 (disabled) or 1 (enabled).

Note
  This option is valid only if RTOS support is enabled.

#define BRD_DRV_RX_EN_B_PIN AVR32_PIN_PX00

RX enable on MCU side.

#define BRD_DRV_SHORT_PRESS 5

Define "period" in which will be button press evaluated as short.

Short RESET_I2S_BTN press clean error message, long reset I2S bus and
connector.

#define BRD_DRV_SUPPORT_GENERIC_DRIVER 1

Option for generic driver support.

Options: 0 (support disabled) or 1 (support enabled)

#define BRD_DRV_SUPPORT_RTOS 1

Option for FreeRTOS support.

Options: 0 (support disabled) or 1 (support enabled)

#define BRD_DRV_TLV_FAILED_SET_HEADPHONE_VOL_DB {"Can not set headphone volume in DB\n"}

Can not set headphone volume in dB.

#define BRD_DRV_TX_EN_B_PIN AVR32_PIN_PX58

TX enable on CON side.

#define BRD_DRV_UNLOCK_ADC_MODULE_IF_RTOS xSemaphoreGive( mutexADC );

## Enumeration Type Documentation

enum e_brd_drv_con_state

Connector voltage states.

Generally voltage on connector side can have

Enumerator
brd_drv_con_low_vol | brd_drv_con_low_vol Isolators turned off brd_drv_con_save_vol Isolators works with save voltage
brd_drv_con_save_vol | brd_drv_con_high_vol Isolators works with high voltage
brd_drv_con_high_vol | brd_drv_con_undefined Undefined state. For state machine
brd_drv_con_undefined |

enum e_brd_drv_dir_t

Pin directions.

Symbolic names for pin directions

Enumerator
brd_drv_dir_in | brd_drv_dir_in Input direction
brd_drv_dir_out | brd_drv_dir_out Output direction
brd_drv_dir_hiz | brd_drv_dir_hiz Hi-Z ("input" from both sides)

## Function Documentation

GD_RES_CODE brd_drv_draw_logo | ( | void | ) |  |
| inline

Draw Sonochan mk II logo on display.

Function assume, that LCD_init() od LCD_clear() was called

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_init | ( | void | ) |  |

Basic initialization of board components.

This function initialize rest of hardware on board. It assume, that debug
print output, clock and I/O pins have been initialized by
brd_drv_pre_init() function.

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_pre_init | ( | void | ) |  |

Initialization that MUST be done as soon as possible.

Because some parts should be set as soon as possible (I/O pins, set clock
for MCU) this function should be called in main on first line.

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_reset_i2s | ( | void | ) |  |

Preset I2S connector to default state. Also reset codec.

Returns
  GD_SUCCESS (0) if all OK

Todo:
  Complete this function. it need functions to set I/O for isolators

void brd_drv_send_error_msg | ( | const char * | p_msg,
|  | uint8_t | i_write_to_DBG,
|  | uint8_t | i_write_to_LCD
| ) |  |
| inline

Write error message and turn on ERROR LED.

Function do not return any return code. Just hope, that everything else
will work.

Parameters

  p_msg | Pointer to message
  i_write_to_DBG | Options: 0 - do not write to debug output ; 1 - write to debug output
  i_write_to_LCD | 0 - do not write to LCD ; 1 - write to LCD

void brd_drv_send_msg | ( | const char * | p_msg,
|  | uint8_t | i_write_to_DBG,
|  | uint8_t | i_write_to_LCD,
|  | uint8_t | i_LCD_line
| ) |  |
| inline

Write message to selected outputs.

Function do not return any return code. Just hope, that everything
will work.

Parameters

  p_msg | Pointer to message
  i_write_to_DBG | Options: 0 - do not write to debug output ; 1 - write to debug output
  i_write_to_LCD | 0 - do not write to LCD ; 1 - write to LCD
  i_LCD_line | Define on which line should be message placed. If value is 255 (-1), or invalid (higher than 5) then just write message message on the following line.

void brd_drv_send_warning_msg | ( | const char * | p_msg,
|  | uint8_t | i_write_to_DBG,
|  | uint8_t | i_write_to_LCD
| ) |  |
| inline

Write warning message.

When writing warning message on LCD, then is there reserved 2 lines for
message. It can be longer, but 2 lines will be cleared. First line is
defined in .h file as BRD_DRV_LCD_WARN_MSG_LINE

Parameters

  p_msg | Pointer to message
  i_write_to_DBG | Options: 0 - do not write to debug output ; 1 - write to debug output
  i_write_to_LCD | 0 - do not write to LCD ; 1 - write to LCD

GD_RES_CODE brd_drv_set_bclk_dir | ( | e_brd_drv_dir_t | e_bclk_dir) |  |

Set BCLK direction.

Parameters

  e_bclk_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_frame_sync_dir | ( | e_brd_drv_dir_t | e_frame_sync_dir) |  |

Set direction of FRAME_SYNC.

Parameters

  e_frame_sync_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_isolators_to_HiZ | ( | void | ) |  |

Set pins, that control signal direction at digital isolators, to low.

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_set_mclk_dir | ( | e_brd_drv_dir_t | e_mclk_dir) |  |

Set direction of MCLK.

Parameters

  e_mclk_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_mute | ( | uint8_t | i_mute_flag) |  |

Set mute flag.

If signal MUTE is input, then just MUTE MCU output. If MUTE signal is
output then set MUTE signal and MUTE MCU output.

Parameters

  i_mute_flag | 0 - mute off ; 1 - mute on

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_set_mute_dir | ( | e_brd_drv_dir_t | e_mute_dir) |  |

Allow set MUTE pin direction.

Parameters

  e_mute_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_rst_i2s | ( | uint8_t | i_reset_i2s_flag) |  |

Set RESET_I2S pin if configured as output.

If signal RESET_I2S is set as output, then just set signal RESET_I2S.
If signal RESET_I2S is set as input, then reset I2S bus on AVR side.

Parameters

  i_reset_i2s_flag | 0 - disable ; 1 - enable reset

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_rst_i2s_dir | ( | e_brd_drv_dir_t | e_rst_i2s_dir) |  |

Allow set RESET_I2S pin direction.

Parameters

  e_rst_i2s_dir | Options: 0 (input) ; 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all right

GD_RES_CODE brd_drv_set_rx_data_dir | ( | e_brd_drv_dir_t | e_rx_data_dir) |  |

Set RX_DATA direction (IN/Hi-Z)

Parameters

  e_rx_data_dir | Options: 0 (input) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_set_tx_data_dir | ( | e_brd_drv_dir_t | e_tx_data_dir) |  |

Set TX_DATA direction (OUT/Hi-Z)

Long story short: allow set as output or Hi-Z.

Parameters

  e_tx_data_dir | Options: 1 (output) ; 2 (Hi-Z)

Returns
  GD_SUCCESS (0) if all OK

GD_RES_CODE brd_drv_show_volume | ( | void | ) |  |
| inline

Show volume value on LCD.

Returns
  GD_SUCCESS (0) if all right

void brd_drv_task | ( | void | ) |  |

Board driver task. Watch ADC and buttons.

If detected some change, then start processing. Else return

## Variable Documentation

const gd_config_struct BRD_DRV_config_table_flash[]

Todo:
  Move definitions here

Todo:
  Try to remove this dependency

const gd_metadata BRD_DRV_metadata