//****************************************************************************** /// \brief Initialize mXT device and read the info block /// \return #mxt_rc static int mxt_init_chip(struct libmaxtouch_ctx *ctx, struct mxt_device **mxt, struct mxt_conn_info **conn) { int ret; if (!*conn) { ret = mxt_scan(ctx, conn, false); if (ret == MXT_ERROR_NO_DEVICE) { mxt_err(ctx, "Unable to find a device"); return ret; } else if (ret) { mxt_err(ctx, "Failed to find device"); return ret; } } ret = mxt_new_device(ctx, *conn, mxt); if (ret) return ret; #ifdef HAVE_LIBUSB if ((*mxt)->conn->type == E_USB && usb_is_bootloader(*mxt)) { mxt_free_device(*mxt); mxt_err(ctx, "USB device in bootloader mode"); return MXT_ERROR_UNEXPECTED_DEVICE_STATE; } #endif ret = mxt_get_info(*mxt); if (ret) return ret; return MXT_SUCCESS; }
/*! * @brief Entry point for the config_loader utility. * @return Zero on success, negative for error. */ int main (int argc, char *argv[]) { bool override_checking = false; struct stat file_info; char *filename = NULL; printf("Config loader tool v. %s for Atmel maXTouch chips\n\n", VERSION); /* Parse input arguments */ if (argc > 1) { filename = argv[1]; if (argc > 2 && strcmp(argv[2], "-f") == 0) { override_checking = true; } } else { display_usage(); return -1; } /* Check configuration file exists */ if (stat(filename, &file_info) != 0) { printf("Specified file does not exist\n\n"); display_usage(); return -1; } /* Find an mXT device and read the info block */ switch (mxt_scan()) { case 1: /* Device found - continue */ break; case 0: printf("Could not find a device, exiting...\n"); return -1; default: printf("Error initializing, exiting...\n"); return -1; } if (mxt_get_info() < 0) { printf("Error reading info\n"); return -1; } /* Load and back-up the configuration file */ if (mxt_load_config_file(filename, override_checking) < 0) { printf("Error loading the configuration, exiting...\n"); mxt_release(); return -1; } printf("Configuration loaded\n"); if (mxt_backup_config() < 0) { printf("Error backing up, exiting...\n"); mxt_release(); return -1; } printf("Configuration backed up\n"); /* Reset the chip to apply new configuration */ if (mxt_reset_chip(false) < 0) { printf("Error reseting, exiting...\n"); mxt_release(); return -1; } printf("Chip reset\n"); mxt_release(); printf("\nConfiguration file loader ran successfully\n"); return 0; }