一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

RT-Thread PIN驅(qū)動(dòng)添加

RT-Thread官方賬號(hào) ? 2025-03-28 18:59 ? 次閱讀

Pin驅(qū)動(dòng)框架

c9476c30-0bc3-11f0-9434-92fbcf53809c.png

NXP MCXA153為例

PIN設(shè)備驅(qū)動(dòng)層

單純的提供接口給應(yīng)用層用,其中PIN設(shè)備驅(qū)動(dòng)框架接口包含rt_pin_read等,具體在pin.c 文件中查看

pin.c是提供應(yīng)用接口

drv_gpio.c是具體實(shí)現(xiàn)

實(shí)現(xiàn)操作方法原理

struct rt_pin_ops{ void (*pin_mode)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode); void (*pin_write)(struct rt_device *device, rt_base_t pin, rt_uint8_t value); rt_ssize_t (*pin_read)(struct rt_device *device, rt_base_t pin); rt_err_t (*pin_attach_irq)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode, void (*hdr)(void *args), void *args); rt_err_t (*pin_detach_irq)(struct rt_device *device, rt_base_t pin); rt_err_t (*pin_irq_enable)(struct rt_device *device, rt_base_t pin, rt_uint8_t enabled); rt_base_t (*pin_get)(const char *name);#ifdef RT_USING_DM rt_err_t (*pin_irq_mode)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode); rt_ssize_t (*pin_parse)(struct rt_device *device, struct rt_ofw_cell_args *args, rt_uint32_t *flags);#endif#ifdef RT_USING_PINCTRL rt_err_t (*pin_ctrl_confs_apply)(struct rt_device *device, void *fw_conf_np);#endif /* RT_USING_PINCTRL */};

rt_pin_ops 成員介紹

pin_mode

引腳初始化

pin_write

引腳寫

pin_read

引腳讀

pin_attach_irq

中斷操作 為某個(gè)引腳綁定一個(gè)中斷回調(diào)函數(shù),使能中斷,當(dāng)中斷來(lái)時(shí)調(diào)用該函數(shù)

pin_detach_irq

中斷操作 脫離某個(gè)引腳的中斷回調(diào)函數(shù)

pin_irq_enable

中斷操作 開(kāi)啟或關(guān)閉中斷

pin_get

獲取某個(gè)pin腳編號(hào)

pin_irq_mode

pin_parse

pin_ctrl_confs_apply

引腳編號(hào)

#define GET_GPIO_PORT(x) ((x) / 32)#defineGET_GPIO_PIN(x)((x)%32)

rt_pin_ops 賦值

rt_hw_pin_init(){ int ret = RT_EOK; mcx_pin_ops.pin_mode = mcx_pin_mode; mcx_pin_ops.pin_read = mcx_pin_read; mcx_pin_ops.pin_write = mcx_pin_write; mcx_pin_ops.pin_attach_irq = mcx_pin_attach_irq; mcx_pin_ops.pin_detach_irq = mcx_pin_detach_irq; mcx_pin_ops.pin_irq_enable = mcx_pin_irq_enable; mcx_pin_ops.pin_get = RT_NULL, ret = rt_device_pin_register("pin", &mcx_pin_ops, RT_NULL);// return ret;}INIT_BOARD_EXPORT(rt_hw_pin_init);

注意:這里的操作很奇怪INIT_BOARD_EXPORT ,根據(jù)老師的講解是在預(yù)編譯的時(shí)候就處理了,具體后面再學(xué)習(xí)。。。

drv_pin.c 的 rt_hw_pin_init 將底層驅(qū)動(dòng)和驅(qū)動(dòng)框架進(jìn)行鏈接起來(lái),此文件實(shí)現(xiàn)gpio的初始化

添加Pin驅(qū)動(dòng)代碼流程

編寫drv_pin.c文件

實(shí)現(xiàn) rt_pin_ops 的各種操作接口函數(shù)

然后利用 rt_hw_pin_init 進(jìn)行鏈接驅(qū)動(dòng)層

實(shí)際上就是指針的賦值

實(shí)驗(yàn)代碼

rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */rt_pin_mode(KEY_BAND, PIN_MODE_INPUT);rt_kprintf("MCXA153 HelloWorld\r\n");while (1){ rt_thread_mdelay(1000); if(rt_pin_read(KEY_BAND)) rt_pin_write(LED_PIN, PIN_HIGH); /* Set GPIO output 1 */ else rt_pin_write(LED_PIN, PIN_LOW); /* Set GPIO output 0 */ #if 0 rt_pin_write(LED_PIN, PIN_HIGH); /* Set GPIO output 1 */ rt_thread_mdelay(500); /* Delay 500mS */ rt_pin_write(LED_PIN, PIN_LOW); /* Set GPIO output 0 */ rt_thread_mdelay(500); /* Delay 500mS */ #endif}

注意:這里延遲1s,目的是為了有msh 功能

總結(jié)

學(xué)習(xí)了PIN設(shè)備驅(qū)動(dòng)框架的添加

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 驅(qū)動(dòng)
    +關(guān)注

    關(guān)注

    12

    文章

    1878

    瀏覽量

    86346
  • PIN
    PIN
    +關(guān)注

    關(guān)注

    1

    文章

    311

    瀏覽量

    25036
  • RT-Thread
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    RT-Thread NUC97x 移植 LVGL

    不涉及 rt-thread 驅(qū)動(dòng),但是它是 LVGL 和 rt-thread 的接口。LVGL 在 rt-thread 上運(yùn)行的基石。
    發(fā)表于 07-08 09:37 ?1599次閱讀

    RT-Thread ssd1306驅(qū)動(dòng)

    RT-Thread 驅(qū)動(dòng)ssd1306
    的頭像 發(fā)表于 04-21 10:08 ?26.5w次閱讀
    <b class='flag-5'>RT-Thread</b> ssd1306<b class='flag-5'>驅(qū)動(dòng)</b>

    RT-Thread編程指南

    RT-Thread編程指南——RT-Thread開(kāi)發(fā)組(2015-03-31)。RT-Thread做為國(guó)內(nèi)有較大影響力的開(kāi)源實(shí)時(shí)操作系統(tǒng),本文是RT-Thread實(shí)時(shí)操作系統(tǒng)的編程指南
    發(fā)表于 11-26 16:06 ?0次下載

    RT-Thread用戶手冊(cè)

    RT-Thread用戶手冊(cè)——本書是RT-Thread的編程手冊(cè),用于指導(dǎo)在RT-Thread實(shí)時(shí)操作系統(tǒng)環(huán)境下如何進(jìn)行編 程。
    發(fā)表于 11-26 16:16 ?0次下載

    RT-Thread Studio驅(qū)動(dòng)SD卡

    RT-Thread Studio驅(qū)動(dòng)SD卡前言一、創(chuàng)建基本工程1、創(chuàng)建Bootloader2、創(chuàng)建項(xiàng)目工程二、配置RT-Thread Settings三、代碼分析1.引入庫(kù)2.讀入數(shù)據(jù)四、效果驗(yàn)證
    發(fā)表于 12-27 19:13 ?20次下載
    <b class='flag-5'>RT-Thread</b> Studio<b class='flag-5'>驅(qū)動(dòng)</b>SD卡

    RT-Thread開(kāi)源作品秀】基于RT-Thread的星務(wù)平臺(tái)研究

    本作品為了驗(yàn)證星務(wù)軟件在RT-Thread系統(tǒng)運(yùn)行的可行性,底層是否能夠驅(qū)動(dòng)星務(wù)軟件,同時(shí)擴(kuò)展RT-Thread應(yīng)用范圍。ART-Pi作為衛(wèi)星下位機(jī),...
    發(fā)表于 01-25 18:26 ?6次下載
    【<b class='flag-5'>RT-Thread</b>開(kāi)源作品秀】基于<b class='flag-5'>RT-Thread</b>的星務(wù)平臺(tái)研究

    RT-Thread全球技術(shù)大會(huì):Kconfig在RT-Thread中的工作機(jī)制

    RT-Thread全球技術(shù)大會(huì):Kconfig在RT-Thread中的工作機(jī)制 ? ? ? ? ? ? ? 審核編輯:彭靜
    的頭像 發(fā)表于 05-27 14:49 ?1691次閱讀
    <b class='flag-5'>RT-Thread</b>全球技術(shù)大會(huì):Kconfig在<b class='flag-5'>RT-Thread</b>中的工作機(jī)制

    RT-Thread全球技術(shù)大會(huì):RT-Thread測(cè)試用例集合案例

    RT-Thread全球技術(shù)大會(huì):RT-Thread測(cè)試用例集合案例 ? ? ? ? ? 審核編輯:彭靜
    的頭像 發(fā)表于 05-27 16:34 ?2262次閱讀
    <b class='flag-5'>RT-Thread</b>全球技術(shù)大會(huì):<b class='flag-5'>RT-Thread</b>測(cè)試用例集合案例

    RT-Thread學(xué)習(xí)筆記 RT-Thread的架構(gòu)概述

    RT-Thread 簡(jiǎn)介 作為一名 RTOS 的初學(xué)者,也許你對(duì) RT-Thread 還比較陌生。然而,隨著你的深入接觸,你會(huì)逐漸發(fā)現(xiàn) RT-Thread 的魅力和它相較于其他同類型 RTOS
    的頭像 發(fā)表于 07-09 11:27 ?4825次閱讀
    <b class='flag-5'>RT-Thread</b>學(xué)習(xí)筆記 <b class='flag-5'>RT-Thread</b>的架構(gòu)概述

    RT-Thread文檔_RT-Thread 簡(jiǎn)介

    RT-Thread文檔_RT-Thread 簡(jiǎn)介
    發(fā)表于 02-22 18:22 ?5次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> 簡(jiǎn)介

    RT-Thread文檔_RT-Thread 潘多拉 STM32L475 上手指南

    RT-Thread文檔_RT-Thread 潘多拉 STM32L475 上手指南
    發(fā)表于 02-22 18:23 ?10次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> 潘多拉 STM32L475 上手指南

    RT-Thread文檔_RT-Thread SMP 介紹與移植

    RT-Thread文檔_RT-Thread SMP 介紹與移植
    發(fā)表于 02-22 18:31 ?9次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> SMP 介紹與移植

    RT-Thread文檔_PIN 設(shè)備

    RT-Thread文檔_PIN 設(shè)備
    發(fā)表于 02-22 18:33 ?0次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>PIN</b> 設(shè)備

    基于RT-Thread Studio學(xué)習(xí)

    前期準(zhǔn)備:從官網(wǎng)下載 RT-Thread Studio,弄個(gè)賬號(hào)登陸,開(kāi)啟rt-thread學(xué)習(xí)之旅。
    的頭像 發(fā)表于 05-15 11:00 ?4791次閱讀
    基于<b class='flag-5'>RT-Thread</b> Studio學(xué)習(xí)

    RT-Thread設(shè)備驅(qū)動(dòng)開(kāi)發(fā)指南》基礎(chǔ)篇--以先楫bsp的hwtimer設(shè)備為例

    一、概述(一)RT-Thread設(shè)備驅(qū)動(dòng)RT-Thread設(shè)備驅(qū)動(dòng)開(kāi)發(fā)指南》書籍是RT-thread官方出品撰寫,系統(tǒng)講解
    的頭像 發(fā)表于 02-24 08:16 ?2304次閱讀
    《<b class='flag-5'>RT-Thread</b>設(shè)備<b class='flag-5'>驅(qū)動(dòng)</b>開(kāi)發(fā)指南》基礎(chǔ)篇--以先楫bsp的hwtimer設(shè)備為例