c++写stm32 GPIO篇

大家好我是逸风,第一次写博客,此文给那些想提供一个具有入门视角,易上手的代码讲解。

#ifndef GPIO_H_
#define GPIO_H_

namespace stm32 {
               //作用域

	extern int log2(unsigned int value);
	/*
	以下是引脚分组,模式等的枚举类型,mask都是从
	官方库里复制粘贴的*/
	typedef enum {
   
        Port_A = 0x00,Port_B = 0x01,Port_C,Port_D,Port_E,Port_F,Port_G
    } Port;
    typedef enum {
   
        Pin_0 = 0x0001,
        Pin_1 = 0x0002,
        Pin_2 = 0x0004,     
        Pin_3 = 0x0008,
        Pin_4 = 0x0010,
        Pin_5 = 0x0020,
        Pin_6 = 0x0040,
        Pin_7 = 0x0080,
        Pin_8 = 0x0100,
        Pin_9 = 0x0200,
        Pin_10 = 0x0400,
        Pin_11 = 0x0800,
        Pin_12 = 0x1000,
        Pin_13 = 0x2000,
        Pin_14 = 0x4000,
        Pin_15 = 0x8000,
        Pin_Low8 = 0x00ff,
        Pin_High8 = 0xff00,
        Pin_All = 0xffff
    } Pin;

    typedef enum {
   
        J_Mode_Output_10MHz = 1,
        J_Mode_Output_2MHz,
        J_Mode_Output_50MHz
    } Mode;

    typedef enum {
   
        J_GPIO_Mode_AIN = 0x0,
				J_GPIO_Mode_IN_FLOATING = 0x04,
				J_GPIO_Mode_IPD = 0x28,
				J_GPIO_Mode_IPU = 0x48,
				J_GPIO_Mode_Out_OD = 0x14,
				J_GPIO_Mode_Out_PP = 0x10,
				J_GPIO_Mode_AF_OD = 0x1C,
				J_GPIO_Mode_AF_PP = 0x18
    } IOMode
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值