Add support for key release events

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5464 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-12-27 14:01:59 +00:00
parent d028533b8a
commit 7459202633
6 changed files with 330 additions and 126 deletions
+53 -46
View File
@@ -1,4 +1,4 @@
/********************************************************************************************
/****************************************************************************
* libc/msic/lib_kbddecode.c
* Decoding side of the Keyboard CODEC
*
@@ -32,38 +32,43 @@
* 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 <debug.h>
#include <nuttx/streams.h>
#include <nuttx/ascii.h>
#include <nuttx/input/kbd_codec.h>
/********************************************************************************************
/****************************************************************************
* Pre-Processor Definitions
********************************************************************************************/
****************************************************************************/
#define NDX_ESC 0
#define NDX_BRACKET 1
#define NDX_CODE 2
#define NCX_SEMICOLON 3
#define NDX_ESC 0
#define NDX_BRACKET 1
#define NDX_CODE 2
#define NDX_TERMINATOR 3
#define NCH_ESC 1
#define NCH_BRACKET 2
#define NCH_CODE 3
#define NCH_SEMICOLON 4
#define NCH_ESC 1
#define NCH_BRACKET 2
#define NCH_CODE 3
#define NCH_TERMINATOR 4
/********************************************************************************************
#define TERM_MIN ('a' + KBD_RELEASE)
#define TERM_MAX ('a' + KBD_SPECREL)
#define TERM_RETURN(a) ((a) - 'a')
/****************************************************************************
* Private Functions
********************************************************************************************/
****************************************************************************/
/****************************************************************************
* Name: kbd_reget
@@ -76,16 +81,11 @@
* stream - An instance of lib_instream_s to do the low-level get
* operation.
* pch - The location character to save the returned value. This may be
* either a normal, "in-band" ASCII characer or a special, "out-of-band"
* command.
* state - A user provided buffer to support parsing. This structure
* should be cleared the first time that kbd_get is called.
* either a normal, character code or a special command from enum
* kbd_keycode_e
*
* Returned Value:
* 2 - Indicates the successful receipt of a special, "out-of-band" command
* 1 - Indicates the successful receipt of normal, "in-band" ASCII data.
* 0 - Indicates end-of-file or that the stream has been closed
* EOF - An error has getting the next character (reported by the stream).
* KBD_PRESS - Indicates the successful receipt of norma keyboard data.
*
****************************************************************************/
@@ -96,15 +96,15 @@ static int kbd_reget(FAR struct kbd_getstate_s *state, FAR uint8_t *pch)
*pch = state->buf[state->ndx];
state->ndx++;
state->nch--;
return KBD_NORMAL;
return KBD_PRESS;
}
/********************************************************************************************
/****************************************************************************
* Public Functions
********************************************************************************************/
****************************************************************************/
/****************************************************************************
* Name: kbd_get
* Name: kbd_decode
*
* Description:
* Get one byte of data or special command from the driver provided input
@@ -113,24 +113,30 @@ static int kbd_reget(FAR struct kbd_getstate_s *state, FAR uint8_t *pch)
* Input Parameters:
* stream - An instance of lib_instream_s to do the low-level get
* operation.
* pch - The location character to save the returned value. This may be
* either a normal, "in-band" ASCII characer or a special, "out-of-band"
* command.
* pch - The location to save the returned value. This may be
* either a normal, character code or a special command from enum
* kbd_keycode_e
* state - A user provided buffer to support parsing. This structure
* should be cleared the first time that kbd_get is called.
* should be cleared the first time that kbd_decode is called.
*
* Returned Value:
* 1 - Indicates the successful receipt of a special, "out-of-band" command.
* The returned value in pch is a value from enum kbd_getstate_s.
* 0 - Indicates the successful receipt of normal, "in-band" ASCII data.
* The returned value in pch is a simple byte of text or control data.
*
* KBD_PRESS - Indicates the successful receipt of normal, keyboard data.
* This corresponds to a keypress event. The returned value in pch is a
* simple byte of text or control data corresponding to the pressed key.
* KBD_RELEASE - Indicates a key release event. The returned value in pch
* is the byte of text or control data corresponding to the released key.
* KBD_SPECPRESS - Indicates the successful receipt of a special keyboard
* command. The returned value in pch is a value from enum kbd_getstate_s.
* KBD_SPECREL - Indicates a special key release event. The returned value
* in pch is a value from enum kbd_getstate_s.
* EOF - An error has getting the next character (reported by the stream).
* Normally indicates the end of file.
* Normally indicates the end of file.
*
****************************************************************************/
int kbd_get(FAR struct lib_instream_s *stream,
FAR struct kbd_getstate_s *state, FAR uint8_t *pch)
int kbd_decode(FAR struct lib_instream_s *stream,
FAR struct kbd_getstate_s *state, FAR uint8_t *pch)
{
int ch;
@@ -147,7 +153,7 @@ int kbd_get(FAR struct lib_instream_s *stream,
state->ndx = 0;
/* No, ungotten characters. Check for the beginning of an esc sequence. */
/* No, ungotten characters. Check for the beginning of an ESC sequence. */
ch = stream->get(stream);
if (ch == EOF)
@@ -195,7 +201,7 @@ int kbd_get(FAR struct lib_instream_s *stream,
}
}
/* Get and verify the special, "out-of-band" command code */
/* Get and verify the special keyboard data to decode */
ch = stream->get(stream);
if (ch == EOF)
@@ -234,12 +240,12 @@ int kbd_get(FAR struct lib_instream_s *stream,
}
else
{
state->buf[NCX_SEMICOLON] = (uint8_t)ch;
state->nch = NCH_SEMICOLON;
state->buf[NDX_TERMINATOR] = (uint8_t)ch;
state->nch = NCH_TERMINATOR;
/* Check for a valid special command code */
if (ch != ';')
if (ch < TERM_MIN || ch > TERM_MAX)
{
/* Not a special command code, return the ESC now and the next two
* characters later.
@@ -250,11 +256,12 @@ int kbd_get(FAR struct lib_instream_s *stream,
}
/* We have successfully parsed the the entire escape sequence. Return the
* special code in pch and the value 2.
* keyboard value in pch and the value an indication determined by the
* terminating character.
*/
*pch = state->buf[NDX_CODE];
state->nch = 0;
return KBD_SPECIAL;
return TERM_RETURN(state->buf[NDX_TERMINATOR]);
}
+86 -19
View File
@@ -1,4 +1,4 @@
/********************************************************************************************
/****************************************************************************
* libc/msic/lib_kbdencode.c
* Encoding side of the Keyboard CODEC
*
@@ -32,11 +32,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
********************************************************************************************/
****************************************************************************/
/********************************************************************************************
/****************************************************************************
* Included Files
********************************************************************************************/
****************************************************************************/
#include <nuttx/config.h>
@@ -47,19 +47,67 @@
#include <nuttx/ascii.h>
#include <nuttx/input/kbd_codec.h>
/********************************************************************************************
/****************************************************************************
* Pre-Processor Definitions
********************************************************************************************/
/********************************************************************************************
* Public Functions
********************************************************************************************/
****************************************************************************/
/****************************************************************************
* Name: kbd_putspecial
* Name: kbd_encode
*
* Description:
* Put one special, "out-of-band" command into the output stream.
* Encode one special special sequence command into the output stream.
*
* Input Parameters:
* keycode - 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 void kbd_encode(uint8_t keycode, FAR struct lib_outstream_s *stream,
uint8_t terminator)
{
stream->put(stream, ASCII_ESC);
stream->put(stream, '[');
stream->put(stream, (int)keycode);
stream->put(stream, terminator);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: kbd_release
*
* Description:
* Encode the release of a normal key.
*
* Input Parameters:
* ch - The character associated with the key that was releared.
* stream - An instance of lib_outstream_s to do the low-level put
* operation.
*
* Returned Value:
* None
*
****************************************************************************/
void kbd_release(uint8_t ch, FAR struct lib_outstream_s *stream)
{
kbd_encode(ch, stream, ('a' + KBD_RELEASE));
}
/****************************************************************************
* Name: kbd_specpress
*
* Description:
* Denotes a special key press event. Put one special keyboard command
* into the output stream.
*
* Input Parameters:
* keycode - The command to be added to the output stream.
@@ -71,14 +119,33 @@
*
****************************************************************************/
void kbd_putspecial(enum kbd_keycode_e keycode,
FAR struct lib_outstream_s *stream)
void kbd_specpress(enum kbd_keycode_e keycode,
FAR struct lib_outstream_s *stream)
{
DEBUGASSERT(stream && keycode >= KEYCODE_FWDDEL && keycode <= LAST_KEYCODE);
stream->put(stream, ASCII_ESC);
stream->put(stream, '[');
stream->put(stream, (int)keycode);
stream->put(stream, ';');
kbd_encode((uint8_t)keycode, stream, ('a' + KBD_SPECPRESS));
}
/****************************************************************************
* Name: kbd_specrel
*
* Description:
* Denotes a special key release event. Put one special keyboard
* command into the output stream.
*
* Input Parameters:
* keycode - The command to be added to the output stream.
* stream - An instance of lib_outstream_s to do the low-level put
* operation.
*
* Returned Value:
* None
*
****************************************************************************/
void kbd_specrel(enum kbd_keycode_e keycode,
FAR struct lib_outstream_s *stream)
{
DEBUGASSERT(stream && keycode >= KEYCODE_FWDDEL && keycode <= LAST_KEYCODE);
kbd_encode((uint8_t)keycode, stream, ('a' + KBD_SPECREL));
}