Esempio n. 1
0
//=========================================================================
// 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;
}
Esempio n. 2
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;
}
SKYETEK_STATUS 
SPIDevice_Open(LPSKYETEK_DEVICE device)
{
  LPSPI_INFO info;

	if( device == NULL || device->user == NULL )
		return SKYETEK_INVALID_PARAMETER;

  if( device->readFD != 0 && device->writeFD != 0 )
	  return SKYETEK_SUCCESS;

  info = (LPSPI_INFO)device->user;
  info->spiHandle = aa_open(info->port_number);

  if( info->spiHandle < 1 )
  {
    device->readFD = device->writeFD = 0;
    return SKYETEK_FAILURE;
  }

  if( info->type == AA_FEATURE_I2C )
  {
    if( 0 > aa_configure(info->spiHandle, AA_CONFIG_GPIO_I2C) )
      goto failure;
    aa_i2c_pullup(info->spiHandle, AA_I2C_PULLUP_BOTH);
    aa_i2c_bitrate(info->spiHandle, 400);
  }
  else
  {
    /* Set communication parameters */
    if( 0 > aa_configure(info->spiHandle, AA_CONFIG_SPI_GPIO) )
      goto failure;
    if( AA_OK != aa_spi_configure(info->spiHandle,AA_SPI_POL_FALLING_RISING,AA_SPI_PHASE_SETUP_SAMPLE,AA_SPI_BITORDER_MSB) )
      goto failure;
    if( 0 > aa_spi_bitrate(info->spiHandle, 400) ) /* 400 kHz */
      goto failure;
    if( AA_OK != aa_spi_master_ss_polarity(info->spiHandle, AA_SPI_SS_ACTIVE_LOW) )
      goto failure;
    if( AA_OK != aa_gpio_direction(info->spiHandle, 0x00) )
      goto failure;
    if( 0 > aa_gpio_pullup(info->spiHandle, 0x02) )
      goto failure;
  }


  device->readFD = (SKYETEK_DEVICE_FILE)1;
  device->writeFD = (SKYETEK_DEVICE_FILE)1;
	return SKYETEK_SUCCESS;
failure:
  aa_close(info->spiHandle);
  return SKYETEK_FAILURE;
}
Esempio n. 4
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;
}