Skip to content
Snippets Groups Projects
Commit dd4853e3 authored by moon2's avatar moon2 :speech_balloon:
Browse files

captouch: composite AFE (helps petal 2 a bit)

parent 181d4652
No related branches found
No related tags found
1 merge request!631captouch: composite afe
Pipeline #9515 passed
...@@ -42,10 +42,16 @@ static esp_err_t _sequence_request(ad7147_chip_t *chip, bool reprogram) { ...@@ -42,10 +42,16 @@ static esp_err_t _sequence_request(ad7147_chip_t *chip, bool reprogram) {
int8_t channel = seq[i]; int8_t channel = seq[i];
int8_t offset = chip->channels[channel].afe_offset; int8_t offset = chip->channels[channel].afe_offset;
seq_out.channels[i] = channel; seq_out.channels[i] = channel;
seq_out.pos_afe_offsets[i] = offset;
// seq_out.idle_to_bias[i] = !(chip->is_bot && (channel < 10)); // jumpy // seq_out.idle_to_bias[i] = !(chip->is_bot && (channel < 10)); // jumpy
// petal 2 // petal 2
seq_out.idle_to_bias[i] = !chip->is_bot; seq_out.idle_to_bias[i] = !chip->is_bot;
if (offset < 63) {
seq_out.neg_afe_offsets[i] = offset;
seq_out.pos_afe_offsets[i] = 0;
} else {
seq_out.neg_afe_offsets[i] = 63;
seq_out.pos_afe_offsets[i] = offset - 63;
}
} }
esp_err_t ret; esp_err_t ret;
...@@ -119,7 +125,7 @@ static bool _channel_afe_tweak(ad7147_chip_t *chip, size_t cix) { ...@@ -119,7 +125,7 @@ static bool _channel_afe_tweak(ad7147_chip_t *chip, size_t cix) {
// Saturated, can't do anything. // Saturated, can't do anything.
return false; return false;
} }
if (offset >= 63 && diff > 0) { if (offset >= 126 && diff > 0) {
// Saturated, can't do anything. // Saturated, can't do anything.
return false; return false;
} }
...@@ -128,8 +134,8 @@ static bool _channel_afe_tweak(ad7147_chip_t *chip, size_t cix) { ...@@ -128,8 +134,8 @@ static bool _channel_afe_tweak(ad7147_chip_t *chip, size_t cix) {
if (offset < 0) { if (offset < 0) {
offset = 0; offset = 0;
} }
if (offset > 63) { if (offset > 126) {
offset = 63; offset = 126;
} }
#if 0 #if 0
...@@ -151,9 +157,9 @@ static void _on_data(void *user, uint16_t *data, size_t len) { ...@@ -151,9 +157,9 @@ static void _on_data(void *user, uint16_t *data, size_t len) {
if (chip->calibration_cycles > 0) { if (chip->calibration_cycles > 0) {
// We're doing a calibration cycle on our channels. Instead of writing // We're doing a calibration cycle on our channels. Instead of writing
// the data to channel->cdc, write it to channel->amb_meas. // the data to channel->cdc, write it to channel->amb_meas.
size_t j = chip->calibration_cycles - 1; int8_t j = chip->calibration_cycles - 1;
if (j < _AD7147_CALIB_CYCLES) { if (j < _AD7147_CALIB_CYCLES) { // throw away first few datapoints
for (size_t i = 0; i < len; i++) { for (int8_t i = 0; i < len; i++) {
chip->channels[_channel_from_readout(chip, i)].amb_meas[j] = chip->channels[_channel_from_readout(chip, i)].amb_meas[j] =
data[i]; data[i];
} }
...@@ -186,9 +192,18 @@ static void _on_data(void *user, uint16_t *data, size_t len) { ...@@ -186,9 +192,18 @@ static void _on_data(void *user, uint16_t *data, size_t len) {
// Calibration measurements done. Calculate average amb data for // Calibration measurements done. Calculate average amb data for
// each channel. // each channel.
for (size_t i = 0; i < chip->nchannels; i++) { for (size_t i = 0; i < chip->nchannels; i++) {
#if 1
uint16_t avg = uint16_t avg =
_average_calib_measurements(chip->channels[i].amb_meas); _average_calib_measurements(chip->channels[i].amb_meas);
chip->channels[i].amb = avg; chip->channels[i].amb = avg;
#else
// TODO: compare performance
uint32_t avg = 0;
for (uint8_t j = 0; j < _AD7147_CALIB_CYCLES; j++) {
avg += chip->channels[i].amb_meas[j];
}
chip->channels[i].amb = avg / _AD7147_CALIB_CYCLES;
#endif
} }
char msg[256]; char msg[256];
...@@ -210,11 +225,11 @@ static void _on_data(void *user, uint16_t *data, size_t len) { ...@@ -210,11 +225,11 @@ static void _on_data(void *user, uint16_t *data, size_t len) {
rerun |= (1 << i); rerun |= (1 << i);
} }
} }
if (rerun != 0) { if (rerun != 0) {
// Rerun calibration again, // Rerun calibration again,
ESP_LOGI(TAG, ESP_LOGI(TAG,
"%s: calibration done, but can do better (%04x). " "%s: calibration cycle complete, but can do "
"better (%04x). "
"Retrying.", "Retrying.",
chip->name, rerun); chip->name, rerun);
chip->calibration_cycles = _AD7147_CALIB_CYCLES + 2; chip->calibration_cycles = _AD7147_CALIB_CYCLES + 2;
......
...@@ -276,6 +276,10 @@ esp_err_t ad7147_hw_init(ad7147_hw_t *device, flow3r_i2c_address addr, ...@@ -276,6 +276,10 @@ esp_err_t ad7147_hw_init(ad7147_hw_t *device, flow3r_i2c_address addr,
return _configure_full(device); return _configure_full(device);
} }
static inline uint8_t afe_limit(int8_t offset) {
return offset < 0 ? 0 : (offset > 63 ? 63 : offset);
}
esp_err_t ad7147_hw_configure_stages(ad7147_hw_t *device, esp_err_t ad7147_hw_configure_stages(ad7147_hw_t *device,
const ad7147_sequence_t *seq, const ad7147_sequence_t *seq,
bool reprogram) { bool reprogram) {
...@@ -291,10 +295,14 @@ esp_err_t ad7147_hw_configure_stages(ad7147_hw_t *device, ...@@ -291,10 +295,14 @@ esp_err_t ad7147_hw_configure_stages(ad7147_hw_t *device,
// Configure stages as requested. // Configure stages as requested.
for (size_t i = 0; i < seq->len; i++) { for (size_t i = 0; i < seq->len; i++) {
int8_t channel = seq->channels[i]; int8_t channel = seq->channels[i];
int8_t offset = seq->pos_afe_offsets[i];
device->stage_config[i].cinX_connection_setup[channel] = CIN_CDC_POS; device->stage_config[i].cinX_connection_setup[channel] = CIN_CDC_POS;
unsigned int pos_offset = offset < 0 ? 0 : (offset > 63 ? 63 : offset);
device->stage_config[i].pos_afe_offset = pos_offset; device->stage_config[i].pos_afe_offset =
afe_limit(seq->pos_afe_offsets[i]);
device->stage_config[i].neg_afe_offset =
afe_limit(seq->neg_afe_offsets[i]);
device->stage_config[i].neg_afe_offset_swap = true;
device->stage_config[i].pos_afe_offset_swap = false;
} }
device->dev_config.sequence_stage_num = seq->len - 1; device->dev_config.sequence_stage_num = seq->len - 1;
device->dev_config.stageX_complete_int_enable[seq->len - 1] = true; device->dev_config.stageX_complete_int_enable[seq->len - 1] = true;
......
...@@ -102,6 +102,7 @@ typedef struct { ...@@ -102,6 +102,7 @@ typedef struct {
int8_t pos_afe_offsets[12]; int8_t pos_afe_offsets[12];
// Whether idle pads are supposed to be connected to bias. Awful hack. // Whether idle pads are supposed to be connected to bias. Awful hack.
bool idle_to_bias[12]; bool idle_to_bias[12];
int8_t neg_afe_offsets[12];
} ad7147_sequence_t; } ad7147_sequence_t;
// Configure sequencer stages. // Configure sequencer stages.
......
...@@ -401,7 +401,7 @@ static uint16_t amb_limit(int32_t data) { ...@@ -401,7 +401,7 @@ static uint16_t amb_limit(int32_t data) {
} }
static uint8_t afe_limit(int32_t data) { static uint8_t afe_limit(int32_t data) {
return data > 63 ? 63 : (data < 0 ? 0 : data); return data > 126 ? 126 : (data < 0 ? 0 : data);
} }
void flow3r_bsp_captouch_set_calibration_data(int32_t *data) { void flow3r_bsp_captouch_set_calibration_data(int32_t *data) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment