xref: /btstack/port/stm32-f4discovery-cc256x/Src/i2c.c (revision 225f4ba4fe806afeda1ee8519bb5f4a8ce540af2)
1 /**
2   ******************************************************************************
3   * File Name          : I2C.c
4   * Description        : This file provides code for the configuration
5   *                      of the I2C instances.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Includes ------------------------------------------------------------------*/
21 #include "i2c.h"
22 
23 /* USER CODE BEGIN 0 */
24 
25 /* USER CODE END 0 */
26 
27 I2C_HandleTypeDef hi2c1;
28 
29 /* I2C1 init function */
MX_I2C1_Init(void)30 void MX_I2C1_Init(void)
31 {
32 
33   hi2c1.Instance = I2C1;
34   hi2c1.Init.ClockSpeed = 100000;
35   hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
36   hi2c1.Init.OwnAddress1 = 0;
37   hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
38   hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
39   hi2c1.Init.OwnAddress2 = 0;
40   hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
41   hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
42   if (HAL_I2C_Init(&hi2c1) != HAL_OK)
43   {
44     Error_Handler();
45   }
46 
47 }
48 
HAL_I2C_MspInit(I2C_HandleTypeDef * i2cHandle)49 void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
50 {
51 
52   GPIO_InitTypeDef GPIO_InitStruct = {0};
53   if(i2cHandle->Instance==I2C1)
54   {
55   /* USER CODE BEGIN I2C1_MspInit 0 */
56 
57   /* USER CODE END I2C1_MspInit 0 */
58 
59     __HAL_RCC_GPIOB_CLK_ENABLE();
60     /**I2C1 GPIO Configuration
61     PB6     ------> I2C1_SCL
62     PB9     ------> I2C1_SDA
63     */
64     GPIO_InitStruct.Pin = Audio_SCL_Pin|Audio_SDA_Pin;
65     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
66     GPIO_InitStruct.Pull = GPIO_PULLUP;
67     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
68     GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
69     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
70 
71     /* I2C1 clock enable */
72     __HAL_RCC_I2C1_CLK_ENABLE();
73   /* USER CODE BEGIN I2C1_MspInit 1 */
74 
75   /* USER CODE END I2C1_MspInit 1 */
76   }
77 }
78 
HAL_I2C_MspDeInit(I2C_HandleTypeDef * i2cHandle)79 void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
80 {
81 
82   if(i2cHandle->Instance==I2C1)
83   {
84   /* USER CODE BEGIN I2C1_MspDeInit 0 */
85 
86   /* USER CODE END I2C1_MspDeInit 0 */
87     /* Peripheral clock disable */
88     __HAL_RCC_I2C1_CLK_DISABLE();
89 
90     /**I2C1 GPIO Configuration
91     PB6     ------> I2C1_SCL
92     PB9     ------> I2C1_SDA
93     */
94     HAL_GPIO_DeInit(GPIOB, Audio_SCL_Pin|Audio_SDA_Pin);
95 
96   /* USER CODE BEGIN I2C1_MspDeInit 1 */
97 
98   /* USER CODE END I2C1_MspDeInit 1 */
99   }
100 }
101 
102 /* USER CODE BEGIN 1 */
103 
104 /* USER CODE END 1 */
105 
106 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
107