2012-12-27 15:01:59 +01:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* libs/libc/misc/lib_kbdencode.c
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
2012-12-27 15:01:59 +01:00
|
|
|
****************************************************************************/
|
2012-12-25 18:22:58 +01:00
|
|
|
|
2012-12-27 15:01:59 +01:00
|
|
|
/****************************************************************************
|
2012-12-25 18:22:58 +01:00
|
|
|
* Included Files
|
2012-12-27 15:01:59 +01:00
|
|
|
****************************************************************************/
|
2012-12-25 18:22:58 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <nuttx/streams.h>
|
|
|
|
#include <nuttx/ascii.h>
|
|
|
|
#include <nuttx/input/kbd_codec.h>
|
|
|
|
|
2012-12-27 15:01:59 +01:00
|
|
|
/****************************************************************************
|
2015-04-08 15:32:08 +02:00
|
|
|
* Pre-processor Definitions
|
2012-12-27 15:01:59 +01:00
|
|
|
****************************************************************************/
|
2012-12-25 18:22:58 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2012-12-27 15:01:59 +01:00
|
|
|
* Name: kbd_encode
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-12-27 15:01:59 +01:00
|
|
|
* Encode one special special sequence command into the output stream.
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-12-26 19:54:59 +01:00
|
|
|
* keycode - The command to be added to the output stream.
|
|
|
|
* stream - An instance of lib_outstream_s to do the low-level put
|
|
|
|
* operation.
|
2012-12-27 15:01:59 +01:00
|
|
|
* terminator - Escape sequence terminating character.
|
2012-12-25 18:22:58 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-12-27 15:01:59 +01:00
|
|
|
static void kbd_encode(uint8_t keycode, FAR struct lib_outstream_s *stream,
|
|
|
|
uint8_t terminator)
|
2012-12-25 18:22:58 +01:00
|
|
|
{
|
2022-12-04 10:35:13 +01:00
|
|
|
lib_stream_putc(stream, ASCII_ESC);
|
|
|
|
lib_stream_putc(stream, '[');
|
|
|
|
lib_stream_putc(stream, (int)keycode);
|
|
|
|
lib_stream_putc(stream, terminator);
|
2012-12-25 18:22:58 +01:00
|
|
|
}
|
|
|
|
|
2012-12-27 15:01:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
2014-04-13 22:32:20 +02:00
|
|
|
kbd_encode(ch, stream, ('a' + KBD_RELEASE));
|
2012-12-27 15:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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.
|
|
|
|
* stream - An instance of lib_outstream_s to do the low-level put
|
|
|
|
* operation.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void kbd_specpress(enum kbd_keycode_e keycode,
|
|
|
|
FAR struct lib_outstream_s *stream)
|
|
|
|
{
|
2021-04-02 14:56:34 +02:00
|
|
|
DEBUGASSERT(stream &&
|
|
|
|
keycode >= KEYCODE_FWDDEL &&
|
|
|
|
keycode <= LAST_KEYCODE);
|
2014-04-13 22:32:20 +02:00
|
|
|
kbd_encode((uint8_t)keycode, stream, ('a' + KBD_SPECPRESS));
|
2012-12-27 15:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
2021-04-02 14:56:34 +02:00
|
|
|
DEBUGASSERT(stream &&
|
|
|
|
keycode >= KEYCODE_FWDDEL &&
|
|
|
|
keycode <= LAST_KEYCODE);
|
2014-04-13 22:32:20 +02:00
|
|
|
kbd_encode((uint8_t)keycode, stream, ('a' + KBD_SPECREL));
|
2012-12-27 15:01:59 +01:00
|
|
|
}
|