This completes the functions for ANSI escapes. It required the LCD read
functionality from last commit to be efficient (memory wise).
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Implemented functions for reading the LCD's DDRAM/CGRAM. Which is read
is dependent on the last 'address set' instruction. The functions
implemented are as follows:
Internal use only:
- readLCDDBusByte_
No busy flag (BF) check. Sets RS=RW=1 and the data bus lines as
inputs, reads them regardless of mode and returns the byte read.
Externally accessable:
- readCharFromLCD
- readLCDLine
- readCharsFromLCD
Note: more thorough documentation of the aforementioned functions is
required, though all have been tested and seen to be working.
Additionally, renamed the following for clarity's sake:
enableLCDOutput -> setLCDDBusAsOutputs
disableLCDOutput -> setLCDDBusAsInputs
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
The initLCD function had the options of the function set instruction
hard coded, and thus would cause issues while initializing screens with
one line. This commit resolves this issue by checking the value of
LCD_NUMBER_OF_LINES at compile time and creating a macro LCD_LINES with
the appropriate bitmask for INSTR_FUNC_SET_N set or clear which is then
used during the definition of the initLCD function.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Added LCD_FONT in lcdLib.h which is the bitmask to enable 5x8 or 5x10
font when doing the function set instruction (in the definition of
initLCD).
LCD_FONT_5x8 or LCD_FONT_5x10 should be defined to enable the intended
font. One always needs to be defined.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Allow the user to enable or disable support for ANSI escapes by defining
LCD_ANSI_ESCAPE_ENABLE. lcdLibConfig.h has it enabled by default but for
projects where memory is tight, or ANSI escapes are not used or needed,
they can be disabled, which saves 3434 bytes of memory in my tests using
an Atmega328P.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Change the name of the following functions:
writeLCDNibble_ -> writeLCDDBusNibble_
writeLCDByte_ -> writeLCDDBusByte_
Created a function 'writeLCDDBusByte' which waits for the busy flag (BF)
to be cleared and then writes the given 8-bit integer to the LCD data
bus regardless of the mode the LCD is operating in (default (8-bit
mode), 8-bit arbitrary pin mode, or 4-bit mode).
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Added function declarations and empty/implementation incomplete
definitions in lcdLib.h and lcdLib.c respectively for remaining ANSI
escape sequences; namely:
- scrollUp
- scrollDown
- eraseDisplay
- eraseInline
Prematurely edited the parsing of any ASCII escape which causes the
screen to be cleared (Eg. '\n' on the last line), to use the new (but
yet to be implemented) scrolling functions; thus after these functions have been
filled in and tested, the ANSI escape support will be complete.
Additionally, escapes that are not supported are passed over without
printing any characters. The two cases that are handled in this commit
are DSR and SGR. The parsing for DSR which when received, normally
prints the current location of the cursor to standard output in the form
"\e[n;mR", where n is the row and m is the column, is left unsupported
but may be supported in the future (thus comments have been left
indicating condition where a valid parse occurs).
The SGR ANSI escape sequence can vary in length and thus needs to be
completely consumed from the input before processing the next character.
This is taken care of correctly in this commit, and has been tested.
In a previous commit, forgot to add the declarations of the following
utility functions to the lcdLib.h header file:
- blinkCursorOff
- blinkCursorOn
- displayOff
- displayOn
There are still a few functions that will be needed for reading
data from the LCD that have not been declared/defined. These functions
are required for efficiently scrolling the screen up and down. They also
will be needed to finish the last remaining piece of this library which,
after completion of ANSI escapes and associated functions, leaves
support for custom characters. Namely writing characters to CGRAM and
displaying custom characters (from CGRAM) using ASCII codes 0-7 (or 0-3
if 5x10 font is used).
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Adds ANSI escape parsing for DECTCEM escapes (hide/show cursor) as well
as utility functions hideCursor and showCursor. To do this correctly,
the state of the LCD needs to be remembered by sofware.
Keep track of the state of the LCD using the 3 LSB of lcdState as follows:
0: Cursor blink
1: Cursor off/on
2: Display off/on
In the future, the 5 MSB's may be used to store other data used for the
remembering the state of the LCD. For example, the instruction
INSTR_MOV_SHIFT and INSTR_ENTRY_SET; specifically:
INSTR_MOV_SHIFT
3+1=4: Move cursor/shift display
3+2=5: Shift left/right
INSTR_ENTRY_SET
3+3=6: decrement/increment cursor position
3+4=7: display shift off/on
The LCD state information could then be read for the correct instruction
using bit shifting. Note that this would require modifying the functions
defined in this commit to do the appropriate bit shifting.
Additionally, utility functions (that don't have associated ANSI
escapes) have been defined:
- blinkCursorOff
- blinkCursorOn
- displayOff
- displayOn
Note: care needs to be taken to check whether the display is actually on
before sending data to it, as during testing the data will not show up
after the display has been sent the display off instruction, and it will
not write any incoming data to DDRAM. Whether it will accept other
instructions besides writing to DDRAM is unknown but suspected to also
not work. This issue still needs to be rectified after further testing.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Add support for ANSI escape sequence for saving the current location of
the cursor "\e[s" and for recalling the last saved location "\e[u".
Note: if no location had been saved yet and the restore cursor
position (RPC) ANSI escape is received, defaults to 1,1 (top left of the
screen).
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
The C89 standard dictates that global variables be initialized to zero
by default. By explicitly defining a global to be zero, previous flash
memory is wasted.
See: http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_varinit
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Fixed ansii parsing (some issues still remain), and tested cursor
movement functions, though they don't seem to work properly through
serial yet. Also now when '\e' is read through serial, pause and
accumulate a the possible ansi escape to send to writeStringToLCD.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
In the function initLCD, since the loop_until_LCD_BF_clear is working,
there is no need for manual delays at a point through the software
initialization. This fix is a remnant of commit
435c8eb07b, where the busy flag check was
fixed.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Before this commit the cursor would be incremented (automatically by
hardware) after printing the last character on the line, which would
leave it the next line in memory, which doesn't necessarily correspond
to the next physical line on the display. This would be corrected when
the next character is received but is incorrect behavior; the cursor
should always be at where the next character is to inserted. This was
due to an off-by-one logical error. This commit solves this bug.
Along with the bug fix, keycodes from the serial terminal are now
deciphered correctly and the corresponding key or keys are sent to the
LCD accordingly.
Further work is required with regards to updating the serial
console (the connected client) so that their serial console looks
exactly like the LCD they are connected to.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Move code that checked for escapes from the writeStringToLCD function to
the writeCharToLCD function.
Note: There seems to be an issue connecting to USART when the programmer
is not connected. This is likely a wiring issue related to ISP.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
The writeStringtoLCD function now wraps text correctly and proceeds to
the next line when '\n' is reached in its argument.
Note: during debugging of this feature it was noticed that the function
loop_until_LCD_BF_clear is broken, as previously suspected. This forces
delays to be placed in the clearDisplay and returnHome functions and
could cause other undefined behavior if timing requirements aren't met.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Tested mode 1 (default 8-bit mode), and mode 2 (8-bit mode with
arbitrary pins for the data lines).
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
1. Default mode (8-bit data bus, control lines on any PINs)
2. 8-bit arbitrary pin mode (8-bit data bus on any PIN, control lines on
any PINs)
3. 4-bit mode (4-bit data bus, control lines on any PINs)
Default mode is tested and working. The others still require testing.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>