Version using MEMS microphone and CODEC for the program "F746_RealtimeSpectrumAnalyzer". "F746_RealtimeSpectrumAnalyzer" の入力を MEMS のマイクと CODEC に変更.このプログラムは Tomona Nanase さんが作成し DISCO-F746NG_Oscilloscope の名前で登録しているプログラムで, CODEC を使って入力する部分を参考にして作成.このプログラムの説明は,CQ出版社のインターフェース誌,2016年4月号に掲載.

Dependencies:   BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed

MyClasses_Functions/WaveformDisplay.hpp

Committer:
MikamiUitOpen
Date:
2016-01-07
Revision:
2:5644475f01ea
Parent:
1:ac0a67a0deec
Child:
4:2cdaad00d208

File content as of revision 2:5644475f01ea:

//-----------------------------------------------------------
//  Class for waveform display
//
//  2015/01/07, Copyright (c) 2015 MIKAMI, Naoki
//-----------------------------------------------------------

#ifndef F746_WAVEFORM_DISPLAY_HPP
#define F746_WAVEFORM_DISPLAY_HPP

#include "mbed.h"

namespace Mikami
{
    class WaveformDisplay
    {
    public:
        WaveformDisplay(LCD_DISCO_F746NG &lcd,
                        uint16_t x0, uint16_t y0, int nData,
                        uint16_t rShift,
                        uint32_t axisColor, uint32_t lineColor,
                        uint32_t backColor)
            : X0_(x0), Y0_(y0), N_DATA_(nData), R_SHIFT_(rShift),
              AXIS_COLOR_(axisColor), LINE_COLOR_(lineColor),
              BACK_COLOR_(backColor), lcd_(lcd) { Axis(); }
        
        void Execute(const int16_t xn[])
        {
            Axis();
            lcd_.SetTextColor(LINE_COLOR_);
            uint16_t x1 = X0_;
            uint16_t y1 = Clip(xn[0]);
            for (int n=1; n<N_DATA_; n++)
            {
                uint16_t x2 = X0_ + n;
                uint16_t y2 = Clip(xn[n]);
                lcd_.DrawLine(x1, y1, x2, y2);
                x1 = x2;
                y1 = y2;
            }
            lcd_.SetTextColor(BACK_COLOR_);
            lcd_.DrawLine(X0_, Y0_-LIMIT_ , X0_+N_DATA_, Y0_-LIMIT_ );       
            lcd_.DrawLine(X0_, Y0_+LIMIT_ , X0_+N_DATA_, Y0_+LIMIT_ );       
        }
        
    private:
        const uint16_t X0_;
        const uint16_t Y0_;
        const int N_DATA_;
        const uint16_t R_SHIFT_;
        const uint32_t AXIS_COLOR_;
        const uint32_t LINE_COLOR_;
        const uint32_t BACK_COLOR_;
        static const int LIMIT_ = 32;
        
        LCD_DISCO_F746NG& lcd_;
        
        // Clipping
        uint16_t Clip(int16_t xn)
        {
            int16_t x = xn >> R_SHIFT_;
            if (x >  LIMIT_ ) x =  LIMIT_ ;
            if (x < -LIMIT_ ) x = -LIMIT_ ;
            return Y0_ - x;
        }
        
        void Axis()
        {
            lcd_.SetTextColor(BACK_COLOR_);
            lcd_.FillRect(X0_, Y0_-LIMIT_, N_DATA_, LIMIT_*2);

            lcd_.SetTextColor(AXIS_COLOR_);
            lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_);
        }        

        // disallow copy constructor and assignment operator
        WaveformDisplay(const WaveformDisplay& );
        WaveformDisplay& operator=(const WaveformDisplay& );
    };
}
#endif  // F746_WAVEFORM_DISPLAY_HPP