Move current UART echo program that was being used to test the library
into an exmaples folder. Also ready another example
'digital_thermometer'. All examples will have unique Makefiles and
lcdLibConfig.h's but use symbolic links to the libraries to limit
repetition.
Included the boilerplate for a README as well as a GPLv3 LICENSE file.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
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>
Supported ANSI escapes consist of SCI "\e[" followed by:
1. A optional number (max 3 digits) specified in ASCII followed by a
control character.
2. A optional number (max 3 digits) followed by ';' and then by another
optional number (max 3 digits), concluded with a control character.
This means that when receiving char by char via UART a buffer needs to
be allocated that can store the longest possible ANSI escape sequence.
This would be:
2 + 3 + 1 + 3 + 1 = 10
| | | | |
CSI First number ; Second number Control Character
Note however the buffer needs to be null character terminated, thus the
buffer must be 11 bytes. In the future, an optimization could possibly
be achieved here by using malloc to do dynamic allocation as more memory
is needed instead of allocating for the worst case scenario to the stack
as is done here.
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>
There are a few things that still need to be commented, furthermore,
usage of the library needs to be explained in more detail. Also things
are still somewhat unorganized as the lcdLib library is packaged up with
the lcdOutput application for testing. Also a tiny USART library is
included but has nothing to do with the lcdLib except that its used by
the lcdOutput demo program. When the lcdLib library is ready it will be
split into its own repository with accompanying examples (one of which
may be the USART echo example (lcdOutput.c as of this commit).
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
At some point perhaps switch to using doxygen to output nice
documentation. This will require using doxygen conventions, which aren't
currently used but easily adapted to.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
After changing the transmitBytes function and renaming it, missed
changing the function definition in the header file to match the new declaration.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
Working for clear screen, Backspace, and newline. Still needs to be
implemented to match the columns and rows of the LCD (which will require
that lcdLib.c provide access to currentLineChars and currentLineNum via
functions like getCurrentRow and getCurrentColumn.
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>
Removed the repeated #defines for LCD_DBUS*[,_PORT,_DDR,_PIN] used for
both FOUR_BIT_MODE and EIGHT_BIT_ARBITRARY_PIN_MODE.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
After trying FOUR_BIT_MODE to ensure it worked properly, forgot to
comment it out so that the default mode is enabled as expected and
documented.
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>