当前位置:首页 > 嵌入式 > 嵌入式硬件
[导读]这几天看了下 mbed 的源码,给上层应用调用的接口封装的还是不错的。代码质量比较高,注释也很详细,文档和例程比较全。但是驱动层的程序全是 C 语言编写的,代码质量就没有那么高了,注释比较少而且不规范,比较怀疑 mbed 的稳定性。mbed 的实时内核是用的 RTX5 ,文件系统用的 FatFs ,还有一些开源的协议栈,整套系统比较繁杂。mbed 框架是为物联网设备开发的,工业控制级别的产品可以考虑用 RTE 框架。RTE 框架目前驱动层程序还不太完善,有好多需要自己去实现,可能在过一段时间会好一些吧。总

这几天看了下 mbed 的源码,给上层应用调用的接口封装的还是不错的。代码质量比较高,注释也很详细,文档和例程比较全。但是驱动层的程序全是 C 语言编写的,代码质量就没有那么高了,注释比较少而且不规范,比较怀疑 mbed 的稳定性。mbed 的实时内核是用的 RTX5 ,文件系统用的 FatFs ,还有一些开源的协议栈,整套系统比较繁杂。mbed 框架是为物联网设备开发的,工业控制级别的产品可以考虑用 RTE 框架。RTE 框架目前驱动层程序还不太完善,有好多需要自己去实现,可能在过一段时间会好一些吧。总之物联网产品可以用 mbed ,工业控制产品可以用 RTE 。这几天封装了 EXTI ,距离整套系统可以产生生产力还有很长的距离要走,我也不知道整个系统会成什么样子,我能坚持多久,不管了先做再说。在这里分享我的 STM32F4 C++ 封装之旅。今天分享《STM32F4 C++ 封装库 之 EXTI》,直接上代码了~

stm32f4xx_xexTI.h 文件

/**

******************************************************************************

* \file stm32f4xx_xexTI.h

* \author XinLi

* \version v1.0

* \date 20-March-2018

* \brief Header file for external interrupt/event controller module.

******************************************************************************

* \attention

*

* Copyright © 2018 XinLi

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

******************************************************************************

*/

#ifndef STM32F4XX_XEXTI_H

#define STM32F4XX_XEXTI_H

#include "stm32f4xx_ll_exti.h"

/*! External interrupt/event controller module. */

class XExti

{

public:

/*! Enumerate of EXTI lines. */

enum ExtiLine

{

Line0 = LL_EXTI_LINE_0, /*!< EXTI line 0. */

Line1 = LL_EXTI_LINE_1, /*!< EXTI line 1. */

Line2 = LL_EXTI_LINE_2, /*!< EXTI line 2. */

Line3 = LL_EXTI_LINE_3, /*!< EXTI line 3. */

Line4 = LL_EXTI_LINE_4, /*!< EXTI line 4. */

Line5 = LL_EXTI_LINE_5, /*!< EXTI line 5. */

Line6 = LL_EXTI_LINE_6, /*!< EXTI line 6. */

Line7 = LL_EXTI_LINE_7, /*!< EXTI line 7. */

Line8 = LL_EXTI_LINE_8, /*!< EXTI line 8. */

Line9 = LL_EXTI_LINE_9, /*!< EXTI line 9. */

Line10 = LL_EXTI_LINE_10, /*!< EXTI line 10. */

Line11 = LL_EXTI_LINE_11, /*!< EXTI line 11. */

Line12 = LL_EXTI_LINE_12, /*!< EXTI line 12. */

Line13 = LL_EXTI_LINE_13, /*!< EXTI line 13. */

Line14 = LL_EXTI_LINE_14, /*!< EXTI line 14. */

Line15 = LL_EXTI_LINE_15, /*!< EXTI line 15. */

#ifdef LL_EXTI_LINE_16

Line16 = LL_EXTI_LINE_16, /*!< EXTI line 16. */

#endif

#ifdef LL_EXTI_LINE_17

Line17 = LL_EXTI_LINE_17, /*!< EXTI line 17. */

#endif

#ifdef LL_EXTI_LINE_18

Line18 = LL_EXTI_LINE_18, /*!< EXTI line 18. */

#endif

#ifdef LL_EXTI_LINE_19

Line19 = LL_EXTI_LINE_19, /*!< EXTI line 19. */

#endif

#ifdef LL_EXTI_LINE_20

Line20 = LL_EXTI_LINE_20, /*!< EXTI line 20. */

#endif

#ifdef LL_EXTI_LINE_21

Line21 = LL_EXTI_LINE_21, /*!< EXTI line 21. */

#endif

#ifdef LL_EXTI_LINE_22

Line22 = LL_EXTI_LINE_22, /*!< EXTI line 22. */

#endif

#ifdef LL_EXTI_LINE_23

Line23 = LL_EXTI_LINE_23, /*!< EXTI line 23. */

#endif

#ifdef LL_EXTI_LINE_24

Line24 = LL_EXTI_LINE_24, /*!< EXTI line 24. */

#endif

#ifdef LL_EXTI_LINE_25

Line25 = LL_EXTI_LINE_25, /*!< EXTI line 25. */

#endif

#ifdef LL_EXTI_LINE_26

Line26 = LL_EXTI_LINE_26, /*!< EXTI line 26. */

#endif

#ifdef LL_EXTI_LINE_27

Line27 = LL_EXTI_LINE_27, /*!< EXTI line 27. */

#endif

#ifdef LL_EXTI_LINE_28

Line28 = LL_EXTI_LINE_28, /*!< EXTI line 28. */

#endif

#ifdef LL_EXTI_LINE_29

Line29 = LL_EXTI_LINE_29, /*!< EXTI line 29. */

#endif

#ifdef LL_EXTI_LINE_30

Line30 = LL_EXTI_LINE_30, /*!< EXTI line 30. */

#endif

#ifdef LL_EXTI_LINE_31

Line31 = LL_EXTI_LINE_31, /*!< EXTI line 31. */

#endif

};

/*! Enumerate of EXTI modes. */

enum ExtiMode

{

ModeInterrupt = LL_EXTI_MODE_IT, /*!< EXTI interrupt mode. */

ModeEvent = LL_EXTI_MODE_EVENT, /*!< EXTI event mode. */

ModeInterruptEvent = LL_EXTI_MODE_IT_EVENT, /*!< EXTI interrupt and event mode. */

};

/*! Enumerate of EXTI triggers. */

enum ExtiTrigger

{

TriggerNone = LL_EXTI_TRIGGER_NONE, /*!< EXTI none trigger. */

TriggerRising = LL_EXTI_TRIGGER_RISING, /*!< EXTI rising trigger. */

TriggerFalling = LL_EXTI_TRIGGER_FALLING, /*!< EXTI falling trigger. */

TriggerRisingFalling = LL_EXTI_TRIGGER_RISING_FALLING, /*!< EXTI rising and falling trigger. */

};

XExti(ExtiLine line, ExtiMode mode, ExtiTrigger trigger = TriggerNone);

virtual ~XExti();

void setLine(ExtiLine line);

ExtiLine getLine() const;

void setMode(ExtiMode mode);

ExtiMode getMode() const;

void setTrigger(ExtiTrigger trigger);

ExtiTrigger getTrigger() const;

void setFlag();

void clearFlag();

bool isFlagSet() const;

bool open();

void close();

bool isOpen() const;

private:

ExtiLine line;

ExtiMode mode;

ExtiTrigger trigger;

bool openFlag;

XExti(const XExti &) = delete;

XExti & operator = (const XExti &) = delete;

};

#endif // STM32F4XX_XEXTI_H

stm32f4xx_xexti.cpp 文件

/**

******************************************************************************

* \file stm32f4xx_xexti.cpp

* \author XinLi

* \version v1.0

* \date 20-March-2018

* \brief External interrupt/event controller module driver.

******************************************************************************

* \attention

*

* Copyright © 2018 XinLi

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

******************************************************************************

*/

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

LED驱动电源的输入包括高压工频交流(即市电)、低压直流、高压直流、低压高频交流(如电子变压器的输出)等。

关键字: 驱动电源

在工业自动化蓬勃发展的当下,工业电机作为核心动力设备,其驱动电源的性能直接关系到整个系统的稳定性和可靠性。其中,反电动势抑制与过流保护是驱动电源设计中至关重要的两个环节,集成化方案的设计成为提升电机驱动性能的关键。

关键字: 工业电机 驱动电源

LED 驱动电源作为 LED 照明系统的 “心脏”,其稳定性直接决定了整个照明设备的使用寿命。然而,在实际应用中,LED 驱动电源易损坏的问题却十分常见,不仅增加了维护成本,还影响了用户体验。要解决这一问题,需从设计、生...

关键字: 驱动电源 照明系统 散热

根据LED驱动电源的公式,电感内电流波动大小和电感值成反比,输出纹波和输出电容值成反比。所以加大电感值和输出电容值可以减小纹波。

关键字: LED 设计 驱动电源

电动汽车(EV)作为新能源汽车的重要代表,正逐渐成为全球汽车产业的重要发展方向。电动汽车的核心技术之一是电机驱动控制系统,而绝缘栅双极型晶体管(IGBT)作为电机驱动系统中的关键元件,其性能直接影响到电动汽车的动力性能和...

关键字: 电动汽车 新能源 驱动电源

在现代城市建设中,街道及停车场照明作为基础设施的重要组成部分,其质量和效率直接关系到城市的公共安全、居民生活质量和能源利用效率。随着科技的进步,高亮度白光发光二极管(LED)因其独特的优势逐渐取代传统光源,成为大功率区域...

关键字: 发光二极管 驱动电源 LED

LED通用照明设计工程师会遇到许多挑战,如功率密度、功率因数校正(PFC)、空间受限和可靠性等。

关键字: LED 驱动电源 功率因数校正

在LED照明技术日益普及的今天,LED驱动电源的电磁干扰(EMI)问题成为了一个不可忽视的挑战。电磁干扰不仅会影响LED灯具的正常工作,还可能对周围电子设备造成不利影响,甚至引发系统故障。因此,采取有效的硬件措施来解决L...

关键字: LED照明技术 电磁干扰 驱动电源

开关电源具有效率高的特性,而且开关电源的变压器体积比串联稳压型电源的要小得多,电源电路比较整洁,整机重量也有所下降,所以,现在的LED驱动电源

关键字: LED 驱动电源 开关电源

LED驱动电源是把电源供应转换为特定的电压电流以驱动LED发光的电压转换器,通常情况下:LED驱动电源的输入包括高压工频交流(即市电)、低压直流、高压直流、低压高频交流(如电子变压器的输出)等。

关键字: LED 隧道灯 驱动电源
关闭