int i2c_master_tx_rx(uint8_t addr, uint8_t *tx_data, int tx_len, uint8_t *rx_data, int rx_len) { int i; I2C0_SA = addr; // Set the slave addr I2C0_CNT = tx_len & 0xFF; // Set the tx data count I2C0_CON |= (1 << 9) | (1 << 10); // Set the Master Tx mode if (send_start()) I2C_QUIT_OP; // Trigger by sending Start for (i = 0; i < tx_len; i++) // Send Data { if (send_data(tx_data[i])) I2C_QUIT_OP; } while (!(I2C0_IRQSTATUS & I2C_ST_AR)) // Wait for ready for accessing registers after the tx complete ; I2C0_IRQSTATUS |= I2C_ST_AR; I2C0_CNT = rx_len & 0xFF; // Set the rx data count I2C0_CON &= ~(1 << 9); // Set the Master Rx mode - note master is already set if (send_restart()) I2C_QUIT_OP; // Trigger by sending Start again for (i = 0; i < rx_len; i++) // Receive Data { if (recv_data(&rx_data[i])) I2C_QUIT_OP; } send_stop(); // Done, so Stop return 0; }
int main (int argc, char **argv) { bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); gtk_init (&argc, &argv); if (argc < 2) usage (); if (strcmp (argv[1], "restart") == 0) send_restart (); else if (strcmp (argv[1], "reload-theme") == 0) send_reload_theme (); else if (strcmp (argv[1], "enable-keybindings") == 0) send_set_keybindings (TRUE); else if (strcmp (argv[1], "disable-keybindings") == 0) send_set_keybindings (FALSE); else if (strcmp (argv[1], "toggle-verbose") == 0) { #ifndef WITH_VERBOSE_MODE g_printerr (_("Metacity was compiled without support for verbose mode\n")); return 1; #else send_toggle_verbose (); #endif } else usage (); return 0; }