//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; int bitrate = 100; int res = 0; FILE *logfile = 0; if (argc < 2) { printf("usage: aalights PORT\n"); return 1; } port = atoi(argv[1]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Enable logging logfile = fopen("log.txt", "at"); if (logfile != 0) { aa_log(handle, 3, fileno(logfile)); } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Power the board using the Aardvark adapter's power supply. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Set the bitrate bitrate = aa_i2c_bitrate(handle, I2C_BITRATE); printf("Bitrate set to %d kHz\n", bitrate); res = flash_lights(handle); if (res < 0) printf("error: %s\n", aa_status_string(res)); // Close the device and exit aa_close(handle); // Close the logging file fclose(logfile); return 0; }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; u08 addr = 0; char *filename; int bitrate; if (argc < 4) { printf("usage: aai2c_file PORT SLAVE_ADDR filename\n"); printf(" SLAVE_ADDR is the target slave address\n"); printf("\n"); printf(" 'filename' should contain data to be sent\n"); printf(" to the downstream i2c device\n"); return 1; } port = atoi(argv[1]); addr = (u08)strtol(argv[2], 0, 0); filename = argv[3]; // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Enable the Aardvark adapter's power pins. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Setup the bitrate bitrate = aa_i2c_bitrate(handle, I2C_BITRATE); printf("Bitrate set to %d kHz\n", bitrate); blast_bytes(handle, addr, filename); // Close the device aa_close(handle); return 0; }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; int bitrate = 100; u08 device; u08 addr; u16 length; int bus_timeout; const char *command; if (argc < 7) { printf("usage: aai2c_eeprom PORT BITRATE read SLAVE_ADDR OFFSET LENGTH\n"); printf("usage: aai2c_eeprom PORT BITRATE write SLAVE_ADDR OFFSET LENGTH\n"); printf("usage: aai2c_eeprom PORT BITRATE zero SLAVE_ADDR OFFSET LENGTH\n"); return 1; } port = atoi(argv[1]); bitrate = atoi(argv[2]); command = argv[3]; device = (u08)strtol(argv[4], 0, 0); addr = (u08)strtol(argv[5], 0, 0); length = atoi(argv[6]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Power the EEPROM using the Aardvark adapter's power supply. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Set the bitrate bitrate = aa_i2c_bitrate(handle, bitrate); printf("Bitrate set to %d kHz\n", bitrate); // Set the bus lock timeout bus_timeout = aa_i2c_bus_timeout(handle, BUS_TIMEOUT); printf("Bus lock timeout set to %d ms\n", bus_timeout); // Perform the operation if (strcmp(command, "write") == 0) { _writeMemory(handle, device, addr, length, 0); printf("Wrote to EEPROM\n"); } else if (strcmp(command, "read") == 0) { _readMemory(handle, device, addr, length); } else if (strcmp(command, "zero") == 0) { _writeMemory(handle, device, addr, length, 1); printf("Zeroed EEPROM\n"); } else { printf("unknown command: %s\n", command); } // Close the device and exit aa_close(handle); return 0; }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; u08 addr = 0; int timeout_ms = 0; u08 slave_resp[SLAVE_RESP_SIZE]; int i; /* if (argc < 4) { printf("usage: aai2c_slave PORT SLAVE_ADDR TIMEOUT_MS\n"); printf(" SLAVE_ADDR is the slave address for this device\n"); printf("\n"); printf(" The timeout value specifies the time to\n"); printf(" block until the first packet is received.\n"); printf(" If the timeout is -1, the program will\n"); printf(" block indefinitely.\n"); return 1; } */ /* port = atoi(argv[1]); addr = (u08)strtol(argv[2], 0, 0); timeout_ms = atoi(argv[3]); */ port = 0; //atoi(argv[1]); addr = 0x08; //(u08)strtol(argv[5], 0, 0); timeout_ms = 1*1000; //atoi(argv[6]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Disable the Aardvark adapter's power pins. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_NONE); // Set the slave response; this won't be used unless the master // reads bytes from the slave. for (i=0; i<SLAVE_RESP_SIZE; ++i) slave_resp[i] = 'A' + i; //No response: aa_i2c_slave_set_response(handle, SLAVE_RESP_SIZE, slave_resp); aa_i2c_slave_set_response(handle, 0, NULL); // Enable the slave aa_i2c_slave_enable(handle, addr, 0, 0); // Watch the I2C port printf("Press 'q' to exit the program!!! \n"); do { dump(handle, timeout_ms); } while(getch_noblock() != 'q' ); // Disable the slave and close the device aa_i2c_slave_disable(handle); aa_close(handle); return 0; }