cherry8x16.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Copyright (c) 2009 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef CHERRY8x16_H
  41. #define CHERRY8x16_H
  42. /*lint ++flb "Enter library region" */
  43. #include <stdbool.h>
  44. #include <stdint.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /** @file
  49. * @brief Cherry 8x16 keyboard matrix driver
  50. *
  51. *
  52. * @defgroup nrf_drivers_cherry8x16 Cherry 8x16 keyboard matrix driver
  53. * @{
  54. * @ingroup ext_drivers
  55. * @brief Cherry 8x16 keyboard matrix driver.
  56. */
  57. #define CHERRY8x16_MAX_NUM_OF_PRESSED_KEYS 6 //!< Maximum number of pressed keys kept in buffers
  58. #define CHERRY8x16_DEFAULT_KEY_LOOKUP_MATRIX (const uint8_t*)0 //!< If passed to @ref cherry8x16_init, default lookup matrix will be used
  59. #define KEY_PACKET_MODIFIER_KEY_INDEX (0) //!< Index in the key packet where modifier keys such as ALT and Control are stored
  60. #define KEY_PACKET_RESERVED_INDEX (1) //!< Index in the key packet where OEMs can store information
  61. #define KEY_PACKET_KEY_INDEX (2) //!< Start index in the key packet where pressed keys are stored
  62. #define KEY_PACKET_MAX_KEYS (6) //!< Maximum number of keys that can be stored into the key packet
  63. #define KEY_PACKET_SIZE (KEY_PACKET_KEY_INDEX + KEY_PACKET_MAX_KEYS) //!< Total size of the key packet in bytes
  64. #define KEY_PACKET_NO_KEY (0) //!< Value to be stored to key index to indicate no key is pressed
  65. /**
  66. * Describes return values for:
  67. * @ref cherry8x16_init
  68. */
  69. typedef enum
  70. {
  71. CHERRY8x16_OK, /*!< Operation was succesful. */
  72. CHERRY8x16_NOT_DETECTED, /*!< Product/Revision ID was not what was expected */
  73. CHERRY8x16_INVALID_PARAMETER /*!< Given parameters were not valid */
  74. } cherry8x16_status_t;
  75. /**
  76. * @brief Function for initializing the driver.
  77. *
  78. * @note Before calling this function, setup row_port as IO inputs with pulldowns enabled and column_port as IO outputs.
  79. *
  80. * @param row_port Pointer to GPIO port address that is used as key matrix row input.
  81. * @param column_port Pointer to GPIO port address that is used as key matrix column output.
  82. * @param key_lookup_matrix If NULL, use a default key lookup matrix. Otherwise pointer to a 128 (8x16) element array containing HID keycodes.
  83. * @return
  84. * @retval CHERRY8X16_OK Peripheral was initialized succesfully.
  85. * @retval CHERRY8X16_NOT_DETECTED Could not detect the peripheral.
  86. */
  87. cherry8x16_status_t cherry8x16_init(const uint8_t volatile * row_port, uint16_t * column_port, const uint8_t * key_lookup_matrix);
  88. /**
  89. * @brief Function for creating a new key packet if new data is available and key ghosting is not detected.
  90. *
  91. * @param p_key_packet Array that will hold the created key packet. Previously created packet will be discarded.
  92. * @param p_key_packet_size Key packet size in bytes.
  93. * @return
  94. * @retval true If new packet was created.
  95. * @retval false If packet was not created.
  96. */
  97. bool cherry8x16_new_packet(const uint8_t ** p_key_packet, uint8_t *p_key_packet_size);
  98. /**
  99. *@}
  100. **/
  101. /*lint --flb "Leave library region" */
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif