input_knob.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2022 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file knob 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. struct k_work knob_work;
  20. uint32_t knob_val = 0;
  21. static void _knob_work_handler(struct k_work *work)
  22. {
  23. sys_event_report_input(knob_val);
  24. }
  25. static void knob_notify_callback(struct device *dev,struct input_value *val)
  26. {
  27. knob_val = val->keypad.value;
  28. k_work_submit(&knob_work);
  29. }
  30. int input_knob_device_init(void)
  31. {
  32. // input_drv_t input_drv;
  33. const struct device *input_dev = device_get_binding(KNOB_ENCODER_DEV_NAME);
  34. if (!input_dev) {
  35. SYS_LOG_ERR("cannot found key dev knobencoder\n");
  36. return -ENODEV;
  37. }
  38. input_dev_register_notify(input_dev, knob_notify_callback);
  39. k_work_init(&knob_work, _knob_work_handler);
  40. return 0;
  41. }