/* * lcd_an_write_register * @lcd: LCD driver on which a byte is needed to be written. * @rs: Flag to specify if we are writing a data register or command register. * TRUE: If we need to write a data register. * FALSE: If we need to write a command register. * @byte: Byte needed to be written. * @return: Success will be returned if bytes was successfully written * LCD_AN_TIME_OUT will be returned if timed out waiting for LCD. * This function write a register to the LCD. */ static int32_t lcd_an_write_register(LCD_AN *lcd, uint8_t rs, uint8_t byte) { #ifndef LCD_AN_NO_BUSY_WAIT uint8_t cmd_byte; uint32_t sys_time = current_system_tick(); #endif /* LCD_AN_NO_BUSY_WAIT */ int32_t status = SUCCESS; #ifndef LCD_AN_NO_BUSY_WAIT /* Wait for LCD. */ do { /* Read command register. */ lcd_an_read_register(lcd, FALSE, &cmd_byte); /* If we are still busy. */ if (cmd_byte & (1 << 7)) { /* Yield the task. */ task_yield(); } } while ((current_system_tick() - sys_time) < (MS_TO_TICK(LCD_AN_BUSY_TIMEOUT)) && (cmd_byte & (1 << 7))); /* If we did not timeout waiting for the LCD. */ if (((cmd_byte & (1 << 7)) == 0) || (rs & LCD_IGNORE_WAIT)) #endif /* LCD_AN_NO_BUSY_WAIT */ { /* Select required register. */ if (rs & LCD_DATA_REG) { /* Select data register. */ lcd->set_rs(lcd); } else { /* Select command register. */ lcd->clr_rs(lcd); } /* We are writing data. */ lcd->clr_rw(lcd); /* Disable the LCD data line. */ lcd->clr_en(lcd); /* Put byte on the LCD. */ lcd_an_send_nibble(lcd, ((byte >> 4) & 0x0F)); lcd_an_send_nibble(lcd, (byte & 0x0F)); #ifdef LCD_AN_NO_BUSY_WAIT /* Yield the task to put delay in transaction.. */ task_yield(); #else } else {
/* * lcd_an_write_register * @lcd: LCD driver on which a byte is needed to be written. * @rs: Flag to specify if we are writing a data register or command register. * TRUE: If we need to write a data register. * FALSE: If we need to write a command register. * @byte: Byte needed to be written. * @return: Success will be returned if bytes was successfully written * LCD_AN_TIME_OUT will be returned if timed out waiting for LCD. * This function write a register to the LCD. */ int32_t lcd_an_write_register(LCD_AN *lcd, uint8_t rs, uint8_t byte) { uint8_t cmd_byte = 0xFF; uint64_t sys_time = current_system_tick(); int32_t status = SUCCESS; /* Wait for LCD. */ while ((current_system_tick() - sys_time) < (MS_TO_TICK(LCD_AN_BUSY_TIMEOUT)) && (cmd_byte & (1 << 7))) { /* Read command register. */ lcd_an_read_register(lcd, FALSE, &cmd_byte); /* If we are still busy. */ if (cmd_byte & (1 << 7)) { /* Yield the task. */ task_yield(); } } /* If we did not timeout waiting for the LCD. */ if ((cmd_byte & (1 << 7)) == 0) { /* Select required register. */ if (rs == TRUE) { /* Select data register. */ LCD_AN_TGT_SET_RS(lcd); } else { /* Select command register. */ LCD_AN_TGT_CLR_RS(lcd); } /* We are writing data. */ LCD_AN_TGT_CLR_RW(lcd); /* Disable the LCD data line. */ LCD_AN_TGT_CLR_EN(lcd); /* Put byte on the LCD. */ lcd_an_send_nibble(lcd, ((byte >> 4) & 0x0F)); lcd_an_send_nibble(lcd, (byte & 0x0F)); } else {