Introduce support for the "graycode" logic pattern. Generate up to
64 bits of graycode output (all logic lines, no repetition, not limited
by the generator's internal pattern buffer). The implementation was
tested with 16 channels.
"all-low",
"all-high",
"squid",
"all-low",
"all-high",
"squid",
};
static const uint32_t scanopts[] = {
};
static const uint32_t scanopts[] = {
+static uint64_t encode_number_to_gray(uint64_t nr)
+{
+ return nr ^ (nr >> 1);
+}
+
+static void set_logic_data(uint64_t bits, uint8_t *data, size_t len)
+{
+ while (len--) {
+ *data++ = bits & 0xff;
+ bits >>= 8;
+ }
+}
+
static void logic_generator(struct sr_dev_inst *sdi, uint64_t size)
{
struct dev_context *devc;
static void logic_generator(struct sr_dev_inst *sdi, uint64_t size)
{
struct dev_context *devc;
uint8_t *sample;
const uint8_t *image_col;
size_t col_count, col_height;
uint8_t *sample;
const uint8_t *image_col;
size_t col_count, col_height;
devc->step %= col_count;
}
break;
devc->step %= col_count;
}
break;
+ case PATTERN_GRAYCODE:
+ for (i = 0; i < size; i += devc->logic_unitsize) {
+ devc->step++;
+ devc->step &= devc->all_logic_channels_mask;
+ gray = encode_number_to_gray(devc->step);
+ gray &= devc->all_logic_channels_mask;
+ set_logic_data(gray, &devc->logic_data[i], devc->logic_unitsize);
+ }
+ break;
default:
sr_err("Unknown pattern: %d.", devc->logic_pattern);
break;
default:
sr_err("Unknown pattern: %d.", devc->logic_pattern);
break;
* something that can get recognized.
*/
PATTERN_SQUID,
* something that can get recognized.
*/
PATTERN_SQUID,
+
+ /** Gray encoded data, like rotary encoder signals. */
+ PATTERN_GRAYCODE,
};
/* Analog patterns we can generate. */
};
/* Analog patterns we can generate. */