Skip to content

Commit

Permalink
Touch pad name interface
Browse files Browse the repository at this point in the history
  • Loading branch information
whowechina committed Apr 5, 2024
1 parent c026cee commit 361d031
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 2 additions & 0 deletions firmware/src/mpr121.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef MP121_H
#define MP121_H

#define MPR121_BASE_ADDR 0x5A

void mpr121_init(uint8_t addr);

uint16_t mpr121_touched(uint8_t addr);
Expand Down
46 changes: 31 additions & 15 deletions firmware/src/touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "config.h"
#include "mpr121.h"

#define MPR121_ADDR 0x5A

static uint16_t touch[3];
static unsigned touch_counts[36];

Expand All @@ -36,12 +34,27 @@ void touch_init()
gpio_pull_up(I2C_SCL);

for (int m = 0; m < 3; m++) {
mpr121_init(MPR121_ADDR + m);
mpr121_init(MPR121_BASE_ADDR + m);
}
touch_update_config();
memcpy(touch_map, mai_cfg->alt.touch, sizeof(touch_map));
}

const char *touch_pad_name(unsigned i)
{
static char name[3] = { 0 };
if (i < 18) {
name[0] = "ABC"[i / 8];
name[1] = '1' + i % 8;
} else if (i < 34) {
name[0] = "DE"[(i - 18) / 8];
name[1] = '1' + (i - 18) % 8;
} else {
return "XX";
}
return name;
}

static uint64_t touch_reading;

static void remap_reading()
Expand Down Expand Up @@ -73,9 +86,9 @@ static void touch_stat()

void touch_update()
{
touch[0] = mpr121_touched(MPR121_ADDR) & 0x0fff;
touch[1] = mpr121_touched(MPR121_ADDR + 1) & 0x0fff;
touch[2] = mpr121_touched(MPR121_ADDR + 2) & 0x0fff;
touch[0] = mpr121_touched(MPR121_BASE_ADDR) & 0x0fff;
touch[1] = mpr121_touched(MPR121_BASE_ADDR + 1) & 0x0fff;
touch[2] = mpr121_touched(MPR121_BASE_ADDR + 2) & 0x0fff;

remap_reading();

Expand All @@ -97,7 +110,7 @@ const uint16_t *touch_raw()
uint16_t buf[36];

for (int i = 0; i < 3; i++) {
sensor_ok[i] = mpr121_raw(MPR121_ADDR + i, buf + i * 12, 12);
sensor_ok[i] = mpr121_raw(MPR121_BASE_ADDR + i, buf + i * 12, 12);
}

for (int i = 0; i < 34; i++) {
Expand Down Expand Up @@ -135,13 +148,16 @@ void touch_reset_stat()
void touch_update_config()
{
for (int m = 0; m < 3; m++) {
mpr121_debounce(MPR121_ADDR + m, mai_cfg->sense.debounce_touch,
mai_cfg->sense.debounce_release);
mpr121_sense(MPR121_ADDR + m, mai_cfg->sense.global,
mai_cfg->sense.zones + m * 12,
m != 2 ? 12 : 10);
mpr121_filter(MPR121_ADDR + m, mai_cfg->sense.filter >> 6,
(mai_cfg->sense.filter >> 4) & 0x03,
mai_cfg->sense.filter & 0x07);
mpr121_debounce(MPR121_BASE_ADDR + m,
mai_cfg->sense.debounce_touch,
mai_cfg->sense.debounce_release);
mpr121_sense(MPR121_BASE_ADDR + m,
mai_cfg->sense.global,
mai_cfg->sense.zones + m * 12,
m != 2 ? 12 : 10);
mpr121_filter(MPR121_BASE_ADDR + m,
mai_cfg->sense.filter >> 6,
(mai_cfg->sense.filter >> 4) & 0x03,
mai_cfg->sense.filter & 0x07);
}
}
3 changes: 3 additions & 0 deletions firmware/src/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ enum touch_pads {
B1, B2, B3, B4, B5, B6, B7, B8,
C1, C2, D1, D2, D3, D4, D5, D6, D7, D8,
E1, E2, E3, E4, E5, E6, E7, E8,
XX = 255
};

const char *touch_pad_name(unsigned i);

void touch_init();
void touch_update();
bool touch_touched(unsigned key);
Expand Down

0 comments on commit 361d031

Please sign in to comment.