132 #define DEFAULT_I2C I2C0
134 #define I2C_EEPROM_BUS DEFAULT_I2C
135 #define I2C_IOX_BUS DEFAULT_I2C
137 #define SPEED_100KHZ 100000
138 #define SPEED_400KHZ 400000
141 static const char menu[] =
142 "**************** I2C Demo Menu ****************\r\n"
144 "\t1: Select I2C peripheral [\033[1;32mI2C%d\033[0;37m]\r\n"
145 "\t2: Toggle mode POLLING/INTERRUPT [\033[1;32m%s\033[0;37m]\r\n"
146 "\t3: Probe for Slave devices\r\n"
147 "\t4: Read slave data\r\n"
148 "\t5: Write slave data\r\n"
149 "\t6: Write/Read slave data\r\n";
156 #define I2C_SLAVE_EEPROM_SIZE 64
157 #define I2C_SLAVE_EEPROM_ADDR 0x5A
158 #define I2C_SLAVE_IOX_ADDR 0x5B
192 for (i = 0; i < sz; i++) {
193 if (!(i & 0xF))
DEBUGOUT(
"\r\n%02X: ", i);
208 while (!input_valid) {
217 if (x ==
EOF)
continue;
218 if (i >=
sizeof(ch) - 2)
break;
219 if ((x ==
'\r' || x ==
'\n') && i) {
234 i = strtol(ch, &ptr, 0);
237 DEBUGOUT(
"Invalid input. Retry!\r\n");
274 for (i = 0; i < tmp; i++) {
289 NVIC_EnableIRQ(
id ==
I2C0 ? I2C0_IRQn : I2C1_IRQn);
292 NVIC_DisableIRQ(
id ==
I2C0 ? I2C0_IRQn : I2C1_IRQn);
316 DEBUGOUT(
"Probing available I2C devices...\r\n");
317 DEBUGOUT(
"\r\n 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
318 DEBUGOUT(
"\r\n====================================================");
319 for (i = 0; i <= 0x7F; i++) {
320 if (!(i & 0x0F))
DEBUGOUT(
"\r\n%02X ", i >> 4);
321 if (i <= 7 || i > 0x78) {
344 xfer->
rxSz = xfer->
txSz = sz - buff[0] + 1;
350 static int is_addr = 1;
369 if (seep_xfer.
rxSz == 1)
376 if (seep_xfer.
txSz == 1)
426 if(iox_xfer.
txSz == 1) {
503 DEBUGOUT(
"End of I2C Demo! Bye!\r\n");
520 DEBUGOUT(
"Invalid I2C Device [Must be 0 or 1]\r\n");
540 if (xfer.
txSz == 0)
break;
548 if (!tmp && !xfer.
txSz)
break;
550 DEBUGOUT(
"Master transfer : %s\r\n",
557 DEBUGOUT(
"Input Invalid! Try Again.\r\n");