Final version.
Fork of F746_SAI_IO by
Diff: SAI_InOut.hpp
- Revision:
- 0:eade5d3ae0eb
- Child:
- 1:48ed86c8430a
diff -r 000000000000 -r eade5d3ae0eb SAI_InOut.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SAI_InOut.hpp Thu May 05 11:12:45 2016 +0000 @@ -0,0 +1,96 @@ +//----------------------------------------------------------- +// SiaIO class (Header) +// 2016/05/05, Copyright (c) 2016 MIKAMI, Naoki +//----------------------------------------------------------- + +#ifndef F746_SAI_IO_HPP +#define F746_SAI_IO_HPP + +#include "mbed.h" +#include "stm32746g_discovery_audio.h" +#include "BSP_AudioIn_Overwrite.hpp" +#include "BSP_AudioOut_Overwrite.hpp" + +namespace Mikami +{ + class SaiIO + { + public: + enum InOutBoth { INPUT, // input only + OUTPUT, // output only + BOTH }; // input and output + // Constructor + // inputDevice: INPUT_DEVICE_DIGITAL_MICROPHONE_2 or + // INPUT_DEVICE_INPUT_LINE_1 + // inputDevice == 0 : not use input device + SaiIO(InOutBoth ioBoth, int size, int fs, + uint16_t inputDevice = 0); + ~SaiIO(); + + int32_t GetLength() { return nData_; } + + void StopAudioIn(); + + // sw = 0: DIGITAL_MICROPHONE_2 + // 1: LINE_1 + void SwitchInputDevice(int sw); + + bool IsCaptured(); + void ResetCaptured() { captured_ = false; } + void Input(int16_t &xL, int16_t &xR); + + bool IsXferred(); + void ResetXferred() { xferred_ = false; } + void Output(int16_t xL, int16_t xR); + void Stop() { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); } + void Pause(); + void Resume(); + + // IF you use both input and output of SAI, + // you can use following two functions. + bool IsCompleted() + { return IsCaptured() && IsXferred(); } + void Reset() + { captured_ = false; xferred_ = false; } + + // Following two member functions are called from + // callback functions in "BSP_AudioIn_Overwrite.cpp" + static void Captured1st() { Captured(0); } + static void Captured2nd() { Captured(bufferSize_/2); } + + // Following two member functions are called from + // callback functions in "BSP_AudioOut_Overwrite.cpp" + static void FillBuffer1st() { FillBuffer(0); } + static void FillBuffer2nd() { FillBuffer(bufferSize_/2); } + + // Called form the functions in "BSP_AudioIn_Overwrite.cpp" + // and "BSP_AudioOut_Overwrite.cpp" + static void ErrorTrap(); + + private: + const int FS_; + const InOutBoth IOBOTH_; + + int16_t* inBuffer_; + static int16_t* outBuffer_; + static int16_t* tmp_; + __IO int32_t inIndex_; + __IO int32_t tmpIndex_; + + static int32_t nData_; + static int32_t bufferSize_; + static __IO bool captured_; + static __IO int32_t inOffset_; + static __IO bool xferred_; + + + void InitCodec(uint16_t inputDevice); + void InitInput(); + void InitOutput(); + void ClearBuffer(); + + static void Captured(int32_t offset); + static void FillBuffer(uint32_t offset); + }; +} +#endif // F746_SAI_IO_HPP