完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
` 第一篇试用报告见 https://bbs.elecfans.com/jishu_2113628_1_1.html 感谢发烧友,经过反馈,积极的协调最终将两条线缆和包装盒单独发快递发给了我,再次感谢,热心肠的发烧友超可爱。一套开发板终于完美的在一起了。 首先分析下面的工程: 工程:soc_thermometer_mock app.c文件中可以找到按键让灯亮的代码,如下 /**************************************************************************//** * Simple Button * Button state changed callback * @param[in] handle Button event handle *****************************************************************************/ void sl_button_on_change(const sl_button_t *handle) { // Button pressed. if (sl_button_get_state(handle) == SL_SIMPLE_BUTTON_PRESSED) { if (&sl_button_btn0 == handle) { sl_led_turn_on(&sl_led_led0); app_btn0_pressed = true; //当按键按下时,让LED0亮 } } // Button released. else if (sl_button_get_state(handle) == SL_SIMPLE_BUTTON_RELEASED) { if (&sl_button_btn0 == handle) { sl_led_turn_off(&sl_led_led0); //当按键释放时,让LED0灭 app_btn0_pressed = false; } } } 在sl_led.c文件中可以找到点灯和灭灯和反转的函数,如下 void sl_led_turn_on(const sl_led_t *led_handle) { led_handle->turn_on(led_handle->context); } void sl_led_turn_off(const sl_led_t *led_handle) { led_handle->turn_off(led_handle->context); } void sl_led_toggle(const sl_led_t *led_handle) { led_handle->toggle(led_handle->context); } /// A LED instance typedef struct { void *context; ///< The context for this LED instance sl_status_t (*init)(void *context); ///< Member function to initialize LED instance void (*turn_on)(void *context); ///< Member function to turn on LED void (*turn_off)(void *context); ///< Member function to turn off LED void (*toggle)(void *context); ///< Member function to toggle LED sl_led_state_t (*get_state)(void *context); ///< Member function to retrieve LED state } sl_led_t; /***************************************************************************//** * Turn on the LED. * * @param[in] led_handle Pointer to instance of sl_led_t to turn on ******************************************************************************/ void sl_led_turn_on(const sl_led_t *led_handle); /***************************************************************************//** * Turn off the LED. * * @param[in] led_handle Pointer to instance of sl_led_t to turn off ******************************************************************************/ void sl_led_turn_off(const sl_led_t *led_handle); /***************************************************************************//** * Toggle the LED. Turn it on if it is off, and off if it is on. * * @param[in] led_handle Pointer to instance of sl_led_t to toggle ******************************************************************************/ void sl_led_toggle(const sl_led_t *led_handle); /***************************************************************************//** * Get the current state of the LED. * * @param[in] led_handle Pointer to instance of sl_led_t to check * * @return sl_led_state_t Current state of LED. 1 for on, 0 for off ******************************************************************************/ sl_led_state_t sl_led_get_state(const sl_led_t *led_handle); 在文件SL_SIMPLE_LED_Instances.c中可以找到等的引脚定义 sl_simple_led_context_t simple_led0_context = { .port = SL_SIMPLE_LED_LED0_PORT, .pin = SL_SIMPLE_LED_LED0_PIN, .polarity = SL_SIMPLE_LED_LED0_POLARITY, }; const sl_led_t sl_led_led0 = { .context = &simple_led0_context, .init = sl_simple_led_init, .turn_on = sl_simple_led_turn_on, .turn_off = sl_simple_led_turn_off, .toggle = sl_simple_led_toggle, .get_state = sl_simple_led_get_state, }; #define SL_SIMPLE_LED_LED0_PORT gpioPortC #define SL_SIMPLE_LED_LED0_PIN 4 #if (_GPIO_PORT_C_PIN_COUNT > 0) /** Port C. */ gpioPortC = 2, #endif 按键的分析: 定义 #define SL_SIMPLE_BUTTON_DISABLED 2U ///< BUTTON state is disabled #define SL_SIMPLE_BUTTON_PRESSED 1U ///< BUTTON state is pressed #define SL_SIMPLE_BUTTON_RELEASED 0U ///< BUTTON state is released 获取按键的状态: sl_button_state_t sl_button_get_state(const sl_button_t *handle) { if (handle->get_state != NULL) { return handle->get_state(handle->context); } else { return (sl_button_state_t)BUTTON_ERROR; } } /// A BUTTON instance typedef struct { void *context; ///< The context for this BUTTON instance sl_status_t (*init)(void *context); ///< Member function to initialize BUTTON instance void (*poll)(void *context); ///< Member function to poll BUTTON void (*enable)(void *context); ///< Member function to enable BUTTON void (*disable)(void *context); ///< Member function to disable BUTTON sl_button_state_t (*get_state)(void *context); ///< Member function to retrieve BUTTON state } sl_button_t; 按键0的定义 const sl_button_t sl_button_btn0 = { .context = &simple_btn0_context, .init = sl_simple_button_init, .get_state = sl_simple_button_get_state, .poll = sl_simple_button_poll_step, .enable = sl_simple_button_enable, .disable = sl_simple_button_disable, }; 至此,可以看出按键让灯亮灭的代码,结合硬件原理图可以进行相应的更改。 `
|
|
相关推荐
|
|
你正在撰写讨论
如果你是对讨论或其他讨论精选点评或询问,请使用“评论”功能。
高通的蓝牙QCC308x和51xx芯片开发工具和文档必须高通审核才能下载和使用吗?
1190 浏览 0 评论
1501 浏览 0 评论
会员风采!华秋电子——致力于“为电子产业增效降本”的数字化智造平台
991 浏览 0 评论
【应用笔记】BlueNRG-LP、BlueNRG-LPS+省电模式
8042 浏览 1 评论
11263 浏览 0 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-21 18:45 , Processed in 0.875098 second(s), Total 66, Slave 48 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号