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

當前位置:首頁 > 單片機 > 單片機
[導(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)系本站刪除。
換一批
延伸閱讀

樹莓派,(英語:Raspberry Pi,簡寫為RPi,別名為RasPi / RPI)是為學習計算機編程教育而設(shè)計,只有信用卡大小的微型電腦,其系統(tǒng)基于Linux。隨著Windows 10 IoT的發(fā)布,用戶可以用上運行...

關(guān)鍵字: 樹莓派 gpio gpio編程

串行外設(shè)接口(SPI)是微控制器和外圍IC(如傳感器、ADC、DAC、移位寄存器、SRAM等)之間使用最廣泛的接口之一。本文先簡要說明SPI接口,然后介紹ADI公司支持SPI的模擬開關(guān)與多路轉(zhuǎn)換器,以及它們?nèi)绾螏椭鷾p少系...

關(guān)鍵字: gpio spi 串行外設(shè)接口

一、什么是GPIO? GPIO,英文全稱為General-Purpose IO ports,也就是通用IO口。嵌入式系統(tǒng)中常常有數(shù)量眾多,但是結(jié)構(gòu)卻比較簡單的外部設(shè)備/電路,對這些設(shè)備/電路有的需要C

關(guān)鍵字: gpio 通用io口

//**********************************************************************//************************************...

關(guān)鍵字: gpio STM32

GPIO(General Purpose I/O Ports)意思為通用輸入/輸出端口,通俗地說,就是一些引腳,可以通過它們輸出高低電平或者通過它們讀入引腳的狀態(tài)-是高電平或是低電平。 S3C2410共有117個I...

關(guān)鍵字: ARM gpio 硬件介紹

Ⅰ、寫在前面完事開頭難,只要肯努力;師傅領(lǐng)進門,修行看個人;當你看到本文,說明你是幸運的,作者接下來推出的一系列STM8S教程,將助你踏入STM8S的世界。本文是STM8S教程的開始,寫給剛?cè)腴TSTM8S的朋友。學習本文

關(guān)鍵字: gpio stm8s 基礎(chǔ)知識

以下是驅(qū)動的源碼。#includelinux/config.h//配置頭文件#includelinux/kernel.h//用于調(diào)用kmalloc和kfree#includelinux/sched.h//調(diào)度,進程睡眠,...

關(guān)鍵字: gpio mini2440 驅(qū)動led

一、API說明HAL庫一共包含如下6個IO操作函數(shù):1、讀取某個引腳的電平狀態(tài):HAL_GPIO_ReadPin()2、寫入某個引腳的電平狀態(tài):HAL_GPIO_WritePin()3、翻轉(zhuǎn)某個引腳的電平狀態(tài):HAL_G...

關(guān)鍵字: gpio LED STM32

GPIO作為常用個開關(guān)量控制信號,廣泛應(yīng)用于工業(yè)領(lǐng)域的數(shù)據(jù)采集和驅(qū)動控制。當GPIO配置為DI和DO時,干節(jié)點與濕節(jié)點設(shè)計規(guī)范是否一致呢?GPIO配置為DI采集時,隔離方案是選擇

關(guān)鍵字: gpio 電源技術(shù)解析

// PXn引腳的初始化// 輸出配置void GPIO_Init(void){PX_DDR |= 1

關(guān)鍵字: gpio stm8s 引腳功能
關(guān)閉
關(guān)閉