查看: 795|回复: 0

[评测分享] 【Telink-泰凌微电子 B91通用开发套件】USB鼠标测试

[复制链接]
  • TA的每日心情
    奋斗
    14 小时前
  • 签到天数: 1970 天

    连续签到: 26 天

    [LV.Master]伴坛终老

    发表于 2022-11-4 23:00:26 | 显示全部楼层 |阅读模式
    分享到:
    本次测试一下USB设备。
    导入通用驱动项目后,选择USB_Demo。
    1.jpg
    然后打开app_config.h配置一下。
    2.jpg

    main.c如下
    1. int main (void)
    2. {

    3. #if(MCU_CORE_B91)
    4.     sys_init(LDO_1P4_LDO_1P8, VBAT_MAX_VALUE_GREATER_THAN_3V6);
    5.     //Note: This function can improve the performance of some modules, which is described in the function comments.
    6.         //Called immediately after sys_init, set in other positions, some calibration values may not take effect.
    7.         user_read_flash_value_calib();
    8.     CCLK_24M_HCLK_24M_PCLK_24M;

    9. #elif(MCU_CORE_B92)
    10.     sys_init();
    11.     write_reg8(0x1401fb, 192/48);
    12. #endif
    13.         user_init();
    14.         while (1)
    15.         {
    16.                 main_loop ();
    17.         }
    18.         return 0;
    19. }
    复制代码
    mouse_app.c初始化和主循环代码如下。修改了一下原来的例子,利用板上4个按键模拟鼠标X,Y轴。
    1. /********************************************************************************************************
    2. * @file        mouse_app.c
    3. *
    4. * @brief        This is the source file for B91m
    5. *
    6. * @author        Driver Group
    7. * @date        2019
    8. *
    9. * @par     Copyright (c) 2019, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
    10. *          All rights reserved.
    11. *
    12. *          Licensed under the Apache License, Version 2.0 (the "License");
    13. *          you may not use this file except in compliance with the License.
    14. *          You may obtain a copy of the License at
    15. *
    16. *              http://www.apache.org/licenses/LICENSE-2.0
    17. *
    18. *          Unless required by applicable law or agreed to in writing, software
    19. *          distributed under the License is distributed on an "AS IS" BASIS,
    20. *          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    21. *          See the License for the specific language governing permissions and
    22. *          limitations under the License.
    23. *
    24. *******************************************************************************************************/
    25. #include "app_config.h"
    26. #if(USB_DEMO_TYPE==USB_MOUSE)
    27. #include "application/usbstd/usb.h"
    28. #include "application/usb_app/usbmouse.h"

    29. char  mouse[4];
    30. volatile unsigned long g_led_time;
    31. volatile unsigned long g_key_time;

    32. void user_init(void)
    33. {
    34.         //1.enable USB DP pull up 1.5k
    35.         usb_set_pin_en();
    36.         //2.enable USB manual interrupt(in auto interrupt mode,USB device would be USB printer device)
    37.         usb_init_interrupt();
    38.         //3.enable global interrupt
    39.         core_interrupt_enable();
    40. #if(MCU_CORE_B91)
    41.         usbhw_set_irq_mask(USB_IRQ_RESET_MASK|USB_IRQ_SUSPEND_MASK);
    42. #endif

    43.         //initiate LED for indication
    44.         gpio_function_en(LED1|LED2|LED3|LED4);
    45.         gpio_input_dis(LED1|LED2|LED3|LED4);
    46.         gpio_output_en(LED1|LED2|LED3|LED4);
    47.         gpio_set_high_level(LED1|LED2|LED3|LED4);
    48.         delay_us(100000);
    49.         gpio_set_low_level(LED1|LED2|LED3|LED4);

    50.         //initiate Button for Mouse input
    51.         gpio_function_en(GPIO_PC0);
    52.         gpio_input_en(GPIO_PC0);
    53.         gpio_output_dis(GPIO_PC0);
    54.         gpio_set_up_down_res(GPIO_PC0, GPIO_PIN_PULLUP_10K);
    55.         gpio_function_en(GPIO_PC2);
    56.         gpio_input_en(GPIO_PC2);
    57.         gpio_output_dis(GPIO_PC2);
    58.         gpio_set_up_down_res(GPIO_PC2, GPIO_PIN_PULLUP_10K);

    59.         //output
    60.         gpio_function_en(GPIO_PC1);
    61.         gpio_input_dis(GPIO_PC1);
    62.         gpio_output_en(GPIO_PC1);
    63.         gpio_set_high_level(GPIO_PC1);

    64.         gpio_function_en(GPIO_PC3);
    65.         gpio_input_dis(GPIO_PC3);
    66.         gpio_output_en(GPIO_PC3);
    67.         gpio_set_low_level(GPIO_PC3);

    68.         g_led_time = stimer_get_tick();
    69.         g_key_time = stimer_get_tick();
    70. }

    71. /* enum to USB input device and simulate the left click and right click of mouse */
    72. void main_loop (void)
    73. {
    74.         usb_handle_irq();

    75.         if(clock_time_exceed(g_led_time, 500*1000))
    76.         {
    77.                 g_led_time = stimer_get_tick();
    78.                 gpio_toggle(LED2);        //BLINK LED
    79.         }

    80.         if(clock_time_exceed(g_key_time, 30*1000))
    81.         {
    82.                 g_key_time = stimer_get_tick();
    83. //                gpio_toggle(LED3);        //BLINK LED

    84.                 gpio_set_high_level(GPIO_PC1);
    85.                 gpio_set_low_level(GPIO_PC3);
    86.                 delay_ms(2);
    87.                 if(gpio_get_level(GPIO_PC0)==0)
    88.                 {
    89.                         gpio_set_high_level(LED1);
    90.                         //printf("Key:Mouse  Click ! \r\n");
    91.                         mouse[0] = 0;// BIT(0) - left key; BIT(1) - right key; BIT(2) - middle key; BIT(3) - side key; BIT(4) - external key
    92.                         mouse[1] = -5;          // Displacement relative to x coordinate
    93.                         mouse[2] = 0;          // Displacement relative to y coordinate
    94.                         mouse[3] = 0;     // Displacement relative to the roller
    95.                         if(g_usb_config != 0 )   usbmouse_hid_report(USB_HID_MOUSE,(unsigned char*)mouse,4);
    96.                 }

    97.                 if(gpio_get_level(GPIO_PC2)==0)
    98.                 {
    99.                         gpio_set_low_level(LED1);
    100.                         //printf("Key:Mouse  Click ! \r\n");
    101.                         mouse[0] = 0;// BIT(0) - left key; BIT(1) - right key; BIT(2) - middle key; BIT(3) - side key; BIT(4) - external key
    102.                         mouse[1] = 5;          // Displacement relative to x coordinate
    103.                         mouse[2] = 0;          // Displacement relative to y coordinate
    104.                         mouse[3] = 0;     // Displacement relative to the roller
    105.                         if(g_usb_config != 0 )   usbmouse_hid_report(USB_HID_MOUSE,(unsigned char*)mouse,4);
    106.                 }

    107.                 gpio_set_high_level(GPIO_PC3);
    108.                 gpio_set_low_level(GPIO_PC1);
    109.                 delay_ms(2);

    110.                 if(gpio_get_level(GPIO_PC0)==0)
    111.                 {
    112.                         gpio_set_high_level(LED4);
    113.                         //printf("Key:Mouse  Click ! \r\n");
    114.                         mouse[0] = 0;// BIT(0) - left key; BIT(1) - right key; BIT(2) - middle key; BIT(3) - side key; BIT(4) - external key
    115.                         mouse[1] = 0;          // Displacement relative to x coordinate
    116.                         mouse[2] = 5;          // Displacement relative to y coordinate
    117.                         mouse[3] = 0;     // Displacement relative to the roller
    118.                         if(g_usb_config != 0 )   usbmouse_hid_report(USB_HID_MOUSE,(unsigned char*)mouse,4);
    119.                 }

    120.                 if(gpio_get_level(GPIO_PC2)==0)
    121.                 {
    122.                         gpio_set_low_level(LED4);
    123.                         //printf("Key:Mouse  Click ! \r\n");
    124.                         mouse[0] = 0;// BIT(0) - left key; BIT(1) - right key; BIT(2) - middle key; BIT(3) - side key; BIT(4) - external key
    125.                         mouse[1] = 0;          // Displacement relative to x coordinate
    126.                         mouse[2] = -5;          // Displacement relative to y coordinate
    127.                         mouse[3] = 0;     // Displacement relative to the roller
    128.                         if(g_usb_config != 0 )   usbmouse_hid_report(USB_HID_MOUSE,(unsigned char*)mouse,4);
    129.                 }
    130.         }
    131. }

    132. #endif
    复制代码


    板上4个按键是矩阵扫描方式的。见如下电路图。使用io是PC0,PC1,PC2,PC3.
    4.jpg
    3.jpg
    编译下载
    5.jpg

    打开BDT下载软件,找到编译的固件资料。然后点Download下载。
    6.jpg

    复位板子,就可以识别到鼠标设备了。
    7.jpg

    可以通过板上4个按键,可以看到鼠标的指针移动了。






    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-22 23:27 , Processed in 0.124136 second(s), 17 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.