/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

/*
	Built with nrf commit 065270c5f016aea2a791d0e1fe34b2e972d92fda
*/

#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <sys/printk.h>
#include <sys/byteorder.h>
#include <zephyr.h>
#include <drivers/gpio.h>
#include <soc.h>

#include <nrfx.h>
//#include <nrfx_i2s.h>

#define PIN_MCK 	11
#define PIN_SCK 	12
#define PIN_LRCK	13
#define PIN_SDOUT	14
#define PIN_SDIN	15

static void error(void)
{
	while (true) {
		printk("Error!\n");
		/* Spin for ever */
		k_sleep(K_MSEC(1000)); //1000ms
	}
}

void i2s_data_handler(nrfx_i2s_buffers_t const * p_released, uint32_t status)
{

}

nrfx_i2s_config_t i2s_cfg = NRFX_I2S_DEFAULT_CONFIG(PIN_SCK, PIN_LRCK, PIN_MCK, PIN_SDOUT, PIN_SDIN);

void main(void)
{
	nrfx_err_t err = 0;

	printk("Starting I2S test\n");

	err = nrfx_i2s_init(&i2s_cfg, i2s_data_handler);	
	
	if (err) 
	{
		printk("BLE initialization failed\n");
		error(); //Catch error
	}


	for (;;) 
	{
		// Main loop
		
		k_sleep(K_MSEC(1000)); //1000ms
	}
}
