key_hal.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <os_common_api.h>
  7. #include <shell/shell.h>
  8. #include "key_hal.h"
  9. void * key_device_open(key_notify_cb cb,char * dev_name)
  10. {
  11. struct key_handle * handle = mem_malloc(sizeof(struct key_handle));
  12. if(handle == NULL)
  13. {
  14. SYS_LOG_ERR("adc key in mem_malloc failed need %d bytes ",(int)sizeof(struct key_handle));
  15. return NULL;
  16. }
  17. handle->input_dev = (struct device *)device_get_binding(dev_name);
  18. if (!handle->input_dev) {
  19. printk("cannot found key dev %s\n",dev_name);
  20. mem_free(handle);
  21. return NULL;
  22. }
  23. input_dev_enable(handle->input_dev);
  24. input_dev_register_notify(handle->input_dev, cb);
  25. handle->key_notify = cb;
  26. return handle;
  27. }
  28. void key_device_close(void * handle)
  29. {
  30. struct key_handle * key = (struct key_handle *)handle;
  31. input_dev_unregister_notify(key->input_dev, key->key_notify);
  32. input_dev_disable(key->input_dev);
  33. mem_free(key);
  34. }
  35. void key_device_abort_cb(void * handle)
  36. {
  37. struct key_handle * key = (struct key_handle *)handle;
  38. input_dev_unregister_notify(key->input_dev, key->key_notify);
  39. }
  40. void key_device_enable_cb(void * handle)
  41. {
  42. struct key_handle * key = (struct key_handle *)handle;
  43. input_dev_register_notify(key->input_dev, key->key_notify);
  44. }
  45. int key_device_inquiry(void * handle, struct input_value *val)
  46. {
  47. struct key_handle * key = (struct key_handle *)handle;
  48. if (val)
  49. {
  50. input_dev_inquiry(key->input_dev, val);
  51. }
  52. return 0;
  53. }