DISCO-F746NGのAudioInからの音声信号をLCDに波形として出力する、簡易なオシロスコープです。 This program is easy oscilloscope. The program draws waveform of signals from AudioIn on DISCO-F746NG.

Dependencies:   BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG mbed

Files at this revision

API Documentation at this revision

Comitter:
nanase
Date:
Sat Dec 26 14:51:48 2015 +0000
Commit message:
First commit

Changed in this revision

BSP_DISCO_F746NG_patch_fixed.lib Show annotated file Show diff for this revision Revisions of this file
BSP_overwrite.cpp Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
common.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG_patch_fixed.lib	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/the_sz/code/BSP_DISCO_F746NG_patch_fixed/#3c0a51826ecc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_overwrite.cpp	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,95 @@
+#include "main.h"
+
+DMA_HandleTypeDef hdma_sai_rx;
+
+/* ----- AUDIO IN ----- */
+
+void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
+{
+    audio_in_buffer_offset = 0;
+    audio_in_buffer_length = BufferSize / 2;
+    audio_in_buffer_captured = true;
+}
+
+void BSP_AUDIO_IN_TransferComplete_CallBack(void)
+{
+    audio_in_buffer_offset = BufferSize / 2;
+    audio_in_buffer_length = BufferSize / 2;
+    audio_in_buffer_captured = true;
+}
+
+void BSP_AUDIO_IN_Error_CallBack(void)
+{
+    error_trap();
+}
+
+void AUDIO_IN_SAIx_DMAx_IRQHandler(void)
+{
+    HAL_DMA_IRQHandler(&hdma_sai_rx);
+}
+
+void  BSP_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params)
+{
+    //static DMA_HandleTypeDef hdma_sai_rx;
+    GPIO_InitTypeDef  gpio_init_structure;
+
+    /* Enable SAI clock */
+    AUDIO_IN_SAIx_CLK_ENABLE();
+
+    /* Enable SD GPIO clock */
+    AUDIO_IN_SAIx_SD_ENABLE();
+    /* CODEC_SAI pin configuration: SD pin */
+    gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN;
+    gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+    gpio_init_structure.Pull = GPIO_NOPULL;
+    gpio_init_structure.Speed = GPIO_SPEED_FAST;
+    gpio_init_structure.Alternate = AUDIO_IN_SAIx_SD_AF;
+    HAL_GPIO_Init(AUDIO_IN_SAIx_SD_GPIO_PORT, &gpio_init_structure);
+
+    /* Enable Audio INT GPIO clock */
+    AUDIO_IN_INT_GPIO_ENABLE();
+    /* Audio INT pin configuration: input */
+    gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN;
+    gpio_init_structure.Mode = GPIO_MODE_INPUT;
+    gpio_init_structure.Pull = GPIO_NOPULL;
+    gpio_init_structure.Speed = GPIO_SPEED_FAST;
+    HAL_GPIO_Init(AUDIO_IN_INT_GPIO_PORT, &gpio_init_structure);
+
+    /* Enable the DMA clock */
+    AUDIO_IN_SAIx_DMAx_CLK_ENABLE();
+
+    if(hsai->Instance == AUDIO_IN_SAIx) {
+        /* Configure the hdma_sai_rx handle parameters */
+        hdma_sai_rx.Init.Channel             = AUDIO_IN_SAIx_DMAx_CHANNEL;
+        hdma_sai_rx.Init.Direction           = DMA_PERIPH_TO_MEMORY;
+        hdma_sai_rx.Init.PeriphInc           = DMA_PINC_DISABLE;
+        hdma_sai_rx.Init.MemInc              = DMA_MINC_ENABLE;
+        hdma_sai_rx.Init.PeriphDataAlignment = AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE;
+        hdma_sai_rx.Init.MemDataAlignment    = AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE;
+        hdma_sai_rx.Init.Mode                = DMA_CIRCULAR;
+        hdma_sai_rx.Init.Priority            = DMA_PRIORITY_HIGH;
+        hdma_sai_rx.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
+        hdma_sai_rx.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
+        hdma_sai_rx.Init.MemBurst            = DMA_MBURST_SINGLE;
+        hdma_sai_rx.Init.PeriphBurst         = DMA_MBURST_SINGLE;
+
+        hdma_sai_rx.Instance = AUDIO_IN_SAIx_DMAx_STREAM;
+
+        /* Associate the DMA handle */
+        __HAL_LINKDMA(hsai, hdmarx, hdma_sai_rx);
+
+        /* Deinitialize the Stream for new transfer */
+        HAL_DMA_DeInit(&hdma_sai_rx);
+
+        /* Configure the DMA Stream */
+        HAL_DMA_Init(&hdma_sai_rx);
+    }
+
+    /* SAI DMA IRQ Channel configuration */
+    HAL_NVIC_SetPriority(AUDIO_IN_SAIx_DMAx_IRQ, AUDIO_IN_IRQ_PREPRIO, 0);
+    HAL_NVIC_EnableIRQ(AUDIO_IN_SAIx_DMAx_IRQ);
+
+    /* Audio INT IRQ Channel configuration */
+    HAL_NVIC_SetPriority(AUDIO_IN_INT_IRQ, AUDIO_IN_IRQ_PREPRIO, 0);
+    HAL_NVIC_EnableIRQ(AUDIO_IN_INT_IRQ);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F746NG.lib	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common.cpp	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,22 @@
+#include "main.h"
+
+DigitalOut led1(LED1);
+
+void error_trap()
+{
+    printlcd("### ERROR");
+    while(1) {
+        led1 = !led1;
+        wait_ms(250);
+    }
+}
+
+void printlcd(const char *str)
+{
+    printlcdAt(str, 0);
+}
+
+void printlcdAt(const char *str, uint16_t line)
+{
+    lcd.DisplayStringAt(0, LINE(line), (uint8_t *)str, LEFT_MODE);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,77 @@
+#include "main.h"
+
+LCD_DISCO_F746NG lcd;
+
+int16_t audio_in_buffer[BufferSize];
+__IO bool audio_in_buffer_captured = false;
+__IO int32_t audio_in_buffer_offset = 0;
+__IO int32_t audio_in_buffer_length = 0;
+
+void init_audio_in()
+{
+    if (BSP_AUDIO_IN_Init(INPUT_DEVICE_INPUT_LINE_1, AudioInVolume, SamplingFreq) == AUDIO_ERROR)
+        error_trap();
+
+    NVIC_SetVector(AUDIO_IN_SAIx_DMAx_IRQ, (uint32_t)&AUDIO_IN_SAIx_DMAx_IRQHandler);
+}
+
+void record_audio_in()
+{
+    if (BSP_AUDIO_IN_Record((uint16_t*)&audio_in_buffer[0], BufferByteSize / 2) == AUDIO_ERROR)
+        error_trap();
+}
+
+
+int main()
+{
+    char strbuf[64];
+    uint16_t width, height, height_2, graph_height;
+    double y_factor;
+
+    lcd.Clear(LCD_COLOR_BLACK);
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.SetFont(&Font12);
+    sprintf(strbuf, "SamplingFreq: %d Hz", SamplingFreq);
+    lcd.DisplayStringAt(0, 0, (uint8_t *)strbuf, LEFT_MODE);
+
+    width = lcd.GetXSize() - 1;
+    height = lcd.GetYSize() - 1;
+    graph_height = height - LINE(1);
+    height_2 = graph_height / 2;
+    y_factor = (graph_height * 0.5 * AudioInGraphYFactor) / 32768.0;
+
+    init_audio_in();
+    record_audio_in();
+    
+    while(1) {
+        if (audio_in_buffer_captured) {
+            lcd.SetTextColor(LCD_COLOR_BLACK);
+            lcd.FillRect(0, LINE(1), width, graph_height);
+            lcd.SetTextColor(LCD_COLOR_WHITE);
+
+            for (int32_t i = audio_in_buffer_offset, j = 0; j < audio_in_buffer_length / 2 - 1 && j < width - 1; j++) {
+                uint16_t k = (uint16_t)j;
+                int16_t y1 =  (int16_t)(audio_in_buffer[i + 0] * y_factor);
+                int16_t y2 =  (int16_t)(audio_in_buffer[i + 4] * y_factor);
+
+                if (y1 > height_2)
+                    y1 = height_2;
+                else if (y1 < -height_2)
+                    y1 = -height_2;
+
+                if (y2 > height_2)
+                    y2 = height_2;
+                else if (y2 < -height_2)
+                    y2 = -height_2;
+
+                lcd.DrawLine(k, (uint16_t)(height_2 + y1 + LINE(1)), k + 1, (uint16_t)(height_2 + y2 + LINE(1)));
+
+                i += 4;
+            }
+            audio_in_buffer_captured = false;
+        }
+
+        wait_ms(AudioInLCDInterval);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+#include "stm32746g_discovery_audio.h"
+#include "LCD_DISCO_F746NG.h"
+
+#define PI                      ((double)3.1415926535897932384626433832795028)
+#define SamplingFreq            I2S_AUDIOFREQ_32K
+
+#define BufferSize              (4096)                          /* Sample Size */
+#define BufferByteSize          (BufferSize * AUDIODATA_SIZE)   /* Byte Size */
+
+#define AudioInLCDInterval      (RK043FN48H_VSYNC * RK043FN48H_FREQUENCY_DIVIDER)
+#define AudioInGraphYFactor     ((double)6.0)
+#define AudioInVolume           (86)
+
+extern LCD_DISCO_F746NG lcd;
+extern DigitalOut led1;
+
+extern int16_t audio_in_buffer[BufferSize];
+extern __IO bool audio_in_buffer_captured;
+extern __IO int32_t audio_in_buffer_offset;
+extern __IO int32_t audio_in_buffer_length;
+
+void AUDIO_IN_SAIx_DMAx_IRQHandler();
+
+void error_trap();
+void printlcd(const char *str);
+void printlcdAt(const char *str, uint16_t line);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 26 14:51:48 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file