text: /**
    ******************************************************************************
    * @file    Audio/Audio_playback_and_record/Inc/main.h 
    * @author  MCD Application Team
    * @brief   Header for main.c module
    ******************************************************************************
    * @attention
    *
    * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V. 
    * All rights reserved.</center></h2>
    *
    * Redistribution and use in source and binary forms, with or without 
    * modification, are permitted, provided that the following conditions are met:
    *
    * 1. Redistribution of source code must retain the above copyright notice, 
    *    this list of conditions and the following disclaimer.
    * 2. Redistributions in binary form must reproduce the above copyright notice,
    *    this list of conditions and the following disclaimer in the documentation
    *    and/or other materials provided with the distribution.
    * 3. Neither the name of STMicroelectronics nor the names of other 
    *    contributors to this software may be used to endorse or promote products 
    *    derived from this software without specific written permission.
    * 4. This software, including modifications and/or derivative works of this 
    *    software, must execute solely and exclusively on microcontroller or
    *    microprocessor devices manufactured by or for STMicroelectronics.
    * 5. Redistribution and use of this software other than as permitted under 
    *    this license is void and will automatically terminate your rights under 
    *    this license. 
    *
    * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
    * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
    * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
    * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
    * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
    * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    ******************************************************************************
    */
    
  /* Define to prevent recursive inclusion -------------------------------------*/
  #ifndef __MAIN_H
  #define __MAIN_H
  
  /* Includes ------------------------------------------------------------------*/
  #include "stdio.h"
  #include "usbh_core.h"
  #include "stm32f4xx_hal.h"
  #include "stm32446e_eval.h"
  #include "stm32446e_eval_io.h"
  #include "stm32446e_eval_audio.h"
  #include "lcd_log.h"
  #include "ff.h"    
  #include "ff_gen_drv.h"
  #include "usbh_diskio_dma.h"
  
  /* Exported Defines ----------------------------------------------------------*/
  #define AUDIO_OUT_BUFFER_SIZE                      8192
  #define AUDIO_IN_PCM_BUFFER_SIZE                   4*2304 /* buffer size in half-word */
  #define AUDIO_IN_PDM_BUFFER_SIZE                   INTERNAL_BUFF_SIZE
  
  #define FILEMGR_LIST_DEPDTH                        24
  #define FILEMGR_FILE_NAME_SIZE                     40
  #define FILEMGR_FULL_PATH_SIZE                     256
  #define FILEMGR_MAX_LEVEL                          4    
  #define FILETYPE_DIR                               0
  #define FILETYPE_FILE                              1
  
  /* Exported types ------------------------------------------------------------*/
  /* Application State Machine Structure */
  typedef enum {
    APPLICATION_IDLE = 0,  
    APPLICATION_START,   
    APPLICATION_READY,
    APPLICATION_DISCONNECT,
  }AUDIO_ApplicationTypeDef;
      
  /* Audio Demo State Structure */    
  typedef enum {
    AUDIO_DEMO_IDLE = 0,
    AUDIO_DEMO_WAIT,  
    AUDIO_DEMO_EXPLORE,
    AUDIO_DEMO_PLAYBACK,
    AUDIO_DEMO_IN,  
  }AUDIO_Demo_State;
  
  /* Audio Demo State Machine Structure */
  typedef struct _DemoStateMachine {
    __IO AUDIO_Demo_State state;
    __IO uint8_t select;  
  }AUDIO_DEMO_StateMachine;
  
  typedef enum {
    AUDIO_STATE_IDLE = 0,
    AUDIO_STATE_WAIT,    
    AUDIO_STATE_INIT,    
    AUDIO_STATE_PLAY,
    AUDIO_STATE_RECORD,  
    AUDIO_STATE_NEXT,  
    AUDIO_STATE_PREVIOUS,
    AUDIO_STATE_FORWARD,   
    AUDIO_STATE_BACKWARD,
    AUDIO_STATE_STOP,   
    AUDIO_STATE_PAUSE,
    AUDIO_STATE_RESUME,
    AUDIO_STATE_VOLUME_UP,
    AUDIO_STATE_VOLUME_DOWN,
    AUDIO_STATE_ERROR,  
  }AUDIO_PLAYBACK_StateTypeDef;
  
  typedef enum {
    AUDIO_SELECT_MENU = 0,
    AUDIO_PLAYBACK_CONTROL,  
  }AUDIO_DEMO_SelectMode;
  
  typedef enum {
    BUFFER_OFFSET_NONE = 0,  
    BUFFER_OFFSET_HALF,  
    BUFFER_OFFSET_FULL,     
  }BUFFER_StateTypeDef;
  
  /* Audio buffer control struct */
  typedef struct {
    uint8_t buff[AUDIO_OUT_BUFFER_SIZE];
    BUFFER_StateTypeDef state;
    uint32_t fptr;
  }AUDIO_OUT_BufferTypeDef;
  
  typedef enum {
    BUFFER_EMPTY = 0,  
    BUFFER_FULL,     
  }WR_BUFFER_StateTypeDef;
  
  typedef struct {
    uint16_t pdm_buff[AUDIO_IN_PDM_BUFFER_SIZE];
    uint16_t pcm_buff[AUDIO_IN_PCM_BUFFER_SIZE];
    uint32_t pcm_ptr;
    WR_BUFFER_StateTypeDef wr_state;
    uint32_t offset;  
    uint32_t fptr;
  }AUDIO_IN_BufferTypeDef;
  
  typedef struct {
    uint32_t ChunkID;       /* 0 */ 
    uint32_t FileSize;      /* 4 */
    uint32_t FileFormat;    /* 8 */
    uint32_t SubChunk1ID;   /* 12 */
    uint32_t SubChunk1Size; /* 16*/  
    uint16_t AudioFormat;   /* 20 */ 
    uint16_t NbrChannels;   /* 22 */   
    uint32_t SampleRate;    /* 24 */
    
    uint32_t ByteRate;      /* 28 */
    uint16_t BlockAlign;    /* 32 */  
    uint16_t BitPerSample;  /* 34 */  
    uint32_t SubChunk2ID;   /* 36 */   
    uint32_t SubChunk2Size; /* 40 */    
  }WAVE_FormatTypeDef;
  
  typedef struct _FILELIST_LineTypeDef {
    uint8_t type;
    uint8_t name[FILEMGR_FILE_NAME_SIZE];
  }FILELIST_LineTypeDef;
  
  typedef struct _FILELIST_FileTypeDef {
    FILELIST_LineTypeDef  file[FILEMGR_LIST_DEPDTH] ;
    uint16_t              ptr; 
  }FILELIST_FileTypeDef;
  
  typedef enum {
    AUDIO_ERROR_NONE = 0,  
    AUDIO_ERROR_IO,
    AUDIO_ERROR_EOF,
    AUDIO_ERROR_INVALID_VALUE,     
  }AUDIO_ErrorTypeDef;
  
  extern USBH_HandleTypeDef hUSBHost;
  extern AUDIO_ApplicationTypeDef appli_state;
  extern AUDIO_PLAYBACK_StateTypeDef AudioState;
  extern FATFS USBH_fatfs;
  extern FIL WavFile;
  
  /* Exported constants --------------------------------------------------------*/
  /* Exported macro ------------------------------------------------------------*/
  /* Exported functions ------------------------------------------------------- */
  /* Menu API */
  void AUDIO_MenuInit(void);
  void AUDIO_MenuProcess(void);
  uint8_t AUDIO_ShowWavFiles(void);
  
  /* Disk Explorer API */
  uint8_t AUDIO_StorageInit(void);
  FRESULT AUDIO_StorageParse(void);
  uint16_t AUDIO_GetWavObjectNumber(void);
  
  /* Toggle LEDs */
  void Toggle_Leds(void);
  
  #endif /* __MAIN_H */
  
  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  