Commit Graph

39 Commits

Author SHA1 Message Date
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 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 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 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 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 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 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 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 e5cc008cc7 Code cleanup/commenting
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-02 03:46:44 -04:00
Collin J. Doering 569316a8ae Fixed init issue with EIGHT_BIT_ARBITRARY_PIN_MODE
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-02 03:27:13 -04:00
Collin J. Doering 04be2b85da Tested operational 4-bit mode
Cleaned up a few comments and tested and verified operation of 4-bit mode.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-02 02:46:23 -04:00
Collin J. Doering 0a36d6cf77 All 8-bit modes functional
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>
2015-10-01 04:06:08 -04:00
Collin J. Doering fc0de88b8e Finished (but untested) modes
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>
2015-10-01 03:43:07 -04:00
Collin J. Doering 5777e2b831 Prepare for 4 bit mode of operation
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-01 03:04:33 -04:00
Collin J. Doering 3ba737fc7b Fixed timing issues, working again
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-09-30 05:02:43 -04:00
Collin J. Doering 047c4b5c31 Broken likely due to timing
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-09-30 04:46:49 -04:00
Collin J. Doering 1acda4a55a Some cleanup
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-09-29 06:06:37 -04:00
Collin J. Doering bfb78be425 Initial commit
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-09-29 02:48:09 -04:00