test public

Dependencies:   HttpServer_snapshot_mbed-os

Committer:
anhtran
Date:
Fri Oct 18 03:09:43 2019 +0000
Revision:
0:e9fd5575b10e
abc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anhtran 0:e9fd5575b10e 1 /*******************************************************************************
anhtran 0:e9fd5575b10e 2 * DISCLAIMER
anhtran 0:e9fd5575b10e 3 * This software is supplied by Renesas Electronics Corporation and is only
anhtran 0:e9fd5575b10e 4 * intended for use with Renesas products. No other uses are authorized. This
anhtran 0:e9fd5575b10e 5 * software is owned by Renesas Electronics Corporation and is protected under
anhtran 0:e9fd5575b10e 6 * all applicable laws, including copyright laws.
anhtran 0:e9fd5575b10e 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
anhtran 0:e9fd5575b10e 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
anhtran 0:e9fd5575b10e 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
anhtran 0:e9fd5575b10e 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
anhtran 0:e9fd5575b10e 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
anhtran 0:e9fd5575b10e 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
anhtran 0:e9fd5575b10e 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
anhtran 0:e9fd5575b10e 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
anhtran 0:e9fd5575b10e 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
anhtran 0:e9fd5575b10e 16 * Renesas reserves the right, without notice, to make changes to this software
anhtran 0:e9fd5575b10e 17 * and to discontinue the availability of this software. By using this software,
anhtran 0:e9fd5575b10e 18 * you agree to the additional terms and conditions found by accessing the
anhtran 0:e9fd5575b10e 19 * following link:
anhtran 0:e9fd5575b10e 20 * http://www.renesas.com/disclaimer*
anhtran 0:e9fd5575b10e 21 * Copyright (C) 2018 Renesas Electronics Corporation. All rights reserved.
anhtran 0:e9fd5575b10e 22 *******************************************************************************/
anhtran 0:e9fd5575b10e 23
anhtran 0:e9fd5575b10e 24 #include "R_BSP_Spdif.h"
anhtran 0:e9fd5575b10e 25 #if (R_BSP_SPDIF_ENABLE == 1)
anhtran 0:e9fd5575b10e 26 #include "r_bsp_cmn.h"
anhtran 0:e9fd5575b10e 27 #include "spdif_if.h"
anhtran 0:e9fd5575b10e 28 #include "spdif_api.h"
anhtran 0:e9fd5575b10e 29
anhtran 0:e9fd5575b10e 30 R_BSP_Spdif::R_BSP_Spdif(PinName audio_clk, PinName tx, PinName rx) : spdif_ch(-1) {
anhtran 0:e9fd5575b10e 31 int32_t wk_channel;
anhtran 0:e9fd5575b10e 32
anhtran 0:e9fd5575b10e 33 wk_channel = spdif_init(audio_clk, tx, rx);
anhtran 0:e9fd5575b10e 34 if (wk_channel != NC) {
anhtran 0:e9fd5575b10e 35 spdif_ch = wk_channel;
anhtran 0:e9fd5575b10e 36 }
anhtran 0:e9fd5575b10e 37 }
anhtran 0:e9fd5575b10e 38
anhtran 0:e9fd5575b10e 39 R_BSP_Spdif::~R_BSP_Spdif() {
anhtran 0:e9fd5575b10e 40 // do nothing
anhtran 0:e9fd5575b10e 41 }
anhtran 0:e9fd5575b10e 42
anhtran 0:e9fd5575b10e 43 void R_BSP_Spdif::init(const spdif_channel_cfg_t* const p_ch_cfg, int32_t max_write_num, int32_t max_read_num) {
anhtran 0:e9fd5575b10e 44 if (spdif_ch >= 0) {
anhtran 0:e9fd5575b10e 45 init_channel(R_SPDIF_MakeCbTbl_mbed(), spdif_ch, (void *)p_ch_cfg, max_write_num, max_read_num);
anhtran 0:e9fd5575b10e 46 }
anhtran 0:e9fd5575b10e 47 }
anhtran 0:e9fd5575b10e 48
anhtran 0:e9fd5575b10e 49 bool R_BSP_Spdif::ConfigChannel(const spdif_channel_cfg_t* const p_ch_cfg) {
anhtran 0:e9fd5575b10e 50 return ioctl(SPDIF_CONFIG_CHANNEL, (void *)p_ch_cfg);
anhtran 0:e9fd5575b10e 51 }
anhtran 0:e9fd5575b10e 52
anhtran 0:e9fd5575b10e 53 bool R_BSP_Spdif::SetChannelStatus(uint32_t status_Lch, uint32_t status_Rch) {
anhtran 0:e9fd5575b10e 54 spdif_channel_status_t channel_status;
anhtran 0:e9fd5575b10e 55
anhtran 0:e9fd5575b10e 56 channel_status.Lch = status_Lch;
anhtran 0:e9fd5575b10e 57 channel_status.Rch = status_Rch;
anhtran 0:e9fd5575b10e 58
anhtran 0:e9fd5575b10e 59 return ioctl(SPDIF_SET_CHANNEL_STATUS, (void *)&channel_status);
anhtran 0:e9fd5575b10e 60 }
anhtran 0:e9fd5575b10e 61
anhtran 0:e9fd5575b10e 62 bool R_BSP_Spdif::GetChannelStatus(uint32_t * p_status_Lch, uint32_t * p_status_Rch) {
anhtran 0:e9fd5575b10e 63 spdif_channel_status_t channel_status;
anhtran 0:e9fd5575b10e 64
anhtran 0:e9fd5575b10e 65 if (ioctl(SPDIF_GET_CHANNEL_STATUS, (void *)&channel_status) != false) {
anhtran 0:e9fd5575b10e 66 if (p_status_Lch != NULL) {
anhtran 0:e9fd5575b10e 67 *p_status_Lch = channel_status.Lch;
anhtran 0:e9fd5575b10e 68 }
anhtran 0:e9fd5575b10e 69 if (p_status_Rch != NULL) {
anhtran 0:e9fd5575b10e 70 *p_status_Rch = channel_status.Rch;
anhtran 0:e9fd5575b10e 71 }
anhtran 0:e9fd5575b10e 72 }
anhtran 0:e9fd5575b10e 73
anhtran 0:e9fd5575b10e 74 return true;
anhtran 0:e9fd5575b10e 75 }
anhtran 0:e9fd5575b10e 76
anhtran 0:e9fd5575b10e 77 bool R_BSP_Spdif::SetTransAudioBit(int direction, char length) {
anhtran 0:e9fd5575b10e 78 spdif_chcfg_audio_bit_t audio_bit;
anhtran 0:e9fd5575b10e 79 int control_type;
anhtran 0:e9fd5575b10e 80
anhtran 0:e9fd5575b10e 81 if (direction == 0) {
anhtran 0:e9fd5575b10e 82 control_type = SPDIF_SET_TRANS_AUDIO_BIT;
anhtran 0:e9fd5575b10e 83 } else {
anhtran 0:e9fd5575b10e 84 control_type = SPDIF_SET_RECV_AUDIO_BIT;
anhtran 0:e9fd5575b10e 85 }
anhtran 0:e9fd5575b10e 86
anhtran 0:e9fd5575b10e 87 switch (length) {
anhtran 0:e9fd5575b10e 88 case 16:
anhtran 0:e9fd5575b10e 89 audio_bit = SPDIF_CFG_AUDIO_BIT_16;
anhtran 0:e9fd5575b10e 90 break;
anhtran 0:e9fd5575b10e 91 case 20:
anhtran 0:e9fd5575b10e 92 audio_bit = SPDIF_CFG_AUDIO_BIT_20;
anhtran 0:e9fd5575b10e 93 break;
anhtran 0:e9fd5575b10e 94 case 24:
anhtran 0:e9fd5575b10e 95 audio_bit = SPDIF_CFG_AUDIO_BIT_24;
anhtran 0:e9fd5575b10e 96 break;
anhtran 0:e9fd5575b10e 97 default:
anhtran 0:e9fd5575b10e 98 return false;
anhtran 0:e9fd5575b10e 99 }
anhtran 0:e9fd5575b10e 100
anhtran 0:e9fd5575b10e 101 return ioctl(control_type, (void *)&audio_bit);
anhtran 0:e9fd5575b10e 102 }
anhtran 0:e9fd5575b10e 103
anhtran 0:e9fd5575b10e 104 #endif /* R_BSP_SPDIF_ENABLE */