Subversion Repositories NaviCtrl

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2
* File Name          : 91x_i2c.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 05/18/2006 : Version 1.0
5
* Description        : This file provides all the I2C software functions.
6
********************************************************************************
7
* History:
8
* 05/22/2007 : Version 1.2
9
* 05/24/2006 : Version 1.1
10
* 05/18/2006 : Version 1.0
11
********************************************************************************
12
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
15
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
16
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
17
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
19
 
20
/* Includes ------------------------------------------------------------------*/
21
#include "91x_i2c.h"
22
#include "91x_scu.h"
23
 
24
/* Private typedef -----------------------------------------------------------*/
25
/* Private define ------------------------------------------------------------*/
26
 
27
/* I2C IT enable */
28
#define  I2C_IT_Enable     0x01
29
#define  I2C_IT_Disable    0xFE
30
 
31
/* I2C Peripheral Enable/Disable */
32
#define  I2C_PE_Set        0x20
33
#define  I2C_PE_Reset      0xDF
34
 
35
/* Address direction bit */
36
#define I2C_ADD0_Set       0x01
37
#define I2C_ADD0_Reset     0xFE
38
 
39
/* I2C START Enable/Disable */
40
#define  I2C_Start_Enable       0x08
41
#define  I2C_Start_Disable      0xF7
42
 
43
/* I2C STOP Enable/Disable */
44
#define  I2C_Stop_Enable        0x02
45
#define  I2C_Stop_Disable       0xFD
46
 
47
/* I2C Masks */
48
#define  I2C_Frequency_Mask     0x1F
49
#define  I2C_AddressHigh_Mask   0xF9
50
#define  I2C_OwnAddress_Mask    0x0300
51
#define  I2C_StandardMode_Mask  0x7f
52
#define  I2C_FastMode_Mask      0x80
53
#define  I2C_Event_Mask         0x3FFF
54
#define  I2C_HeaderSet_Mask     0xF1
55
#define  I2C_HeaderReset_Mask   0xFE
56
 
57
/* Private macro -------------------------------------------------------------*/
58
/* Private variables ---------------------------------------------------------*/
59
/* Private function prototypes -----------------------------------------------*/
60
/* Private functions ---------------------------------------------------------*/
61
/*******************************************************************************
62
* Function Name  : I2C_DeInit
63
* Description    : Deinitializes the I2C peripheral registers to their default
64
*                  reset values.
65
* Input          :- I2Cx: I2C peripheral can be:
66
*                    - I2C0
67
*                                        - I2C1  
68
* Output         : None
69
* Return         : None
70
*******************************************************************************/
71
void I2C_DeInit(I2C_TypeDef* I2Cx)
72
{
73
  if (I2Cx == I2C0)
74
  {
75
  /* Reset the I2C0 registers values */
76
   SCU_APBPeriphReset(__I2C0, ENABLE);
77
   SCU_APBPeriphReset(__I2C0, DISABLE);
78
  }
79
   if (I2Cx == I2C1)
80
  {
81
  /* Reset the I2C1 registers values */
82
  SCU_APBPeriphReset(__I2C1, ENABLE);
83
  SCU_APBPeriphReset(__I2C1, DISABLE);
84
  }
85
}
86
 
87
/*******************************************************************************
88
* Function Name  : I2C_Init
89
* Description    : Initializes the I2C  peripheral according to the specified
90
*                  parameters in the I2C_InitTypeDef structure.
91
* Input          :- I2Cx: I2C peripheral can be:
92
*                    - I2C0
93
*                                        - I2C1  
94
*
95
*                  - I2C_InitStruct: pointer to an I2C_InitTypeDef structure that
96
*                  contains the configuration information for the specified I2C
97
*                  peripheral.
98
* Output         : None
99
* Return         : None
100
*******************************************************************************/
101
void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
102
{
103
  u16 wResult = 0x0F;
104
  u32 dPCLK = 25000000;
105
 
106
  /* Get PCLK frequency value */
107
 dPCLK = SCU_GetPCLKFreqValue()*1000;
108
  /* Disable I2C peripheral to set FR[2:0] bits */
109
  I2C_Cmd (I2Cx, DISABLE);
110
  /* Clear frequency FR[2:0] bits */
111
  I2Cx->OAR2 &= I2C_Frequency_Mask;
112
  /* Set frequency bits depending on PCLK value */
113
  if ((dPCLK <1667000) & (dPCLK > 10000000))
114
    I2Cx->OAR2 |= 0x20;
115
  else if (dPCLK < 26670000)
116
    I2Cx->OAR2 |= 0x40;
117
  else if (dPCLK < 40000000)
118
    I2Cx->OAR2 |= 0x60;
119
  else if (dPCLK < 53330000)
120
    I2Cx->OAR2 |= 0x80;
121
  else if (dPCLK < 66000000)
122
    I2Cx->OAR2 |= 0xA0;
123
  else if (dPCLK < 80000000)
124
    I2Cx->OAR2 |= 0xC0;
125
  else if (dPCLK < 100000000)
126
    I2Cx->OAR2 |= 0xE0;
127
  I2C_Cmd (I2Cx, ENABLE);
128
 
129
  /* Configure general call */
130
  if (I2C_InitStruct->I2C_GeneralCall == I2C_GeneralCall_Enable)
131
  {
132
    /* Enable general call */
133
    I2Cx->CR |= I2C_GeneralCall_Enable;
134
  }
135
  else
136
  {
137
    /* Disable general call */
138
    I2Cx->CR &= I2C_GeneralCall_Disable;
139
  }
140
  /* Configure acknowledgement */
141
  if (I2C_InitStruct->I2C_Ack == I2C_Ack_Enable)
142
  {
143
    /* Enable acknowledgement */
144
    I2Cx->CR |= I2C_Ack_Enable;
145
  }
146
  else
147
  {
148
    /* Disable acknowledgement */
149
    I2Cx->CR &= I2C_Ack_Disable;
150
  }
151
 
152
  /* Configure LSB own address */
153
  I2Cx->OAR1 = I2C_InitStruct->I2C_OwnAddress;
154
  /* Clear MSB own address ADD[9:8] bits */
155
  I2Cx->OAR2 &= I2C_AddressHigh_Mask;
156
  /* Set MSB own address value */
157
  I2Cx->OAR2 |= (I2C_InitStruct->I2C_OwnAddress & I2C_OwnAddress_Mask)>>7;
158
 
159
  /* Configure speed in standard mode */
160
  if (I2C_InitStruct->I2C_CLKSpeed <= 100000)
161
  {
162
    /* Standard mode speed calculate */
163
    wResult = ((dPCLK/I2C_InitStruct->I2C_CLKSpeed)-7)/2;
164
    /* Set speed value and clear FM/SM bit for standard mode in LSB clock divider */
165
    I2Cx->CCR = wResult & I2C_StandardMode_Mask;
166
  }
167
  /* Configure speed in fast mode */
168
  else if (I2C_InitStruct->I2C_CLKSpeed <= 400000)
169
  {
170
    /* Fast mode speed calculate */
171
    wResult = ((dPCLK/I2C_InitStruct->I2C_CLKSpeed)-9)/3;
172
    /* Set speed value and set FM/SM bit for fast mode in LSB clock divider */
173
    I2Cx->CCR = wResult | I2C_FastMode_Mask;
174
  }
175
  /* Set speed in MSB clock divider */
176
  I2Cx->ECCR = wResult >>7;
177
}
178
 
179
/*******************************************************************************
180
* Function Name  : I2C_StructInit                                      
181
* Description    : Initialize the I2C Init Structure parameters
182
* Input          : - I2C_InitStruct: pointer to an I2C_InitTypeDef structure
183
                     which will be initialized.
184
* Output         : None
185
* Return         : None.                                               
186
*******************************************************************************/
187
void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
188
{
189
  /* Initialize the I2C_CLKSpeed member */
190
  I2C_InitStruct->I2C_CLKSpeed = 5000;
191
 
192
  /* Initialize the I2C_OwnAddress member */
193
  I2C_InitStruct->I2C_OwnAddress = 0x0;
194
 
195
  /* Initialize the I2C_GeneralCall member */
196
  I2C_InitStruct->I2C_GeneralCall = I2C_GeneralCall_Disable;
197
 
198
  /* Initialize the I2C_Ack member */
199
  I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
200
}
201
 
202
/*******************************************************************************
203
* Function Name  : I2C_Cmd
204
* Description    : Enables or disables the specified I2C peripheral.
205
* Input          :- I2Cx: I2C peripheral can be:
206
*                    - I2C0
207
*                                        - I2C1  
208
*                 - NewState: new state of the I2C peripheral. This parameter
209
*                    can be: ENABLE or DISABLE.
210
* Output         : None
211
* Return         : None.
212
*******************************************************************************/
213
void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
214
{
215
  if (NewState == ENABLE)
216
  {
217
    /* Enable the I2C peripheral by setting twice the PE bit on the CR register */
218
    I2Cx->CR |= I2C_PE_Set;
219
          I2Cx->CR |= I2C_PE_Set;
220
  }
221
  else
222
  {
223
    /* Disable the I2C peripheral */
224
    I2Cx->CR &= I2C_PE_Reset;
225
  }
226
}
227
 
228
/*******************************************************************************
229
* Function Name  : I2C_GenerateSTART
230
* Description    : Generates I2C communication START condition.
231
* Input          :- I2Cx: I2C peripheral can be:
232
*                    - I2C0
233
*                                        - I2C1  
234
*
235
*                 - NewState: new state of the Start condition. This parameter
236
*                    can be: ENABLE or DISABLE.
237
* Output         : None
238
* Return         : None.
239
*******************************************************************************/
240
void I2C_GenerateStart(I2C_TypeDef* I2Cx, FunctionalState NewState)
241
{
242
  if (NewState == ENABLE)
243
  {
244
    /* Generate a START condition */
245
    I2Cx->CR |= I2C_Start_Enable;
246
  }
247
  else
248
  {
249
    /* Disable the START condition generation */
250
    I2Cx->CR &= I2C_Start_Disable;
251
  }
252
}
253
 
254
/*******************************************************************************
255
* Function Name  : I2C_GenerateSTOP
256
* Description    : Generates I2C communication STOP condition.
257
* Input          :- I2Cx: I2C peripheral can be:
258
*                    - I2C0
259
*                                        - I2C1  
260
*
261
*                  - NewState: new state of the Stop condition. This parameter
262
*                    can be: ENABLE or DISABLE.
263
* Output         : None
264
* Return         : None.
265
*******************************************************************************/
266
void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)
267
{
268
  if (NewState == ENABLE)
269
  {
270
    /* Generate a SIOP condition */
271
    I2Cx->CR |= I2C_Stop_Enable;
272
  }
273
  else
274
  {
275
    /* Disable the STOP condition generation */
276
    I2Cx->CR &= I2C_Stop_Disable;
277
  }
278
}
279
 
280
/*******************************************************************************
281
* Function Name  : I2C_AcknowledgeConfig
282
* Description    : Enables or disables I2C acknowledge feature.
283
* Input          :- I2Cx: I2C peripheral can be:
284
*                    - I2C0
285
*                                        - I2C1  
286
*                 - NewState: new state of the Acknowledgement. This parameter
287
*                    can be: ENABLE or DISABLE.
288
* Output         : None
289
* Return         : None.
290
*******************************************************************************/
291
void I2C_AcknowledgeConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
292
{
293
  if (NewState == ENABLE)
294
  {
295
    /* Enable the acknowledgement */
296
    I2Cx->CR |= I2C_Ack_Enable;
297
  }
298
  else
299
  {
300
    /* Disable the acknowledgement */
301
    I2Cx->CR &= I2C_Ack_Disable;
302
  }
303
}
304
 
305
/*******************************************************************************
306
* Function Name  : I2C_ITConfig
307
* Description    : Enables or disables I2C interrupt feature.
308
* Input          :- I2Cx: I2C peripheral can be:
309
*                    - I2C0
310
*                                        - I2C1  
311
*                  - NewState: new state of the specified I2C interrupt.
312
*                    This parameter can be: ENABLE or DISABLE.
313
* Output         : None
314
* Return         : None.
315
*******************************************************************************/
316
void I2C_ITConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
317
{
318
  if (NewState == ENABLE)
319
  {
320
    /* Enable the I2C interrupt */
321
    I2Cx->CR |= I2C_IT_Enable;
322
  }
323
  else
324
  {
325
    /* Disable the I2C interrupt */
326
    I2Cx->CR &= I2C_IT_Disable;
327
  }
328
}
329
 
330
/*******************************************************************************
331
* Function Name  : I2C_ReadRegister
332
* Description    : Reads any I2C register and returns its value.
333
* Input          :- I2Cx: I2C peripheral can be:
334
*                    - I2C0
335
*                                        - I2C1    
336
*                 - I2C_Register: the I2C register to be read. This parameter
337
*                    can be one of the following values:
338
*                         - I2C_CR:   CR register.
339
*                         - I2C_SR1:  SR1 register.
340
*                         - I2C_SR2:  SR2 register.
341
*                         - I2C_CCR:  CCR register.
342
*                         - I2C_OAR1: OAR1 register.
343
*                         - I2C_OAR2: OAR2 register.
344
*                         - I2C_DR:   DR register.
345
*                         - I2C_ECCR: ECCR register.
346
* Output         : None
347
* Return         : The value of the register passed as parameter
348
*******************************************************************************/
349
u8 I2C_ReadRegister(I2C_TypeDef* I2Cx, u8 I2C_Register)
350
{
351
  /* Return the selected register value */
352
  if (I2Cx == I2C0)
353
  {
354
  return (*(u8 *)(I2C0_BASE + I2C_Register));
355
  }
356
  if (I2Cx == I2C1)
357
  {
358
  return (*(u8 *)(I2C1_BASE + I2C_Register));
359
  }
360
 return 0;
361
}
362
 
363
/*******************************************************************************
364
* Function Name  : I2C_GetFlagStatus
365
* Description    : Checks whether the specified I2C flag is set or not.
366
* Input          :- I2Cx: I2C peripheral can be:
367
*                    - I2C0
368
*                                        - I2C1  
369
*                 - I2C_FLAG: flag to check. This parameter can be one of the
370
*                    following values:
371
*                         - I2C_FLAG_SB: Start bit flag
372
*                         - I2C_FLAG_M_SL: Master/Slave flag
373
*                         - I2C_FLAG_ADSL: Adress matched flag
374
*                         - I2C_FLAG_BTF: Byte transfer finished flag
375
*                         - I2C_FLAG_BUSY: Bus busy flag
376
*                         - I2C_FLAG_TRA: Transmitter/Receiver flag
377
*                         - I2C_FLAG_ADD10: 10-bit addressing in Master mode flag
378
*                         - I2C_FLAG_EVF: Event flag
379
*                         - I2C_FLAG_GCAL: General call flag
380
*                         - I2C_FLAG_BERR: Bus error flag
381
*                         - I2C_FLAG_ARLO: Arbitration lost flag
382
*                         - I2C_FLAG_STOPF: Stop detection flag
383
*                         - I2C_FLAG_AF: Acknowledge failure flag
384
*                         - I2C_FLAG_ENDAD: End of address transmission flag
385
*                         - I2C_FLAG_ACK: Acknowledge enable flag
386
* Output         : None
387
* Return         : The NewState of the I2C_Flag (SET or RESET).
388
*******************************************************************************/
389
FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, u16 I2C_FLAG)
390
{
391
  u16 wFlag1=0, wFlag2=0, wTmp=0;
392
 
393
  wFlag1 = I2Cx->SR2;
394
  wFlag1 = wFlag1<<8;
395
  wFlag2 = I2Cx->CR & 0x04;
396
 
397
  /* Get all the I2C flags in a unique register*/
398
  wTmp = (((I2Cx->SR1 | (wFlag1)) & I2C_Event_Mask) | (wFlag2<<12));
399
 
400
  /* Check the status of the specified I2C flag */
401
  if((wTmp & I2C_FLAG) != RESET)
402
  {
403
    /* Return SET if I2C_FLAG is set */
404
    return SET;
405
  }
406
  else
407
  {
408
    /* Return RESET if I2C_FLAG is reset */
409
    return RESET;
410
  }
411
}
412
 
413
/*******************************************************************************
414
* Function Name  : I2C_ClearFlag
415
* Description    : Clears the I2C Flag passed as a parameter
416
* Input          :- I2Cx: I2C peripheral can be:
417
*                    - I2C0
418
*                                        - I2C1
419
*                 - I2C_FLAG: flag to check. This parameter can be one of the
420
*                    following values:
421
*                         - I2C_FLAG_SB: Start bit flag
422
*                         - I2C_FLAG_M_SL: Master/Slave flag
423
*                         - I2C_FLAG_ADSL: Adress matched flag
424
*                         - I2C_FLAG_BTF: Byte transfer finished flag
425
*                         - I2C_FLAG_BUSY: Bus busy flag
426
*                         - I2C_FLAG_TRA: Transmitter/Receiver flag
427
*                         - I2C_FLAG_ADD10: 10-bit addressing in Master mode flag
428
*                         - I2C_FLAG_EVF: Event flag
429
*                         - I2C_FLAG_GCAL: General call flag
430
*                         - I2C_FLAG_BERR: Bus error flag
431
*                         - I2C_FLAG_ARLO: Arbitration lost flag
432
*                         - I2C_FLAG_STOPF: Stop detection flag
433
*                         - I2C_FLAG_AF: Acknowledge failure flag
434
*                         - I2C_FLAG_ENDAD: End of address transmission flag
435
*                         - I2C_FLAG_ACK: Acknowledge enable flag
436
*                  - parameter needed in the case that the flag to be cleared
437
*                    need a write in one register
438
* Output         : None
439
* Return         : None.
440
*******************************************************************************/
441
void I2C_ClearFlag(I2C_TypeDef* I2Cx, u16 I2C_FLAG, ...)
442
{
443
  u8 bTmp = (u8)*((u32 *) & I2C_FLAG + sizeof(I2C_FLAG));
444
 
445
  /* flags that need a read of the SR2 register to be cleared */
446
  if ((I2C_FLAG==I2C_FLAG_ADD10) || (I2C_FLAG==I2C_FLAG_EVF) || (I2C_FLAG==I2C_FLAG_BERR) || (I2C_FLAG==I2C_FLAG_ARLO) |
447
      (I2C_FLAG==I2C_FLAG_STOPF) ||(I2C_FLAG==I2C_FLAG_AF)  || (I2C_FLAG==I2C_FLAG_ENDAD))
448
  {
449
    /* Read the SR2 register */
450
    I2Cx->SR2;
451
 
452
    /* Two flags need a second step to be cleared */
453
    switch (I2C_FLAG)
454
    {
455
       case  I2C_FLAG_ADD10:
456
         /* Send the MSB 10bit address passed as second parameter */
457
         I2Cx->DR = bTmp;
458
         break;
459
       case  I2C_FLAG_ENDAD:
460
         /* Write to the I2C_CR register by setting PE bit */
461
         I2Cx->CR |= I2C_PE_Set;
462
         break;
463
    }
464
  }
465
 
466
  /* flags that need a read of the SR1 register to be cleared */
467
  else if (I2C_FLAG==I2C_FLAG_SB || I2C_FLAG==I2C_FLAG_ADSL || I2C_FLAG==I2C_FLAG_BTF || I2C_FLAG==I2C_FLAG_TRA)
468
  {
469
    /* Read the SR1 register */
470
    (void)I2Cx->SR1;
471
 
472
    /* three flags need a second step to be cleared */
473
    if (I2C_FLAG == I2C_FLAG_SB)
474
    {
475
      /* Send the address byte passed as second parameter */
476
      I2Cx->DR = bTmp;
477
    }
478
    else if (I2C_FLAG==I2C_FLAG_BTF || I2C_FLAG==I2C_FLAG_TRA)
479
    {
480
      /* return the received byte in the variable passed as second parameter  */
481
      bTmp=I2Cx->DR;
482
    }
483
  }
484
 
485
  /* flags that need to disable the I2C interface */
486
  else if ( I2C_FLAG==I2C_FLAG_M_SL || I2C_FLAG==I2C_FLAG_GCAL)
487
  {
488
    I2C_Cmd(I2Cx, DISABLE);
489
    I2C_Cmd(I2Cx, ENABLE);
490
  }
491
}
492
 
493
/*******************************************************************************
494
* Function Name  : I2C_Send7bitAddress                                            
495
* Description    : Transmits the address byte to select the slave device.      
496
* Input          :- I2Cx: I2C peripheral can be:
497
*                    - I2C0
498
*                                        - I2C1
499
*                 - Address: specifies the slave address which will be transmitted    
500
*                 - Direction: specifies whether the I2C device will be a
501
*                    Transmitter or a Receiver. This parameter can be one of the
502
*                    following values
503
*                         - I2C_MODE_TRANSMITTER: Transmitter mode
504
*                         - I2C_MODE_RECEIVER: Receiver mode  
505
* Output         : None
506
* Return         : None.                                                      
507
*******************************************************************************/
508
void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, u8 Address, u8 Direction)
509
{
510
  /* Test on the direction to define the read/write bit */
511
  if (Direction == I2C_MODE_RECEIVER)
512
  {
513
    /* Set the address bit0 for read */
514
    Address |= I2C_ADD0_Set;
515
  }
516
  else
517
  {
518
    /* Reset the address bit0 for write */
519
    Address &= I2C_ADD0_Reset;
520
  }
521
  /* Send the address */
522
  I2Cx->DR = Address;
523
}
524
 
525
/*******************************************************************************
526
* Function Name  : I2C_SendData
527
* Description    : Send a data byte.
528
* Input          :- I2Cx: I2C peripheral can be:
529
*                    - I2C0
530
*                                        - I2C1  
531
*                   - bData : the byte to be sent
532
* Output         : None
533
* Return         : None.
534
*******************************************************************************/
535
void I2C_SendData(I2C_TypeDef* I2Cx, u8 bData)
536
{
537
  /* Write in the DR register the byte to be sent */
538
  I2Cx->DR = bData;
539
}
540
 
541
/*******************************************************************************
542
* Function Name  : I2C_ReceiveData
543
* Description    : Read the received byte.
544
* Input          : - I2Cx: I2C peripheral can be:
545
*                    - I2C0
546
*                                        - I2C1
547
* Output         : None
548
* Return         : The received byte
549
*******************************************************************************/
550
u8 I2C_ReceiveData(I2C_TypeDef* I2Cx)
551
{
552
  /* Return from the DR register the received byte */
553
  return I2Cx->DR;
554
}
555
 
556
/*******************************************************************************
557
* Function Name  : I2C_GetLastEvent
558
* Description    : Get the Last happened I2C Event.
559
* Input          :- I2Cx: I2C peripheral can be:
560
*                    - I2C0
561
*                                        - I2C1  
562
* Output         : None
563
* Return         : The Last happened Event.
564
*******************************************************************************/
565
u16 I2C_GetLastEvent(I2C_TypeDef* I2Cx)
566
{
567
  u16 wFlag1=0, wFlag2 =0, wLastEvent=0;
568
  wFlag2 = I2Cx->SR1;
569
  wFlag1 = I2Cx->SR2;
570
  wFlag1 = wFlag1<<8;
571
  /* Get the last event value from I2C status register */
572
  wLastEvent = ((( wFlag2 | (wFlag1)) & I2C_Event_Mask));
573
  /* Return the last event */
574
  return wLastEvent;
575
}
576
 
577
/*******************************************************************************
578
* Function Name  : I2C_CheckEvent
579
* Description    : Checks whether the Last I2C Event is equal to the one passed
580
*                  as parameter.
581
* Input          :- I2Cx: I2C peripheral can be:
582
*                    - I2C0
583
*                                        - I2C1  
584
*                  - I2C_EVENT: the event to check. This parameter can be one of
585
*                    the following values:
586
*                         - I2C_EVENT_SLAVE_ADDRESS_MATCHED
587
*                         - I2C_EVENT_SLAVE_BYTE_RECEIVED
588
*                         - I2C_EVENT_SLAVE_BYTE_TRANSMITTED
589
*                         - I2C_EVENT_MASTER_MODE_SELECT
590
*                         - I2C_EVENT_MASTER_MODE_SELECTED
591
*                         - I2C_EVENT_MASTER_BYTE_RECEIVED
592
*                         - I2C_EVENT_MASTER_BYTE_TRANSMITTED
593
*                         - I2C_EVENT_MASTER_MODE_ADDRESS10
594
*                         - I2C_EVENT_SLAVE_STOP_DETECTED
595
*                         - I2C_EVENT_SLAVE_ACK_FAILURE
596
* Output         : None
597
* Return         : An ErrorStatus enumuration value:
598
*                         - SUCCESS: Last event is equal to the I2C_Event
599
*                         - ERROR: Last event is different from the I2C_Event
600
*******************************************************************************/
601
ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx,u16 I2C_EVENT)
602
{
603
  u16  wLastEvent = I2C_GetLastEvent(I2Cx);
604
 
605
  /* Check whther the last event is equal to I2C_EVENT */
606
  if (wLastEvent == I2C_EVENT)
607
  {
608
    /* Return SUCCESS when last event is equal to I2C_EVENT */
609
    return SUCCESS;
610
  }
611
  else
612
  {
613
    /* Return ERROR when last event is different from I2C_EVENT */
614
    return ERROR;
615
  }
616
}
617
 
618
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/