/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * 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.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER 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.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file u_fm_radio.h
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *
 *  @par Description:
 *       This header file contains the FM Radio Connection Handler specific
 *       definitions that are exported.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_CONN_MNGR_FM_RADIO FM Radio
 *  @ingroup  groupMW_CONN_MNGR
 *  @brief    Provides a unified interface for FM radio connection
 *  @see      groupMW_CONN_MNGR
 *
 *  @{
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_FM_RADIO_H_
#define _U_FM_RADIO_H_

/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/

#include "u_common.h"
#include "u_cm.h"
#include "u_handle.h"

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/

#define FM_RADIO_HANDLER_DEFAULT_NAME                               "fm_radio"    /**< Default name of FM radio handler */

/* Connection command codes */
#define FM_RADIO_CONN_OFFSET                   ((CM_COMMAND_CODE_T) 0x80050000)   /**< Command codes offset */
#define FM_RADIO_COMMAND(_x)                      (FM_RADIO_CONN_OFFSET + (_x))

#define FM_RADIO_CONN_SVC_LST_ID                            FM_RADIO_COMMAND(0)   /**< Connection command codes - Service list ID */
#define FM_RADIO_CONN_SVC_LST_NAME                          FM_RADIO_COMMAND(1)   /**< Connection command codes - Service list name */
#define FM_RADIO_CONN_SVL_REC_ID                            FM_RADIO_COMMAND(2)   /**< Connection command codes - SVL record ID */
#define FM_RADIO_CONN_DELIVERY_SYS                          FM_RADIO_COMMAND(3)   /**< Connection command codes - Delivery system */
#define FM_RADIO_CONN_FREQUENCY                             FM_RADIO_COMMAND(4)   /**< Connection command codes - Frequency */
#define FM_RADIO_CONN_FREQUENCY_BOUND                       FM_RADIO_COMMAND(5)   /**< Connection command codes - Frequency bound */


#define FM_RADIO_HANDLER_OFFSET                             ((CM_CTRL_TYPE_T) 0x03000000) 
#define FM_RADIO_SET_GET(_x)            (CM_CTRL_HANDLER_PRIVATE_OFFSET + FM_RADIO_HANDLER_OFFSET + (_x))   /**< FM Radio specific commands to use with x_cm_set/get */

#define FM_RADIO_CTRL_SET_TUNE_FREQ                       FM_RADIO_SET_GET(101)   /**< Set commands - Set tuning frequency */
#define FM_RADIO_CTRL_SET_DET_CHANNEL                     FM_RADIO_SET_GET(102)   /**< Set commands - Set to detect channel */

#define FM_RADIO_DISC_AS_REQUESTED                                         0U     /**< Disconnection reasons - As requested */
#define FM_RADIO_DISC_OTHER_REASON                                         1U     /**< Disconnection reasons - Other reason */
#define FM_RADIO_DISC_NEW_CONNECTION                                       2U     /**< Disconnection reasons - New connection */
#define FM_RADIO_DISC_NO_TUNER_FOUND                                       3U     /**< Disconnection reasons - No tuner is found */
#define FM_RADIO_DISC_COMP_BUSY                                            4U     /**< Disconnection reasons - Components are busy */
#define FM_RADIO_DISC_COULD_NOT_SET_TUNER_PROPERTIES                       5U     /**< Disconnection reasons - Could not set tuner properties*/
#define FM_RADIO_DISC_COULD_NOT_CONNECT_TUNER                              6U     /**< Disconnection reasons - Could not coonect to tuner */
#define FM_RADIO_DISC_SVL_ERROR                                            7U     /**< Disconnection reasons - SVL error */
#define FM_RADIO_DISC_SVL_CLOSED                                           8U     /**< Disconnection reasons - SVL closed */
#define FM_RADIO_DISC_TUNER_SIGNAL_LOST                                    9U     /**< Disconnection reasons - Tuner signal lost */
#define FM_RADIO_DISC_TUNER_UNKNOWN_LNB                                   10U     /**< Disconnection reasons - Tuner unknow LNB */
#define FM_RADIO_DISC_TUNER_OUT_OF_RANGE                                  11U     /**< Disconnection reasons - Tuner is out of range */
#define FM_RADIO_DISC_NO_AUDIO_DECODER_FOUND                              12U     /**< Disconnection reasons - No audio decoder found */
#define FM_RADIO_DISC_COULD_NOT_SET_AUDIO_DECODER_PROPERTIES              13U     /**< Disconnection reasons - Cound not set audio decoder properties */
#define FM_RADIO_DISC_COULD_NOT_CONNECT_AUDIO_DECODER                     14U     /**< Disconnection reasons - Count not connect audio decoder */
#define FM_RADIO_DISC_COULD_NOT_STOP_AUDIO_DECODER                        15U     /**< Disconnection reasons - Count not stop audio decoder */

/*---------------------------------------------------------------------------*/
/*! @struct FM_RADIO_DETECT_DONE_T
 *  @brief  This structure contains the information when detection is done
 *
 *  @code
 *  typedef struct
 *  {
 *      BOOL      b_detected;
 *      UINT32    ui4_freq;
 *      UINT8     ui1_sgl_lvl;
 *  } FM_RADIO_DETECT_DONE_T;
 *  @endcode
 *
 *  @li@c   b_detected  - Detectd (TRUE or FALSE)
 *  @li@c   ui4_freq    - Frequency
 *  @li@c   ui1_sgl_lvl - Signal level
 */
/*---------------------------------------------------------------------------*/
typedef struct
{
    BOOL      b_detected;
    UINT32    ui4_freq;
    UINT8     ui1_sgl_lvl;
} FM_RADIO_DETECT_DONE_T;

#define FM_RADIO_CONN_INFO_DETECT_DONE                       CM_HANDLER_COND(1)    /**< FM radio handler's own conditions (CM_COND_T) - Detection is done */

/*! @} */

#endif /*  _U_FM_RADIO_H_ */

