#ifndef _SDLIB16_H_
#define _SDLIB16_H_
#include <xc.h>

/************************************************************
 *  2016 board version
header file for the support routines for the kit board
* At present, included are:
* Delay routines
* serial (spi) LCD (SPI2 with D7 as chip select
* serial port routines (UART1)
* switcher to allow stdout to go to LCD or serial port
*/

// LCD Function prototypes

/* specific to spi display */

void LCD_init(void);
void LCD_char(char val);
void LCD_display_on(void);
void LCD_display_off(void);
void LCD_clear(void);
void LCD_backlight(char val);
void LCD_contrast(char val);
void LCD_setpos(char row, char col);

/* simple input routines */
unsigned int getdec(void);
unsigned int gethex(void);
signed int getint(void);




/* FTDI part is on U1 on this board*/

unsigned char getu(void);  // get char
void putu(unsigned char val); // put char
void serial_init(unsigned long rate);
#define u1_buff_full U1STAbits.UTXBF  // int flag for tx buff
#define u1_data_avail U1STAbits.URXDA   // int flag for rx buff

/* serial I/O via usart 2 prototypes*/

#define u2_buff_full U2STAbits.UTXBF  // int flag for tx buff
#define u2_data_avail U2STAbits.URXDA   // int flag for rx buff
unsigned char getu2(void);  // get char
void putu2(unsigned char val); // put char

void serial2_init(unsigned long rate);

void set_output_device(unsigned char device);

/* delay routines*/
void set_sys_clock(unsigned long val);
unsigned long get_sys_clock(void);
void set_pb_clock(unsigned long val);
unsigned long get_pb_clock(void);
void delay_ms(unsigned long val);
void delay_us(unsigned long val);



#endif //SDLIB15_H
