Demo program of SAI_IO class for audio signal input and output. DISCO-F746 搭載の CODEC (WM8994) を使ってオーディオ信号の入出力を行うための SAI_IO クラスの使用例.

Dependencies:   BSP_DISCO_F746NG F746_GUI F746_SAI_IO LCD_DISCO_F746NG TS_DISCO_F746NG mbed

Committer:
MikamiUitOpen
Date:
Mon Mar 12 04:52:03 2018 +0000
Revision:
11:0bb3dfef6d78
Parent:
8:6cb2c40946c4
12

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:089c5e022aa8 1 //-----------------------------------------------------------
MikamiUitOpen 0:089c5e022aa8 2 // Class for waveform display
MikamiUitOpen 0:089c5e022aa8 3 //
MikamiUitOpen 8:6cb2c40946c4 4 // 2017/03/16, Copyright (c) 2017 MIKAMI, Naoki
MikamiUitOpen 0:089c5e022aa8 5 //-----------------------------------------------------------
MikamiUitOpen 0:089c5e022aa8 6
MikamiUitOpen 0:089c5e022aa8 7 #ifndef F746_WAVEFORM_DISPLAY_HPP
MikamiUitOpen 0:089c5e022aa8 8 #define F746_WAVEFORM_DISPLAY_HPP
MikamiUitOpen 0:089c5e022aa8 9
MikamiUitOpen 0:089c5e022aa8 10 #include "mbed.h"
MikamiUitOpen 0:089c5e022aa8 11
MikamiUitOpen 0:089c5e022aa8 12 namespace Mikami
MikamiUitOpen 0:089c5e022aa8 13 {
MikamiUitOpen 0:089c5e022aa8 14 class WaveformDisplay
MikamiUitOpen 0:089c5e022aa8 15 {
MikamiUitOpen 0:089c5e022aa8 16 public:
MikamiUitOpen 8:6cb2c40946c4 17 WaveformDisplay(LCD_DISCO_F746NG &lcd,
MikamiUitOpen 0:089c5e022aa8 18 uint16_t x0, uint16_t y0, int nData,
MikamiUitOpen 0:089c5e022aa8 19 uint16_t rShift,
MikamiUitOpen 0:089c5e022aa8 20 uint32_t axisColor, uint32_t lineColor,
MikamiUitOpen 0:089c5e022aa8 21 uint32_t backColor)
MikamiUitOpen 0:089c5e022aa8 22 : X0_(x0), Y0_(y0), N_DATA_(nData), R_SHIFT_(rShift),
MikamiUitOpen 0:089c5e022aa8 23 AXIS_COLOR_(axisColor), LINE_COLOR_(lineColor),
MikamiUitOpen 0:089c5e022aa8 24 BACK_COLOR_(backColor), lcd_(lcd) { Axis(); }
MikamiUitOpen 0:089c5e022aa8 25
MikamiUitOpen 0:089c5e022aa8 26 void Execute(const int16_t xn[])
MikamiUitOpen 0:089c5e022aa8 27 {
MikamiUitOpen 0:089c5e022aa8 28 static const uint16_t LIMIT1 = Y0_ + LIMIT2_;
MikamiUitOpen 0:089c5e022aa8 29 static const uint16_t LIMIT2 = Y0_ - LIMIT2_;
MikamiUitOpen 0:089c5e022aa8 30 Axis();
MikamiUitOpen 8:6cb2c40946c4 31 lcd_.SetTextColor(LINE_COLOR_);
MikamiUitOpen 0:089c5e022aa8 32 uint16_t x1 = X0_;
MikamiUitOpen 0:089c5e022aa8 33 uint16_t y1 = Clip(xn[0]);
MikamiUitOpen 0:089c5e022aa8 34 for (int n=1; n<N_DATA_; n++)
MikamiUitOpen 0:089c5e022aa8 35 {
MikamiUitOpen 0:089c5e022aa8 36 uint16_t x2 = X0_ + n;
MikamiUitOpen 0:089c5e022aa8 37 uint16_t y2 = Clip(xn[n]);
MikamiUitOpen 0:089c5e022aa8 38 if ( ((y2 == LIMIT1) && (y1 == LIMIT1)) ||
MikamiUitOpen 0:089c5e022aa8 39 ((y2 == LIMIT2) && (y1 == LIMIT2)) )
MikamiUitOpen 0:089c5e022aa8 40 { // Out of displaying boundaries
MikamiUitOpen 8:6cb2c40946c4 41 lcd_.SetTextColor(LCD_COLOR_RED);
MikamiUitOpen 8:6cb2c40946c4 42 lcd_.DrawHLine(x1, y1, 1);
MikamiUitOpen 8:6cb2c40946c4 43 lcd_.SetTextColor(LINE_COLOR_);
MikamiUitOpen 0:089c5e022aa8 44 }
MikamiUitOpen 0:089c5e022aa8 45 else
MikamiUitOpen 8:6cb2c40946c4 46 lcd_.DrawLine(x1, y1, x2, y2);
MikamiUitOpen 0:089c5e022aa8 47 if ((y1 == LIMIT1) || (y1 == LIMIT2))
MikamiUitOpen 8:6cb2c40946c4 48 lcd_.DrawPixel(x1, y1, LCD_COLOR_RED);
MikamiUitOpen 0:089c5e022aa8 49 x1 = x2;
MikamiUitOpen 0:089c5e022aa8 50 y1 = y2;
MikamiUitOpen 0:089c5e022aa8 51 }
MikamiUitOpen 8:6cb2c40946c4 52 lcd_.SetTextColor(BACK_COLOR_);
MikamiUitOpen 0:089c5e022aa8 53 }
MikamiUitOpen 0:089c5e022aa8 54
MikamiUitOpen 0:089c5e022aa8 55 private:
MikamiUitOpen 0:089c5e022aa8 56 const uint16_t X0_;
MikamiUitOpen 0:089c5e022aa8 57 const uint16_t Y0_;
MikamiUitOpen 0:089c5e022aa8 58 const int N_DATA_;
MikamiUitOpen 0:089c5e022aa8 59 const uint16_t R_SHIFT_;
MikamiUitOpen 0:089c5e022aa8 60 const uint32_t AXIS_COLOR_;
MikamiUitOpen 0:089c5e022aa8 61 const uint32_t LINE_COLOR_;
MikamiUitOpen 0:089c5e022aa8 62 const uint32_t BACK_COLOR_;
MikamiUitOpen 0:089c5e022aa8 63 static const int LIMIT_ = 32;
MikamiUitOpen 0:089c5e022aa8 64 static const int LIMIT2_ = LIMIT_ + 1;
MikamiUitOpen 0:089c5e022aa8 65
MikamiUitOpen 8:6cb2c40946c4 66 LCD_DISCO_F746NG &lcd_;
MikamiUitOpen 0:089c5e022aa8 67
MikamiUitOpen 0:089c5e022aa8 68 // Clipping
MikamiUitOpen 0:089c5e022aa8 69 uint16_t Clip(int16_t xn)
MikamiUitOpen 0:089c5e022aa8 70 {
MikamiUitOpen 0:089c5e022aa8 71 int16_t x = xn >> R_SHIFT_;
MikamiUitOpen 0:089c5e022aa8 72 if (x > LIMIT_ ) x = LIMIT2_;
MikamiUitOpen 0:089c5e022aa8 73 if (x < -LIMIT_ ) x = -LIMIT2_ ;
MikamiUitOpen 0:089c5e022aa8 74 return Y0_ - x;
MikamiUitOpen 0:089c5e022aa8 75 }
MikamiUitOpen 0:089c5e022aa8 76
MikamiUitOpen 0:089c5e022aa8 77 void Axis()
MikamiUitOpen 0:089c5e022aa8 78 {
MikamiUitOpen 8:6cb2c40946c4 79 lcd_.SetTextColor(BACK_COLOR_);
MikamiUitOpen 8:6cb2c40946c4 80 lcd_.FillRect(X0_, Y0_-LIMIT2_, N_DATA_, LIMIT2_*2+1);
MikamiUitOpen 0:089c5e022aa8 81
MikamiUitOpen 8:6cb2c40946c4 82 lcd_.SetTextColor(AXIS_COLOR_);
MikamiUitOpen 8:6cb2c40946c4 83 lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_);
MikamiUitOpen 0:089c5e022aa8 84 }
MikamiUitOpen 0:089c5e022aa8 85
MikamiUitOpen 0:089c5e022aa8 86 // disallow copy constructor and assignment operator
MikamiUitOpen 0:089c5e022aa8 87 WaveformDisplay(const WaveformDisplay& );
MikamiUitOpen 0:089c5e022aa8 88 WaveformDisplay& operator=(const WaveformDisplay& );
MikamiUitOpen 0:089c5e022aa8 89 };
MikamiUitOpen 0:089c5e022aa8 90 }
MikamiUitOpen 0:089c5e022aa8 91 #endif // F746_WAVEFORM_DISPLAY_HPP