22
22
******************************************************************************/
23
23
24
24
// Test configuration block
25
- namespace {
25
+ namespace
26
+ {
26
27
const int ntests = 1000 ;
27
28
const int i2c_freq_hz = 400000 ;
28
29
const int i2c_delay_us = 0 ;
@@ -71,7 +72,6 @@ I2C i2c(p28, p27);
71
72
int main ()
72
73
{
73
74
const int EEPROM_MEM_ADDR = 0xA0 ;
74
- int i2c_stat = 0 ;
75
75
bool result = true ;
76
76
77
77
i2c.frequency (i2c_freq_hz);
@@ -85,14 +85,16 @@ int main()
85
85
data[0 ] = ((0xFF00 & addr) >> 8 ) & 0x00FF ;
86
86
data[1 ] = (addr & 0x00FF );
87
87
88
- if ((i2c_stat = i2c.write (EEPROM_MEM_ADDR, data, sizeof (data))) != 0 )
88
+ if (i2c.write (EEPROM_MEM_ADDR, data, sizeof (data)) != 0 ) {
89
89
write_errors++;
90
+ }
90
91
91
92
while (i2c.write (EEPROM_MEM_ADDR, NULL , 0 )) ; // wait to complete
92
93
93
94
// us delay if specified
94
- if (i2c_delay_us != 0 )
95
+ if (i2c_delay_us != 0 ) {
95
96
wait_us (i2c_delay_us);
97
+ }
96
98
}
97
99
98
100
printf (" [%s]\r\n " , write_errors ? " FAIL" : " OK" );
@@ -108,15 +110,17 @@ int main()
108
110
data[1 ] = (addr & 0x00FF );
109
111
110
112
// Set address for read
111
- if ((i2c_stat = i2c.write (EEPROM_MEM_ADDR, data, 2 , true ) ) != 0 ) {
113
+ if (i2c.write (EEPROM_MEM_ADDR, data, 2 , true ) != 0 ) {
112
114
}
113
115
114
- if ((i2c_stat = i2c.read (EEPROM_MEM_ADDR, data, 8 )) != 0 )
116
+ if (i2c.read (EEPROM_MEM_ADDR, data, 8 ) != 0 ) {
115
117
read_errors++;
118
+ }
116
119
117
120
static char pattern[] = { PATTERN_MASK };
118
- if (memcmp (pattern, data, sizeof (data)))
121
+ if (memcmp (pattern, data, sizeof (data))) {
119
122
pattern_errors++;
123
+ }
120
124
}
121
125
122
126
printf (" [%s]\r\n " , read_errors ? " FAIL" : " OK" );
0 commit comments