A truly modular keyboard
C
keyword: drop the blocking scan and relay drain, keybit_bus_service does both
Nathan7737b2e293ba
diff --git a/firmware/keyword/Core/Inc/keybit_bus.h b/firmware/keyword/Core/Inc/keybit_bus.hindex 2737adc..ff64f3d 100644--- a/firmware/keyword/Core/Inc/keybit_bus.h+++ b/firmware/keyword/Core/Inc/keybit_bus.h@@ -70,25 +70,17 @@ int keybit_bus_unstick(I2C_HandleTypeDef *i2c);* how many were assigned. */int keybit_bus_assign(I2C_HandleTypeDef *i2c);-/* Read every assigned Keybit into out. Returns the count. Probes all- * addresses, so it takes tens of ms; run it every few hundred ms. */-int keybit_bus_scan(I2C_HandleTypeDef *i2c, keybit_info_t *out, int max);--/* Fast path for typing: refresh key_down of the n Keybits from the last- * scan, one 1-byte read each (well under 1 ms apiece at 100 kHz). Returns a- * bitmask of entries whose key state changed. */+/* Refresh key_down of the Keybits before v12, one 1-byte read each (~2 ms+ * apiece at 20 kHz). Returns a bitmask of entries whose key state changed. */uint32_t keybit_bus_poll_keys(I2C_HandleTypeDef *i2c, keybit_info_t *k, int n);-/* Drain relayed events from the n touching Keybits into the remote table- * (r, with *rn entries in use) and age out silent ones. Run it with- * keybit_bus_poll_keys. Returns 1 if any entry changed. */-int keybit_bus_poll_relay(I2C_HandleTypeDef *i2c, keybit_info_t *k, int n,- keybit_remote_t *r, int *rn);--/* All the side bus work, a little per call: key polls every 15 ms, event- * drains (every 15 ms from a Keybit that relays chained ones, else 60 ms),- * and an address scan that looks at one address per call on calls with- * nothing else to do, about every 500 ms. Call it every main loop pass. */+/* All the side bus work, a little per call. v12 Keybits: one status stream+ * read (key, events) per slot, round robin, at up to 100 kHz while every+ * touching Keybit is v12 (stepping down when reads fail). Older ones: key+ * polls every 15 ms and event drains every 15 ms (60 ms if nothing is+ * chained behind it) at 20 kHz. An address scan looks at one address per+ * call on calls with nothing else to do, about every 500 ms, at 20 kHz.+ * Call it every main loop pass. */#define KEYBIT_CHANGED 1 /* a key, a Keybit or where one is changed */#define KEYBIT_JOINED 2 /* a Keybit joined, touching or chained */int keybit_bus_service(I2C_HandleTypeDef *i2c, keybit_info_t *k, int *n, keybit_remote_t *r, int *rn);diff --git a/firmware/keyword/Core/Src/keybit_bus.c b/firmware/keyword/Core/Src/keybit_bus.cindex 0c10f70..630ec32 100644--- a/firmware/keyword/Core/Src/keybit_bus.c+++ b/firmware/keyword/Core/Src/keybit_bus.c@@ -235,33 +235,6 @@ static char keyword_side(char keybit_side)}}-int keybit_bus_scan(I2C_HandleTypeDef *i2c, keybit_info_t *out, int max)-{- int n = 0;- for (uint8_t a = ADDR_FIRST; a <= ADDR_LAST && n < max; a++) {- IWDG->KR = 0xAAAA;- if (a == KEYBIT_DEFAULT_ADDR || a == LINK_ADDR || a == CHARGER_ADDR) continue;- if (!is_ready(i2c, a)) continue;-- uint8_t head[10];- if (!read_regs(i2c, a, REG_MAGIC, head, sizeof(head)) || head[0] != MAGIC) continue;-- keybit_info_t *k = &out[n];- memset(k, 0, sizeof(*k));- /* Reading the UID also catches two Keybits on one address: the loser of- * the arbitration drops its address and turns up on the default one. */- if (!read_regs(i2c, a, REG_UID, k->uid, sizeof(k->uid))) continue;- k->addr = a;- k->fw = head[1];- k->key_down = head[6] & 1;- k->keybit_side = (char)head[7];- k->at = keyword_side(k->keybit_side);- k->backwards = k->fw >= 6 ? head[9] & 0x0F : 0; /* reg 0x09 is new in v6 */- n++;- }- return n;-}-uint32_t keybit_bus_poll_keys(I2C_HandleTypeDef *i2c, keybit_info_t *k, int n){uint32_t changed = 0;@@ -453,14 +426,6 @@ static int relay_age(keybit_remote_t *r, int rn)return changed;}-int keybit_bus_poll_relay(I2C_HandleTypeDef *i2c, keybit_info_t *k, int n,- keybit_remote_t *r, int *rn)-{- int changed = 0, remote = 0;- for (int i = 0; i < n; i++) changed |= relay_one(i2c, k, n, i, r, rn, &remote);- return changed | relay_age(r, *rn);-}-/* ------------------------------------------------------------------------ *//* The whole side bus, a little at a time from the main loop */