bs8116a_sample.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <rtthread.h>
  2. #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
  3. #include <finsh.h>
  4. #include "bs8116a.h"
  5. /* 芯片1对应的键值 */
  6. static rt_uint8_t keyvalue1[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  7. /* 芯片2对应的键值 */
  8. static rt_uint8_t keyvalue2[15] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
  9. /* 芯片3对应的键值 */
  10. static rt_uint8_t keyvalue3[6] = {31, 32, 33, 34, 35, 36};
  11. /* 按键的初始化数组 */
  12. static rt_uint8_t touch_key_init_buff[22] = {
  13. 0x00, /* 触发模式 */
  14. 0x00, 0x83, 0xF3, /* 固定协议 */
  15. 0x98, /* 省电模式 */
  16. 0x20, 0x20, 0x20, 0x20, 0x20, /* 触摸阈值 */
  17. 0x20, 0x20, 0x20, 0x20, 0x20, /* 触摸阈值 */
  18. 0x20, 0x20, 0x20, 0x20, 0x20, /* 触摸阈值 */
  19. 0x40, /* 中断模式 */
  20. 0x2E /* SUM校验和 */
  21. };
  22. /* 使用BS8116A芯片的数量 */
  23. rt_uint8_t BS8116A_CHIP_NUMS = 3;
  24. /* 按键触发调用函数 */
  25. void got_key_callback(rt_uint8_t key_code) {
  26. rt_kprintf("got_key:%d\n", key_code);
  27. }
  28. static void bs8116a_test_func(void) {
  29. rt_kprintf("BS8116A_CHIP_NUMS : %d\n", BS8116A_CHIP_NUMS);
  30. /* 需要与 BS8116A_CHIP_NUMS 数量对应*/
  31. static struct bs8116a_irq_arg b_i_a[3];
  32. /* 芯片1的参数配置*/
  33. static struct bs8116a_key_arg b_k_a_1 = {
  34. .key_value = keyvalue1,
  35. .key_size = 15,
  36. .init_buff = touch_key_init_buff,
  37. };
  38. b_i_a[0].key = &b_k_a_1;
  39. b_i_a[0].irq_pin_id = 29;
  40. strcpy(b_i_a[0].bus_name, "i2c1soft");
  41. /* 芯片2的参数配置*/
  42. static struct bs8116a_key_arg b_k_a_2 = {
  43. .key_value = keyvalue2,
  44. .key_size = 15,
  45. .init_buff = touch_key_init_buff,
  46. };
  47. b_i_a[1].key = &b_k_a_2;
  48. b_i_a[1].irq_pin_id = 28;
  49. strcpy(b_i_a[1].bus_name, "i2c2soft");
  50. /* 芯片3的参数配置*/
  51. static struct bs8116a_key_arg b_k_a_3 = {
  52. .key_value = keyvalue3,
  53. .key_size = 6,
  54. .init_buff = touch_key_init_buff,
  55. };
  56. b_i_a[2].key = &b_k_a_3;
  57. b_i_a[2].irq_pin_id = 27;
  58. strcpy(b_i_a[2].bus_name, "i2c3soft");
  59. /* 申请i2c总线函数 */
  60. keypad_init(b_i_a);
  61. /* 对BS8116A芯片进行初始化配置,需要在上电后的8秒内调用 */
  62. init_buf_to_bus(b_i_a);
  63. /* 注册中断引脚 绑定中断函数 */
  64. key_irq_entry(b_i_a);
  65. }
  66. MSH_CMD_EXPORT(bs8116a_test_func, bs8116a test function.);
  67. #endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */