欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

添加 Ti Botton Driver

程序员文章站 2022-04-02 20:17:19
目录环境1. 添加Button 插件2. 添加相关代码环境系统:Windows 10SDK:simplelink_cc13x2_26x2_sdk_4_20_01_04IDE:Code Composer Studio, Version: 10.0.0.00010代码工程:simple_peripheral_oad_offchip_CC26X2R1_LAUNCHXL_tirtos_ccs (已删除不必要的代码,请看:删除simple_peripheral_oad_offchip工程多余的代码)...

环境

  1. 系统:Windows 10
  2. SDK:simplelink_cc13x2_26x2_sdk_4_20_01_04
  3. IDE:Code Composer Studio, Version: 10.0.0.00010
  4. 代码工程:simple_peripheral_oad_offchip_CC26X2R1_LAUNCHXL_tirtos_ccs (已删除不必要的代码,请看:删除simple_peripheral_oad_offchip工程多余的代码)

1. 添加Button 插件

添加4个Button, 并配置好IO。

添加 Ti Botton Driver添加 Ti Botton Driver

2. 添加相关代码

初始化代码:

void hal_button_init(void)
{
    Button_Params params;

    Button_Params_init(&params);
    params.longPressDuration = 5000;

    Button_open(CONFIG_BUTTON_LEFT, hal_button_left_cb, &params);

    Button_open(CONFIG_BUTTON_RIGHT, hal_button_right_cb, &params);

    Button_open(CONFIG_BUTTON_BACK, hal_button_back_cb, &params);

    Button_open(CONFIG_BUTTON_ENTER, hal_button_enter_cb, &params);
}

回调函数代码:

   
void hal_button_left_cb(Button_Handle handle, Button_EventMask events)
{
    Debug("button_left: 0x%02x", events);

    /*! Button pressed down, may or may not subsequently have been released */
    if (events & Button_EV_PRESSED)
    {
        hal_buzzer_start(50, 50, 1);
    }
    /*! Button held down for more than tLongpress (ms) */
    if (events & Button_EV_LONGPRESSED)
    {

    }
    /*! Button released after press or longpress */
    if (events & Button_EV_RELEASED)
    {

    }
    /*! Button was pressed and released, but was not a long press */
    if (events & Button_EV_CLICKED)
    {

    }
    /*!
     * Button was pressed and released, and held for longer than
     * longPressDuration (ms)
     */
    if (events & Button_EV_LONGCLICKED)
    {

    }
    /*! Button was pressed when double click detection was active */
    if (events & Button_EV_DOUBLECLICKED)
    {
    }

}
void hal_button_right_cb(Button_Handle handle, Button_EventMask events)
{
    Debug("button_right: 0x%02x", events);

    /*! Button pressed down, may or may not subsequently have been released */
    if (events & Button_EV_PRESSED)
    {
        hal_buzzer_start(50, 50, 1);
    }
    /*! Button held down for more than tLongpress (ms) */
    if (events & Button_EV_LONGPRESSED)
    {

    }
    /*! Button released after press or longpress */
    if (events & Button_EV_RELEASED)
    {

    }
    /*! Button was pressed and released, but was not a long press */
    if (events & Button_EV_CLICKED)
    {

    }
    /*!
     * Button was pressed and released, and held for longer than
     * longPressDuration (ms)
     */
    if (events & Button_EV_LONGCLICKED)
    {

    }
    /*! Button was pressed when double click detection was active */
    if (events & Button_EV_DOUBLECLICKED)
    {
        hal_buzzer_start(50, 950, 2);
    }
}
void hal_button_back_cb(Button_Handle handle, Button_EventMask events)
{
    Debug("button_back: 0x%02x", events);

    /*! Button pressed down, may or may not subsequently have been released */
    if (events & Button_EV_PRESSED)
    {
        hal_buzzer_start(50, 50, 1);
    }
    /*! Button held down for more than tLongpress (ms) */
    if (events & Button_EV_LONGPRESSED)
    {
        SystemReset();
    }
    /*! Button released after press or longpress */
    if (events & Button_EV_RELEASED)
    {

    }
    /*! Button was pressed and released, but was not a long press */
    if (events & Button_EV_CLICKED)
    {

    }
    /*!
     * Button was pressed and released, and held for longer than
     * longPressDuration (ms)
     */
    if (events & Button_EV_LONGCLICKED)
    {

    }
    /*! Button was pressed when double click detection was active */
    if (events & Button_EV_DOUBLECLICKED)
    {

    }
}
void hal_button_enter_cb(Button_Handle handle, Button_EventMask events)
{
    Debug("button_enter: 0x%02x", events);

    /*! Button pressed down, may or may not subsequently have been released */
    if (events & Button_EV_PRESSED)
    {
        hal_buzzer_start(50, 950, 3);
    }
    /*! Button held down for more than tLongpress (ms) */
    if (events & Button_EV_LONGPRESSED)
    {

    }
    /*! Button released after press or longpress */
    if (events & Button_EV_RELEASED)
    {

    }
    /*! Button was pressed and released, but was not a long press */
    if (events & Button_EV_CLICKED)
    {

    }
    /*!
     * Button was pressed and released, and held for longer than
     * longPressDuration (ms)
     */
    if (events & Button_EV_LONGCLICKED)
    {

    }
    /*! Button was pressed when double click detection was active */
    if (events & Button_EV_DOUBLECLICKED)
    {

    }
}

本文地址:https://blog.csdn.net/qq_21352095/article/details/108999121