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) |
Referenced by gui_print_q15_bar(), and gui_print_q15_signal().
#define Q15_DATA_MASK (0x7fff) |
Referenced by gain_q15_buffer().
#define Q15_MAX (0.99997) |
#define Q15_MIN (-1.0) |
Referenced by gui_print_q15_bar(), and gui_print_q15_signal().
#define Q15_SIG_MASK (0x8000) |
Referenced by fft_process(), gain_q15_buffer(), and u16_to_q15().
#define SIGNAL_VAL_MAX 0xFFF |
Referenced by app_widget_fft_on().
#define TRIGGER_TC TC0 |
Referenced by app_widget_fft_on(), and tc_trigger_init().
#define TRIGGER_TC_CH 0 |
Referenced by app_widget_fft_on(), and tc_trigger_init().
#define TRIGGER_TC_ID ID_TC0 |
Referenced by tc_trigger_init().
#define WORD_LENGTH (16) |
Referenced by gui_print_q15_bar(), and gui_print_q15_signal().
|
static |
Initialize ADC input.
References ADC_CH, adc_enable_channel(), adc_enable_interrupt(), adc_get_pdc_base(), ADC_TRIG_TIO_CH_0, AUDIO_FRAME_SIZE, AUDIO_SAMPLE_RATE, frame_buffer, pdc_enable_transfer(), pdc_rx_init(), pmc_enable_periph_clk(), sysclk_get_cpu_hz(), pdc_packet::ul_addr, and pdc_packet::ul_size.
Referenced by app_widget_fft_on().
void app_widget_fft_on | ( | void | ) |
Turn on FFT example.
References adc_buf_ndx, adc_input_init(), adc_nb_samples, AUDIO_BUFFER_SIZE, AUDIO_FRAME_SIZE, AUDIO_SAMPLE_RATE, BGCOLOR, DEMO_FFT_MODE, demo_get_special_mode_status(), DRAW_H, DRAW_W, fft_delay, fft_process(), gain_q15_buffer(), get_available_nb_sample(), GFX_COLOR_BLACK, GFX_COLOR_BLUE, GFX_COLOR_WHITE, gfx_draw_filled_rect, gfx_draw_string_aligned(), gfx_get_height(), gfx_get_width(), gui_print_q15_bar(), gui_print_q15_signal(), MAX_FFT_DISP_FREQ, NB_VAL, OFFSET_X, OFFSET_Y, p_proc_src, proc_buffer, proc_ndx, SIGNAL_VAL_MAX, sysclk_get_cpu_hz(), sysfont, SYSTICK_FREQ, tc_ch_rc, tc_trigger_init(), tc_write_ra(), tc_write_rc(), TEXT_ALIGN_LEFT, TEXT_POS_CENTER, TRIGGER_TC, TRIGGER_TC_CH, and u16_to_q15().
Referenced by widget_frame_command_handler().
|
static |
Process FFT.
buffer | Pointer to the data buffer. |
fft_size | Size to process. |
References FFT_OUT_GAIN, and Q15_SIG_MASK.
Referenced by app_widget_fft_on().
|
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 |
Get available number of sample data.
References AUDIO_BUFFER_SIZE.
Referenced by app_widget_fft_on().
|
static |
Display 1.15 format data with bar.
signal | Signal value. |
signal_size | Signal size. |
x | Position X. |
y | Position Y. |
w | Width. |
h | Height. |
fg_color | foreground color. |
bg_color | background 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 |
Display 1.15 format data with signal.
signal | Signal value. |
signal_size | Signal size. |
x | Position X. |
y | Position Y. |
w | Width. |
h | Height. |
fg_color | foreground color. |
bg_color | background color. |
References Abs, gfx_draw_filled_rect, gfx_draw_line, Min, Q15_B, Q15_MIN, and WORD_LENGTH.
Referenced by app_widget_fft_on().
|
static |
Initialize TC trigger.
References AUDIO_SAMPLE_RATE, pmc_enable_periph_clk(), sysclk_get_cpu_hz(), tc_ch_rc, tc_find_mck_divisor(), tc_init(), tc_start(), tc_write_ra(), tc_write_rc(), TRIGGER_TC, TRIGGER_TC_CH, and TRIGGER_TC_ID.
Referenced by app_widget_fft_on().
|
static |
Convert unsigned short to 1.15 format.
p_u16 | Unsigned short value. |
p_q15 | Pointer to the converted data. |
size | data size. |
u16_max | Maximum unsigned short value. |
u16_min | Minimum unsigned short value. |
b_centerize | Is 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 frame_buffer[AUDIO_NB_BUFFER][AUDIO_FRAME_SIZE] |
Referenced by ADC_Handler(), adc_input_init(), enter_wifi_firmware_download(), and serial_bridge_process_frame().
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 |
Referenced by app_widget_fft_on(), and tc_trigger_init().