74 #define DEFAULT_I2C I2C0
76 #define I2C_EEPROM_BUS DEFAULT_I2C
77 #define I2C_IOX_BUS DEFAULT_I2C
79 #define SPEED_100KHZ 100000
80 #define SPEED_400KHZ 400000
83 static const char menu[] =
84 "**************** I2C Demo Menu ****************\r\n"
86 "\t1: Select I2C peripheral [\033[1;32mI2C%d\033[0;37m]\r\n"
87 "\t2: Toggle mode POLLING/INTERRUPT [\033[1;32m%s\033[0;37m]\r\n"
88 "\t3: Probe for Slave devices\r\n"
89 "\t4: Read slave data\r\n"
90 "\t5: Write slave data\r\n"
91 "\t6: Write/Read slave data\r\n";
98 #define I2C_SLAVE_EEPROM_SIZE 64
99 #define I2C_SLAVE_EEPROM_ADDR 0x5A
100 #define I2C_SLAVE_IOX_ADDR 0x5B
135 for (i = 0; i < sz; i++) {
136 if (!(i & 0xF))
DEBUGOUT(
"\r\n%02X: ", i);
151 while (!input_valid) {
160 if (x ==
EOF)
continue;
161 if (i >=
sizeof(ch) - 2)
break;
162 if ((x ==
'\r' || x ==
'\n') && i) {
177 i = strtol(ch, &ptr, 0);
180 DEBUGOUT(
"Invalid input. Retry!\r\n");
187 static int sind = -1;
189 if (sind >=
sizeof(val)) sind = -1;
190 while (sind < 0 && (
tick_cnt & 0x7F)) {}
222 for (i = 0; i < tmp; i++) {
237 NVIC_EnableIRQ(I2C0_IRQn);
240 NVIC_DisableIRQ(I2C0_IRQn);
264 DEBUGOUT(
"Probing available I2C devices...\r\n");
265 DEBUGOUT(
"\r\n 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
266 DEBUGOUT(
"\r\n====================================================");
267 for (i = 0; i <= 0x7F; i++) {
268 if (!(i & 0x0F))
DEBUGOUT(
"\r\n%02X ", i >> 4);
269 if (i <= 7 || i > 0x78) {
292 xfer->
rxSz = xfer->
txSz = sz - buff[0] + 1;
298 static int is_addr = 1;
317 if (seep_xfer.
rxSz == 1)
324 if (seep_xfer.
txSz == 1)
374 if(iox_xfer.
txSz == 1) {
442 DEBUGOUT(
"End of I2C Demo! Bye!\r\n");
466 if (xfer.
txSz == 0)
break;
474 if (!tmp && !xfer.
txSz)
break;
476 DEBUGOUT(
"Master transfer : %s\r\n",
483 DEBUGOUT(
"Input Invalid! Try Again.\r\n");