#include "st7032i.h"
#include "mcc_generated_files/mcc.h"

void lcd_init(void){

    __delay_ms(40);
    lcd_cmd(0x38);      // Function set
    lcd_cmd(0x39);      // Function set w/ IS bit
    lcd_cmd(0x14);      // Internal OSC freq
    lcd_cmd(0x70);      // Contrast set
    lcd_cmd(0x56);      // Power/ICON/Contrast control
    lcd_cmd(0x6C);      // Follower control
    __delay_ms(200);
    lcd_cmd(0x38);      // Function set w/o IS bit
    lcd_cmd(0x0C);      // Display On
    lcd_cmd(0x01);      // Clear Display
}
void lcd_send_char(uint8_t cont, uint8_t dat){
    const i2c1_address_t LCD_addr = 0x3e;
    uint8_t buf[2];
    
    buf[0] = cont;
    buf[1] = dat;

    while(!I2C1_Open(LCD_addr)); // sit here until we get the bus..
    I2C1_SetBuffer(buf,sizeof(buf));
    I2C1_SetAddressNackCallback(NULL,NULL); //NACK polling?
    I2C1_MasterWrite();
    while(I2C1_BUSY == I2C1_Close()); // sit here until finished.
    if( cont == LCD_CMD && dat < 0x4)
        __delay_ms(2);
    else
        __delay_us(30);
}
