iocfg.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. *********************************************************************************************************
  3. * xmk guide
  4. *
  5. * (c) Copyright 2016-2020, hualijidian.com
  6. * All Rights Reserved
  7. *
  8. * @file iocfg.c
  9. * @author eric
  10. * @brief io define
  11. * @version V0.0.1
  12. *********************************************************************************************************
  13. */
  14. #ifndef __IOCFG_H
  15. #define __IOCFG_H
  16. #include "stdint.h"
  17. #include "stm32f4xx_hal.h"
  18. typedef struct {
  19. GPIO_TypeDef* GPIOx;
  20. uint16_t GPIO_Pin;
  21. } IO_PORT_TypeDef;
  22. //位带操作,实现51类似的GPIO控制功能
  23. //具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).M4同M3类似,只是寄存器地址变了.
  24. //IO口操作宏定义
  25. #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
  26. #define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
  27. #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
  28. //IO口地址映射
  29. #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014
  30. #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414
  31. #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814
  32. #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14
  33. #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014
  34. #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414
  35. #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814
  36. #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14
  37. #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014
  38. #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010
  39. #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410
  40. #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810
  41. #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10
  42. #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010
  43. #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410
  44. #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810
  45. #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10
  46. #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010
  47. //IO口操作,只对单一的IO口!
  48. //确保n的值小于16!
  49. #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
  50. #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入
  51. #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
  52. #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入
  53. #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
  54. #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入
  55. #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
  56. #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入
  57. #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
  58. #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入
  59. #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
  60. #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入
  61. #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
  62. #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入
  63. #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出
  64. #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入
  65. #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出
  66. #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入
  67. /*板载LED0*/
  68. #define LED0_GPRO GPIOB //判断acr运行灯
  69. #define LED0_PIN (GPIO_PIN_9)
  70. #define LED0 (PBout(9))
  71. /*LED1*/
  72. #define LED1_V1_GPRO GPIOD //没用到
  73. #define LED1_V1_PIN (GPIO_PIN_1)
  74. #define LED1_V1 (PDout(1))
  75. #define LED1_V2_GPRO GPIOD//没用到
  76. #define LED1_V2_PIN (GPIO_PIN_3)
  77. #define LED1_V2 (PDout(3))
  78. #define LED1_V3_GPRO GPIOD//没用到
  79. #define LED1_V3_PIN (GPIO_PIN_4)
  80. #define LED1_V3 (PDout(4))
  81. /*LED2*/
  82. #define LED2_V1_GPRO GPIOD//没用到
  83. #define LED2_V1_PIN (GPIO_PIN_7)
  84. #define LED2_V1 (PDout(7))
  85. #define LED2_V2_GPRO GPIOG//没用到
  86. #define LED2_V2_PIN (GPIO_PIN_9)
  87. #define LED2_V2 (PGout(9))
  88. #define LED2_V3_GPRO GPIOG//没用到
  89. #define LED2_V3_PIN (GPIO_PIN_10)
  90. #define LED2_V3 (PGout(10))
  91. /*SPK*/
  92. #define SPK_V1_GPRO GPIOA //用哪个
  93. #define SPK_V1_PIN (GPIO_PIN_15)
  94. #define SPK_V1 (PAout(15))
  95. #define SPK_V2_GPRO GPIOD
  96. #define SPK_V2_PIN (GPIO_PIN_0)
  97. #define SPK_V2 (PDout(0))
  98. /*RUN*/
  99. #define RUN_GPRO GPIOE //用到运行
  100. #define RUN_PIN (GPIO_PIN_6)
  101. #define IN_RUN (PEin(6))
  102. /*Button IN*/
  103. #define IN1_GPRO GPIOI
  104. #define IN1_PIN (GPIO_PIN_8)
  105. #define IN_REV (PIin(8))
  106. #define IN2_GPRO GPIOC
  107. #define IN2_PIN (GPIO_PIN_13)
  108. #define IN2 (PCin(13))
  109. #define IN3_GPRO GPIOI
  110. #define IN3_PIN (GPIO_PIN_9)
  111. #define IN3 (PIin(9))
  112. #define IN4_GPRO GPIOI
  113. #define IN4_PIN (GPIO_PIN_10)
  114. #define IN4 (PIin(10))
  115. #define IN5_GPRO GPIOI
  116. #define IN5_PIN (GPIO_PIN_11)
  117. #define IN5 (PIin(11))
  118. /*RMC*/
  119. #define RMC_IN1_GPRO GPIOF
  120. #define RMC_IN1_PIN (GPIO_PIN_0)
  121. #define RMC_IN1 (PFin(0))
  122. #define RMC_IN2_GPRO GPIOF
  123. #define RMC_IN2_PIN (GPIO_PIN_1)
  124. #define RMC_IN2 (PFin(1))
  125. #define RMC_IN3_GPRO GPIOF
  126. #define RMC_IN3_PIN (GPIO_PIN_2)
  127. #define RMC_IN3 (PFin(2))
  128. #define RMC_IN4_GPRO GPIOF
  129. #define RMC_IN4_PIN (GPIO_PIN_3)
  130. #define RMC_IN4 (PFin(3))
  131. #define RMC_IN5_GPRO GPIOF
  132. #define RMC_IN5_PIN (GPIO_PIN_4)
  133. #define RMC_IN5 (PFin(4))
  134. #define RMC_IN6_GPRO GPIOF
  135. #define RMC_IN6_PIN (GPIO_PIN_5)
  136. #define RMC_IN6 (PFin(5))
  137. #define RMC_IN7_GPRO GPIOF
  138. #define RMC_IN7_PIN (GPIO_PIN_8)
  139. #define RMC_IN7 (PFin(8))
  140. #define RMC_IN8_GPRO GPIOF
  141. #define RMC_IN8_PIN (GPIO_PIN_9)
  142. #define RMC_IN8 (PFin(9))
  143. #define RMC_IN9_GPRO GPIOF
  144. #define RMC_IN9_PIN (GPIO_PIN_10)
  145. #define RMC_IN9 (PFin(10))
  146. #define RMC_IN10_GPRO GPIOC
  147. #define RMC_IN10_PIN (GPIO_PIN_0)
  148. #define RMC_IN10 (PCin(0))
  149. #define RMC_IN11_GPRO GPIOC
  150. #define RMC_IN11_PIN (GPIO_PIN_2)
  151. #define RMC_IN11 (PCin(2))
  152. /*OBS1*/
  153. #define OBS1_IN1_GPRO GPIOI
  154. #define OBS1_IN1_PIN (GPIO_PIN_7)
  155. #define OBS1_IN1 (PIin(7))
  156. #define OBS1_IN2_GPRO GPIOE
  157. #define OBS1_IN2_PIN (GPIO_PIN_2)
  158. #define OBS1_IN2 (PEin(2))
  159. #define OBS1_IN3_GPRO GPIOE
  160. #define OBS1_IN3_PIN (GPIO_PIN_3)
  161. #define OBS1_IN3 (PEin(3))
  162. #define OBS1_IN4_GPRO GPIOE
  163. #define OBS1_IN4_PIN (GPIO_PIN_4)
  164. #define OBS1_IN4 (PEin(4))
  165. #define OBS1_OUT1_GPRO GPIOG
  166. #define OBS1_OUT1_PIN (GPIO_PIN_11)
  167. #define OBS1_OUT1 (PGout(11))
  168. #define OBS1_OUT2_GPRO GPIOG
  169. #define OBS1_OUT2_PIN (GPIO_PIN_12)
  170. #define OBS1_OUT2 (PGout(12))
  171. #define OBS1_OUT3_GPRO GPIOB
  172. #define OBS1_OUT3_PIN (GPIO_PIN_8)
  173. #define OBS1_OUT3 (PBout(8))
  174. #define OBS1_OUT4_GPRO GPIOG
  175. #define OBS1_OUT4_PIN (GPIO_PIN_15)
  176. #define OBS1_OUT4 (PGout(15))
  177. /*OBS2*/
  178. #define OBS2_IN1_GPRO GPIOC
  179. #define OBS2_IN1_PIN (GPIO_PIN_9)
  180. #define OBS2_IN1 (PCin(9))
  181. #define OBS2_IN2_GPRO GPIOC
  182. #define OBS2_IN2_PIN (GPIO_PIN_8)
  183. #define OBS2_IN2 (PCin(8))
  184. #define OBS2_IN3_GPRO GPIOG
  185. #define OBS2_IN3_PIN (GPIO_PIN_7)
  186. #define OBS2_IN3 (PGin(7))
  187. #define OBS2_IN4_GPRO GPIOG
  188. #define OBS2_IN4_PIN (GPIO_PIN_6)
  189. #define OBS2_IN4 (PGin(6))
  190. #define OBS2_OUT1_GPRO GPIOG
  191. #define OBS2_OUT1_PIN (GPIO_PIN_5)
  192. #define OBS2_OUT1 (PGout(5))
  193. #define OBS2_OUT2_GPRO GPIOG
  194. #define OBS2_OUT2_PIN (GPIO_PIN_4)
  195. #define OBS2_OUT2 (PGout(4))
  196. #define OBS2_OUT3_GPRO GPIOG
  197. #define OBS2_OUT3_PIN (GPIO_PIN_3)
  198. #define OBS2_OUT3 (PGout(3))
  199. #define OBS2_OUT4_GPRO GPIOG
  200. #define OBS2_OUT4_PIN (GPIO_PIN_2)
  201. #define OBS2_OUT4 (PGout(2))
  202. /*OBS3*/
  203. #define OBS3_IN1_GPRO GPIOB
  204. #define OBS3_IN1_PIN (GPIO_PIN_1)
  205. #define OBS3_IN1 (PBin(1))
  206. #define OBS3_IN2_GPRO GPIOF
  207. #define OBS3_IN2_PIN (GPIO_PIN_11)
  208. #define OBS3_IN2 (PFin(11))
  209. #define OBS3_IN3_GPRO GPIOF
  210. #define OBS3_IN3_PIN (GPIO_PIN_12)
  211. #define OBS3_IN3 (PFin(12))
  212. #define OBS3_IN4_GPRO GPIOF
  213. #define OBS3_IN4_PIN (GPIO_PIN_13)
  214. #define OBS3_IN4 (PFin(13))
  215. #define OBS3_OUT1_GPRO GPIOF
  216. #define OBS3_OUT1_PIN (GPIO_PIN_14)
  217. #define OBS3_OUT1 (PFout(14))
  218. #define OBS3_OUT2_GPRO GPIOF
  219. #define OBS3_OUT2_PIN (GPIO_PIN_15)
  220. #define OBS3_OUT2 (PFout(15))
  221. #define OBS3_OUT3_GPRO GPIOG
  222. #define OBS3_OUT3_PIN (GPIO_PIN_0)
  223. #define OBS3_OUT3 (PGout(0))
  224. #define OBS3_OUT4_GPRO GPIOG
  225. #define OBS3_OUT4_PIN (GPIO_PIN_1)
  226. #define OBS3_OUT4 (PGout(1))
  227. /*OBS4*/
  228. #define OBS4_IN1_GPRO GPIOE
  229. #define OBS4_IN1_PIN (GPIO_PIN_7)
  230. #define OBS4_IN1 (PEin(7))
  231. #define OBS4_IN2_GPRO GPIOE
  232. #define OBS4_IN2_PIN (GPIO_PIN_8)
  233. #define OBS4_IN2 (PEin(8))
  234. #define OBS4_IN3_GPRO GPIOE
  235. #define OBS4_IN3_PIN (GPIO_PIN_9)
  236. #define OBS4_IN3 (PEin(9))
  237. #define OBS4_IN4_GPRO GPIOE
  238. #define OBS4_IN4_PIN (GPIO_PIN_10)
  239. #define OBS4_IN4 (PEin(10))
  240. #define OBS4_OUT1_GPRO GPIOE
  241. #define OBS4_OUT1_PIN (GPIO_PIN_11)
  242. #define OBS4_OUT1 (PEout(11))
  243. #define OBS4_OUT2_GPRO GPIOE
  244. #define OBS4_OUT2_PIN (GPIO_PIN_12)
  245. #define OBS4_OUT2 (PEout(12))
  246. #define OBS4_OUT3_GPRO GPIOE
  247. #define OBS4_OUT3_PIN (GPIO_PIN_13)
  248. #define OBS4_OUT3 (PEout(13))
  249. #define OBS4_OUT4_GPRO GPIOE
  250. #define OBS4_OUT4_PIN (GPIO_PIN_14)
  251. #define OBS4_OUT4 (PEout(14))
  252. /*NPN Input-1*/
  253. #define NPN1_IN1_GPRO GPIOC
  254. #define NPN1_IN1_PIN (GPIO_PIN_3)
  255. #define NPN1_IN1 (PCin(3))
  256. #define NPN1_IN2_GPRO GPIOA
  257. #define NPN1_IN2_PIN (GPIO_PIN_0)
  258. #define NPN1_IN2 (PAin(0))
  259. #define NPN2_IN3_GPRO GPIOH
  260. #define NPN2_IN3_PIN (GPIO_PIN_2)
  261. #define NPN2_IN3 (PHin(2))
  262. #define NPN2_IN4_GPRO GPIOH
  263. #define NPN2_IN4_PIN (GPIO_PIN_3)
  264. #define NPN2_IN4 (PHin(3))
  265. #define NPN3_IN5_GPRO GPIOH
  266. #define NPN3_IN5_PIN (GPIO_PIN_4)
  267. #define NPN3_IN5 (PHin(4))
  268. #define NPN3_IN6_GPRO GPIOH
  269. #define NPN3_IN6_PIN (GPIO_PIN_5)
  270. #define NPN3_IN6 (PHin(5))
  271. /*NPN Input-2*/
  272. #define NPN4_IN7_GPRO GPIOA
  273. #define NPN4_IN7_PIN (GPIO_PIN_4)
  274. #define NPN4_IN7 (PAin(4))
  275. #define NPN4_IN8_GPRO GPIOA
  276. #define NPN4_IN8_PIN (GPIO_PIN_5)
  277. #define NPN4_IN8 (PAin(5))
  278. #define NPN5_IN9_GPRO GPIOA
  279. #define NPN5_IN9_PIN (GPIO_PIN_6)
  280. #define NPN5_IN9 (PAin(6))
  281. #define NPN5_IN10_GPRO GPIOB
  282. #define NPN5_IN10_PIN (GPIO_PIN_0)
  283. #define NPN5_IN10 (PBin(0))
  284. /*LIFT*/
  285. #define LIFT_V1_GPRO GPIOH
  286. #define LIFT_V1_PIN (GPIO_PIN_9)
  287. #define LIFT_V1 (PHout(9))
  288. #define LIFT_V2_GPRO GPIOH
  289. #define LIFT_V2_PIN (GPIO_PIN_10)
  290. #define LIFT_V2 (PHout(10))
  291. #define LIFT_V3_GPRO GPIOH
  292. #define LIFT_V3_PIN (GPIO_PIN_11)
  293. #define LIFT_V3 (PHout(11))
  294. #define LIFT_V4_GPRO GPIOH
  295. #define LIFT_V4_PIN (GPIO_PIN_12)
  296. #define LIFT_V4 (PHout(12))
  297. #define LIFT_V5_GPRO GPIOB
  298. #define LIFT_V5_PIN (GPIO_PIN_14)
  299. #define LIFT_V5 (PBout(14))
  300. #define LIFT_V6_GPRO GPIOB
  301. #define LIFT_V6_PIN (GPIO_PIN_15)
  302. #define LIFT_V6 (PBout(15))
  303. #define LIFT_V7_GPRO GPIOD
  304. #define LIFT_V7_PIN (GPIO_PIN_10)
  305. #define LIFT_V7 (PDout(10))
  306. #define LIFT_V8_GPRO GPIOD
  307. #define LIFT_V8_PIN (GPIO_PIN_11)
  308. #define LIFT_V8 (PDout(11))
  309. #define LIFT_V9_GPRO GPIOD
  310. #define LIFT_V9_PIN (GPIO_PIN_14)
  311. #define LIFT_V9 (PDout(14))
  312. #define LIFT_V10_GPRO GPIOD
  313. #define LIFT_V10_PIN (GPIO_PIN_15)
  314. #define LIFT_V10 (PDout(15))
  315. /*MOTOR-1*/
  316. #define MOTOR1_FR1_GPRO GPIOI
  317. #define MOTOR1_FR1_PIN (GPIO_PIN_4)
  318. #define MOTOR1_FR1 (PIout(4))
  319. #define MOTOR1_EN1_GPRO GPIOI
  320. #define MOTOR1_EN1_PIN (GPIO_PIN_5)
  321. #define MOTOR1_EN1 (PIout(5))
  322. #define MOTOR1_BK1_GPRO GPIOI
  323. #define MOTOR1_BK1_PIN (GPIO_PIN_6)
  324. #define MOTOR1_BK1 (PIout(6))
  325. #define MOTOR1_SV1_GPRO GPIOD
  326. #define MOTOR1_SV1_PIN (GPIO_PIN_13)
  327. #define MOTOR1_SV1 (PDin(13))
  328. #define MOTOR1_DET1_GPRO GPIOE
  329. #define MOTOR1_DET1_PIN (GPIO_PIN_5)
  330. #define MOTOR1_DET1 (PEin(5))
  331. /*MOTOR-2*/
  332. #define MOTOR2_FR2_GPRO GPIOE
  333. #define MOTOR2_FR2_PIN (GPIO_PIN_15)
  334. #define MOTOR2_FR2 (PEout(15))
  335. #define MOTOR2_EN2_GPRO GPIOH
  336. #define MOTOR2_EN2_PIN (GPIO_PIN_6)
  337. #define MOTOR2_EN2 (PHout(6))
  338. #define MOTOR2_BK2_GPRO GPIOH
  339. #define MOTOR2_BK2_PIN (GPIO_PIN_7)
  340. #define MOTOR2_BK2 (PHout(7))
  341. #define MOTOR1_SV2_GPRO GPIOD
  342. #define MOTOR1_SV2_PIN (GPIO_PIN_12)
  343. #define MOTOR1_SV2 (PDin(12))
  344. #define MOTOR2_DET2_GPRO GPIOH
  345. #define MOTOR2_DET2_PIN (GPIO_PIN_8)
  346. #define MOTOR2_DET2 (PHin(8))
  347. #define RS485_GPIO_OUT GPIOI
  348. #define RS485_PIN_OUT (GPIO_PIN_1)
  349. #define RS485_TX_EN PIout(1)
  350. #endif