Detect Mares Quad with more flash memory

The latest variant of the Mares Quad has 4 times more flash memory
compared to the original variant (1M vs 256K). Therefore this variant
supports a new command to read the size of the flash memory.

At the moment, it's unknown whether the previous variant also supports
this new command or not. Probably not, because none of the other
compatible models seems to support it either. Hence we only attempt to
read the flash memory size for the Quad, and a failure is not considered
a fatal error. The disadvantage of this approach is that a temporary
communication problem can result in a misdetection of the flash memory
size.

Reported-by: Janice McLaughlin <janice@moremobilesoftware.com>
This commit is contained in:
Jef Driesen 2019-03-06 20:38:01 +01:00
parent 5c55760fd5
commit 7b29c5d43d

View File

@ -380,6 +380,20 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_
// Autodetect the model using the version packet.
device->model = mares_iconhd_get_model (device);
// Read the size of the flash memory.
unsigned int memsize = 0;
if (device->model == QUAD) {
unsigned char cmd_flash[] = {0xB3, 0x16};
unsigned char rsp_flash[4] = {0};
status = mares_iconhd_transfer (device, cmd_flash, sizeof (cmd_flash), rsp_flash, sizeof (rsp_flash));
if (status != DC_STATUS_SUCCESS) {
WARNING (context, "Failed to read the flash memory size.");
} else {
memsize = array_uint32_le (rsp_flash);
DEBUG (context, "Flash memory size is %u bytes.", memsize);
}
}
// Load the correct memory layout.
switch (device->model) {
case MATRIX:
@ -391,10 +405,17 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_
case NEMOWIDE2:
case SMART:
case SMARTAPNEA:
case QUAD:
device->layout = &mares_nemowide2_layout;
device->packetsize = 256;
break;
case QUAD:
if (memsize > 0x40000) {
device->layout = &mares_iconhd_layout;
} else {
device->layout = &mares_nemowide2_layout;
}
device->packetsize = 256;
break;
case QUADAIR:
case SMARTAIR:
device->layout = &mares_iconhdnet_layout;