Hello World for SSIF. I2S master write.

Dependencies:   R_BSP mbed-rtos mbed

main.cpp

Committer:
dkato
Date:
2015-06-23
Revision:
1:dccda89861bd
Parent:
0:599ab6da8e4d

File content as of revision 1:dccda89861bd:

#include "mbed.h"
#include "R_BSP_Ssif.h"
#include "sine_data_tbl.h"

//I2S send only, The upper limit of write buffer is 8.
R_BSP_Ssif ssif(P4_4, P4_5, P4_7, P4_6, 0x80, 8, 0);

static void callback_ssif_write_end(void * p_data, int32_t result, void * p_app_data) {
    if (result < 0) {
        printf("ssif write callback error %d\n", result);
    }
}

int main() {
    rbsp_data_conf_t   ssif_write_end_conf = {&callback_ssif_write_end, NULL};
    ssif_channel_cfg_t ssif_cfg;
    int32_t            result;

    //I2S Master, 44.1kHz, 16bit, 2ch
    ssif_cfg.enabled                = true;
    ssif_cfg.int_level              = 0x78;
    ssif_cfg.slave_mode             = false;
    ssif_cfg.sample_freq            = 44100u;
    ssif_cfg.clk_select             = SSIF_CFG_CKS_AUDIO_X1;
    ssif_cfg.multi_ch               = SSIF_CFG_MULTI_CH_1;
    ssif_cfg.data_word              = SSIF_CFG_DATA_WORD_16;
    ssif_cfg.system_word            = SSIF_CFG_SYSTEM_WORD_32;
    ssif_cfg.bclk_pol               = SSIF_CFG_FALLING;
    ssif_cfg.ws_pol                 = SSIF_CFG_WS_LOW;
    ssif_cfg.padding_pol            = SSIF_CFG_PADDING_LOW;
    ssif_cfg.serial_alignment       = SSIF_CFG_DATA_FIRST;
    ssif_cfg.parallel_alignment     = SSIF_CFG_LEFT;
    ssif_cfg.ws_delay               = SSIF_CFG_DELAY;
    ssif_cfg.noise_cancel           = SSIF_CFG_DISABLE_NOISE_CANCEL;
    ssif_cfg.tdm_mode               = SSIF_CFG_DISABLE_TDM;
    ssif_cfg.romdec_direct.mode     = SSIF_CFG_DISABLE_ROMDEC_DIRECT;
    ssif_cfg.romdec_direct.p_cbfunc = NULL;
    result = ssif.ConfigChannel(&ssif_cfg);
    if (result < 0) {
        printf("ssif config error %d\n", result);
    }

    while (1) {
        //The upper limit of write buffer is 8.
        result = ssif.write((void *)sin_data_44100Hz_16bit_2ch, 
                            sizeof(sin_data_44100Hz_16bit_2ch), &ssif_write_end_conf);
        if (result < 0) {
            printf("ssif write api error %d\n", result);
        }
    }
}