stm322xg_eval.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. /**
  2. ******************************************************************************
  3. * @file stm322xg_eval.c
  4. * @author MCD Application Team
  5. * @brief This file provides a set of firmware functions to manage LEDs,
  6. * push-buttons and COM ports available on STM322xG-EVAL evaluation
  7. * board(MB786) RevB from STMicroelectronics.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* File Info: ------------------------------------------------------------------
  38. User NOTE
  39. This driver requires the stm322xg_eval_io.c driver to manage the joystick
  40. ------------------------------------------------------------------------------*/
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm322xg_eval.h"
  43. #include "stm322xg_eval_io.h"
  44. /** @defgroup BSP BSP
  45. * @{
  46. */
  47. /** @defgroup STM322xG_EVAL STM322xG_EVAL
  48. * @{
  49. */
  50. /** @defgroup STM322xG_EVAL_LOW_LEVEL STM322xG EVAL LOW LEVEL
  51. * @{
  52. */
  53. /** @defgroup STM322xG_EVAL_LOW_LEVEL_Private_TypesDefinitions STM322xG EVAL LOW LEVEL Private TypesDefinitions
  54. * @{
  55. */
  56. typedef struct
  57. {
  58. __IO uint16_t REG;
  59. __IO uint16_t RAM;
  60. }LCD_CONTROLLER_TypeDef;
  61. /**
  62. * @}
  63. */
  64. /** @defgroup STM322xG_EVAL_LOW_LEVEL_Private_Defines STM322xG EVAL LOW LEVEL Private Defines
  65. * @{
  66. */
  67. /**
  68. * @brief STM322xG EVAL BSP Driver version number V7.0.1
  69. */
  70. #define __STM322xG_EVAL_BSP_VERSION_MAIN (0x07) /*!< [31:24] main version */
  71. #define __STM322xG_EVAL_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
  72. #define __STM322xG_EVAL_BSP_VERSION_SUB2 (0x01) /*!< [15:8] sub2 version */
  73. #define __STM322xG_EVAL_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
  74. #define __STM322xG_EVAL_BSP_VERSION ((__STM322xG_EVAL_BSP_VERSION_MAIN << 24)\
  75. |(__STM322xG_EVAL_BSP_VERSION_SUB1 << 16)\
  76. |(__STM322xG_EVAL_BSP_VERSION_SUB2 << 8 )\
  77. |(__STM322xG_EVAL_BSP_VERSION_RC))
  78. #define FSMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000))
  79. #define FSMC_BANK3 ((LCD_CONTROLLER_TypeDef *) FSMC_BANK3_BASE)
  80. #define I2C_TIMEOUT 100 /*<! Value of Timeout when I2C communication fails */
  81. /**
  82. * @}
  83. */
  84. /** @defgroup STM322xG_EVAL_LOW_LEVEL_Private_Variables STM322xG EVAL LOW LEVEL Private Variables
  85. * @{
  86. */
  87. GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT,
  88. LED2_GPIO_PORT,
  89. LED3_GPIO_PORT,
  90. LED4_GPIO_PORT};
  91. const uint16_t GPIO_PIN[LEDn] = {LED1_PIN,
  92. LED2_PIN,
  93. LED3_PIN,
  94. LED4_PIN};
  95. GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT,
  96. TAMPER_BUTTON_GPIO_PORT,
  97. KEY_BUTTON_GPIO_PORT};
  98. const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN,
  99. TAMPER_BUTTON_PIN,
  100. KEY_BUTTON_PIN};
  101. const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn,
  102. TAMPER_BUTTON_EXTI_IRQn,
  103. KEY_BUTTON_EXTI_IRQn};
  104. USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
  105. GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
  106. GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
  107. const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
  108. const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
  109. const uint16_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
  110. const uint16_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
  111. I2C_HandleTypeDef heval_I2c;
  112. static ADC_HandleTypeDef hEvalADC;
  113. static uint8_t Is_LCD_IO_Initialized = 0;
  114. /**
  115. * @}
  116. */
  117. /** @defgroup STM322xG_EVAL_LOW_LEVEL_Private_FunctionPrototypes STM322xG EVAL LOW LEVEL Private FunctionPrototypes
  118. * @{
  119. */
  120. static void I2Cx_Init(void);
  121. static void I2Cx_ITConfig(void);
  122. static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
  123. static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg);
  124. static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length);
  125. static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length);
  126. static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
  127. static void I2Cx_Error(uint8_t Addr);
  128. static void I2Cx_MspInit(void);
  129. static void FSMC_BANK3_WriteData(uint16_t Data);
  130. static void FSMC_BANK3_WriteReg(uint8_t Reg);
  131. static uint16_t FSMC_BANK3_ReadData(void);
  132. static void FSMC_BANK3_Init(void);
  133. static void FSMC_BANK3_MspInit(void);
  134. /* IOExpander IO functions */
  135. void IOE_Init(void);
  136. void IOE_ITConfig(void);
  137. void IOE_Delay(uint32_t Delay);
  138. void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
  139. uint8_t IOE_Read(uint8_t Addr, uint8_t Reg);
  140. uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
  141. /* LCD IO functions */
  142. void LCD_IO_Init(void);
  143. void LCD_IO_WriteData(uint16_t Data);
  144. void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
  145. void LCD_IO_WriteReg(uint8_t Reg);
  146. uint16_t LCD_IO_ReadData(uint16_t Reg);
  147. /* AUDIO IO functions */
  148. void AUDIO_IO_Init(void);
  149. void AUDIO_IO_DeInit(void);
  150. void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
  151. uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
  152. /* Camera IO functions */
  153. void CAMERA_IO_Init(void);
  154. void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
  155. uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg);
  156. void CAMERA_Delay(uint32_t Delay);
  157. /* I2C EEPROM IO function */
  158. void EEPROM_IO_Init(void);
  159. HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
  160. HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
  161. HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
  162. /**
  163. * @}
  164. */
  165. /** @defgroup STM322xG_EVAL_LOW_LEVEL_Private_Functions STM322xG EVAL LOW LEVEL Private Functions
  166. * @{
  167. */
  168. /**
  169. * @brief This method returns the STM322xG EVAL BSP Driver revision
  170. * @retval version: 0xXYZR (8bits for each decimal, R for RC)
  171. */
  172. uint32_t BSP_GetVersion(void)
  173. {
  174. return __STM322xG_EVAL_BSP_VERSION;
  175. }
  176. /**
  177. * @brief Configures LED GPIO.
  178. * @param Led: LED to be configured.
  179. * This parameter can be one of the following values:
  180. * @arg LED1
  181. * @arg LED2
  182. * @arg LED3
  183. * @arg LED4
  184. * @retval None
  185. */
  186. void BSP_LED_Init(Led_TypeDef Led)
  187. {
  188. GPIO_InitTypeDef GPIO_InitStruct;
  189. /* Enable the GPIO_LED clock */
  190. LEDx_GPIO_CLK_ENABLE(Led);
  191. /* Configure the GPIO_LED pin */
  192. GPIO_InitStruct.Pin = GPIO_PIN[Led];
  193. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  194. GPIO_InitStruct.Pull = GPIO_PULLUP;
  195. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  196. HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
  197. }
  198. /**
  199. * @brief Turns selected LED On.
  200. * @param Led: LED to be set on
  201. * This parameter can be one of the following values:
  202. * @arg LED1
  203. * @arg LED2
  204. * @arg LED3
  205. * @arg LED4
  206. */
  207. void BSP_LED_On(Led_TypeDef Led)
  208. {
  209. HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
  210. }
  211. /**
  212. * @brief Turns selected LED Off.
  213. * @param Led: LED to be set off
  214. * This parameter can be one of the following values:
  215. * @arg LED1
  216. * @arg LED2
  217. * @arg LED3
  218. * @arg LED4
  219. */
  220. void BSP_LED_Off(Led_TypeDef Led)
  221. {
  222. HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
  223. }
  224. /**
  225. * @brief Toggles the selected LED.
  226. * @param Led: LED to be toggled
  227. * This parameter can be one of the following values:
  228. * @arg LED1
  229. * @arg LED2
  230. * @arg LED3
  231. * @arg LED4
  232. */
  233. void BSP_LED_Toggle(Led_TypeDef Led)
  234. {
  235. HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
  236. }
  237. /**
  238. * @brief Configures button GPIO and EXTI Line.
  239. * @param Button: Button to be configured
  240. * This parameter can be one of the following values:
  241. * @arg BUTTON_WAKEUP: Wakeup Push Button
  242. * @arg BUTTON_TAMPER: Tamper Push Button
  243. * @arg BUTTON_KEY: Key Push Button
  244. * @arg BUTTON_RIGHT: Joystick Right Push Button
  245. * @arg BUTTON_LEFT: Joystick Left Push Button
  246. * @arg BUTTON_UP: Joystick Up Push Button
  247. * @arg BUTTON_DOWN: Joystick Down Push Button
  248. * @arg BUTTON_SEL: Joystick Sel Push Button
  249. * @param Button_Mode: Button mode
  250. * This parameter can be one of the following values:
  251. * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
  252. * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
  253. * with interrupt generation capability
  254. */
  255. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
  256. {
  257. GPIO_InitTypeDef GPIO_InitStruct;
  258. /* Enable the BUTTON clock */
  259. BUTTONx_GPIO_CLK_ENABLE(Button);
  260. if(Button_Mode == BUTTON_MODE_GPIO)
  261. {
  262. /* Configure Button pin as input */
  263. GPIO_InitStruct.Pin = BUTTON_PIN[Button];
  264. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  265. GPIO_InitStruct.Pull = GPIO_NOPULL;
  266. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  267. HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
  268. }
  269. if(Button_Mode == BUTTON_MODE_EXTI)
  270. {
  271. /* Configure Button pin as input with External interrupt */
  272. GPIO_InitStruct.Pin = BUTTON_PIN[Button];
  273. GPIO_InitStruct.Pull = GPIO_NOPULL;
  274. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  275. if(Button != BUTTON_WAKEUP)
  276. {
  277. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  278. }
  279. else
  280. {
  281. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  282. }
  283. HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
  284. /* Enable and set Button EXTI Interrupt to the lowest priority */
  285. HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x0);
  286. HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
  287. }
  288. }
  289. /**
  290. * @brief Returns the selected button state.
  291. * @param Button: Button to be checked
  292. * This parameter can be one of the following values:
  293. * @arg BUTTON_WAKEUP: Wakeup Push Button
  294. * @arg BUTTON_TAMPER: Tamper Push Button
  295. * @arg BUTTON_KEY: Key Push Button
  296. * @arg BUTTON_RIGHT: Joystick Right Push Button
  297. * @arg BUTTON_LEFT: Joystick Left Push Button
  298. * @arg BUTTON_UP: Joystick Up Push Button
  299. * @arg BUTTON_DOWN: Joystick Down Push Button
  300. * @arg BUTTON_SEL: Joystick Sel Push Button
  301. * @retval The Button GPIO pin value
  302. */
  303. uint32_t BSP_PB_GetState(Button_TypeDef Button)
  304. {
  305. return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
  306. }
  307. /**
  308. * @brief Configures COM port.
  309. * @param COM: COM port to be configured.
  310. * This parameter can be one of the following values:
  311. * @arg COM1
  312. * @arg COM2
  313. * @param huart: Pointer to a UART_HandleTypeDef structure that contains the
  314. * configuration information for the specified USART peripheral.
  315. */
  316. void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
  317. {
  318. GPIO_InitTypeDef GPIO_InitStruct;
  319. /* Enable GPIO clock */
  320. EVAL_COMx_TX_GPIO_CLK_ENABLE(COM);
  321. EVAL_COMx_RX_GPIO_CLK_ENABLE(COM);
  322. /* Enable USART clock */
  323. EVAL_COMx_CLK_ENABLE(COM);
  324. /* Configure USART Tx as alternate function */
  325. GPIO_InitStruct.Pin = COM_TX_PIN[COM];
  326. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  327. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  328. GPIO_InitStruct.Pull = GPIO_PULLUP;
  329. GPIO_InitStruct.Alternate = COM_TX_AF[COM];
  330. HAL_GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStruct);
  331. /* Configure USART Rx as alternate function */
  332. GPIO_InitStruct.Pin = COM_RX_PIN[COM];
  333. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  334. GPIO_InitStruct.Alternate = COM_RX_AF[COM];
  335. HAL_GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStruct);
  336. /* USART configuration */
  337. huart->Instance = COM_USART[COM];
  338. HAL_UART_Init(huart);
  339. }
  340. /**
  341. * @brief Init Potentiometer.
  342. */
  343. void BSP_POTENTIOMETER_Init(void)
  344. {
  345. GPIO_InitTypeDef GPIO_InitStruct;
  346. ADC_ChannelConfTypeDef ADC_Config;
  347. /* ADC an GPIO Periph clock enable */
  348. ADCx_CLK_ENABLE();
  349. ADCx_CHANNEL_GPIO_CLK_ENABLE();
  350. /* ADC Channel GPIO pin configuration */
  351. GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN;
  352. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  353. GPIO_InitStruct.Pull = GPIO_NOPULL;
  354. HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct);
  355. /* Configure the ADC peripheral */
  356. hEvalADC.Instance = ADCx;
  357. HAL_ADC_DeInit(&hEvalADC);
  358. hEvalADC.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; /* Asynchronous clock mode, input ADC clock not divided */
  359. hEvalADC.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */
  360. hEvalADC.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */
  361. hEvalADC.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
  362. hEvalADC.Init.EOCSelection = DISABLE; /* EOC flag picked-up to indicate conversion end */
  363. hEvalADC.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
  364. hEvalADC.Init.NbrOfConversion = 1; /* Parameter discarded because sequencer is disabled */
  365. hEvalADC.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
  366. hEvalADC.Init.NbrOfDiscConversion = 0; /* Parameter discarded because sequencer is disabled */
  367. hEvalADC.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; /* Software start to trig the 1st conversion manually, without external event */
  368. hEvalADC.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
  369. hEvalADC.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected */
  370. HAL_ADC_Init(&hEvalADC);
  371. /* Configure ADC regular channel */
  372. ADC_Config.Channel = ADCx_CHANNEL; /* Sampled channel number */
  373. ADC_Config.Rank = 1; /* Rank of sampled channel number ADCx_CHANNEL */
  374. ADC_Config.SamplingTime = ADC_SAMPLETIME_3CYCLES; /* Sampling time (number of clock cycles unit) */
  375. ADC_Config.Offset = 0; /* Parameter discarded because offset correction is disabled */
  376. HAL_ADC_ConfigChannel(&hEvalADC, &ADC_Config);
  377. }
  378. /**
  379. * @brief Get Potentiometer level in 12 bits.
  380. * @retval Potentiometer level(0..0xFFF) / 0xFFFFFFFF : Error
  381. */
  382. uint32_t BSP_POTENTIOMETER_GetLevel(void)
  383. {
  384. if(HAL_ADC_Start(&hEvalADC) == HAL_OK)
  385. {
  386. /* Wait for the end of conversion */
  387. if(HAL_ADC_PollForConversion(&hEvalADC, ADCx_POLL_TIMEOUT)== HAL_OK)
  388. {
  389. /* Check if the continuous conversion of regular channel is finished */
  390. if((HAL_ADC_GetState(&hEvalADC) & HAL_ADC_STATE_EOC_REG) == HAL_ADC_STATE_EOC_REG)
  391. {
  392. /* return the converted value of regular channel */
  393. return (HAL_ADC_GetValue(&hEvalADC));
  394. }
  395. }
  396. }
  397. return 0xFFFFFFFF;
  398. }
  399. /**
  400. * @brief Configures joystick GPIO and EXTI modes.
  401. * @param Joy_Mode: Button mode.
  402. * This parameter can be one of the following values:
  403. * @arg JOY_MODE_GPIO: Joystick pins will be used as simple IOs
  404. * @arg JOY_MODE_EXTI: Joystick pins will be connected to EXTI line
  405. * with interrupt generation capability
  406. * @retval IO_OK: if all initializations are OK. Other value if error.
  407. */
  408. uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode)
  409. {
  410. uint8_t ret = 0;
  411. /* Initialize the IO functionalities */
  412. ret = BSP_IO_Init();
  413. /* Configure joystick pins in IT mode */
  414. if(Joy_Mode == JOY_MODE_EXTI)
  415. {
  416. /* Configure joystick pins in IT mode */
  417. BSP_IO_ConfigPin(JOY_ALL_PINS, IO_MODE_IT_FALLING_EDGE);
  418. }
  419. return ret;
  420. }
  421. /**
  422. * @brief Returns the current joystick status.
  423. * @retval Code of the joystick key pressed
  424. * This code can be one of the following values:
  425. * @arg JOY_NONE
  426. * @arg JOY_SEL
  427. * @arg JOY_DOWN
  428. * @arg JOY_LEFT
  429. * @arg JOY_RIGHT
  430. * @arg JOY_UP
  431. */
  432. JOYState_TypeDef BSP_JOY_GetState(void)
  433. {
  434. uint8_t tmp = 0;
  435. /* Read the status joystick pins */
  436. tmp = (uint8_t)BSP_IO_ReadPin(JOY_ALL_PINS);
  437. /* Check the pressed keys */
  438. if((tmp & JOY_NONE_PIN) == JOY_NONE)
  439. {
  440. return(JOYState_TypeDef) JOY_NONE;
  441. }
  442. else if(!(tmp & JOY_SEL_PIN))
  443. {
  444. return(JOYState_TypeDef) JOY_SEL;
  445. }
  446. else if(!(tmp & JOY_DOWN_PIN))
  447. {
  448. return(JOYState_TypeDef) JOY_DOWN;
  449. }
  450. else if(!(tmp & JOY_LEFT_PIN))
  451. {
  452. return(JOYState_TypeDef) JOY_LEFT;
  453. }
  454. else if(!(tmp & JOY_RIGHT_PIN))
  455. {
  456. return(JOYState_TypeDef) JOY_RIGHT;
  457. }
  458. else if(!(tmp & JOY_UP_PIN))
  459. {
  460. return(JOYState_TypeDef) JOY_UP;
  461. }
  462. else
  463. {
  464. return(JOYState_TypeDef) JOY_NONE;
  465. }
  466. }
  467. /*******************************************************************************
  468. BUS OPERATIONS
  469. *******************************************************************************/
  470. /**************************** I2C Routines ************************************/
  471. /**
  472. * @brief Initializes I2C MSP.
  473. */
  474. static void I2Cx_MspInit(void)
  475. {
  476. GPIO_InitTypeDef GPIO_InitStruct;
  477. /*** Configure the GPIOs ***/
  478. /* Enable GPIO clock */
  479. EVAL_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
  480. /* Workaround: Configure I2C SCL/SDA pins as Output Push Pull Mode inorder
  481. to force the high state before connecting the I2C alternate function */
  482. GPIO_InitStruct.Pin = EVAL_I2Cx_SCL_PIN;
  483. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  484. GPIO_InitStruct.Pull = GPIO_PULLUP;
  485. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  486. HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
  487. GPIO_InitStruct.Pin = EVAL_I2Cx_SDA_PIN;
  488. HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
  489. HAL_GPIO_WritePin(EVAL_I2Cx_SCL_SDA_GPIO_PORT, EVAL_I2Cx_SCL_PIN, GPIO_PIN_SET);
  490. HAL_GPIO_WritePin(EVAL_I2Cx_SCL_SDA_GPIO_PORT, EVAL_I2Cx_SDA_PIN, GPIO_PIN_SET);
  491. /* Configure I2C SCL as alternate function */
  492. GPIO_InitStruct.Pin = EVAL_I2Cx_SCL_PIN;
  493. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  494. GPIO_InitStruct.Alternate = EVAL_I2Cx_SCL_SDA_AF;
  495. HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
  496. /* Configure I2C SDA as alternate function */
  497. GPIO_InitStruct.Pin = EVAL_I2Cx_SDA_PIN;
  498. HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
  499. /*** Configure the I2C peripheral ***/
  500. /* Enable I2C clock */
  501. EVAL_I2Cx_CLK_ENABLE();
  502. /* Force the I2C peripheral clock reset */
  503. EVAL_I2Cx_FORCE_RESET();
  504. /* Release the I2C peripheral clock reset */
  505. EVAL_I2Cx_RELEASE_RESET();
  506. /* Set priority and enable I2Cx event Interrupt */
  507. HAL_NVIC_SetPriority(EVAL_I2Cx_EV_IRQn, 0x0F, 0);
  508. HAL_NVIC_EnableIRQ(EVAL_I2Cx_EV_IRQn);
  509. /* Set priority and enable I2Cx error Interrupt */
  510. HAL_NVIC_SetPriority(EVAL_I2Cx_ER_IRQn, 0x0F, 0);
  511. HAL_NVIC_EnableIRQ(EVAL_I2Cx_ER_IRQn);
  512. }
  513. /**
  514. * @brief Initializes I2C HAL.
  515. */
  516. static void I2Cx_Init(void)
  517. {
  518. if(HAL_I2C_GetState(&heval_I2c) == HAL_I2C_STATE_RESET)
  519. {
  520. heval_I2c.Instance = EVAL_I2Cx;
  521. heval_I2c.Init.ClockSpeed = BSP_I2C_SPEED;
  522. heval_I2c.Init.DutyCycle = I2C_DUTYCYCLE_2;
  523. heval_I2c.Init.OwnAddress1 = 0;
  524. heval_I2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  525. heval_I2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
  526. heval_I2c.Init.OwnAddress2 = 0;
  527. heval_I2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
  528. heval_I2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
  529. /* Init the I2C */
  530. I2Cx_MspInit();
  531. HAL_I2C_Init(&heval_I2c);
  532. }
  533. }
  534. /**
  535. * @brief Configures I2C Interrupt.
  536. */
  537. static void I2Cx_ITConfig(void)
  538. {
  539. static uint8_t I2C_IT_Enabled = 0;
  540. GPIO_InitTypeDef GPIO_InitStruct;
  541. if(I2C_IT_Enabled == 0)
  542. {
  543. I2C_IT_Enabled = 1;
  544. /* Enable the GPIO EXTI clock */
  545. __HAL_RCC_GPIOI_CLK_ENABLE();
  546. __HAL_RCC_SYSCFG_CLK_ENABLE();
  547. GPIO_InitStruct.Pin = GPIO_PIN_2;
  548. GPIO_InitStruct.Pull = GPIO_NOPULL;
  549. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  550. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  551. HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
  552. /* Set priority and Enable GPIO EXTI Interrupt */
  553. HAL_NVIC_SetPriority((IRQn_Type)(EXTI2_IRQn), 0x0F, 0);
  554. HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI2_IRQn));
  555. }
  556. }
  557. /**
  558. * @brief Reads a single data.
  559. * @param Addr: I2C address
  560. * @param Reg: Reg address
  561. * @retval Data to be read
  562. */
  563. static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg)
  564. {
  565. HAL_StatusTypeDef status = HAL_OK;
  566. uint8_t Value = 0;
  567. status = HAL_I2C_Mem_Read(&heval_I2c, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2C_TIMEOUT);
  568. /* Check the communication status */
  569. if(status != HAL_OK)
  570. {
  571. /* Execute user timeout callback */
  572. I2Cx_Error(Addr);
  573. }
  574. return Value;
  575. }
  576. /**
  577. * @brief Writes a single data.
  578. * @param Addr: I2C address
  579. * @param Reg: Reg address
  580. * @param Value: Data to be written
  581. */
  582. static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
  583. {
  584. HAL_StatusTypeDef status = HAL_OK;
  585. status = HAL_I2C_Mem_Write(&heval_I2c, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2C_TIMEOUT);
  586. /* Check the communication status */
  587. if(status != HAL_OK)
  588. {
  589. /* I2C error occured */
  590. I2Cx_Error(Addr);
  591. }
  592. }
  593. /**
  594. * @brief Reads multiple data.
  595. * @param Addr: I2C address
  596. * @param Reg: Reg address
  597. * @param MemAddress Internal memory address
  598. * @param Buffer: Pointer to data buffer
  599. * @param Length: Length of the data
  600. * @retval Number of read data
  601. */
  602. static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
  603. {
  604. HAL_StatusTypeDef status = HAL_OK;
  605. status = HAL_I2C_Mem_Read(&heval_I2c, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, I2C_TIMEOUT);
  606. /* Check the communication status */
  607. if(status != HAL_OK)
  608. {
  609. /* I2C error occured */
  610. I2Cx_Error(Addr);
  611. }
  612. return status;
  613. }
  614. /**
  615. * @brief Write a value in a register of the device through BUS in using DMA mode
  616. * @param Addr: Device address on BUS Bus.
  617. * @param Reg: The target register address to write
  618. * @param MemAddress Internal memory address
  619. * @param Buffer: The target register value to be written
  620. * @param Length: buffer size to be written
  621. * @retval HAL status
  622. */
  623. static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
  624. {
  625. HAL_StatusTypeDef status = HAL_OK;
  626. status = HAL_I2C_Mem_Write(&heval_I2c, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, I2C_TIMEOUT);
  627. /* Check the communication status */
  628. if(status != HAL_OK)
  629. {
  630. /* Re-Initiaize the I2C Bus */
  631. I2Cx_Error(Addr);
  632. }
  633. return status;
  634. }
  635. /**
  636. * @brief Checks if target device is ready for communication.
  637. * @note This function is used with Memory devices
  638. * @param DevAddress: Target device address
  639. * @param Trials: Number of trials
  640. * @retval HAL status
  641. */
  642. static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
  643. {
  644. return (HAL_I2C_IsDeviceReady(&heval_I2c, DevAddress, Trials, I2C_TIMEOUT));
  645. }
  646. /**
  647. * @brief Manages error callback by re-initializing I2C.
  648. * @param Addr: I2C Address
  649. */
  650. static void I2Cx_Error(uint8_t Addr)
  651. {
  652. /* De-initialize the IOE comunication BUS */
  653. HAL_I2C_DeInit(&heval_I2c);
  654. /* Re-Initiaize the IOE comunication BUS */
  655. I2Cx_Init();
  656. }
  657. /*************************** FSMC Routines ************************************/
  658. /**
  659. * @brief Initializes FSMC_BANK3 MSP.
  660. */
  661. static void FSMC_BANK3_MspInit(void)
  662. {
  663. GPIO_InitTypeDef GPIO_Init_Structure;
  664. /* Enable FSMC clock */
  665. __HAL_RCC_FSMC_CLK_ENABLE();
  666. /* Enable GPIOs clock */
  667. __HAL_RCC_GPIOD_CLK_ENABLE();
  668. __HAL_RCC_GPIOE_CLK_ENABLE();
  669. __HAL_RCC_GPIOF_CLK_ENABLE();
  670. __HAL_RCC_GPIOG_CLK_ENABLE();
  671. /* Common GPIO configuration */
  672. GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP;
  673. GPIO_Init_Structure.Pull = GPIO_PULLUP;
  674. GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH;
  675. GPIO_Init_Structure.Alternate = GPIO_AF12_FSMC;
  676. /* GPIOD configuration */
  677. GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 |\
  678. GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 |\
  679. GPIO_PIN_14 | GPIO_PIN_15;
  680. HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);
  681. /* GPIOE configuration */
  682. GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3| GPIO_PIN_4 | GPIO_PIN_7 |\
  683. GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\
  684. GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  685. HAL_GPIO_Init(GPIOE, &GPIO_Init_Structure);
  686. /* GPIOF configuration */
  687. GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
  688. GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  689. HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure);
  690. /* GPIOG configuration */
  691. GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
  692. GPIO_PIN_5 | GPIO_PIN_10;
  693. HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure);
  694. }
  695. /**
  696. * @brief Initializes LCD IO.
  697. */
  698. static void FSMC_BANK3_Init(void)
  699. {
  700. SRAM_HandleTypeDef hsram;
  701. FSMC_NORSRAM_TimingTypeDef SRAM_Timing;
  702. /*** Configure the SRAM Bank 3 ***/
  703. /* Configure IPs */
  704. hsram.Instance = FSMC_NORSRAM_DEVICE;
  705. hsram.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
  706. SRAM_Timing.AddressSetupTime = 5;
  707. SRAM_Timing.AddressHoldTime = 1;
  708. SRAM_Timing.DataSetupTime = 9;
  709. SRAM_Timing.BusTurnAroundDuration = 0;
  710. SRAM_Timing.CLKDivision = 2;
  711. SRAM_Timing.DataLatency = 2;
  712. SRAM_Timing.AccessMode = FSMC_ACCESS_MODE_A;
  713. hsram.Init.NSBank = FSMC_NORSRAM_BANK3;
  714. hsram.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
  715. hsram.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
  716. hsram.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
  717. hsram.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
  718. hsram.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
  719. hsram.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
  720. hsram.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
  721. hsram.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
  722. hsram.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
  723. hsram.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
  724. hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
  725. hsram.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
  726. /* Initialize the SRAM controller */
  727. FSMC_BANK3_MspInit();
  728. HAL_SRAM_Init(&hsram, &SRAM_Timing, &SRAM_Timing);
  729. }
  730. /**
  731. * @brief Writes register value.
  732. * @param Data: Data to be written
  733. */
  734. static void FSMC_BANK3_WriteData(uint16_t Data)
  735. {
  736. /* Write 16-bit Reg */
  737. FSMC_BANK3->RAM = Data;
  738. }
  739. /**
  740. * @brief Writes register address.
  741. * @param Reg: Register to be written
  742. */
  743. static void FSMC_BANK3_WriteReg(uint8_t Reg)
  744. {
  745. /* Write 16-bit Index, then write register */
  746. FSMC_BANK3->REG = Reg;
  747. }
  748. /**
  749. * @brief Reads register value.
  750. * @retval Read value
  751. */
  752. static uint16_t FSMC_BANK3_ReadData(void)
  753. {
  754. return FSMC_BANK3->RAM;
  755. }
  756. /*******************************************************************************
  757. LINK OPERATIONS
  758. *******************************************************************************/
  759. /***************************** LINK IOE ***************************************/
  760. /**
  761. * @brief Initializes IOE low level.
  762. */
  763. void IOE_Init(void)
  764. {
  765. I2Cx_Init();
  766. }
  767. /**
  768. * @brief Configures IOE low level Interrupt.
  769. */
  770. void IOE_ITConfig(void)
  771. {
  772. I2Cx_ITConfig();
  773. }
  774. /**
  775. * @brief IOE writes single data.
  776. * @param Addr: I2C address
  777. * @param Reg: Reg address
  778. * @param Value: Data to be written
  779. */
  780. void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
  781. {
  782. I2Cx_Write(Addr, Reg, Value);
  783. }
  784. /**
  785. * @brief IOE reads single data.
  786. * @param Addr: I2C address
  787. * @param Reg: Reg address
  788. * @retval Read data
  789. */
  790. uint8_t IOE_Read(uint8_t Addr, uint8_t Reg)
  791. {
  792. return I2Cx_Read(Addr, Reg);
  793. }
  794. /**
  795. * @brief IOE reads multiple data.
  796. * @param Addr: I2C address
  797. * @param Reg: Reg address
  798. * @param Buffer: Pointer to data buffer
  799. * @param Length: Length of the data
  800. * @retval Number of read data
  801. */
  802. uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
  803. {
  804. return I2Cx_ReadMultiple(Addr, Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
  805. }
  806. /**
  807. * @brief IOE delay.
  808. * @param Delay: Delay in ms
  809. */
  810. void IOE_Delay(uint32_t Delay)
  811. {
  812. HAL_Delay(Delay);
  813. }
  814. /********************************* LINK LCD ***********************************/
  815. /**
  816. * @brief Initializes LCD low level.
  817. */
  818. void LCD_IO_Init(void)
  819. {
  820. if(Is_LCD_IO_Initialized == 0)
  821. {
  822. Is_LCD_IO_Initialized = 1;
  823. FSMC_BANK3_Init();
  824. }
  825. }
  826. /**
  827. * @brief Writes data on LCD data register.
  828. * @param Data: Data to be written
  829. */
  830. void LCD_IO_WriteData(uint16_t Data)
  831. {
  832. /* Write 16-bit Reg */
  833. FSMC_BANK3_WriteData(Data);
  834. }
  835. /**
  836. * @brief Write register value.
  837. * @param pData Pointer on the register value
  838. * @param Size Size of byte to transmit to the register
  839. */
  840. void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size)
  841. {
  842. uint32_t counter;
  843. uint16_t *ptr = (uint16_t *) pData;
  844. for (counter = 0; counter < Size; counter+=2)
  845. {
  846. /* Write 16-bit Reg */
  847. FSMC_BANK3_WriteData(*ptr);
  848. ptr++;
  849. }
  850. }
  851. /**
  852. * @brief Writes register on LCD register.
  853. * @param Reg: Register to be written
  854. */
  855. void LCD_IO_WriteReg(uint8_t Reg)
  856. {
  857. /* Write 16-bit Index, then Write Reg */
  858. FSMC_BANK3_WriteReg(Reg);
  859. }
  860. /**
  861. * @brief Reads data from LCD data register.
  862. * @param Reg: Register to be read
  863. * @retval Read data.
  864. */
  865. uint16_t LCD_IO_ReadData(uint16_t Reg)
  866. {
  867. FSMC_BANK3_WriteReg(Reg);
  868. /* Read 16-bit Reg */
  869. return FSMC_BANK3_ReadData();
  870. }
  871. /********************************* LINK AUDIO *********************************/
  872. /**
  873. * @brief Initializes Audio low level.
  874. */
  875. void AUDIO_IO_Init(void)
  876. {
  877. I2Cx_Init();
  878. }
  879. /**
  880. * @brief DeInitializes Audio low level.
  881. * @note This function is intentionally kept empty, user should define it.
  882. */
  883. void AUDIO_IO_DeInit(void)
  884. {
  885. }
  886. /**
  887. * @brief Writes a single data.
  888. * @param Addr: I2C address
  889. * @param Reg: Reg address
  890. * @param Value: Data to be written
  891. */
  892. void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
  893. {
  894. I2Cx_Write(Addr, Reg, Value);
  895. }
  896. /**
  897. * @brief Reads a single data.
  898. * @param Addr: I2C address
  899. * @param Reg: Reg address
  900. * @retval Data to be read
  901. */
  902. uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg)
  903. {
  904. return I2Cx_Read(Addr, Reg);
  905. }
  906. /***************************** LINK CAMERA ************************************/
  907. /**
  908. * @brief Initializes Camera low level.
  909. */
  910. void CAMERA_IO_Init(void)
  911. {
  912. I2Cx_Init();
  913. }
  914. /**
  915. * @brief Camera writes single data.
  916. * @param Addr: I2C address
  917. * @param Reg: Reg address
  918. * @param Value: Data to be written
  919. */
  920. void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
  921. {
  922. I2Cx_Write(Addr, Reg, Value);
  923. }
  924. /**
  925. * @brief Camera reads single data.
  926. * @param Addr: I2C address
  927. * @param Reg: Reg address
  928. * @retval Read data
  929. */
  930. uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg)
  931. {
  932. return I2Cx_Read(Addr, Reg);
  933. }
  934. /**
  935. * @brief Camera delay.
  936. * @param Delay: Delay in ms
  937. */
  938. void CAMERA_Delay(uint32_t Delay)
  939. {
  940. HAL_Delay(Delay);
  941. }
  942. /******************************** LINK I2C EEPROM *****************************/
  943. /**
  944. * @brief Initializes peripherals used by the I2C EEPROM driver.
  945. */
  946. void EEPROM_IO_Init(void)
  947. {
  948. I2Cx_Init();
  949. }
  950. /**
  951. * @brief Write data to I2C EEPROM driver in using DMA channel
  952. * @param DevAddress: Target device address
  953. * @param MemAddress: Internal memory address
  954. * @param pBuffer: Pointer to data buffer
  955. * @param BufferSize: Amount of data to be sent
  956. * @retval HAL status
  957. */
  958. HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
  959. {
  960. return (I2Cx_WriteMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
  961. }
  962. /**
  963. * @brief Reads data from I2C EEPROM driver in using DMA channel.
  964. * @param DevAddress: Target device address
  965. * @param MemAddress: Internal memory address
  966. * @param pBuffer: Pointer to data buffer
  967. * @param BufferSize: Amount of data to be read
  968. * @retval HAL status
  969. */
  970. HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
  971. {
  972. return (I2Cx_ReadMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
  973. }
  974. /**
  975. * @brief Checks if target device is ready for communication.
  976. * @note This function is used with Memory devices
  977. * @param DevAddress: Target device address
  978. * @param Trials: Number of trials
  979. * @retval HAL status
  980. */
  981. HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
  982. {
  983. return (I2Cx_IsDeviceReady(DevAddress, Trials));
  984. }
  985. /**
  986. * @}
  987. */
  988. /**
  989. * @}
  990. */
  991. /**
  992. * @}
  993. */
  994. /**
  995. * @}
  996. */
  997. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/