18
18
#include "PeripheralNames.h"
19
19
#include "pinmap.h"
20
20
21
- #define I2C_NACK (0)
22
- #define I2C_ACK (1)
23
- #define I2C_TIMEOUT (100000)
24
- #define SELF_ADDR (0xE0)
21
+ #define I2C_NACK (0)
22
+ #define I2C_ACK (1)
23
+ #define I2C_NO_DATA (0)
24
+ #define I2C_READ_ADDRESSED (1)
25
+ #define I2C_WRITE_GENERAL (2)
26
+ #define I2C_WRITE_ADDRESSED (3)
27
+ #define SELF_ADDR (0xE0)
28
+ #define I2C_TIMEOUT (100000)
25
29
26
30
static const PinMap PinMap_I2C_SDA [] = {
27
31
{PC1 , I2C_0 , PIN_DATA (1 , 2 )},
@@ -42,7 +46,7 @@ typedef struct {
42
46
uint32_t prsck ;
43
47
} I2C_clock_setting_t ;
44
48
45
- static const uint32_t I2C_SCK_DIVIDER_TBL [8 ] = { 20 , 24 , 32 , 48 , 80 , 144 , 272 , 528 }; // SCK Divider value table
49
+ static const uint32_t I2C_SCK_DIVIDER_TBL [8 ] = {20 , 24 , 32 , 48 , 80 , 144 , 272 , 528 }; // SCK Divider value table
46
50
static uint32_t start_flag = 0 ;
47
51
I2C_clock_setting_t clk ;
48
52
I2C_State status ;
@@ -68,7 +72,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
68
72
I2CName i2c_name = (I2CName )pinmap_merge (i2c_sda , i2c_scl );
69
73
MBED_ASSERT ((int )i2c_name != NC );
70
74
71
- switch (i2c_name ) {
75
+ switch (i2c_name ) {
72
76
case I2C_0 :
73
77
CG_SetFcPeriphA (CG_FC_PERIPH_I2C0 , ENABLE );
74
78
obj -> i2c = TSB_I2C0 ;
@@ -153,7 +157,6 @@ int i2c_stop(i2c_t *obj)
153
157
void i2c_reset (i2c_t * obj )
154
158
{
155
159
I2C_SWReset (obj -> i2c );
156
- return ;
157
160
}
158
161
159
162
int i2c_read (i2c_t * obj , int address , char * data , int length , int stop )
@@ -165,7 +168,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
165
168
start_flag = 1 ; // Start Condition
166
169
if (i2c_byte_write (obj , (int32_t )((uint32_t )address | 1U )) == I2C_ACK ) {
167
170
while (count < length ) {
168
- int32_t pdata = i2c_byte_read (obj , ((count < (length - 1 ))? 0 : 1 ));
171
+ int32_t pdata = i2c_byte_read (obj , ((count < (length - 1 )) ? 0 : 1 ));
169
172
if (pdata < 0 ) {
170
173
break ;
171
174
}
@@ -245,7 +248,7 @@ int i2c_byte_write(i2c_t *obj, int data)
245
248
246
249
I2C_ClearINTOutput (obj -> i2c );
247
250
248
- if (start_flag == 1 ) {
251
+ if (start_flag == 1 ) {
249
252
I2C_Start_Condition (obj , (uint32_t )data );
250
253
start_flag = 0 ;
251
254
} else {
@@ -265,14 +268,6 @@ int i2c_byte_write(i2c_t *obj, int data)
265
268
return (result );
266
269
}
267
270
268
-
269
- #if DEVICE_I2CSLAVE
270
-
271
- #define I2C_NO_DATA (0)
272
- #define I2C_READ_ADDRESSED (1)
273
- #define I2C_WRITE_GENERAL (2)
274
- #define I2C_WRITE_ADDRESSED (3)
275
-
276
271
void i2c_slave_mode (i2c_t * obj , int enable_slave )
277
272
{
278
273
i2c_reset (obj );
@@ -293,7 +288,6 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave)
293
288
I2C_Init (obj -> i2c , & obj -> myi2c );
294
289
}
295
290
296
-
297
291
int i2c_slave_receive (i2c_t * obj )
298
292
{
299
293
int32_t result = I2C_NO_DATA ;
@@ -347,15 +341,3 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
347
341
obj -> address = address & 0xFE ;
348
342
i2c_slave_mode (obj , 1 );
349
343
}
350
-
351
- #endif
352
-
353
- void INTI2C0_IRQHandler (void )
354
- {
355
-
356
- }
357
-
358
- void INTI2C1_IRQHandler (void )
359
- {
360
-
361
- }
0 commit comments