size reduction by using specialized entry funcs
This commit is contained in:
@@ -37,29 +37,33 @@ static void UTOUCH_EventReportJob(Job *job)
|
||||
EventReport_Send(&er);
|
||||
}
|
||||
|
||||
static void UTOUCH_CheckForBinaryEvents(Unit *unit)
|
||||
static void UTOUCH_CheckForBinaryEvents(Unit *const unit)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
uint32_t time_ms = PTIM_GetTime();
|
||||
const uint32_t time_ms = PTIM_GetTime();
|
||||
|
||||
if (priv->last_done_ms == 0) {
|
||||
// avoid bug with trigger on first capture
|
||||
priv->last_done_ms = time_ms;
|
||||
}
|
||||
|
||||
uint64_t ts = PTIM_GetMicrotime();
|
||||
const uint64_t ts = PTIM_GetMicrotime();
|
||||
uint32_t eventpins = 0;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
|
||||
const uint16_t ms_elapsed = (uint16_t) (time_ms - priv->last_done_ms);
|
||||
|
||||
for (uint16_t i = 0; i < 32; i++) {
|
||||
const uint32_t poke = (uint32_t) (1 << i);
|
||||
if (0 == (priv->all_channels_mask & poke)) continue;
|
||||
if (priv->binary_thr[i] == 0) continue; // skip disabled channels
|
||||
|
||||
const bool can_go_up = !(priv->binary_active_bits&poke) && (priv->readouts[i] > (priv->binary_thr[i] + priv->binary_hysteresis));
|
||||
const bool can_go_down = (priv->binary_active_bits&poke) && (priv->readouts[i] < priv->binary_thr[i]);
|
||||
const bool isactive = (bool) (priv->binary_active_bits & poke);
|
||||
const bool can_go_up = !isactive && (priv->readouts[i] > (priv->binary_thr[i] + priv->binary_hysteresis));
|
||||
const bool can_go_down = isactive && (priv->readouts[i] < priv->binary_thr[i]);
|
||||
|
||||
if (can_go_up) {
|
||||
priv->bin_trig_cnt[i] += (time_ms - priv->last_done_ms);
|
||||
priv->bin_trig_cnt[i] += ms_elapsed;
|
||||
if (priv->bin_trig_cnt[i] >= priv->binary_debounce_ms) {
|
||||
priv->binary_active_bits |= poke;
|
||||
priv->bin_trig_cnt[i] = 0; // reset for the other direction of the switch
|
||||
@@ -72,7 +76,7 @@ static void UTOUCH_CheckForBinaryEvents(Unit *unit)
|
||||
}
|
||||
|
||||
if (can_go_down) {
|
||||
priv->bin_trig_cnt[i] -= (time_ms - priv->last_done_ms);
|
||||
priv->bin_trig_cnt[i] -= ms_elapsed;
|
||||
if (priv->bin_trig_cnt[i] <= -priv->binary_debounce_ms) {
|
||||
priv->binary_active_bits &= ~poke;
|
||||
priv->bin_trig_cnt[i] = 0; // reset for the other direction of the switch
|
||||
|
||||
@@ -147,28 +147,28 @@ void UTOUCH_writeIni(Unit *unit, IniWriter *iw)
|
||||
iw_cmt_newline(iw);
|
||||
|
||||
iw_comment(iw, "Pulse generator clock prescaller (1,2,4,...,128)");
|
||||
iw_entry(iw, "pg-clock-prediv", "%d", (int)priv->cfg.pg_presc);
|
||||
iw_entry_d(iw, "pg-clock-prediv", priv->cfg.pg_presc);
|
||||
iw_comment(iw, "Sense pad charging time (1-16)");
|
||||
iw_entry(iw, "charge-time", "%d", (int)priv->cfg.charge_time);
|
||||
iw_entry_d(iw, "charge-time", priv->cfg.charge_time);
|
||||
iw_comment(iw, "Charge transfer time (1-16)");
|
||||
iw_entry(iw, "drain-time", "%d", (int)priv->cfg.drain_time);
|
||||
iw_entry_d(iw, "drain-time", priv->cfg.drain_time);
|
||||
iw_comment(iw, "Measurement timeout (1-7)");
|
||||
iw_entry(iw, "sense-timeout", "%d", (int)priv->cfg.sense_timeout);
|
||||
iw_entry_d(iw, "sense-timeout", priv->cfg.sense_timeout);
|
||||
|
||||
iw_cmt_newline(iw);
|
||||
iw_comment(iw, "Spread spectrum max deviation (0-128,0=off)");
|
||||
iw_entry(iw, "ss-deviation", "%d", (int)priv->cfg.spread_deviation);
|
||||
iw_entry_d(iw, "ss-deviation", priv->cfg.spread_deviation);
|
||||
iw_comment(iw, "Spreading clock prescaller (1,2)");
|
||||
iw_entry(iw, "ss-clock-prediv", "%d", (int)priv->cfg.ss_presc);
|
||||
iw_entry_d(iw, "ss-clock-prediv", priv->cfg.ss_presc);
|
||||
|
||||
iw_cmt_newline(iw);
|
||||
iw_comment(iw, "Optimize for interlaced pads (individual sampling with others floating)");
|
||||
iw_entry(iw, "interlaced-pads", str_yn(priv->cfg.interlaced));
|
||||
iw_entry_s(iw, "interlaced-pads", str_yn(priv->cfg.interlaced));
|
||||
|
||||
iw_cmt_newline(iw);
|
||||
iw_comment(iw, "Button mode debounce (ms) and release hysteresis (lsb)");
|
||||
iw_entry(iw, "btn-debounce", "%d", (int)priv->cfg.binary_debounce_ms);
|
||||
iw_entry(iw, "btn-hysteresis", "%d", (int)priv->cfg.binary_hysteresis);
|
||||
iw_entry_d(iw, "btn-debounce", priv->cfg.binary_debounce_ms);
|
||||
iw_entry_d(iw, "btn-hysteresis", priv->cfg.binary_hysteresis);
|
||||
|
||||
iw_cmt_newline(iw);
|
||||
iw_comment(iw, "Each used group must have 1 sampling capacitor and 1-3 channels.");
|
||||
@@ -179,9 +179,9 @@ void UTOUCH_writeIni(Unit *unit, IniWriter *iw)
|
||||
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));
|
||||
iw_entry_s(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));
|
||||
iw_entry_s(iw, namebuf, cfg_pinmask_encode(priv->cfg.group_channels[i], unit_tmp512, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ enum TouchCmd_ {
|
||||
CMD_READ=0,
|
||||
CMD_SET_BIN_THR=1,
|
||||
CMD_DISABLE_ALL_REPORTS=2,
|
||||
CMD_SET_DEBOUNCE_TIME=3,
|
||||
CMD_SET_HYSTERESIS=4,
|
||||
CMD_GET_CH_COUNT=10,
|
||||
};
|
||||
|
||||
@@ -24,6 +26,11 @@ static error_t UTOUCH_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command,
|
||||
PayloadBuilder pb = pb_start(unit_tmp512, UNIT_TMP_LEN, NULL);
|
||||
|
||||
switch (command) {
|
||||
/**
|
||||
* read the current touch pad values (smaller = higher capacity)
|
||||
*
|
||||
* resp: a list of u16 (order: group and pin, ascending)
|
||||
*/
|
||||
case CMD_READ:
|
||||
if (priv->status == UTSC_STATUS_BUSY) return E_BUSY;
|
||||
if (priv->status == UTSC_STATUS_FAIL) return E_HW_TIMEOUT;
|
||||
@@ -36,6 +43,11 @@ static error_t UTOUCH_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command,
|
||||
com_respond_pb(frame_id, MSG_SUCCESS, &pb);
|
||||
return E_SUCCESS;
|
||||
|
||||
/**
|
||||
* Set thresholds for the button mode.
|
||||
*
|
||||
* pld: a list of u16 for the enabled channels (order: group and pin, ascending)
|
||||
*/
|
||||
case CMD_SET_BIN_THR:
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (priv->all_channels_mask & (1<<i)) {
|
||||
@@ -48,6 +60,30 @@ static error_t UTOUCH_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command,
|
||||
}
|
||||
return E_SUCCESS;
|
||||
|
||||
/**
|
||||
* Set the debounce time in ms (replaces the default value from settings)
|
||||
*
|
||||
* pld: ms:u16
|
||||
*/
|
||||
case CMD_SET_DEBOUNCE_TIME:
|
||||
priv->binary_debounce_ms = pp_u16(pp);
|
||||
return E_SUCCESS;
|
||||
|
||||
/**
|
||||
* Set hysteresis (replaces the default value from settings)
|
||||
*
|
||||
* Hysteresis is added to the threshold value for the switch-off level
|
||||
* (switch-off happens when the measured value is exceeded - capacity of the pad drops)
|
||||
*
|
||||
* pld: hyst:u16
|
||||
*/
|
||||
case CMD_SET_HYSTERESIS:
|
||||
priv->binary_hysteresis = pp_u16(pp);
|
||||
return E_SUCCESS;
|
||||
|
||||
/**
|
||||
* Disable button mode reports. This effectively sets all thresholds to 0, disabling checking.
|
||||
*/
|
||||
case CMD_DISABLE_ALL_REPORTS:
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (priv->all_channels_mask & (1<<i)) {
|
||||
@@ -58,6 +94,11 @@ static error_t UTOUCH_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command,
|
||||
priv->binary_active_bits = 0;
|
||||
return E_SUCCESS;
|
||||
|
||||
/**
|
||||
* Get the number of configured touch pad channels
|
||||
*
|
||||
* resp: count:u8
|
||||
*/
|
||||
case CMD_GET_CH_COUNT:;
|
||||
uint8_t nb = 0;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
|
||||
Reference in New Issue
Block a user