Microchip® Advanced Software Framework

widget_scr_fft.c File Reference

FFT example for SAM toolkit demo application.

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

#include <board.h>
#include <sysclk.h>
#include <asf.h>
#include "arm_math.h"
#include "demo.h"
#include "pdc.h"

Macros

#define ADC_CH   ADC_CHANNEL_4 /* sam4: MIC */
 
#define BGCOLOR   GFX_COLOR_WHITE
 
#define DRAW_H   90
 
#define DRAW_W   200
 
#define OFFSET_X   10
 
#define OFFSET_Y   40
 
#define Q15_A   (1)
 
#define Q15_B   (15)
 
#define Q15_DATA_MASK   (0x7fff)
 
#define Q15_MAX   (0.99997)
 
#define Q15_MIN   (-1.0)
 
#define Q15_SIG_MASK   (0x8000)
 
#define SIGNAL_VAL_MAX   0xFFF
 
#define TRIGGER_TC   TC0
 
#define TRIGGER_TC_CH   0
 
#define TRIGGER_TC_ID   ID_TC0
 
#define WORD_LENGTH   (16)
 

Functions

static void adc_input_init (void)
 Initialize ADC input. More...
 
void app_widget_fft_on (void)
 Turn on FFT example. More...
 
static void fft_process (q15_t *buffer, uint32_t fft_size)
 Process FFT. More...
 
static void gain_q15_buffer (q15_t *buffer, uint32_t size)
 Gain q15 data buffer. More...
 
static uint32_t get_available_nb_sample (uint32_t i_index, uint32_t o_index)
 Get available number of sample data. More...
 
static void gui_print_q15_bar (q15_t *signal, uint16_t signal_size, gfx_coord_t x, gfx_coord_t y, uint16_t w, uint16_t h, gfx_color_t fg_color, gfx_color_t bg_color)
 Display 1.15 format data with bar. More...
 
static void gui_print_q15_signal (q15_t *signal, uint16_t signal_size, gfx_coord_t x, gfx_coord_t y, uint16_t w, uint16_t h, gfx_color_t fg_color, gfx_color_t bg_color)
 Display 1.15 format data with signal. More...
 
static void tc_trigger_init (void)
 Initialize TC trigger. More...
 
static void u16_to_q15 (uint16_t *p_u16, q15_t *p_q15, uint32_t size, uint16_t u16_max, uint16_t u16_min, bool b_centerize)
 Convert unsigned short to 1.15 format. More...
 

Variables

uint8_t adc_buf_ndx = 0
 
uint32_t adc_nb_samples = 0
 
pdc_packet_t adc_nextpacket
 
pdc_packet_t adc_packet
 PDC data packet. More...
 
uint32_t fft_delay
 FFT delay counter. More...
 
bool fft_update
 FFT update flag. More...
 
uint16_t frame_buffer [AUDIO_NB_BUFFER][AUDIO_FRAME_SIZE]
 
uint16_t * p_proc_src = frame_buffer[0]
 
uint16_t proc_buffer [NB_VAL *2]
 
uint32_t proc_ndx = 0
 
uint32_t tc_ch_rc
 

#define ADC_CH   ADC_CHANNEL_4 /* sam4: MIC */

Referenced by adc_input_init().

#define BGCOLOR   GFX_COLOR_WHITE

Referenced by app_widget_fft_on().

#define DRAW_H   90

Referenced by app_widget_fft_on().

#define DRAW_W   200

Referenced by app_widget_fft_on().

#define OFFSET_X   10

Referenced by app_widget_fft_on().

#define OFFSET_Y   40

Referenced by app_widget_fft_on().

#define Q15_A   (1)
#define Q15_B   (15)
#define Q15_DATA_MASK   (0x7fff)

Referenced by gain_q15_buffer().

#define Q15_MAX   (0.99997)
#define Q15_MIN   (-1.0)
#define Q15_SIG_MASK   (0x8000)
#define SIGNAL_VAL_MAX   0xFFF

Referenced by app_widget_fft_on().

#define TRIGGER_TC   TC0
#define TRIGGER_TC_CH   0
#define TRIGGER_TC_ID   ID_TC0

Referenced by tc_trigger_init().

#define WORD_LENGTH   (16)

static void fft_process ( q15_t *  buffer,
uint32_t  fft_size 
)
static

Process FFT.

Parameters
bufferPointer to the data buffer.
fft_sizeSize to process.

References FFT_OUT_GAIN, and Q15_SIG_MASK.

Referenced by app_widget_fft_on().

static void gain_q15_buffer ( q15_t *  buffer,
uint32_t  size 
)
static

Gain q15 data buffer.

References FFT_IN_GAIN, Q15_DATA_MASK, Q15_SIG_MASK, and win_area::size.

Referenced by app_widget_fft_on().

static uint32_t get_available_nb_sample ( uint32_t  i_index,
uint32_t  o_index 
)
static

Get available number of sample data.

References AUDIO_BUFFER_SIZE.

Referenced by app_widget_fft_on().

static void gui_print_q15_bar ( q15_t *  signal,
uint16_t  signal_size,
gfx_coord_t  x,
gfx_coord_t  y,
uint16_t  w,
uint16_t  h,
gfx_color_t  fg_color,
gfx_color_t  bg_color 
)
static

Display 1.15 format data with bar.

Parameters
signalSignal value.
signal_sizeSignal size.
xPosition X.
yPosition Y.
wWidth.
hHeight.
fg_colorforeground color.
bg_colorbackground color.

References gfx_draw_filled_rect, gfx_draw_line, gfx_draw_pixel(), Q15_B, Q15_MIN, and WORD_LENGTH.

Referenced by app_widget_fft_on().

static void gui_print_q15_signal ( q15_t *  signal,
uint16_t  signal_size,
gfx_coord_t  x,
gfx_coord_t  y,
uint16_t  w,
uint16_t  h,
gfx_color_t  fg_color,
gfx_color_t  bg_color 
)
static

Display 1.15 format data with signal.

Parameters
signalSignal value.
signal_sizeSignal size.
xPosition X.
yPosition Y.
wWidth.
hHeight.
fg_colorforeground color.
bg_colorbackground color.
Returns
True if exiting, to destroy the window

References Abs, gfx_draw_filled_rect, gfx_draw_line, Min, Q15_B, Q15_MIN, and WORD_LENGTH.

Referenced by app_widget_fft_on().

static void u16_to_q15 ( uint16_t *  p_u16,
q15_t *  p_q15,
uint32_t  size,
uint16_t  u16_max,
uint16_t  u16_min,
bool  b_centerize 
)
static

Convert unsigned short to 1.15 format.

Parameters
p_u16Unsigned short value.
p_q15Pointer to the converted data.
sizedata size.
u16_maxMaximum unsigned short value.
u16_minMinimum unsigned short value.
b_centerizeIs centerized.

References Q15_SIG_MASK, and win_area::size.

Referenced by app_widget_fft_on().

uint8_t adc_buf_ndx = 0

Referenced by ADC_Handler(), and app_widget_fft_on().

uint32_t adc_nb_samples = 0

Referenced by ADC_Handler(), and app_widget_fft_on().

pdc_packet_t adc_nextpacket
pdc_packet_t adc_packet

PDC data packet.

uint32_t fft_delay

FFT delay counter.

Referenced by app_widget_fft_on(), and SysTick_Handler().

bool fft_update

FFT update flag.

Referenced by SysTick_Handler().

uint16_t* p_proc_src = frame_buffer[0]

Referenced by app_widget_fft_on().

uint16_t proc_buffer[NB_VAL *2]

Referenced by app_widget_fft_on().

uint32_t proc_ndx = 0

Referenced by app_widget_fft_on().

uint32_t tc_ch_rc