My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

lpc17xx_pinsel.c 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /**********************************************************************
  2. * $Id$ lpc17xx_pinsel.c 2010-05-21
  3. *//**
  4. * @file lpc17xx_pinsel.c
  5. * @brief Contains all functions support for Pin connect block firmware
  6. * library on LPC17xx
  7. * @version 2.0
  8. * @date 21. May. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @addtogroup PINSEL
  34. * @{
  35. */
  36. /* Includes ------------------------------------------------------------------- */
  37. #include "lpc17xx_pinsel.h"
  38. /* Public Functions ----------------------------------------------------------- */
  39. static void set_PinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum);
  40. static void set_ResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum);
  41. static void set_OpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum);
  42. /*********************************************************************//**
  43. * @brief Setup the pin selection function
  44. * @param[in] portnum PORT number,
  45. * should be one of the following:
  46. * - PINSEL_PORT_0 : Port 0
  47. * - PINSEL_PORT_1 : Port 1
  48. * - PINSEL_PORT_2 : Port 2
  49. * - PINSEL_PORT_3 : Port 3
  50. *
  51. * @param[in] pinnum Pin number,
  52. * should be one of the following:
  53. - PINSEL_PIN_0 : Pin 0
  54. - PINSEL_PIN_1 : Pin 1
  55. - PINSEL_PIN_2 : Pin 2
  56. - PINSEL_PIN_3 : Pin 3
  57. - PINSEL_PIN_4 : Pin 4
  58. - PINSEL_PIN_5 : Pin 5
  59. - PINSEL_PIN_6 : Pin 6
  60. - PINSEL_PIN_7 : Pin 7
  61. - PINSEL_PIN_8 : Pin 8
  62. - PINSEL_PIN_9 : Pin 9
  63. - PINSEL_PIN_10 : Pin 10
  64. - PINSEL_PIN_11 : Pin 11
  65. - PINSEL_PIN_12 : Pin 12
  66. - PINSEL_PIN_13 : Pin 13
  67. - PINSEL_PIN_14 : Pin 14
  68. - PINSEL_PIN_15 : Pin 15
  69. - PINSEL_PIN_16 : Pin 16
  70. - PINSEL_PIN_17 : Pin 17
  71. - PINSEL_PIN_18 : Pin 18
  72. - PINSEL_PIN_19 : Pin 19
  73. - PINSEL_PIN_20 : Pin 20
  74. - PINSEL_PIN_21 : Pin 21
  75. - PINSEL_PIN_22 : Pin 22
  76. - PINSEL_PIN_23 : Pin 23
  77. - PINSEL_PIN_24 : Pin 24
  78. - PINSEL_PIN_25 : Pin 25
  79. - PINSEL_PIN_26 : Pin 26
  80. - PINSEL_PIN_27 : Pin 27
  81. - PINSEL_PIN_28 : Pin 28
  82. - PINSEL_PIN_29 : Pin 29
  83. - PINSEL_PIN_30 : Pin 30
  84. - PINSEL_PIN_31 : Pin 31
  85. * @param[in] funcnum Function number,
  86. * should be one of the following:
  87. * - PINSEL_FUNC_0 : default function
  88. * - PINSEL_FUNC_1 : first alternate function
  89. * - PINSEL_FUNC_2 : second alternate function
  90. * - PINSEL_FUNC_3 : third alternate function
  91. *
  92. * @return None
  93. **********************************************************************/
  94. static void set_PinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum)
  95. {
  96. uint32_t pinnum_t = pinnum;
  97. uint32_t pinselreg_idx = 2 * portnum;
  98. uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINSEL0;
  99. if (pinnum_t >= 16) {
  100. pinnum_t -= 16;
  101. pinselreg_idx++;
  102. }
  103. *(uint32_t *)(pPinCon + pinselreg_idx) &= ~(0x03UL << (pinnum_t * 2));
  104. *(uint32_t *)(pPinCon + pinselreg_idx) |= ((uint32_t)funcnum) << (pinnum_t * 2);
  105. }
  106. /*********************************************************************//**
  107. * @brief Setup resistor mode for each pin
  108. * @param[in] portnum PORT number,
  109. * should be one of the following:
  110. * - PINSEL_PORT_0 : Port 0
  111. * - PINSEL_PORT_1 : Port 1
  112. * - PINSEL_PORT_2 : Port 2
  113. * - PINSEL_PORT_3 : Port 3
  114. * @param[in] pinnum Pin number,
  115. * should be one of the following:
  116. - PINSEL_PIN_0 : Pin 0
  117. - PINSEL_PIN_1 : Pin 1
  118. - PINSEL_PIN_2 : Pin 2
  119. - PINSEL_PIN_3 : Pin 3
  120. - PINSEL_PIN_4 : Pin 4
  121. - PINSEL_PIN_5 : Pin 5
  122. - PINSEL_PIN_6 : Pin 6
  123. - PINSEL_PIN_7 : Pin 7
  124. - PINSEL_PIN_8 : Pin 8
  125. - PINSEL_PIN_9 : Pin 9
  126. - PINSEL_PIN_10 : Pin 10
  127. - PINSEL_PIN_11 : Pin 11
  128. - PINSEL_PIN_12 : Pin 12
  129. - PINSEL_PIN_13 : Pin 13
  130. - PINSEL_PIN_14 : Pin 14
  131. - PINSEL_PIN_15 : Pin 15
  132. - PINSEL_PIN_16 : Pin 16
  133. - PINSEL_PIN_17 : Pin 17
  134. - PINSEL_PIN_18 : Pin 18
  135. - PINSEL_PIN_19 : Pin 19
  136. - PINSEL_PIN_20 : Pin 20
  137. - PINSEL_PIN_21 : Pin 21
  138. - PINSEL_PIN_22 : Pin 22
  139. - PINSEL_PIN_23 : Pin 23
  140. - PINSEL_PIN_24 : Pin 24
  141. - PINSEL_PIN_25 : Pin 25
  142. - PINSEL_PIN_26 : Pin 26
  143. - PINSEL_PIN_27 : Pin 27
  144. - PINSEL_PIN_28 : Pin 28
  145. - PINSEL_PIN_29 : Pin 29
  146. - PINSEL_PIN_30 : Pin 30
  147. - PINSEL_PIN_31 : Pin 31
  148. * @param[in] modenum: Mode number,
  149. * should be one of the following:
  150. - PINSEL_PINMODE_PULLUP : Internal pull-up resistor
  151. - PINSEL_PINMODE_TRISTATE : Tri-state
  152. - PINSEL_PINMODE_PULLDOWN : Internal pull-down resistor
  153. * @return None
  154. **********************************************************************/
  155. void set_ResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum)
  156. {
  157. uint32_t pinnum_t = pinnum;
  158. uint32_t pinmodereg_idx = 2 * portnum;
  159. uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE0;
  160. if (pinnum_t >= 16) {
  161. pinnum_t -= 16;
  162. pinmodereg_idx++ ;
  163. }
  164. *(uint32_t *)(pPinCon + pinmodereg_idx) &= ~(0x03UL << (pinnum_t * 2));
  165. *(uint32_t *)(pPinCon + pinmodereg_idx) |= ((uint32_t)modenum) << (pinnum_t * 2);
  166. }
  167. /*********************************************************************//**
  168. * @brief Setup Open drain mode for each pin
  169. * @param[in] portnum PORT number,
  170. * should be one of the following:
  171. * - PINSEL_PORT_0 : Port 0
  172. * - PINSEL_PORT_1 : Port 1
  173. * - PINSEL_PORT_2 : Port 2
  174. * - PINSEL_PORT_3 : Port 3
  175. *
  176. * @param[in] pinnum Pin number,
  177. * should be one of the following:
  178. - PINSEL_PIN_0 : Pin 0
  179. - PINSEL_PIN_1 : Pin 1
  180. - PINSEL_PIN_2 : Pin 2
  181. - PINSEL_PIN_3 : Pin 3
  182. - PINSEL_PIN_4 : Pin 4
  183. - PINSEL_PIN_5 : Pin 5
  184. - PINSEL_PIN_6 : Pin 6
  185. - PINSEL_PIN_7 : Pin 7
  186. - PINSEL_PIN_8 : Pin 8
  187. - PINSEL_PIN_9 : Pin 9
  188. - PINSEL_PIN_10 : Pin 10
  189. - PINSEL_PIN_11 : Pin 11
  190. - PINSEL_PIN_12 : Pin 12
  191. - PINSEL_PIN_13 : Pin 13
  192. - PINSEL_PIN_14 : Pin 14
  193. - PINSEL_PIN_15 : Pin 15
  194. - PINSEL_PIN_16 : Pin 16
  195. - PINSEL_PIN_17 : Pin 17
  196. - PINSEL_PIN_18 : Pin 18
  197. - PINSEL_PIN_19 : Pin 19
  198. - PINSEL_PIN_20 : Pin 20
  199. - PINSEL_PIN_21 : Pin 21
  200. - PINSEL_PIN_22 : Pin 22
  201. - PINSEL_PIN_23 : Pin 23
  202. - PINSEL_PIN_24 : Pin 24
  203. - PINSEL_PIN_25 : Pin 25
  204. - PINSEL_PIN_26 : Pin 26
  205. - PINSEL_PIN_27 : Pin 27
  206. - PINSEL_PIN_28 : Pin 28
  207. - PINSEL_PIN_29 : Pin 29
  208. - PINSEL_PIN_30 : Pin 30
  209. - PINSEL_PIN_31 : Pin 31
  210. * @param[in] modenum Open drain mode number,
  211. * should be one of the following:
  212. * - PINSEL_PINMODE_NORMAL : Pin is in the normal (not open drain) mode
  213. * - PINSEL_PINMODE_OPENDRAIN : Pin is in the open drain mode
  214. *
  215. * @return None
  216. **********************************************************************/
  217. void set_OpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum)
  218. {
  219. uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE_OD0;
  220. if (modenum == PINSEL_PINMODE_OPENDRAIN){
  221. *(uint32_t *)(pPinCon + portnum) |= (0x01UL << pinnum);
  222. } else {
  223. *(uint32_t *)(pPinCon + portnum) &= ~(0x01UL << pinnum);
  224. }
  225. }
  226. /* End of Public Functions ---------------------------------------------------- */
  227. /* Public Functions ----------------------------------------------------------- */
  228. /** @addtogroup PINSEL_Public_Functions
  229. * @{
  230. */
  231. /*********************************************************************//**
  232. * @brief Configure trace function
  233. * @param[in] NewState State of the Trace function configuration,
  234. * should be one of the following:
  235. * - ENABLE : Enable Trace Function
  236. * - DISABLE : Disable Trace Function
  237. *
  238. * @return None
  239. **********************************************************************/
  240. void PINSEL_ConfigTraceFunc(FunctionalState NewState)
  241. {
  242. if (NewState == ENABLE) {
  243. LPC_PINCON->PINSEL10 |= (0x01UL << 3);
  244. } else if (NewState == DISABLE) {
  245. LPC_PINCON->PINSEL10 &= ~(0x01UL << 3);
  246. }
  247. }
  248. /*********************************************************************//**
  249. * @brief Setup I2C0 pins
  250. * @param[in] i2cPinMode I2C pin mode,
  251. * should be one of the following:
  252. * - PINSEL_I2C_Normal_Mode : The standard drive mode
  253. * - PINSEL_I2C_Fast_Mode : Fast Mode Plus drive mode
  254. *
  255. * @param[in] filterSlewRateEnable should be:
  256. * - ENABLE: Enable filter and slew rate.
  257. * - DISABLE: Disable filter and slew rate.
  258. *
  259. * @return None
  260. **********************************************************************/
  261. void PINSEL_SetI2C0Pins(uint8_t i2cPinMode, FunctionalState filterSlewRateEnable)
  262. {
  263. uint32_t regVal;
  264. if (i2cPinMode == PINSEL_I2C_Fast_Mode){
  265. regVal = PINSEL_I2CPADCFG_SCLDRV0 | PINSEL_I2CPADCFG_SDADRV0;
  266. }
  267. if (filterSlewRateEnable == DISABLE){
  268. regVal = PINSEL_I2CPADCFG_SCLI2C0 | PINSEL_I2CPADCFG_SDAI2C0;
  269. }
  270. LPC_PINCON->I2CPADCFG = regVal;
  271. }
  272. /*********************************************************************//**
  273. * @brief Configure Pin corresponding to specified parameters passed
  274. * in the PinCfg
  275. * @param[in] PinCfg Pointer to a PINSEL_CFG_Type structure
  276. * that contains the configuration information for the
  277. * specified pin.
  278. * @return None
  279. **********************************************************************/
  280. void PINSEL_ConfigPin(PINSEL_CFG_Type *PinCfg)
  281. {
  282. set_PinFunc(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Funcnum);
  283. set_ResistorMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Pinmode);
  284. set_OpenDrainMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->OpenDrain);
  285. }
  286. /**
  287. * @}
  288. */
  289. /**
  290. * @}
  291. */
  292. /* --------------------------------- End Of File ------------------------------ */