input_encoder.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file input manager interface
  8. */
  9. #include <os_common_api.h>
  10. #include <string.h>
  11. #include <key_hal.h>
  12. #include <app_manager.h>
  13. #include <mem_manager.h>
  14. #include <input_manager.h>
  15. #include <msg_manager.h>
  16. #include <sys_event.h>
  17. #include <property_manager.h>
  18. #include <input_manager_inner.h>
  19. K_MSGQ_DEFINE(encoder_scan_msgq, sizeof(input_dev_data_t), 10, 4);
  20. #ifdef CONFIG_INPUT_DEV_ACTS_ADC_SR
  21. static void encoder_scan_callback(struct device *dev, uint32_t row,
  22. uint32_t col, bool pressed)
  23. {
  24. input_dev_data_t data = {
  25. .point.x = col,
  26. .point.y = row,
  27. .state = pressed ? INPUT_DEV_STATE_PR : INPUT_DEV_STATE_REL,
  28. };
  29. if (k_msgq_put(&encoder_scan_msgq, &data, K_NO_WAIT) != 0) {
  30. SYS_LOG_ERR("Could put input data into queue");
  31. }
  32. }
  33. static bool encoder_scan_read(input_drv_t *drv, input_dev_data_t *data)
  34. {
  35. static input_dev_data_t prev = {
  36. .point.x = 0,
  37. .point.y = 0,
  38. .state = INPUT_DEV_STATE_REL,
  39. };
  40. input_dev_data_t curr;
  41. if (k_msgq_get(&encoder_scan_msgq, &curr, K_NO_WAIT) == 0) {
  42. prev = curr;
  43. }
  44. *data = prev;
  45. return k_msgq_num_used_get(&encoder_scan_msgq) > 0;
  46. }
  47. #endif
  48. int input_encoder_device_init(void)
  49. {
  50. #ifdef CONFIG_INPUT_DEV_ACTS_ADC_SR
  51. input_drv_t input_drv;
  52. struct device *input_dev = device_get_binding(CONFIG_INPUT_DEV_ACTS_ADC_SR_NAME);
  53. if (!input_dev) {
  54. SYS_LOG_ERR("cannot found key dev adckey\n");
  55. return -ENODEV;
  56. }
  57. input_dev_register_notify(input_dev, encoder_scan_callback);
  58. input_drv.type = INPUT_DEV_TYPE_ENCODER;
  59. input_drv.read_cb = encoder_scan_read;
  60. input_driver_register(&input_drv);
  61. #endif
  62. return 0;
  63. }