www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀] 一直有一個想法就是用 C++ 去做 STM32 的開發(fā),但是很少有這方面的資料。經(jīng)過一段時間的思考,決定在官方的 ll 庫的基礎(chǔ)上做一層 C++ 的簡單封裝。因為官方的庫基本實現(xiàn)了全系列的 MCU 都是相同的 API

一直有一個想法就是用 C++ 去做 STM32 的開發(fā),但是很少有這方面的資料。經(jīng)過一段時間的思考,決定在官方的 ll 庫的基礎(chǔ)上做一層 C++ 的簡單封裝。因為官方的庫基本實現(xiàn)了全系列的 MCU 都是相同的 API 接口,所以 C++ 封裝后的庫也有很好的移植性。原理性的東西就不講理了,直接上代碼。

stm32f4xx_xgpio.h 文件

/**

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

* file stm32f4xx_xgpio.h

* author XinLi

* version v1.0

* date 20-March-2018

* brief Header file for general purpose I/O 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_XGPIO_H

#define STM32F4XX_XGPIO_H

#include

#include "stm32f4xx_ll_gpio.h"

/*! General purpose I/O module. */

class XGpio

{

public:

/*! Enumerate GPIO ports. */

enum GpioPort

{

PortA = (uint32_t)GPIOA, /*!< GPIO port A. */

PortB = (uint32_t)GPIOB, /*!< GPIO port B. */

PortC = (uint32_t)GPIOC, /*!< GPIO port C. */

#ifdef GPIOD

PortD = (uint32_t)GPIOD, /*!< GPIO port D. */

#endif // GPIOD

#ifdef GPIOE

PortE = (uint32_t)GPIOE, /*!< GPIO port E. */

#endif // GPIOE

#ifdef GPIOF

PortF = (uint32_t)GPIOF, /*!< GPIO port F. */

#endif // GPIOF

#ifdef GPIOG

PortG = (uint32_t)GPIOG, /*!< GPIO port G. */

#endif // GPIOG

#ifdef GPIOH

PortH = (uint32_t)GPIOH, /*!< GPIO port H. */

#endif // GPIOH

#ifdef GPIOI

PortI = (uint32_t)GPIOI, /*!< GPIO port I. */

#endif // GPIOI

#ifdef GPIOJ

PortJ = (uint32_t)GPIOJ, /*!< GPIO port J. */

#endif // GPIOJ

#ifdef GPIOK

PortK = (uint32_t)GPIOK, /*!< GPIO port K. */

#endif // GPIOK

};

/*! Enumeration of GPIO pins. */

enum GpioPin

{

Pin0 = LL_GPIO_PIN_0, /*!< GPIO pin 0. */

Pin1 = LL_GPIO_PIN_1, /*!< GPIO pin 1. */

Pin2 = LL_GPIO_PIN_2, /*!< GPIO pin 2. */

Pin3 = LL_GPIO_PIN_3, /*!< GPIO pin 3. */

Pin4 = LL_GPIO_PIN_4, /*!< GPIO pin 4. */

Pin5 = LL_GPIO_PIN_5, /*!< GPIO pin 5. */

Pin6 = LL_GPIO_PIN_6, /*!< GPIO pin 6. */

Pin7 = LL_GPIO_PIN_7, /*!< GPIO pin 7. */

Pin8 = LL_GPIO_PIN_8, /*!< GPIO pin 8. */

Pin9 = LL_GPIO_PIN_9, /*!< GPIO pin 9. */

Pin10 = LL_GPIO_PIN_10, /*!< GPIO pin 10. */

Pin11 = LL_GPIO_PIN_11, /*!< GPIO pin 11. */

Pin12 = LL_GPIO_PIN_12, /*!< GPIO pin 12. */

Pin13 = LL_GPIO_PIN_13, /*!< GPIO pin 13. */

Pin14 = LL_GPIO_PIN_14, /*!< GPIO pin 14. */

Pin15 = LL_GPIO_PIN_15, /*!< GPIO pin 15. */

};

/*! Enumeration of GPIO modes. */

enum GpioMode

{

ModeInput = LL_GPIO_MODE_INPUT, /*!< GPIO input mode. */

ModeOutput = LL_GPIO_MODE_OUTPUT, /*!< GPIO output mode. */

ModeAlternate = LL_GPIO_MODE_ALTERNATE, /*!< GPIO alternate function mode. */

ModeAnalog = LL_GPIO_MODE_ANALOG, /*!< GPIO analog mode. */

};

/*! Enumeration of GPIO output types. */

enum GpioOutput

{

OutputPushPull = LL_GPIO_OUTPUT_PUSHPULL, /*!< GPIO push-pull output. */

OutputOpenDrain = LL_GPIO_OUTPUT_OPENDRAIN, /*!< GPIO open-drain output. */

};

/*! Enumeration of GPIO output speeds. */

enum GpioSpeed

{

SpeedLow = LL_GPIO_SPEED_FREQ_LOW, /*!< GPIO low output speed. */

SpeedMedium = LL_GPIO_SPEED_FREQ_MEDIUM, /*!< GPIO medium output speed. */

SpeedHigh = LL_GPIO_SPEED_FREQ_HIGH, /*!< GPIO high output speed. */

SpeedVeryHigh = LL_GPIO_SPEED_FREQ_VERY_HIGH, /*!< GPIO very high output speed. */

};

/*! Enumeration of GPIO pull-up/pull-down. */

enum GpioPull

{

PullNo = LL_GPIO_PULL_NO, /*!< GPIO no pull. */

PullUp = LL_GPIO_PULL_UP, /*!< GPIO pull-up. */

PullDown = LL_GPIO_PULL_DOWN, /*!< GPIO pull-down. */

};

/*! Enumeration of GPIO alternate functions. */

enum GpioAlternate

{

Alternate0 = LL_GPIO_AF_0, /*!< GPIO alternate function 0. */

Alternate1 = LL_GPIO_AF_1, /*!< GPIO alternate function 1. */

Alternate2 = LL_GPIO_AF_2, /*!< GPIO alternate function 2. */

Alternate3 = LL_GPIO_AF_3, /*!< GPIO alternate function 3. */

Alternate4 = LL_GPIO_AF_4, /*!< GPIO alternate function 4. */

Alternate5 = LL_GPIO_AF_5, /*!< GPIO alternate function 5. */

Alternate6 = LL_GPIO_AF_6, /*!< GPIO alternate function 6. */

Alternate7 = LL_GPIO_AF_7, /*!< GPIO alternate function 7. */

Alternate8 = LL_GPIO_AF_8, /*!< GPIO alternate function 8. */

Alternate9 = LL_GPIO_AF_9, /*!< GPIO alternate function 9. */

Alternate10 = LL_GPIO_AF_10, /*!< GPIO alternate function 10. */

Alternate11 = LL_GPIO_AF_11, /*!< GPIO alternate function 11. */

Alternate12 = LL_GPIO_AF_12, /*!< GPIO alternate function 12. */

Alternate13 = LL_GPIO_AF_13, /*!< GPIO alternate function 13. */

Alternate14 = LL_GPIO_AF_14, /*!< GPIO alternate function 14. */

Alternate15 = LL_GPIO_AF_15, /*!< GPIO alternate function 15. */

};

/*! Enumeration of GPIO levels. */

enum GpioLevel

{

LevelLow = 0, /*!< GPIO low level. */

LevelHigh = 1, /*!< GPIO high level. */

};

XGpio(GpioPort port, GpioPin pin, GpioMode mode = ModeInput);

virtual ~XGpio();

void setPort(GpioPort port);

GpioPort getPort() const;

void setPin(GpioPin pin);

GpioPin getPin() const;

void setMode(GpioMode mode);

GpioMode getMode() const;

void setOutput(GpioOutput output);

GpioOutput getOutput() const;

void setSpeed(GpioSpeed speed);

GpioSpeed getSpeed() const;

void setPull(GpioPull pull);

GpioPull getPull() const;

void setAlternate(GpioAlternate alternate);

GpioAlternate getAlternate() const;

void setLevel(GpioLevel level);

GpioLevel getLevel();

void toggle();

bool open();

void close();

bool isOpen() const;

private:

GpioPort port;

GpioPin pin;

GpioMode mode;

GpioOutput output;

GpioSpeed speed;

GpioPull pull;

GpioAlter

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫毥谦F公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險,如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術(shù)學(xué)會聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(shù)(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉