luat_keyboard_air105.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "luat_base.h"
  22. #include "luat_keyboard.h"
  23. #include "app_interface.h"
  24. #define LUAT_LOG_TAG "keyboard"
  25. #include "luat_log.h"
  26. static int32_t kb_cb(void *pData, void *pParam) {
  27. luat_keyboard_irq_cb cb = (luat_keyboard_irq_cb)pParam;
  28. if (cb) {
  29. luat_keyboard_ctx_t ctx;
  30. ctx.port = 0;
  31. ctx.pin_data = (uint16_t) pData;
  32. ctx.state = (((uint32_t)pData) >> 16) & 0x1;
  33. cb(&ctx);
  34. }
  35. }
  36. int luat_keyboard_init(luat_keyboard_conf_t *conf) {
  37. // 按conf->port_conf 设置io复用
  38. if (conf->pin_conf & (1 << 0))
  39. GPIO_Iomux(GPIOD_12, 2); // keyboard0
  40. if (conf->pin_conf & (1 << 1))
  41. GPIO_Iomux(GPIOD_13, 2); // keyboard1
  42. if (conf->pin_conf & (1 << 2))
  43. GPIO_Iomux(GPIOD_14, 2); // keyboard2
  44. if (conf->pin_conf & (1 << 3))
  45. GPIO_Iomux(GPIOD_15, 2); // keyboard3
  46. if (conf->pin_conf & (1 << 4))
  47. GPIO_Iomux(GPIOE_00, 2); // keyboard4
  48. if (conf->pin_conf & (1 << 5))
  49. GPIO_Iomux(GPIOE_01, 2); // keyboard5
  50. if (conf->pin_conf & (1 << 6))
  51. GPIO_Iomux(GPIOE_02, 2); // keyboard6
  52. if (conf->pin_conf & (1 << 7))
  53. GPIO_Iomux(GPIOD_10, 2); // keyboard7
  54. if (conf->pin_conf & (1 << 8))
  55. GPIO_Iomux(GPIOD_11, 2); // keyboard8
  56. //---------------------------
  57. KB_Setup(conf->pin_map, 7, kb_cb, conf->cb);
  58. return 0;
  59. }
  60. int luat_keyboard_deinit(luat_keyboard_conf_t *conf) {
  61. KB_Stop();
  62. return 0;
  63. }