/* 
 * @file SDlib16.h
 * @author Mike Schafer
 * @brief ????????????????????????????????????
 *        2016 board with 8 MHz resonator
 * 
 * edited 22.4.17
 */

#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
 */

//DO WE WANT TO DEFINE EVERYTHING WITH THE LITTLE HEADERS SINCE WE CANNOT ACCESS THE ACTUAL FUNCTIONS?

/* 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);

/* Serial I/O via USART*/
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
unsigned char getu2(void);  // get char
void putu2(unsigned char val); // put char
void serial2_init(unsigned long rate);
#define u2_buff_full U2STAbits.UTXBF  // int flag for tx buff
#define u2_data_avail U2STAbits.URXDA   // int flag for rx buff
unsigned char getu3(void);  // get char
void putu3(unsigned char val); // put char
void serial3_init(unsigned long rate);
#define u3_buff_full U3STAbits.UTXBF  // int flag for tx buff
#define u3_data_avail U3STAbits.URXDA   // int flag for rx buff

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
