snickerdoodle Platform Controller
firmware for STM32F0 platform controller
I2C Functions

Functions

void sd_i2c1_init (void)
 I2C1 Initialization Initialize low-level hardware peripheral and set device handle. More...
 
void sd_i2c2_init (void)
 I2C2 Initialization Initialize low-level hardware peripheral and set device handle. More...
 
void HAL_I2C_MspInit (I2C_HandleTypeDef *hi2c)
 
void HAL_I2C_MspDeInit (I2C_HandleTypeDef *hi2c)
 
enum sd_i2c_err sd_i2C_set_chan (struct sd_i2c_dev *dev, uint8_t chan)
 Set I2C channel Set I2C channel (more than one channel may be specified) to broadcast messages. More...
 
enum sd_i2c_err sd_i2c_en_chan (struct sd_i2c_dev *dev, uint8_t chan)
 Enable I2C channel Enable an I2C channel without altering previously configured channels. More than one channel may be specified. More...
 
enum sd_i2c_err sd_i2c_dis_chan (struct sd_i2c_dev *dev, uint8_t chan)
 Disable I2C channel Disable an I2C channel without altering previously configured channels. More than one channel may be specified. More...
 
static enum sd_i2c_err sd_i2c_dev_init (struct sd_i2c_dev *dev, I2C_HandleTypeDef *hi2c)
 Initialize I2C channel Initialize I2C channel with a peripheral handle and set the device as ready. More...
 

Detailed Description

Function Documentation

◆ HAL_I2C_MspInit()

void HAL_I2C_MspInit ( I2C_HandleTypeDef *  hi2c)

#include <Src/sd_i2c.c>

I2C1 GPIO Configuration

Pin/Port Signal -——
PB8 SCL
PB9 SDA

I2C2 GPIO Configuration

Pin/Port Signal ----—
PB10 SCL
PB11 SDA
148 {
149  GPIO_InitTypeDef GPIO_InitStruct;
150  if (hi2c->Instance==I2C1) {
159  GPIO_InitStruct.Pin = SMB_I2C_SCL_Pin|SMB_I2C_SDA_Pin;
160  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
161  GPIO_InitStruct.Pull = GPIO_PULLUP;
162  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
163  GPIO_InitStruct.Alternate = GPIO_AF1_I2C1;
164  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
165 
166  /* Peripheral clock enable */
167  __I2C1_CLK_ENABLE();
168  } else if (hi2c->Instance==I2C2) {
177  GPIO_InitStruct.Pin = CRYPTO_I2C_SCL_Pin|CRYPTO_I2C_SDA_Pin;
178  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
179  GPIO_InitStruct.Pull = GPIO_PULLUP;
180  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
181  GPIO_InitStruct.Alternate = GPIO_AF1_I2C2;
182  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
183 
184  /* Peripheral clock enable */
185  __I2C2_CLK_ENABLE();
186  }
187 }

◆ sd_i2c1_init()

void sd_i2c1_init ( void  )

#include <Src/sd_i2c.c>

I2C1 Initialization Initialize low-level hardware peripheral and set device handle.

Configure Analog filter

97 {
98  hi2c1.Instance = I2C1;
99  hi2c1.Init.Timing = 0x20303E5D;
100  hi2c1.Init.OwnAddress1 = 0;
101  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
102  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
103  hi2c1.Init.OwnAddress2 = 0;
104  hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
105  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
106  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
107  HAL_I2C_Init(&hi2c1);
108 
112  HAL_I2CEx_AnalogFilter_Config(&hi2c1, I2C_ANALOGFILTER_ENABLED);
113 
114  /* Initialize I2C device */
116 }
struct sd_i2c_dev i2c1_dev
Definition: sd_i2c.c:78
static I2C_HandleTypeDef hi2c1
Definition: sd_i2c.c:67
static enum sd_i2c_err sd_i2c_dev_init(struct sd_i2c_dev *dev, I2C_HandleTypeDef *hi2c)
Initialize I2C channel Initialize I2C channel with a peripheral handle and set the device as ready...
Definition: sd_i2c.c:215

◆ sd_i2c2_init()

void sd_i2c2_init ( void  )

#include <Src/sd_i2c.c>

I2C2 Initialization Initialize low-level hardware peripheral and set device handle.

Configure Analog filter

124 {
125  hi2c2.Instance = I2C2;
126  hi2c2.Init.Timing = 0x20303E5D;
127  hi2c2.Init.OwnAddress1 = 0;
128  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
129  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
130  hi2c2.Init.OwnAddress2 = 0;
131  hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
132  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
133  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
134  HAL_I2C_Init(&hi2c2);
135 
139  HAL_I2CEx_AnalogFilter_Config(&hi2c2, I2C_ANALOGFILTER_ENABLED);
140 
141  /* Initialize I2C device */
143 }
struct sd_i2c_dev i2c2_dev
Definition: sd_i2c.c:79
static enum sd_i2c_err sd_i2c_dev_init(struct sd_i2c_dev *dev, I2C_HandleTypeDef *hi2c)
Initialize I2C channel Initialize I2C channel with a peripheral handle and set the device as ready...
Definition: sd_i2c.c:215
static I2C_HandleTypeDef hi2c2
Definition: sd_i2c.c:68

◆ sd_i2c_dev_init()

enum sd_i2c_err sd_i2c_dev_init ( struct sd_i2c_dev dev,
I2C_HandleTypeDef *  hi2c 
)
static

#include <Src/sd_i2c.c>

Initialize I2C channel Initialize I2C channel with a peripheral handle and set the device as ready.

Parameters
devI2C device to initialize
hi2cI2C device handle to use
Return values
SD_I2C_SUCCESSon success, error state otherwise
216 {
217  memset(dev, 0, sizeof(struct sd_i2c_dev));
218 
219  dev->i2c = hi2c;
220  dev->state = SD_I2C_READY;
221 
222  return SD_I2C_SUCCESS;
223 }
I2C_HandleTypeDef * i2c
Definition: sd_i2c.h:126
enum sd_i2c_state state
Definition: sd_i2c.h:128
Definition: sd_i2c.h:116
Definition: sd_i2c.h:103
I2C device structure.
Definition: sd_i2c.h:125

◆ sd_i2c_dis_chan()

enum sd_i2c_err sd_i2c_dis_chan ( struct sd_i2c_dev dev,
uint8_t  chan 
)

#include <Src/sd_i2c.c>

Disable I2C channel Disable an I2C channel without altering previously configured channels. More than one channel may be specified.

Parameters
devI2C device to configure
chanChannel to disable on the I2C switch
Return values
SD_I2C_SUCCESSon success, error state otherwise
277 {
278  sd_i2c_chan &= ~(chan);
279 
280  if (HAL_I2C_Master_Transmit(dev->i2c, SD_I2C_SWITCH_ADDR, &sd_i2c_chan, 1, 1000) != HAL_OK)
281  return SD_I2C_ERROR;
282 
283  return SD_I2C_SUCCESS;
284 }
I2C_HandleTypeDef * i2c
Definition: sd_i2c.h:126
#define SD_I2C_SWITCH_ADDR
Definition: sd_i2c.h:60
Definition: sd_i2c.h:103
Definition: sd_i2c.h:107

◆ sd_i2c_en_chan()

enum sd_i2c_err sd_i2c_en_chan ( struct sd_i2c_dev dev,
uint8_t  chan 
)

#include <Src/sd_i2c.c>

Enable I2C channel Enable an I2C channel without altering previously configured channels. More than one channel may be specified.

Parameters
devI2C device to configure
chanChannel to enable on the I2C switch
Return values
SD_I2C_SUCCESSon success, error state otherwise
257 {
258  sd_i2c_chan |= chan;
259 
260  if (HAL_I2C_Master_Transmit(dev->i2c, SD_I2C_SWITCH_ADDR, &sd_i2c_chan, 1, 1000) != HAL_OK)
261  return SD_I2C_ERROR;
262 
263  return SD_I2C_SUCCESS;
264 }
I2C_HandleTypeDef * i2c
Definition: sd_i2c.h:126
#define SD_I2C_SWITCH_ADDR
Definition: sd_i2c.h:60
Definition: sd_i2c.h:103
Definition: sd_i2c.h:107

◆ sd_i2C_set_chan()

enum sd_i2c_err sd_i2C_set_chan ( struct sd_i2c_dev dev,
uint8_t  chan 
)

#include <Src/sd_i2c.c>

Set I2C channel Set I2C channel (more than one channel may be specified) to broadcast messages.

Parameters
devI2C device to configure
chanChannel(s) to set on the I2C switch
Return values
SD_I2C_SUCCESSon success, error state otherwise
236 {
237  sd_i2c_chan = chan;
238 
239  /* Set the output state of the switch */
240  if (HAL_I2C_Master_Transmit(dev->i2c, SD_I2C_SWITCH_ADDR, &sd_i2c_chan, 1, 1000) != HAL_OK)
241  return SD_I2C_ERROR;
242 
243  return SD_I2C_SUCCESS;
244 }
I2C_HandleTypeDef * i2c
Definition: sd_i2c.h:126
#define SD_I2C_SWITCH_ADDR
Definition: sd_i2c.h:60
Definition: sd_i2c.h:103
Definition: sd_i2c.h:107