diff --git a/components/flow3r_bsp/flow3r_bsp_ad7147.c b/components/flow3r_bsp/flow3r_bsp_ad7147.c index b45118cc7adee64d86bd2534d1d854f887e21078..8649ea54c4b1b404ca2f451bc0ce1894f6873ad2 100644 --- a/components/flow3r_bsp/flow3r_bsp_ad7147.c +++ b/components/flow3r_bsp/flow3r_bsp_ad7147.c @@ -43,6 +43,9 @@ static esp_err_t _sequence_request(ad7147_chip_t *chip, bool reprogram) { int8_t offset = chip->channels[channel].afe_offset; seq_out.channels[i] = channel; seq_out.pos_afe_offsets[i] = offset; + // seq_out.idle_to_bias[i] = !(chip->is_bot && (channel < 10)); // jumpy + // petal 2 + seq_out.idle_to_bias[i] = !chip->is_bot; } esp_err_t ret; diff --git a/components/flow3r_bsp/flow3r_bsp_ad7147.h b/components/flow3r_bsp/flow3r_bsp_ad7147.h index 42d8d2cbc1ea8793b87199213cce99fa332a5524..47f2889e7fa324536864da8a9e54380bb1be5948 100644 --- a/components/flow3r_bsp/flow3r_bsp_ad7147.h +++ b/components/flow3r_bsp/flow3r_bsp_ad7147.h @@ -40,6 +40,8 @@ typedef struct { typedef struct { // Opaque name used to prefix log messages. const char *name; + // True for bottom chip, false for top + bool is_bot; // [0, n_channels) are the expected connected channels to the inputs of the // chip. diff --git a/components/flow3r_bsp/flow3r_bsp_ad7147_hw.c b/components/flow3r_bsp/flow3r_bsp_ad7147_hw.c index d3f10b731e9c74d29b7c9aa586debc5d391b34d7..d33be9432067ce6fcadf1921b3aa4491cddafc57 100644 --- a/components/flow3r_bsp/flow3r_bsp_ad7147_hw.c +++ b/components/flow3r_bsp/flow3r_bsp_ad7147_hw.c @@ -7,7 +7,7 @@ #define TIMEOUT_MS 1000 -#define CIN CDC_NONE 0 +#define CIN_CDC_NONE 0 #define CIN_CDC_NEG 1 #define CIN_CDC_POS 2 #define CIN_BIAS 3 @@ -281,8 +281,9 @@ esp_err_t ad7147_hw_configure_stages(ad7147_hw_t *device, bool reprogram) { // Reset all stage/channel configuration. for (size_t i = 0; i < 12; i++) { + uint8_t idle_con = seq->idle_to_bias[i] ? CIN_BIAS : CIN_CDC_NONE; for (int8_t j = 0; j < 13; j++) { - device->stage_config[i].cinX_connection_setup[j] = CIN_BIAS; + device->stage_config[i].cinX_connection_setup[j] = idle_con; } device->dev_config.stageX_complete_int_enable[i] = false; } diff --git a/components/flow3r_bsp/flow3r_bsp_ad7147_hw.h b/components/flow3r_bsp/flow3r_bsp_ad7147_hw.h index 5cdfd63b34142dba4000d08a47245d0b37af5536..3eba6417c6c0ea2663d024a743b6119f4d81e00a 100644 --- a/components/flow3r_bsp/flow3r_bsp_ad7147_hw.h +++ b/components/flow3r_bsp/flow3r_bsp_ad7147_hw.h @@ -100,6 +100,8 @@ typedef struct { // For each sequencer stage, AFE offset that this stage should use when // sampling the configured channel. int8_t pos_afe_offsets[12]; + // Whether idle pads are supposed to be connected to bias. Awful hack. + bool idle_to_bias[12]; } ad7147_sequence_t; // Configure sequencer stages. @@ -112,4 +114,4 @@ esp_err_t ad7147_hw_configure_stages(ad7147_hw_t *device, // Polls sequencer status from the chip and calls the user callback if new data // is available / the sequence finished. -esp_err_t ad7147_hw_process(ad7147_hw_t *device); \ No newline at end of file +esp_err_t ad7147_hw_process(ad7147_hw_t *device); diff --git a/components/flow3r_bsp/flow3r_bsp_captouch.c b/components/flow3r_bsp/flow3r_bsp_captouch.c index 34b6977c5e519fc4debbc4f371e67c3dce462795..32bcbe16c78ef9bc541183dbcfbd73c9cf86612e 100644 --- a/components/flow3r_bsp/flow3r_bsp_captouch.c +++ b/components/flow3r_bsp/flow3r_bsp_captouch.c @@ -106,6 +106,7 @@ static bool _interrupt_shared = false; static ad7147_chip_t _top = { .name = "top", + .is_bot = false, .nchannels = 12, .sequences = { { @@ -120,6 +121,7 @@ static ad7147_chip_t _top = { static ad7147_chip_t _bot = { .name = "bot", + .is_bot = true, .nchannels = 13, .sequences = { /// This is the ideal sequence we want. First, all the bottom sensors. diff --git a/components/st3m/st3m_captouch.c b/components/st3m/st3m_captouch.c index fb90c0a53d226424843471424aa21a3d680d5285..590f8ac9da2661aa602297760bee4dedb4e6a5c9 100644 --- a/components/st3m/st3m_captouch.c +++ b/components/st3m/st3m_captouch.c @@ -31,8 +31,7 @@ static bool _calibrating = false; static inline void _pad_feed(st3m_petal_pad_state_t *pad, uint16_t data, uint8_t index) { bool top = (index % 2) == 0; - int32_t thres = - top ? (TOP_PETAL_THRESHOLD) : (BOTTOM_PETAL_THRESHOLD); + int32_t thres = top ? (TOP_PETAL_THRESHOLD) : (BOTTOM_PETAL_THRESHOLD); thres = pad->pressed_prev ? thres - (PETAL_HYSTERESIS) : thres; // some hysteresis pad->raw = data; @@ -85,7 +84,7 @@ static inline void _petal_process(st3m_petal_state_t *petal, uint8_t index) { } else { petal->pressure = (petal->base.pressure + petal->tip.pressure) / 2; int32_t raw = petal->base.raw + petal->tip.raw; - if(index == 5) raw *= 2; + if (index == 5) raw *= 2; petal->pressed = raw > thres; int32_t base = petal->base.raw; int32_t tip = petal->tip.raw;