1
0
mirror of https://github.com/whowechina/chu_pico.git synced 2025-01-31 12:03:43 +01:00

Get MPR121's max sensitivity

This commit is contained in:
whowechina 2023-09-27 20:59:37 +08:00
parent b726e16458
commit 2eb1d66fcc
7 changed files with 44 additions and 9 deletions

Binary file not shown.

View File

@ -393,6 +393,21 @@ static void handle_debounce(int argc, char *argv[])
disp_sense();
}
static void handle_raw()
{
printf("Key raw readings:\n");
const uint16_t *raw = slider_raw();
printf("|");
for (int i = 0; i < 16; i++) {
printf("%3d|", raw[i * 2]);
}
printf("\n|");
for (int i = 0; i < 16; i++) {
printf("%3d|", raw[i * 2 + 1]);
}
printf("\n");
}
static void handle_save()
{
save_request(true);
@ -414,6 +429,7 @@ void cmd_init()
register_command("filter", handle_filter, "Set pre-filter config.");
register_command("sense", handle_sense, "Set sensitivity config.");
register_command("debounce", handle_debounce, "Set debounce config.");
register_command("raw", handle_raw, "Show key raw readings.");
register_command("save", handle_save, "Save config to flash.");
register_command("factory", config_factory_reset, "Reset everything to default.");
}

View File

@ -12,8 +12,8 @@
#define IO_TIMEOUT_US 1000
#define TOUCH_THRESHOLD_BASE 17
#define RELEASE_THRESHOLD_BASE 12
#define TOUCH_THRESHOLD_BASE 22
#define RELEASE_THRESHOLD_BASE 15
#define MPR121_TOUCH_STATUS_REG 0x00
#define MPR121_OUT_OF_RANGE_STATUS_0_REG 0x02
@ -121,10 +121,14 @@ void mpr121_init(uint8_t i2c_addr)
// if only use 0.5uS CDT, the TGL for proximity cannot meet
// Possible if manually set Register0x72=0x03
// (Auto configure result) alone.
write_reg(i2c_addr, 0x7D, 0xc8); // AC up limit /C8/BD/C0/9C
write_reg(i2c_addr, 0x7E, 0x82); // AC low limit /82/7A/7C/65
write_reg(i2c_addr, 0x7F, 0xb4); // AC target /B4/AA/AC/8C target for /3.0V/2.8V/1.8V
write_reg(i2c_addr, 0x5E, 0x8C); // Run 12 touch, CL=2b10, load 5MSB to baseline
// I want to max out sensitivity, I don't care linearity
const uint8_t usl = (3.3 - 0.1) / 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);
write_reg(i2c_addr, 0x5E, 0x8C); // Run 12 touch, load 5MSB to baseline
}
#define ABS(x) ((x) < 0 ? -(x) : (x))
@ -153,6 +157,11 @@ uint16_t mpr121_touched(uint8_t addr)
return touched;
}
void mpr121_raw(uint8_t addr, uint16_t *raw, int num)
{
mpr121_read_many16(addr, MPR121_ELECTRODE_FILTERED_DATA_REG, raw, num);
}
static uint8_t mpr121_stop(uint8_t addr)
{
uint8_t ecr = read_reg(addr, MPR121_ELECTRODE_CONFIG_REG);

View File

@ -10,6 +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);
void mpr121_filter(uint8_t addr, uint8_t ffi, uint8_t sfi);
void mpr121_sense(uint8_t addr, int8_t sense, int8_t *sense_keys);

View File

@ -49,6 +49,14 @@ void slider_update()
touch[2] = mpr121_touched(MPR121_ADDR + 2);
}
const uint16_t *slider_raw()
{
mpr121_raw(MPR121_ADDR, readout, 12);
mpr121_raw(MPR121_ADDR + 1, readout + 12, 12);
mpr121_raw(MPR121_ADDR + 2, readout + 24, 12);
return readout;
}
bool slider_touched(unsigned key)
{
if (key >= 32) {

View File

@ -12,6 +12,7 @@
void slider_init();
void slider_update();
bool slider_touched(unsigned key);
const uint16_t *slider_raw();
void slider_update_config();
#endif

View File

@ -111,11 +111,11 @@ extern "C" {
#define CFG_TUD_HID_EP_BUFSIZE 64
// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 128)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 128)
// CDC Endpoint transfer buffer size, more is faster
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 128)
#ifdef __cplusplus
}