diff --git a/Production/firmware/mai_pico.uf2 b/Production/firmware/mai_pico.uf2 index 8cfc60a..fcaaf03 100644 Binary files a/Production/firmware/mai_pico.uf2 and b/Production/firmware/mai_pico.uf2 differ diff --git a/Production/firmware/mai_pico_max_sense_test.uf2 b/Production/firmware/mai_pico_max_sense_test.uf2 deleted file mode 100644 index ad02dc8..0000000 Binary files a/Production/firmware/mai_pico_max_sense_test.uf2 and /dev/null differ diff --git a/firmware/src/commands.c b/firmware/src/commands.c index aa4950d..2f5e50d 100644 --- a/firmware/src/commands.c +++ b/firmware/src/commands.c @@ -361,8 +361,13 @@ static void print_raw_zones(const char *title, const uint16_t *raw, int num) static void handle_raw() { printf("Touch raw readings:\n"); - printf(" |__1__|__2__|__3__|__4__|__5__|__6__|__7__|__8__|\n"); const uint16_t *raw = touch_raw(); + printf(" Sensor: 0: %s, 1: %s 2: %s\n", + touch_sensor_ok(0) ? "OK" : "ERR", + touch_sensor_ok(1) ? "OK" : "ERR", + touch_sensor_ok(2) ? "OK" : "ERR"); + + printf(" |__1__|__2__|__3__|__4__|__5__|__6__|__7__|__8__|\n"); print_raw_zones("A", raw, 8); print_raw_zones("B", raw + 8, 8); print_raw_zones("C", raw + 16, 2); diff --git a/firmware/src/mpr121.c b/firmware/src/mpr121.c index a6cac5d..997453d 100644 --- a/firmware/src/mpr121.c +++ b/firmware/src/mpr121.c @@ -123,7 +123,7 @@ void mpr121_init(uint8_t i2c_addr) // (Auto configure result) alone. // I want to max out sensitivity, I don't care linearity - const uint8_t usl = (3.3 - 0.1) / 3.3 * 256; + const uint8_t usl = 255; //(3.3 - 0.0) / 3.3 * 256; write_reg(i2c_addr, 0x7D, usl), write_reg(i2c_addr, 0x7E, usl * 0.65), write_reg(i2c_addr, 0x7F, usl * 0.9); @@ -133,21 +133,26 @@ void mpr121_init(uint8_t i2c_addr) #define ABS(x) ((x) < 0 ? -(x) : (x)) -static void mpr121_read_many(uint8_t addr, uint8_t reg, uint8_t *buf, size_t n) +static bool mpr121_read_many(uint8_t addr, uint8_t reg, uint8_t *buf, size_t n) { i2c_write_blocking_until(I2C_PORT, addr, ®, 1, true, time_us_64() + IO_TIMEOUT_US); - i2c_read_blocking_until(I2C_PORT, addr, buf, n, false, - time_us_64() + IO_TIMEOUT_US * n / 2); + int bytes = i2c_read_blocking_until(I2C_PORT, addr, buf, n, false, + time_us_64() + IO_TIMEOUT_US * n / 2); + return bytes == n; } -static void mpr121_read_many16(uint8_t addr, uint8_t reg, uint16_t *buf, size_t n) +static bool mpr121_read_many16(uint8_t addr, uint8_t reg, uint16_t *buf, size_t n) { uint8_t vals[n * 2]; - mpr121_read_many(addr, reg, vals, n * 2); + if (!mpr121_read_many(addr, reg, vals, n * 2)){ + return false; + } + for (int i = 0; i < n; i++) { buf[i] = (vals[i * 2 + 1] << 8) | vals[i * 2]; } + return true; } uint16_t mpr121_touched(uint8_t addr) @@ -157,9 +162,9 @@ uint16_t mpr121_touched(uint8_t addr) return touched; } -void mpr121_raw(uint8_t addr, uint16_t *raw, int num) +bool mpr121_raw(uint8_t addr, uint16_t *raw, int num) { - mpr121_read_many16(addr, MPR121_ELECTRODE_FILTERED_DATA_REG, raw, num); + return mpr121_read_many16(addr, MPR121_ELECTRODE_FILTERED_DATA_REG, raw, num); } static uint8_t mpr121_stop(uint8_t addr) diff --git a/firmware/src/mpr121.h b/firmware/src/mpr121.h index 5b7cfcc..19da7b1 100644 --- a/firmware/src/mpr121.h +++ b/firmware/src/mpr121.h @@ -10,7 +10,7 @@ void mpr121_init(uint8_t addr); uint16_t mpr121_touched(uint8_t addr); -void mpr121_raw(uint8_t addr, uint16_t *raw, int num); +bool mpr121_raw(uint8_t addr, uint16_t *raw, int num); void mpr121_filter(uint8_t addr, uint8_t ffi, uint8_t sfi, uint8_t esi); void mpr121_sense(uint8_t addr, int8_t sense, int8_t *sense_keys, int num); void mpr121_debounce(uint8_t addr, uint8_t touch, uint8_t release); diff --git a/firmware/src/touch.c b/firmware/src/touch.c index 4e6175e..1320cdb 100644 --- a/firmware/src/touch.c +++ b/firmware/src/touch.c @@ -88,13 +88,23 @@ void touch_update() touch_stat(); } +static bool sensor_ok[3]; +bool touch_sensor_ok(unsigned i) +{ + if (i < 3) { + return sensor_ok[i]; + } + return false; +} + const uint16_t *touch_raw() { static uint16_t readout[36]; uint16_t buf[36]; - mpr121_raw(MPR121_ADDR, buf, 12); - mpr121_raw(MPR121_ADDR + 1, buf + 12, 12); - mpr121_raw(MPR121_ADDR + 2, buf + 24, 10); + + for (int i = 0; i < 3; i++) { + sensor_ok[i] = mpr121_raw(MPR121_ADDR + i, buf + i * 12, 12); + } for (int i = 0; i < 34; i++) { readout[touch_map[i]] = buf[i]; diff --git a/firmware/src/touch.h b/firmware/src/touch.h index 129650b..49f41fd 100644 --- a/firmware/src/touch.h +++ b/firmware/src/touch.h @@ -15,6 +15,8 @@ bool touch_touched(unsigned key); uint64_t touch_touchmap(); const uint16_t *touch_raw(); +bool touch_sensor_ok(unsigned i); + void touch_update_config(); unsigned touch_count(unsigned key); void touch_reset_stat();