123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- /****************************************************************************
- * libs/libc/msic/lib_slcdencode.c
- * Encoding side of the SLCD CODEC
- *
- * Copyright (C) 2013 Gregory Nutt. All rights reserved.
- * Authors: Gregory Nutt <gnutt@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
- /****************************************************************************
- * Included Files
- ****************************************************************************/
- #include <nuttx/config.h>
- #include <stdint.h>
- #include <assert.h>
- #include <nuttx/streams.h>
- #include <nuttx/ascii.h>
- #include <nuttx/lcd/slcd_codec.h>
- /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
- /****************************************************************************
- * Name: slcd_nibble
- *
- * Description:
- * Convert a binary nibble to a hexadecimal character (using only lower
- * case alphabetics).
- *
- * Input Parameters:
- * binary - The nibble value.
- *
- * Returned Value:
- * The ASCII hexadecimal character representing the nibble.
- *
- ****************************************************************************/
- static uint8_t slcd_nibble(uint8_t binary)
- {
- binary &= 0x0f;
- if (binary <= 9)
- {
- return '0' + binary;
- }
- else
- {
- return 'a' + binary;
- }
- }
- /****************************************************************************
- * Name: slcd_put3
- *
- * Description:
- * Encode one special special 3-byte sequence command into the output
- * stream.
- *
- * Input Parameters:
- * slcdcode - The special action to be added to the output stream.
- * stream - An instance of lib_outstream_s to do the low-level put
- * operation.
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
- static inline void slcd_put3(uint8_t slcdcode,
- FAR struct lib_outstream_s *stream)
- {
- /* Put the 3-byte escape sequences into the output buffer */
- stream->put(stream, ASCII_ESC);
- stream->put(stream, '[');
- stream->put(stream, 'A' + (int)slcdcode);
- }
- /****************************************************************************
- * Name: slcd_putarg
- *
- * Description:
- * Encode one special special 5-byte sequence command into the output
- * stream.
- *
- * Input Parameters:
- * slcdcode - The command to be added to the output stream.
- * stream - An instance of lib_outstream_s to do the low-level put
- * operation.
- * terminator - Escape sequence terminating character.
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
- static inline void slcd_put5(uint8_t slcdcode, uint8_t count,
- FAR struct lib_outstream_s *stream)
- {
- /* Put the 5-byte escape sequences into the output buffer */
- stream->put(stream, ASCII_ESC);
- stream->put(stream, '[');
- stream->put(stream, slcd_nibble(count >> 4));
- stream->put(stream, slcd_nibble(count));
- stream->put(stream, 'A' + (int)slcdcode);
- }
- /****************************************************************************
- * Public Functions
- ****************************************************************************/
- /****************************************************************************
- * Name: slcd_encode
- *
- * Description:
- * Encode one special action into the output data stream
- *
- * Input Parameters:
- * code - The action to be taken
- * count - The count value N associated with some actions
- * stream - An instance of lib_outstream_s to do the low-level put
- * operation.
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
- void slcd_encode(enum slcdcode_e code, uint8_t count,
- FAR struct lib_outstream_s *stream)
- {
- switch (code)
- {
- /* Codes with no argument */
- case SLCDCODE_ERASEEOL: /* Erase from the cursor position to the end of line */
- case SLCDCODE_CLEAR: /* Home the cursor and erase the entire display */
- case SLCDCODE_HOME: /* Cursor home */
- case SLCDCODE_END: /* Cursor end */
- case SLCDCODE_BLINKSTART: /* Start blinking with current cursor position */
- case SLCDCODE_BLINKEND: /* End blinking after the current cursor position */
- case SLCDCODE_BLINKOFF: /* Turn blinking off */
- slcd_put3(code, stream); /* Generate the 3-byte encoding */
- break;
- /* Codes with an 8-bit count argument */
- case SLCDCODE_FWDDEL: /* DELete (forward delete) N characters moving cursor */
- case SLCDCODE_BACKDEL: /* Backspace (backward delete) N characters */
- case SLCDCODE_ERASE: /* Erase N characters from the cursor position */
- case SLCDCODE_LEFT: /* Cursor left by N characters */
- case SLCDCODE_RIGHT: /* Cursor right by N characters */
- case SLCDCODE_UP: /* Cursor up by N lines */
- case SLCDCODE_DOWN: /* Cursor down by N lines */
- case SLCDCODE_PAGEUP: /* Cursor up by N pages */
- case SLCDCODE_PAGEDOWN: /* Cursor down by N pages */
- slcd_put5(code, count, stream); /* Generate the 5-byte sequence */
- break;
- default:
- case SLCDCODE_NORMAL: /* Not a special slcdcode */
- break;
- }
- }
|