这几天看了下 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 .
*
******************************************************************************
*/
如何找到电源开关回路
物联网可能会威胁到互联网!
一文了解过电流脱扣器
三态门有哪三态_三态门有什么特点
关于信号发生器计量测试解决方案的介绍和应用
STM32F4 C++ 封装库 之 EXTI
加速安全IoT的部署
如何准确测试75 Ohm系统的信号
新型 Linux 病毒出炉 比传统恶意Linux 病毒更恶意
二极管用作收音机半波检波
压力传感器常见问题解答
利用I2C通信接口实现测温的设计方案
充电芯片烧毁竟是电池热插拔惹的祸?
MS2609—兼容全频段,全制式导航低噪声放大器,参数兼容CKRF3509
智能音箱战场诡谲 接下来的路要怎么走只能是八仙过海各显神通
阿里云提速了存储行业的进化
量子世界中的安全
BIM技术知识详解:实质 模型 数据交互
GB 50009-2012《建筑结构荷载规范》| 智慧灯杆国家标准文档免费下载
今年iPhone 12S系列或将搭载屏下ALS环境光传感器