
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"

//#include "nrf_temp.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"

#if 0
	#define	Sensor_SCL				17/*21*/
	#define	Sensor_SDA				16/*22*/
#endif

#define MAX_TEST_DATA_BYTES     (15U)                /**< max number of test bytes to be used for tx and rx. */
#define UART_TX_BUF_SIZE 256                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256                         /**< UART RX buffer size. */

/* TWI instance ID. */
#define TWI_INSTANCE_ID     0

extern	void InitTimerIRQ(void);

void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_code);
    }
}

void uart_init(void)
{
	uint32_t		err_code;
	const app_uart_comm_params_t comm_params =
		{
			19,
			18,
			RTS_PIN_NUMBER,
			CTS_PIN_NUMBER,
			APP_UART_FLOW_CONTROL_DISABLED,
			false,
			UART_BAUDRATE_BAUDRATE_Baud115200
	};
	APP_UART_FIFO_INIT(&comm_params,
						UART_RX_BUF_SIZE,
						UART_TX_BUF_SIZE,
						uart_error_handle,
						APP_IRQ_PRIORITY_LOWEST,
						err_code);
	APP_ERROR_CHECK(err_code);
}


static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    
		NRF_LOG_INFO("RTT Logging initialized\n\r");
}


/**

	* @brief Function for main application entry.
*/
extern	void DS18B20_Run(void);


int main(void)
{

	
	bsp_board_leds_init();

	  uart_init();
    //nrf_temp_init();
		log_init();


	NRF_LOG_INFO("Program START \r\n");
	bsp_board_led_invert(1);
	
	
	
	while(1)
	{
	
		DS18B20_Run();

	}
}


/** @} */
