This commit is contained in:
xenia 2021-06-22 03:57:02 -04:00
parent ef138c0cd7
commit abdd82019a
1 changed files with 49 additions and 19 deletions

View File

@ -229,6 +229,9 @@ enum {
CAP_READING CAP_READING
} sq_state = APP_INIT; } sq_state = APP_INIT;
bool settings_init = false;
unsigned char sq_settings[24] = {0};
FT_STATUS FT_Close(FT_HANDLE ftHandle) { FT_STATUS FT_Close(FT_HANDLE ftHandle) {
/* TRACE("FT_Close"); */ /* TRACE("FT_Close"); */
@ -288,14 +291,14 @@ FT_STATUS FT_OpenEx(PVOID pArg1, DWORD flags, FT_HANDLE* pHandle) {
} }
FT_STATUS FT_Read(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned) { FT_STATUS FT_Read(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned) {
TRACE("FT_Read"); /* TRACE("FT_Read"); */
size_t max_bytes = dwBytesToRead; size_t max_bytes = dwBytesToRead;
if (read_state.len - read_state.pos > max_bytes) { if (read_state.len - read_state.pos > max_bytes) {
max_bytes = read_state.len - read_state.pos; max_bytes = read_state.len - read_state.pos;
} }
printf("req size: %lu | state pos %lu state len %lu\n", max_bytes, /* printf("req size: %lu | state pos %lu state len %lu\n", max_bytes, */
read_state.pos, read_state.len); /* read_state.pos, read_state.len); */
memcpy(lpBuffer, &read_state.data[read_state.pos], max_bytes); memcpy(lpBuffer, &read_state.data[read_state.pos], max_bytes);
read_state.pos += max_bytes; read_state.pos += max_bytes;
*lpBytesReturned = max_bytes; *lpBytesReturned = max_bytes;
@ -336,6 +339,17 @@ void dump(unsigned char* buffer, size_t len) {
printf("\n"); printf("\n");
} }
void dump_with_color(unsigned char* buffer, unsigned char* compare, size_t len) {
for (size_t i = 0; i < len; i++) {
if (buffer[i] == compare[i]) {
printf("%02x ", buffer[i]);
} else {
printf("\x1b[1m\x1b[31m%02x\x1b[m\x0f ", buffer[i]);
}
}
printf("\n");
}
void print_bin(unsigned char b) { void print_bin(unsigned char b) {
for (int i = 7; i >= 0; i--) { for (int i = 7; i >= 0; i--) {
if ((b>>i)&0x1) { if ((b>>i)&0x1) {
@ -347,15 +361,15 @@ void print_bin(unsigned char b) {
} }
FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD written) { FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD written) {
TRACE("FT_Write"); /* TRACE("FT_Write"); */
unsigned char* buffer = (unsigned char*) lpBuffer; unsigned char* buffer = (unsigned char*) lpBuffer;
switch (buffer[0]) { switch (buffer[0]) {
case 0x94: case 0x94:
TRACE("bootloader reset"); /* TRACE("bootloader reset"); */
sq_state = BOOT_INIT; sq_state = BOOT_INIT;
break; break;
case 0x93: case 0x93:
TRACE("app reset"); /* TRACE("app reset"); */
sq_state = APP_INIT; sq_state = APP_INIT;
break; break;
case 0xf1: case 0xf1:
@ -365,8 +379,20 @@ FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD writt
ABORT("wrong code!"); ABORT("wrong code!");
} }
} else { } else {
printf("settings buffer:\n"); if (len != 25) {
dump(buffer, len); dump(buffer, len);
ABORT("bad settings len");
}
printf(" addr: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17\n");
printf("settings data: ");
if (!settings_init) {
dump(&buffer[1], 24);
memcpy(sq_settings, &buffer[1], 24);
printf("saved init settings\n");
settings_init = true;
} else {
dump_with_color(&buffer[1], sq_settings, 24);
}
} }
break; break;
case 0xfd: case 0xfd:
@ -374,24 +400,24 @@ FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD writt
ABORT("wrong 0xfd command"); ABORT("wrong 0xfd command");
} }
if (sq_state == BOOT_INIT) { if (sq_state == BOOT_INIT) {
printf("boot echo\n"); /* printf("boot echo\n"); */
init_read_state("\x01\x01\x01\x01", 4); init_read_state("\x01\x01\x01\x01", 4);
dump(read_state.data, read_state.len); /* dump(read_state.data, read_state.len); */
} else { } else {
printf("app echo\n"); /* printf("app echo\n"); */
init_read_state("\x22\x22\x22\x22", 4); init_read_state("\x22\x22\x22\x22", 4);
dump(read_state.data, read_state.len); /* dump(read_state.data, read_state.len); */
} }
break; break;
case 0xf4: case 0xf4:
TRACE("got trigger settings"); /* TRACE("got trigger settings"); */
dump(buffer, len); /* dump(buffer, len); */
for (size_t i = 1; i < len; i += 4) { for (size_t i = 1; i < len; i += 4) {
unsigned char cfg0 = buffer[i+0]; unsigned char cfg0 = buffer[i+0];
unsigned char cfg1 = buffer[i+1]; unsigned char cfg1 = buffer[i+1];
unsigned char cfg2 = buffer[i+2]; unsigned char cfg2 = buffer[i+2];
unsigned char cfg3 = buffer[i+3]; unsigned char cfg3 = buffer[i+3];
printf("SLOT: "); printf("TRIG SLOT: ");
print_bin(cfg0); print_bin(cfg0);
printf(" "); printf(" ");
print_bin(cfg1); print_bin(cfg1);
@ -405,21 +431,25 @@ FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD writt
case 0xf0: case 0xf0:
switch (buffer[1]) { switch (buffer[1]) {
case 0x00: case 0x00:
printf("state -> ready\n"); /* printf("state -> ready\n"); */
if (sq_state == CAP_READING) {
printf("========= end capture =========\n");
}
sq_state = CAP_READY; sq_state = CAP_READY;
break; break;
case 0x01: case 0x01:
printf("wait for trigger command\n"); /* printf("wait for trigger command\n"); */
init_read_state("\x11\x00\x00\xdd", 4); init_read_state("\x11\x00\x00\xdd", 4);
break; break;
case 0x06: case 0x06:
printf("start read"); /* printf("start read"); */
sq_state = CAP_READING;
read_state.len = 16384; read_state.len = 16384;
read_state.pos = 0; read_state.pos = 0;
for (size_t i = 0; i < 16384; i++) { for (size_t i = 0; i < 16384; i++) {
read_state.data[i] = (i & 0x1) ? 0xf0 : 0xa5; read_state.data[i] = (i & 0x1) ? 0xf0 : 0xa5;
} }
printf("sending to app"); /* printf("sending to app"); */
break; break;
default: default:
printf("unknown capture cmd code\n"); printf("unknown capture cmd code\n");