Commit Graph

62 Commits

Author SHA1 Message Date
Collin J. Doering 3a38d3ff18 Update README.md and doxygen front page
Use README.md as the front page of the documentation generated by
doxygen.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2016-01-12 04:54:49 -05:00
Collin J. Doering 28a71ff8e8 Move included examples to their own repositories
Move examples (digital_thermometer and uart_echo) to their own git
repositories. Later they can be re-added via git submodules, once this
project has been published.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2016-01-11 22:09:11 -05:00
Collin J. Doering 87070fb281 Finished thermometer example
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-29 19:50:26 -04:00
Collin J. Doering 5a65790a84 Copy library to each example sub folder
Instead of using a symbolic link, which doesn't allow for per-example
configuration, copy the entire library to each example sub folder.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-29 19:47:47 -04:00
Collin J. Doering 62eb6bdc82 Restructure project and ready for publishing
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>
2015-10-28 05:55:49 -04:00
Collin J. Doering d8068b8f7a Completed scrollUp and scrollDown functions
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>
2015-10-28 04:53:46 -04:00
Collin J. Doering 85fb4eca6a Read support implemented
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>
2015-10-28 04:30:40 -04:00
Collin J. Doering 3fcbf653a9 Implemented eraseDisplay function
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-28 04:20:35 -04:00
Collin J. Doering b98e632856 Implement eraseInline function
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-28 01:59:02 -04:00
Collin J. Doering 943593d963 Fix support for LCD's with 1 line
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>
2015-10-27 01:02:02 -04:00
Collin J. Doering c52292c802 Support both 5x8 and 5x10 fonts
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>
2015-10-26 22:30:44 -04:00
Collin J. Doering 7678470c3e Add switch to enable/disable ANSI escapes
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>
2015-10-26 05:43:15 -04:00
Collin J. Doering 827989bd51 Refactor, tidy and comment
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-26 05:13:40 -04:00
Collin J. Doering 7977f14d5a Refactor naming to be more consistent
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>
2015-10-25 03:54:54 -04:00
Collin J. Doering 7c18941836 Add boiler plate code for remaining ANSI escapes
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>
2015-10-25 00:27:51 -04:00
Collin J. Doering 307cd3358c Fix bitmasks for INSTR_MOV_SHIFT bits
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-24 04:30:32 -04:00
Collin J. Doering b32954bdae Add Show/Hide cursor function and ANSI escapes
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>
2015-10-24 04:30:26 -04:00
Collin J. Doering 958a337032 Add cursor save and restore ANSI sequence
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>
2015-10-24 00:42:54 -04:00
Collin J. Doering e65b3cf236 Remove unnecessary null exprs from end of cases
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-22 03:23:08 -04:00
Collin J. Doering 0f269a6d33 Don't initialize global variables to zero
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>
2015-10-22 03:00:58 -04:00
Collin J. Doering 2f545041c9 Cleanup as ANSI escapes are complete
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-22 03:00:58 -04:00
Collin J. Doering da600b62dd Fix buf size when receiving ANSI escapes via UART
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>
2015-10-22 03:00:48 -04:00
Collin J. Doering 15e9a7eda8 Fix parsing of 2 argument ANSI escapes
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-22 00:28:28 -04:00
Collin J. Doering 38ce0ce37f Fix off-by-one errors in lcdLib cursor functions
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-22 00:27:54 -04:00
Collin J. Doering 2f8eafd8de Fix ANSCII number parsing
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-20 06:29:09 -04:00
Collin J. Doering 4285c9223f Fixed various motion functions and parsing
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>
2015-10-20 05:21:03 -04:00
Collin J. Doering d63c250630 Initial pass on implementing ANSI escape sequences
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-19 05:04:53 -04:00
Collin J. Doering f7893b7f88 Clean up and comment lcdLib.c
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-19 04:58:03 -04:00
Collin J. Doering 4f9462e983 Move led flashing code from lcdLib to lcdOutput
Refactor led flashing code from lcdLib.c and lcdLib.h to lcdOutput.c.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-15 05:39:07 -04:00
Collin J. Doering 1ba8dd6b86 Replaced unnecessary delays with BF check in init
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>
2015-10-15 02:07:19 -04:00
Collin J. Doering bc48704477 First pass setting up doxygen documentation
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>
2015-10-15 01:23:11 -04:00
Collin J. Doering 89a10c4802 Add remaining ANSI escapes to ansi_escapes.h
All ANSI escapes sequences except "Select graphic rendition" are
supported.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-15 00:27:19 -04:00
Collin J. Doering f84eb1ddda Comment and clean-up lcdLib.c and lcdLib.h
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-15 00:26:46 -04:00
Collin J. Doering c29ef36638 Comment lcdLib.h
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>
2015-10-09 02:59:21 -04:00
Collin J. Doering ea7003ce83 Simplify entry of ANSI escape sequences
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>
2015-10-09 01:35:47 -04:00
Collin J. Doering 4fdb822e50 Fixed renamed transmitBytes and changed parameters
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>
2015-10-09 01:31:50 -04:00
Collin J. Doering 854876217a Update the serial console as to mimic the LCD
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>
2015-10-08 03:15:25 -04:00
Collin J. Doering 8ab9c5a4b0 Add transmitString function to USART library
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-08 03:15:00 -04:00
Collin J. Doering 3d3b9ab5fb Working backspace and fixed bug with cursor
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>
2015-10-07 22:38:57 -04:00
Collin J. Doering 3a6800a2b0 Remove showPrases from startup
No longer show phrases (was used during testing).

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-07 22:38:11 -04:00
Collin J. Doering 172d5e268f Prepare to support various escapes for characters
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>
2015-10-06 05:49:59 -04:00
Collin J. Doering 208d90f4ef Initial USART echoing to LCD example
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-06 04:23:40 -04:00
Collin J. Doering 85c7948848 Fix BAUD rate in Makefile
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-06 04:23:14 -04:00
Collin J. Doering 435c8eb07b Fixed busy flag check
Inspired by
http://web.alfredstate.edu/weimandn/programming/lcd/ATmega328/LCD_code_index.html.
Forgot about the 'data hold time', 'address hold time' and 'enable cycle
time'. These delays should eventually be implemented as preprocessor constants.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-06 03:34:39 -04:00
Collin J. Doering abacb2b30a Take screen characteristics into account
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>
2015-10-06 03:14:24 -04:00
Collin J. Doering 45797f1164 Refactor lcdLib.h
Move mode and settings sanity check to end of file.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-05 05:03:26 -04:00
Collin J. Doering 68d60151dc Initial commit to branch; split done but untested
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-04 22:49:15 -04:00
Collin J. Doering 2a1073f658 Code cleanup of lcdLib.h
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-04 21:20:51 -04:00
Collin J. Doering a7f83fbe63 Add *.lst to .gitignore
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-04 21:20:23 -04:00
Collin J. Doering 8281b3c28e Forgot to turn off FOUR_BIT_MODE after testing
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-02 03:46:57 -04:00