/******************************************************************************
 uart_config.h - nRF52840 UART Protocol API Header file
 Version: 0.9.1
 Created on: 07/04/2021
 Created by: Rohit Rajapure

 Copyright (c) 2017 Shalaka Connected Devices LLP.  All rights reserved.
 Software License Agreement

   Redistribution and use in source and binary forms, with or without
   modification, are not permitted.

   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 Shalaka Connected Devices LLP 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
 OWNER 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.
 ******************************************************************************/

#ifndef UART_CONFIG_H_
#define UART_CONFIG_H_

/******************************************************************************************
*MACROS
*
*******************************************************************************************/
/// Size of the receive ring buffer. Must be power of 2!
#define UART_RX_BUFFER_SIZE                 256
/// Size of the transmit ring buffer. Must be power of 2!
#define UART_TX_BUFFER_SIZE                 256

/* When UART is used for communication with the host do not use flow control.*/
#define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
#define UART_RX_PIN       NRF_GPIO_PIN_MAP(0,26)
#define UART_TX_PIN       NRF_GPIO_PIN_MAP(0,27)

/// Error code of the high byte of getc(): Framing Error
#define UART_FRAME_ERROR      0x10
 /// Error code of the high byte of getc(): Overrun Error
#define UART_OVERRUN_ERROR    0x08
/// Error code of the high byte of getc(): Parity Error
#define UART_PARITY_ERROR     0x04
/// Error code of the high byte of getc(): overflow of the receive ring buffer
#define UART_BUFFER_OVERFLOW  0x02
/// Error code of the high byte of getc(): no receive data available
#define UART_NO_DATA          0x01
/// no error
#define UART_NO_ERROR         0x00

/****************************************************************************/
/***      			 Structs	    	                                  ***/
/****************************************************************************/
/// UART Datenstruktur f?r Fehler und Daten
typedef struct S_UartData_tag
{
    /// Error during reception (parity, overflow...)
	uint8_t Error;
    /// Data
	uint8_t Data;
} S_UartData;

/******************************************************************************************
*Uart pin configuration function
*return void
*******************************************************************************************/
void Uart_Init_Func(void);

/****************************************************************************
 *
 * NAME: UART_GetData
 *
 * DESCRIPTION:
 * Get a byte from the ring buffer.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
S_UartData UART_GetData(void);
/****************************************************************************
 *
 * NAME: vUART_PutString()
 *
 * DESCRIPTION:
 * Description: write a string
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
 /****************************************************************************
 *
 * NAME: vUART_PutByte()
 *
 * DESCRIPTION:
 * Write a byte to the ring buffer to send.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
void vUART_PutByte(uint8_t data);

/****************************************************************************/
void vUART_PutString(const char *s );
/****************************************************************************
 *
 * NAME: vUART_ClearRxErrors()
 *
 * DESCRIPTION:
 * Clear the last receive errors
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
void vUART_ClearRxErrors(void);
/****************************************************************************
 *
 * NAME: UART_GetRxErrors()
 *
 * DESCRIPTION:
 * Read out the last receive error.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
uint8_t UART_GetRxErrors(void);
/****************************************************************************
 *
 * NAME: vUART_CleanUpUart()
 *
 * DESCRIPTION:
 * Read out the last receive error.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
void vUART_CleanUpUart(void);
/****************************************************************************/
/***        END OF FILE                                                   ***/
/****************************************************************************/
#endif /* UART_CONFIG_H_ */