| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- /**
- *********************************************************************************************************
- * xmk guide
- *
- * (c) Copyright 2016-2020, hualijidian.com
- * All Rights Reserved
- *
- * @file iocfg.c
- * @author eric
- * @brief io define
- * @version V0.0.1
- *********************************************************************************************************
- */
- #ifndef __IOCFG_H
- #define __IOCFG_H
- #include "stdint.h"
- #include "stm32f4xx_hal.h"
- typedef struct {
- GPIO_TypeDef* GPIOx;
- uint16_t GPIO_Pin;
- } IO_PORT_TypeDef;
- //位带操作,实现51类似的GPIO控制功能
- //具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).M4同M3类似,只是寄存器地址变了.
- //IO口操作宏定义
- #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
- #define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
- #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
- //IO口地址映射
- #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014
- #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414
- #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814
- #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14
- #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014
- #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414
- #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814
- #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14
- #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014
- #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010
- #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410
- #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810
- #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10
- #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010
- #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410
- #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810
- #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10
- #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010
- //IO口操作,只对单一的IO口!
- //确保n的值小于16!
- #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
- #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入
- #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
- #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入
- #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
- #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入
- #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
- #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入
- #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
- #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入
- #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
- #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入
- #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
- #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入
- #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出
- #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入
- #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出
- #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入
- /*板载LED0*/
- #define LED0_GPRO GPIOB //判断acr运行灯
- #define LED0_PIN (GPIO_PIN_9)
- #define LED0 (PBout(9))
- /*LED1*/
- #define LED1_V1_GPRO GPIOD //没用到
- #define LED1_V1_PIN (GPIO_PIN_1)
- #define LED1_V1 (PDout(1))
- #define LED1_V2_GPRO GPIOD//没用到
- #define LED1_V2_PIN (GPIO_PIN_3)
- #define LED1_V2 (PDout(3))
- #define LED1_V3_GPRO GPIOD//没用到
- #define LED1_V3_PIN (GPIO_PIN_4)
- #define LED1_V3 (PDout(4))
- /*LED2*/
- #define LED2_V1_GPRO GPIOD//没用到
- #define LED2_V1_PIN (GPIO_PIN_7)
- #define LED2_V1 (PDout(7))
- #define LED2_V2_GPRO GPIOG//没用到
- #define LED2_V2_PIN (GPIO_PIN_9)
- #define LED2_V2 (PGout(9))
- #define LED2_V3_GPRO GPIOG//没用到
- #define LED2_V3_PIN (GPIO_PIN_10)
- #define LED2_V3 (PGout(10))
- /*SPK*/
- #define SPK_V1_GPRO GPIOA //用哪个
- #define SPK_V1_PIN (GPIO_PIN_15)
- #define SPK_V1 (PAout(15))
- #define SPK_V2_GPRO GPIOD
- #define SPK_V2_PIN (GPIO_PIN_0)
- #define SPK_V2 (PDout(0))
- /*RUN*/
- #define RUN_GPRO GPIOE //用到运行
- #define RUN_PIN (GPIO_PIN_6)
- #define IN_RUN (PEin(6))
- /*Button IN*/
- #define IN1_GPRO GPIOI
- #define IN1_PIN (GPIO_PIN_8)
- #define IN_REV (PIin(8))
- #define IN2_GPRO GPIOC
- #define IN2_PIN (GPIO_PIN_13)
- #define IN2 (PCin(13))
- #define IN3_GPRO GPIOI
- #define IN3_PIN (GPIO_PIN_9)
- #define IN3 (PIin(9))
- #define IN4_GPRO GPIOI
- #define IN4_PIN (GPIO_PIN_10)
- #define IN4 (PIin(10))
- #define IN5_GPRO GPIOI
- #define IN5_PIN (GPIO_PIN_11)
- #define IN5 (PIin(11))
- /*RMC*/
- #define RMC_IN1_GPRO GPIOF
- #define RMC_IN1_PIN (GPIO_PIN_0)
- #define RMC_IN1 (PFin(0))
- #define RMC_IN2_GPRO GPIOF
- #define RMC_IN2_PIN (GPIO_PIN_1)
- #define RMC_IN2 (PFin(1))
- #define RMC_IN3_GPRO GPIOF
- #define RMC_IN3_PIN (GPIO_PIN_2)
- #define RMC_IN3 (PFin(2))
- #define RMC_IN4_GPRO GPIOF
- #define RMC_IN4_PIN (GPIO_PIN_3)
- #define RMC_IN4 (PFin(3))
- #define RMC_IN5_GPRO GPIOF
- #define RMC_IN5_PIN (GPIO_PIN_4)
- #define RMC_IN5 (PFin(4))
- #define RMC_IN6_GPRO GPIOF
- #define RMC_IN6_PIN (GPIO_PIN_5)
- #define RMC_IN6 (PFin(5))
- #define RMC_IN7_GPRO GPIOF
- #define RMC_IN7_PIN (GPIO_PIN_8)
- #define RMC_IN7 (PFin(8))
- #define RMC_IN8_GPRO GPIOF
- #define RMC_IN8_PIN (GPIO_PIN_9)
- #define RMC_IN8 (PFin(9))
- #define RMC_IN9_GPRO GPIOF
- #define RMC_IN9_PIN (GPIO_PIN_10)
- #define RMC_IN9 (PFin(10))
- #define RMC_IN10_GPRO GPIOC
- #define RMC_IN10_PIN (GPIO_PIN_0)
- #define RMC_IN10 (PCin(0))
- #define RMC_IN11_GPRO GPIOC
- #define RMC_IN11_PIN (GPIO_PIN_2)
- #define RMC_IN11 (PCin(2))
- /*OBS1*/
- #define OBS1_IN1_GPRO GPIOI
- #define OBS1_IN1_PIN (GPIO_PIN_7)
- #define OBS1_IN1 (PIin(7))
- #define OBS1_IN2_GPRO GPIOE
- #define OBS1_IN2_PIN (GPIO_PIN_2)
- #define OBS1_IN2 (PEin(2))
- #define OBS1_IN3_GPRO GPIOE
- #define OBS1_IN3_PIN (GPIO_PIN_3)
- #define OBS1_IN3 (PEin(3))
- #define OBS1_IN4_GPRO GPIOE
- #define OBS1_IN4_PIN (GPIO_PIN_4)
- #define OBS1_IN4 (PEin(4))
- #define OBS1_OUT1_GPRO GPIOG
- #define OBS1_OUT1_PIN (GPIO_PIN_11)
- #define OBS1_OUT1 (PGout(11))
- #define OBS1_OUT2_GPRO GPIOG
- #define OBS1_OUT2_PIN (GPIO_PIN_12)
- #define OBS1_OUT2 (PGout(12))
- #define OBS1_OUT3_GPRO GPIOB
- #define OBS1_OUT3_PIN (GPIO_PIN_8)
- #define OBS1_OUT3 (PBout(8))
- #define OBS1_OUT4_GPRO GPIOG
- #define OBS1_OUT4_PIN (GPIO_PIN_15)
- #define OBS1_OUT4 (PGout(15))
- /*OBS2*/
- #define OBS2_IN1_GPRO GPIOC
- #define OBS2_IN1_PIN (GPIO_PIN_9)
- #define OBS2_IN1 (PCin(9))
- #define OBS2_IN2_GPRO GPIOC
- #define OBS2_IN2_PIN (GPIO_PIN_8)
- #define OBS2_IN2 (PCin(8))
- #define OBS2_IN3_GPRO GPIOG
- #define OBS2_IN3_PIN (GPIO_PIN_7)
- #define OBS2_IN3 (PGin(7))
- #define OBS2_IN4_GPRO GPIOG
- #define OBS2_IN4_PIN (GPIO_PIN_6)
- #define OBS2_IN4 (PGin(6))
- #define OBS2_OUT1_GPRO GPIOG
- #define OBS2_OUT1_PIN (GPIO_PIN_5)
- #define OBS2_OUT1 (PGout(5))
- #define OBS2_OUT2_GPRO GPIOG
- #define OBS2_OUT2_PIN (GPIO_PIN_4)
- #define OBS2_OUT2 (PGout(4))
- #define OBS2_OUT3_GPRO GPIOG
- #define OBS2_OUT3_PIN (GPIO_PIN_3)
- #define OBS2_OUT3 (PGout(3))
- #define OBS2_OUT4_GPRO GPIOG
- #define OBS2_OUT4_PIN (GPIO_PIN_2)
- #define OBS2_OUT4 (PGout(2))
- /*OBS3*/
- #define OBS3_IN1_GPRO GPIOB
- #define OBS3_IN1_PIN (GPIO_PIN_1)
- #define OBS3_IN1 (PBin(1))
- #define OBS3_IN2_GPRO GPIOF
- #define OBS3_IN2_PIN (GPIO_PIN_11)
- #define OBS3_IN2 (PFin(11))
- #define OBS3_IN3_GPRO GPIOF
- #define OBS3_IN3_PIN (GPIO_PIN_12)
- #define OBS3_IN3 (PFin(12))
- #define OBS3_IN4_GPRO GPIOF
- #define OBS3_IN4_PIN (GPIO_PIN_13)
- #define OBS3_IN4 (PFin(13))
- #define OBS3_OUT1_GPRO GPIOF
- #define OBS3_OUT1_PIN (GPIO_PIN_14)
- #define OBS3_OUT1 (PFout(14))
- #define OBS3_OUT2_GPRO GPIOF
- #define OBS3_OUT2_PIN (GPIO_PIN_15)
- #define OBS3_OUT2 (PFout(15))
- #define OBS3_OUT3_GPRO GPIOG
- #define OBS3_OUT3_PIN (GPIO_PIN_0)
- #define OBS3_OUT3 (PGout(0))
- #define OBS3_OUT4_GPRO GPIOG
- #define OBS3_OUT4_PIN (GPIO_PIN_1)
- #define OBS3_OUT4 (PGout(1))
- /*OBS4*/
- #define OBS4_IN1_GPRO GPIOE
- #define OBS4_IN1_PIN (GPIO_PIN_7)
- #define OBS4_IN1 (PEin(7))
- #define OBS4_IN2_GPRO GPIOE
- #define OBS4_IN2_PIN (GPIO_PIN_8)
- #define OBS4_IN2 (PEin(8))
- #define OBS4_IN3_GPRO GPIOE
- #define OBS4_IN3_PIN (GPIO_PIN_9)
- #define OBS4_IN3 (PEin(9))
- #define OBS4_IN4_GPRO GPIOE
- #define OBS4_IN4_PIN (GPIO_PIN_10)
- #define OBS4_IN4 (PEin(10))
- #define OBS4_OUT1_GPRO GPIOE
- #define OBS4_OUT1_PIN (GPIO_PIN_11)
- #define OBS4_OUT1 (PEout(11))
- #define OBS4_OUT2_GPRO GPIOE
- #define OBS4_OUT2_PIN (GPIO_PIN_12)
- #define OBS4_OUT2 (PEout(12))
- #define OBS4_OUT3_GPRO GPIOE
- #define OBS4_OUT3_PIN (GPIO_PIN_13)
- #define OBS4_OUT3 (PEout(13))
- #define OBS4_OUT4_GPRO GPIOE
- #define OBS4_OUT4_PIN (GPIO_PIN_14)
- #define OBS4_OUT4 (PEout(14))
- /*NPN Input-1*/
- #define NPN1_IN1_GPRO GPIOC
- #define NPN1_IN1_PIN (GPIO_PIN_3)
- #define NPN1_IN1 (PCin(3))
- #define NPN1_IN2_GPRO GPIOA
- #define NPN1_IN2_PIN (GPIO_PIN_0)
- #define NPN1_IN2 (PAin(0))
- #define NPN2_IN3_GPRO GPIOH
- #define NPN2_IN3_PIN (GPIO_PIN_2)
- #define NPN2_IN3 (PHin(2))
- #define NPN2_IN4_GPRO GPIOH
- #define NPN2_IN4_PIN (GPIO_PIN_3)
- #define NPN2_IN4 (PHin(3))
- #define NPN3_IN5_GPRO GPIOH
- #define NPN3_IN5_PIN (GPIO_PIN_4)
- #define NPN3_IN5 (PHin(4))
- #define NPN3_IN6_GPRO GPIOH
- #define NPN3_IN6_PIN (GPIO_PIN_5)
- #define NPN3_IN6 (PHin(5))
- /*NPN Input-2*/
- #define NPN4_IN7_GPRO GPIOA
- #define NPN4_IN7_PIN (GPIO_PIN_4)
- #define NPN4_IN7 (PAin(4))
- #define NPN4_IN8_GPRO GPIOA
- #define NPN4_IN8_PIN (GPIO_PIN_5)
- #define NPN4_IN8 (PAin(5))
- #define NPN5_IN9_GPRO GPIOA
- #define NPN5_IN9_PIN (GPIO_PIN_6)
- #define NPN5_IN9 (PAin(6))
- #define NPN5_IN10_GPRO GPIOB
- #define NPN5_IN10_PIN (GPIO_PIN_0)
- #define NPN5_IN10 (PBin(0))
- /*LIFT*/
- #define LIFT_V1_GPRO GPIOH
- #define LIFT_V1_PIN (GPIO_PIN_9)
- #define LIFT_V1 (PHout(9))
- #define LIFT_V2_GPRO GPIOH
- #define LIFT_V2_PIN (GPIO_PIN_10)
- #define LIFT_V2 (PHout(10))
- #define LIFT_V3_GPRO GPIOH
- #define LIFT_V3_PIN (GPIO_PIN_11)
- #define LIFT_V3 (PHout(11))
- #define LIFT_V4_GPRO GPIOH
- #define LIFT_V4_PIN (GPIO_PIN_12)
- #define LIFT_V4 (PHout(12))
- #define LIFT_V5_GPRO GPIOB
- #define LIFT_V5_PIN (GPIO_PIN_14)
- #define LIFT_V5 (PBout(14))
- #define LIFT_V6_GPRO GPIOB
- #define LIFT_V6_PIN (GPIO_PIN_15)
- #define LIFT_V6 (PBout(15))
- #define LIFT_V7_GPRO GPIOD
- #define LIFT_V7_PIN (GPIO_PIN_10)
- #define LIFT_V7 (PDout(10))
- #define LIFT_V8_GPRO GPIOD
- #define LIFT_V8_PIN (GPIO_PIN_11)
- #define LIFT_V8 (PDout(11))
- #define LIFT_V9_GPRO GPIOD
- #define LIFT_V9_PIN (GPIO_PIN_14)
- #define LIFT_V9 (PDout(14))
- #define LIFT_V10_GPRO GPIOD
- #define LIFT_V10_PIN (GPIO_PIN_15)
- #define LIFT_V10 (PDout(15))
- /*MOTOR-1*/
- #define MOTOR1_FR1_GPRO GPIOI
- #define MOTOR1_FR1_PIN (GPIO_PIN_4)
- #define MOTOR1_FR1 (PIout(4))
- #define MOTOR1_EN1_GPRO GPIOI
- #define MOTOR1_EN1_PIN (GPIO_PIN_5)
- #define MOTOR1_EN1 (PIout(5))
- #define MOTOR1_BK1_GPRO GPIOI
- #define MOTOR1_BK1_PIN (GPIO_PIN_6)
- #define MOTOR1_BK1 (PIout(6))
- #define MOTOR1_SV1_GPRO GPIOD
- #define MOTOR1_SV1_PIN (GPIO_PIN_13)
- #define MOTOR1_SV1 (PDin(13))
- #define MOTOR1_DET1_GPRO GPIOE
- #define MOTOR1_DET1_PIN (GPIO_PIN_5)
- #define MOTOR1_DET1 (PEin(5))
- /*MOTOR-2*/
- #define MOTOR2_FR2_GPRO GPIOE
- #define MOTOR2_FR2_PIN (GPIO_PIN_15)
- #define MOTOR2_FR2 (PEout(15))
- #define MOTOR2_EN2_GPRO GPIOH
- #define MOTOR2_EN2_PIN (GPIO_PIN_6)
- #define MOTOR2_EN2 (PHout(6))
- #define MOTOR2_BK2_GPRO GPIOH
- #define MOTOR2_BK2_PIN (GPIO_PIN_7)
- #define MOTOR2_BK2 (PHout(7))
- #define MOTOR1_SV2_GPRO GPIOD
- #define MOTOR1_SV2_PIN (GPIO_PIN_12)
- #define MOTOR1_SV2 (PDin(12))
- #define MOTOR2_DET2_GPRO GPIOH
- #define MOTOR2_DET2_PIN (GPIO_PIN_8)
- #define MOTOR2_DET2 (PHin(8))
- #define RS485_GPIO_OUT GPIOI
- #define RS485_PIN_OUT (GPIO_PIN_1)
- #define RS485_TX_EN PIout(1)
- #endif
|