Compare commits

...

5 commits

Author SHA1 Message Date
Stephan I. Böttcher
231d64480d i2c/run: fix i2c_size bookkeeping 2025-03-03 21:18:36 +01:00
Stephan I. Böttcher
afc22b373a i2c: accept /mag,/acc without additional argument 2025-03-03 14:54:49 +01:00
Stephan I. Böttcher
9da8fda8ca altera_set_register: allow preset writes of zero 2025-03-03 14:47:04 +01:00
Stephan I. Böttcher
b261dd0a3f i2c/addr: optional_expression 2025-03-03 13:24:27 +01:00
Stephan I. Böttcher
3879e0317d parse_expression_square: fix optional_brackets 2025-03-03 13:23:54 +01:00
3 changed files with 10 additions and 13 deletions

View file

@ -419,7 +419,7 @@ int altera_set_register(struct command *cmd, const struct command_par *par,
name = namestr;
snprintf(namestr, sizeof(namestr), "0x%04x", cc&0xdfff);
}
unsigned int p = 0;
unsigned int p = cc >> 16;
if (how & alt_cmd_read)
cc &= ~0x4000;
else if (!e) {
@ -427,13 +427,8 @@ int altera_set_register(struct command *cmd, const struct command_par *par,
cc |= 0x4000;
if (parse_char1(cmd, '='))
cc |= 0x4000;
if (!(cc&0xffff0000)) {
e = parse_expression(cmd, &p);
if (!e)
cc |= 0x4000 | (p<<16);
else if (!(cc & 0x4000))
e = 0;
}
if (!p && !parse_expression(cmd, &p))
cc |= 0x4000 | (p<<16);
}
union {
unsigned short s[2];

10
i2c.c
View file

@ -65,12 +65,14 @@ int i2c_write(struct command *cmd, const struct command_par *par)
unsigned int c = (unsigned int)(par->par);
error_msg_t e = parse_flags(cmd, i2c_write_kw, &c);
unsigned int cc = (c <<= 16) | i2c_register | 0xc001;
if (!e && (cc & 0x03000000) != 0x03000000)
if (!e && (cc & 0x03000000) != 0x03000000 && !(cc & 0x007e0000)) {
// /stop and /unstuck do not use an agrument
// /mag /acc are sufficient
e = parse_expression_square(cmd, &c, optional_brackets);
cc |= c<<16;
}
if (e)
return parser_error_message(cmd, e);
cc |= c<<16;
i2c_size ++;
return altera_set_register(cmd, par, 0, alt_cmd_inj, cc, "i2c");
}
@ -104,7 +106,7 @@ int i2c_addr(struct command *cmd, const struct command_par *par)
}
error_msg_t e = parse_expression_square(cmd, &a, optional_empty | optional_close);
if (!e)
e = parse_expression_square(cmd, &n, optional_brackets | optional_open);
e = parse_expression_square(cmd, &n, optional_any | optional_open);
if (e)
return parser_error_message(cmd, e);
if (n < 0x10000) {
@ -121,7 +123,7 @@ int i2c_addr(struct command *cmd, const struct command_par *par)
a = 0;
case 0x4000:
i2c_address = a;
i2c_size = 0;
i2c_size = n >> 24;
break;
case 0x4001:
i2c_size += 1;

View file

@ -378,7 +378,7 @@ error_msg_t parse_expression_square(struct command *cmd, unsigned int *r, int op
if (!(optional & optional_open && isopen))
e = expect_char(cmd, '[');
isopen = 0;
if (e && !(optional_open & optional_brackets))
if (e && !(optional & optional_brackets))
if (optional & optional_expression)
return 0;
else