G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_i2c.c
Go to the documentation of this file.
1
43#if defined(USE_FULL_DDL_DRIVER)
44
45/* Includes ------------------------------------------------------------------*/
46#include "g32r4xx_ddl_i2c.h"
47#include "g32r4xx_ddl_rcm.h"
48#ifdef USE_FULL_ASSERT
49#include "g32_assert.h"
50#else
51#define ASSERT_PARAM(_PARAM_) ((void)0U)
52#endif
53
57
58#if defined (I2C1)
59
63
64/* Private types -------------------------------------------------------------*/
65/* Private variables ---------------------------------------------------------*/
66/* Private constants ---------------------------------------------------------*/
67/* Private macros ------------------------------------------------------------*/
71
72#define IS_DDL_I2C_PERIPHERAL_MODE(__VALUE__) (((__VALUE__) == DDL_I2C_MODE_I2C) || \
73 ((__VALUE__) == DDL_I2C_MODE_SMBUS_HOST) || \
74 ((__VALUE__) == DDL_I2C_MODE_SMBUS_DEVICE) || \
75 ((__VALUE__) == DDL_I2C_MODE_SMBUS_DEVICE_ARP))
76
77#define IS_DDL_I2C_CLOCK_SPEED(__VALUE__) (((__VALUE__) > 0U) && ((__VALUE__) <= DDL_I2C_MAX_SPEED_FAST))
78
79#define IS_DDL_I2C_DUTY_CYCLE(__VALUE__) (((__VALUE__) == DDL_I2C_DUTYCYCLE_2) || \
80 ((__VALUE__) == DDL_I2C_DUTYCYCLE_16_9))
81
82#if defined(I2C_FILTER_ANFDIS)&&defined(I2C_FILTER_DNFCFG)
83#define IS_DDL_I2C_ANALOG_FILTER(__VALUE__) (((__VALUE__) == DDL_I2C_ANALOGFILTER_ENABLE) || \
84 ((__VALUE__) == DDL_I2C_ANALOGFILTER_DISABLE))
85
86#define IS_DDL_I2C_DIGITAL_FILTER(__VALUE__) ((__VALUE__) <= 0x0000000FU)
87
88#endif
89#define IS_DDL_I2C_OWN_ADDRESS1(__VALUE__) ((__VALUE__) <= 0x000003FFU)
90
91#define IS_DDL_I2C_TYPE_ACKNOWLEDGE(__VALUE__) (((__VALUE__) == DDL_I2C_ACK) || \
92 ((__VALUE__) == DDL_I2C_NACK))
93
94#define IS_DDL_I2C_OWN_ADDRSIZE(__VALUE__) (((__VALUE__) == DDL_I2C_OWNADDRESS1_7BIT) || \
95 ((__VALUE__) == DDL_I2C_OWNADDRESS1_10BIT))
96
99
100/* Private function prototypes -----------------------------------------------*/
101
102/* Exported functions --------------------------------------------------------*/
106
110
118uint32_t DDL_I2C_DeInit(I2C_TypeDef *I2Cx)
119{
120 (void)I2Cx;
121 ErrorStatus status = SUCCESS;
122
123 /* Check the I2C Instance I2Cx */
124 ASSERT_PARAM(IS_I2C_ALL_INSTANCE(I2Cx));
125
126 /* Force reset of I2C clock */
128
129 /* Release reset of I2C clock */
131
132
133 return status;
134}
135
144uint32_t DDL_I2C_Init(I2C_TypeDef *I2Cx, DDL_I2C_InitTypeDef *I2C_InitStruct)
145{
146 DDL_RCM_ClocksTypeDef rcc_clocks;
147
148 /* Check the I2C Instance I2Cx */
149 ASSERT_PARAM(IS_I2C_ALL_INSTANCE(I2Cx));
150
151 /* Check the I2C parameters from I2C_InitStruct */
155#if defined(I2C_FILTER_ANFDIS)&&defined(I2C_FILTER_DNFCFG)
158#endif
162
163 /* Disable the selected I2Cx Peripheral */
164 DDL_I2C_Disable(I2Cx);
165
166 /* Retrieve Clock frequencies */
167 DDL_RCM_GetSystemClocksFreq(&rcc_clocks);
168
169#if defined(I2C_FILTER_ANFDIS)&&defined(I2C_FILTER_DNFCFG)
170 /*---------------------------- I2Cx FLTR Configuration -----------------------
171 * Configure the analog and digital noise filters with parameters :
172 * - AnalogFilter: I2C_FLTR_ANFOFF bit
173 * - DigitalFilter: I2C_FILTER_DNFCFG[3:0] bits
174 */
175 DDL_I2C_ConfigFilters(I2Cx, I2C_InitStruct->AnalogFilter, I2C_InitStruct->DigitalFilter);
176
177#endif
178 /*---------------------------- I2Cx SCL Clock Speed Configuration ------------
179 * Configure the SCL speed :
180 * - ClockSpeed: I2C_CTRL2_CLKFCFG[7:0], I2C_RISETMAX_RISETMAX[7:0], I2C_CLKCTRL_SPEEDCFG,
181 * and I2C_CLKCTRL_CLKS[11:0] bits
182 * - DutyCycle: I2C_CLKCTRL_FDUTYCFG[7:0] bits
183 */
184 DDL_I2C_ConfigSpeed(I2Cx, rcc_clocks.PCLK_Frequency, I2C_InitStruct->ClockSpeed, I2C_InitStruct->DutyCycle);
185
186 /*---------------------------- I2Cx OAR1 Configuration -----------------------
187 * Disable, Configure and Enable I2Cx device own address 1 with parameters :
188 * - OwnAddress1: I2C_SADDR1_ADDR[9:8], I2C_SADDR1_ADDR[7:1] and I2C_SADDR1_ADDR0 bits
189 * - OwnAddrSize: I2C_SADDR1_ADDRLEN bit
190 */
191 DDL_I2C_SetOwnAddress1(I2Cx, I2C_InitStruct->OwnAddress1, I2C_InitStruct->OwnAddrSize);
192
193 /*---------------------------- I2Cx MODE Configuration -----------------------
194 * Configure I2Cx peripheral mode with parameter :
195 * - PeripheralMode: I2C_CTRL1_SMBEN, I2C_CTRL1_SMBTCFG and I2C_CTRL1_ARPEN bits
196 */
197 DDL_I2C_SetMode(I2Cx, I2C_InitStruct->PeripheralMode);
198
199 /* Enable the selected I2Cx Peripheral */
200 DDL_I2C_Enable(I2Cx);
201
202 /*---------------------------- I2Cx CTRL2 Configuration ------------------------
203 * Configure the ACKnowledge or Non ACKnowledge condition
204 * after the address receive match code or next received byte with parameter :
205 * - TypeAcknowledge: I2C_CTRL2_NACK bit
206 */
207 DDL_I2C_AcknowledgeNextData(I2Cx, I2C_InitStruct->TypeAcknowledge);
208
209 return SUCCESS;
210}
211
218{
219 /* Set I2C_InitStruct fields to default values */
220 I2C_InitStruct->PeripheralMode = DDL_I2C_MODE_I2C;
221 I2C_InitStruct->ClockSpeed = 5000U;
222 I2C_InitStruct->DutyCycle = DDL_I2C_DUTYCYCLE_2;
223#if defined(I2C_FILTER_ANFDIS)&&defined(I2C_FILTER_DNFCFG)
225 I2C_InitStruct->DigitalFilter = 0U;
226#endif
227 I2C_InitStruct->OwnAddress1 = 0U;
228 I2C_InitStruct->TypeAcknowledge = DDL_I2C_NACK;
229 I2C_InitStruct->OwnAddrSize = DDL_I2C_OWNADDRESS1_7BIT;
230}
231
235
239
243
244#endif /* I2C1*/
245
249
250#endif /* USE_FULL_DDL_DRIVER */
251
G32 assert template file. This file should be copied to the application folder and renamed to g32_ass...
#define ASSERT_PARAM(_PARAM_)
Definition g32_assert.h:58
Header file of I2C DDL module.
Header file of RCM DDL module.
#define DDL_I2C_ANALOGFILTER_ENABLE
#define DDL_I2C_DUTYCYCLE_2
#define DDL_I2C_NACK
#define DDL_I2C_OWNADDRESS1_7BIT
#define DDL_I2C_MODE_I2C
__STATIC_INLINE void DDL_I2C_ConfigSpeed(I2C_TypeDef *I2Cx, uint32_t PeriphClock, uint32_t ClockSpeed, uint32_t DutyCycle)
Configure the SCL speed.
__STATIC_INLINE void DDL_I2C_ConfigFilters(I2C_TypeDef *I2Cx, uint32_t AnalogFilter, uint32_t DigitalFilter)
Configure Noise Filters (Analog and Digital).
__STATIC_INLINE void DDL_I2C_SetOwnAddress1(I2C_TypeDef *I2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize)
Set the Own Address1.
__STATIC_INLINE void DDL_I2C_SetMode(I2C_TypeDef *I2Cx, uint32_t PeripheralMode)
Configure peripheral mode.
__STATIC_INLINE void DDL_I2C_Enable(I2C_TypeDef *I2Cx)
Enable I2C peripheral (PE = 1).
__STATIC_INLINE void DDL_I2C_Disable(I2C_TypeDef *I2Cx)
Disable I2C peripheral (PE = 0).
__STATIC_INLINE void DDL_I2C_AcknowledgeNextData(I2C_TypeDef *I2Cx, uint32_t TypeAcknowledge)
Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match ...
uint32_t DDL_I2C_DeInit(I2C_TypeDef *I2Cx)
De-initialize the I2C registers to their default reset values.
void DDL_I2C_StructInit(DDL_I2C_InitTypeDef *I2C_InitStruct)
Set each DDL_I2C_InitTypeDef field to default value.
uint32_t DDL_I2C_Init(I2C_TypeDef *I2Cx, DDL_I2C_InitTypeDef *I2C_InitStruct)
Initialize the I2C registers according to the specified parameters in I2C_InitStruct.
#define IS_DDL_I2C_PERIPHERAL_MODE(__VALUE__)
#define IS_DDL_I2C_DIGITAL_FILTER(__VALUE__)
#define IS_DDL_I2C_OWN_ADDRESS1(__VALUE__)
#define IS_DDL_I2C_TYPE_ACKNOWLEDGE(__VALUE__)
#define IS_DDL_I2C_OWN_ADDRSIZE(__VALUE__)
#define IS_DDL_I2C_CLOCK_SPEED(__VALUE__)
#define IS_DDL_I2C_DUTY_CYCLE(__VALUE__)
#define IS_DDL_I2C_ANALOG_FILTER(__VALUE__)
#define DDL_RCM_APB_RESET_I2C
void DDL_RCM_GetSystemClocksFreq(DDL_RCM_ClocksTypeDef *RCM_Clocks)
Return the frequencies of different on chip clocks; System, AHB, APB buses clocks.
__STATIC_INLINE void DDL_RCM_EnableAPBReset(uint32_t Peripheral)
Enable the APB peripheral reset.
__STATIC_INLINE void DDL_RCM_DisableAPBReset(uint32_t Peripheral)
Disable the APB peripheral reset.
RCM Clocks Frequency Structure.