tsc ini structure + debug msgs

This commit is contained in:
2018-02-25 13:37:57 +01:00
parent 639031fc38
commit 1f2d346e23
11 changed files with 184 additions and 115 deletions
+69 -2
View File
@@ -2,6 +2,7 @@
// Created by MightyPork on 2018/02/03.
//
#include <stm32f072xb.h>
#include "platform.h"
#include "unit_base.h"
@@ -32,7 +33,70 @@ error_t UTOUCH_init(Unit *unit)
bool suc = true;
struct priv *priv = unit->data;
//
TRY(rsc_claim(unit, R_TSC));
// enable clock
hw_periph_clock_enable(TSC);
for (int gi = 0; gi < 8; gi++) {
const uint8_t cap = priv->cfg.group_scaps[gi];
const uint8_t ch = priv->cfg.group_channels[gi];
if (cap == 0) {
if (ch != 0) {
dbg("TSC group %d has no cap!", (int)(gi+1));
return E_BAD_CONFIG;
}
continue;
}
if (ch == 0) continue; // if no channels, don't bother setting up anything
if (cap != 2 && cap != 4 && cap != 8 && cap != 16) {
dbg("TSC group %d has more than 1 cap!", (int)(gi+1));
return E_BAD_CONFIG;
}
if (cap & ch) {
dbg("TSC pin can't be both channel and cap! (gpr %d)", (int)(gi+1));
return E_BAD_CONFIG;
}
int chnum = 0;
for (int pi = 0; pi < 4; pi++) {
// pin numbers are 1-based in the config
const bool iscap = 0 != (cap & (2 << pi));
const bool isch = 0 != (ch & (2 << pi));
if (iscap || isch) {
Resource r = utouch_group_rscs[gi][pi];
TRY(rsc_claim(unit, r));
// 7 and 8 (1-based) use AF1, else AF3
TRY(hw_configure_gpiorsc_af(r, gi >= 6 ? LL_GPIO_AF_1 : LL_GPIO_AF_3));
if (iscap) dbg("TSC *cap @ %s", rsc_get_name(r));
else dbg("TSC -ch @ %s", rsc_get_name(r));
}
// Sampling cap
if (iscap) {
TSC->IOSCR |= (cap>>1) << (gi*4);
}
// channels are configured individually when read.
// we prepare bitmaps to use for the read groups (all can be read in at most 3 steps)
if (isch) {
priv->channels_phase[chnum] |= 1 << (gi*4+pi);
priv->pgen_phase[chnum] |= 1 << gi;
chnum++;
}
}
}
dbg("TSC phases:");
for (int i = 0; i < 3; i++) {
dbg(" %d: ch %08"PRIx32", g %02"PRIx32, i+1, priv->channels_phase[i], (uint32_t)priv->pgen_phase[i]);
}
return E_SUCCESS;
}
@@ -45,7 +109,10 @@ void UTOUCH_deInit(Unit *unit)
// de-init peripherals
if (unit->status == E_SUCCESS ) {
//
hw_periph_clock_disable(TSC);
// clear all registers to their default values
__HAL_RCC_TSC_FORCE_RESET();
__HAL_RCC_TSC_RELEASE_RESET();
}
// Release all resources, deinit pins
+7 -1
View File
@@ -26,9 +26,15 @@ struct priv {
uint8_t group_channels[8];
} cfg;
// internal state
uint8_t next_phase;
uint32_t channels_phase[3];
uint8_t pgen_phase[3];
uint16_t readouts[32];
};
extern const char *utouch_group_labels[8];
extern const Resource utouch_group_rscs[8][4];
/** Allocate data structure and set defaults */
error_t UTOUCH_preInit(Unit *unit);
+46 -96
View File
@@ -8,9 +8,27 @@
#define TOUCH_INTERNAL
#include "_touch_internal.h"
// some channels are mapped to nonexistent ports, so just ignore them - clutters the config
#define HAVE_CH7 0
#define HAVE_CH8 0
const char *utouch_group_labels[8] = {
"1:A0, 2:A1, 3:A2, 4:A3",
"1:A4, 2:A5, 3:A6, 4:A7",
"1:C5, 2:B0, 3:B1, 4:B2",
"1:A9, 2:A10, 3:A11, 4:A12",
"1:B3, 2:B4, 3:B6, 4:B7",
"1:B11, 2:B12, 3:B13, 4:B14",
"1:E2, 2:E3, 3:E4, 4:E5",
"1:D12, 2:D13, 3:D14, 4:D15",
};
const Resource utouch_group_rscs[8][4] = {
{R_PA0, R_PA1, R_PA2, R_PA3},
{R_PA4, R_PA5, R_PA6, R_PA7},
{R_PC5, R_PB0, R_PB1, R_PB2},
{R_PA9, R_PA10, R_PA11, R_PA12},
{R_PB3, R_PB4, R_PB6, R_PB7},
{R_PB11, R_PB12, R_PB13, R_PB14},
{R_PE2, R_PE3, R_PE4, R_PE5},
{R_PD12, R_PD13, R_PD14, R_PD15},
};
/** Load from a binary buffer stored in Flash */
void UTOUCH_loadBinary(Unit *unit, PayloadParser *pp)
@@ -73,69 +91,27 @@ error_t UTOUCH_loadIni(Unit *unit, const char *key, const char *value)
else if (streq(key, "sense-timeout")) {
priv->cfg.sense_timeout = cfg_u8_parse(value, &suc);
}
else if (streq(key, "g1_cap")) {
priv->cfg.group_scaps[0] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g2_cap")) {
priv->cfg.group_scaps[1] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g3_cap")) {
priv->cfg.group_scaps[2] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g4_cap")) {
priv->cfg.group_scaps[3] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g5_cap")) {
priv->cfg.group_scaps[4] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g6_cap")) {
priv->cfg.group_scaps[5] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
#if HAVE_CH7
else if (streq(key, "g7_cap")) {
priv->cfg.group_scaps[6] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
#endif
#if HAVE_CH8
else if (streq(key, "g8_cap")) {
priv->cfg.group_scaps[7] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
#endif
else if (streq(key, "g1_ch")) {
priv->cfg.group_channels[0] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g2_ch")) {
priv->cfg.group_channels[1] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g3_ch")) {
priv->cfg.group_channels[2] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g4_ch")) {
priv->cfg.group_channels[3] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g5_ch")) {
priv->cfg.group_channels[4] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
else if (streq(key, "g6_ch")) {
priv->cfg.group_channels[5] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
#if HAVE_CH7
else if (streq(key, "g7_ch")) {
priv->cfg.group_channels[6] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
#endif
#if HAVE_CH8
else if (streq(key, "g8_ch")) {
priv->cfg.group_channels[7] = (uint8_t) cfg_pinmask_parse(value, &suc);
}
#endif
else {
volatile char namebuf[10]; // must be volatile or gcc optimizes out the second compare and fucks it up
for (int i = 0; i < 6; i++) { // skip 7,8
SPRINTF(namebuf, "g%d_cap", i+1);
if (streq(key, namebuf)) {
priv->cfg.group_scaps[i] = (uint8_t) cfg_pinmask_parse(value, &suc);
goto matched;
}
SPRINTF(namebuf, "g%d_ch", i+1);
if (streq(key, namebuf)) {
priv->cfg.group_channels[i] = (uint8_t) cfg_pinmask_parse(value, &suc);
goto matched;
}
}
return E_BAD_KEY;
}
matched:
if (!suc) return E_BAD_VALUE;
return E_SUCCESS;
}
@@ -167,39 +143,13 @@ void UTOUCH_writeIni(Unit *unit, IniWriter *iw)
iw_comment(iw, "Channels are numbered 1,2,3,4");
iw_cmt_newline(iw);
iw_comment(iw, "Group 1: A0,A1,A2,A3");
iw_entry(iw, "g1_cap", cfg_pinmask_encode(priv->cfg.group_scaps[0], unit_tmp512, true));
iw_entry(iw, "g1_ch", cfg_pinmask_encode(priv->cfg.group_channels[0], unit_tmp512, true));
iw_comment(iw, "Group 2: A4,A5,A6,A7");
iw_entry(iw, "g2_cap", cfg_pinmask_encode(priv->cfg.group_scaps[1], unit_tmp512, true));
iw_entry(iw, "g2_ch", cfg_pinmask_encode(priv->cfg.group_channels[1], unit_tmp512, true));
iw_comment(iw, "Group 3: C5,B0,B1,B2");
iw_entry(iw, "g3_cap", cfg_pinmask_encode(priv->cfg.group_scaps[2], unit_tmp512, true));
iw_entry(iw, "g3_ch", cfg_pinmask_encode(priv->cfg.group_channels[2], unit_tmp512, true));
iw_comment(iw, "Group 4: A9,A10,A11,A12");
iw_entry(iw, "g4_cap", cfg_pinmask_encode(priv->cfg.group_scaps[3], unit_tmp512, true));
iw_entry(iw, "g4_ch", cfg_pinmask_encode(priv->cfg.group_channels[3], unit_tmp512, true));
iw_comment(iw, "Group 5: B3,B4,B6,B7");
iw_entry(iw, "g5_cap", cfg_pinmask_encode(priv->cfg.group_scaps[4], unit_tmp512, true));
iw_entry(iw, "g5_ch", cfg_pinmask_encode(priv->cfg.group_channels[4], unit_tmp512, true));
iw_comment(iw, "Group 6: B11,B12,B13,B14");
iw_entry(iw, "g6_cap", cfg_pinmask_encode(priv->cfg.group_scaps[5], unit_tmp512, true));
iw_entry(iw, "g6_ch", cfg_pinmask_encode(priv->cfg.group_channels[5], unit_tmp512, true));
#if HAVE_CH7
iw_comment(iw, "E2,E3,E4,E5");
iw_entry(iw, "g7_cap", cfg_pinmask_encode(priv->cfg.group_scaps[6], unit_tmp512, true));
iw_entry(iw, "g7_ch", cfg_pinmask_encode(priv->cfg.group_channels[6], unit_tmp512, true));
#endif
#if HAVE_CH8
iw_comment(iw, "D12,D13,D14,D15");
iw_entry(iw, "g8_cap", cfg_pinmask_encode(priv->cfg.group_scaps[7], unit_tmp512, true));
iw_entry(iw, "g8_ch", cfg_pinmask_encode(priv->cfg.group_channels[7], unit_tmp512, true));
#endif
char namebuf[10];
for (int i = 0; i < 6; i++) { // skip 7,8
iw_commentf(iw, "Group%d - %s", i+1, utouch_group_labels[i]);
SPRINTF(namebuf, "g%d_cap", i+1);
iw_entry(iw, namebuf, cfg_pinmask_encode(priv->cfg.group_scaps[i], unit_tmp512, true));
SPRINTF(namebuf, "g%d_ch", i+1);
iw_entry(iw, namebuf, cfg_pinmask_encode(priv->cfg.group_channels[i], unit_tmp512, true));
}
}
+1 -1
View File
@@ -11,7 +11,7 @@
// ------------------------------------------------------------------------
enum TouchCmd_ {
//
DUMMY=0
};
/** Handle a request message */