diff --git a/gex.mk b/gex.mk index 46d79b7..feb7cbb 100644 --- a/gex.mk +++ b/gex.mk @@ -92,7 +92,7 @@ GEX_CDEFS = $(GEX_CDEFS_BASE) \ -DASSERT_FILENAMES=1 \ -DDEBUG_VFS=0 \ -DDEBUG_FLASH_WRITE=0 \ - -DVERBOSE_HARDFAULT=1 \ + -DVERBOSE_HARDFAULT=0 \ -DUSE_STACK_MONITOR=1 \ -DUSE_DEBUG_UART=1 \ -DDEBUG_MALLOC=0 \ diff --git a/units/1wire/_ow_settings.c b/units/1wire/_ow_settings.c index 0042c76..c8daa4c 100644 --- a/units/1wire/_ow_settings.c +++ b/units/1wire/_ow_settings.c @@ -64,5 +64,5 @@ void OW_writeIni(Unit *unit, IniWriter *iw) iw_entry(iw, "pin", "%c%d", priv->port_name, priv->pin_number); iw_comment(iw, "Parasitic (bus-powered) mode"); - iw_entry(iw, "parasitic", str_yn(priv->parasitic)); + iw_entry_s(iw, "parasitic", str_yn(priv->parasitic)); } diff --git a/units/adc/_adc_settings.c b/units/adc/_adc_settings.c index de71cea..f48f31e 100644 --- a/units/adc/_adc_settings.c +++ b/units/adc/_adc_settings.c @@ -80,14 +80,14 @@ void UADC_writeIni(Unit *unit, IniWriter *iw) iw_comment(iw, "Enabled channels, comma separated"); iw_comment(iw, " 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17"); iw_comment(iw, "A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 C0 C1 C2 C3 C4 C5 Tsens Vref"); - iw_entry(iw, "channels", cfg_pinmask_encode(priv->cfg.channels, unit_tmp512, true)); + iw_entry_s(iw, "channels", cfg_pinmask_encode(priv->cfg.channels, unit_tmp512, true)); iw_cmt_newline(iw); iw_comment(iw, "Sampling time (0-7)"); - iw_entry(iw, "sample_time", "%d", (int)priv->cfg.sample_time); + iw_entry_d(iw, "sample_time", priv->cfg.sample_time); iw_comment(iw, "Sampling frequency (Hz)"); - iw_entry(iw, "frequency", "%d", (int)priv->cfg.frequency); + iw_entry_d(iw, "frequency", priv->cfg.frequency); iw_cmt_newline(iw); iw_comment(iw, "Sample buffer size"); @@ -95,12 +95,12 @@ void UADC_writeIni(Unit *unit, IniWriter *iw) iw_comment(iw, "- defines the maximum pre-trigger size (divide by # of channels)"); iw_comment(iw, "- captured data is sent in half-buffer chunks"); iw_comment(iw, "- buffer overrun aborts the data capture"); - iw_entry(iw, "buffer_size", "%d", (int)priv->cfg.buffer_size); + iw_entry_d(iw, "buffer_size", priv->cfg.buffer_size); iw_cmt_newline(iw); iw_comment(iw, "Exponential averaging coefficient (permil, range 0-1000 ~ 0.000-1.000)"); iw_comment(iw, "- used formula: y[t]=(1-k)*y[t-1]+k*u[t]"); iw_comment(iw, "- not available when a capture is running"); - iw_entry(iw, "avg_factor", "%d", priv->cfg.averaging_factor); + iw_entry_d(iw, "avg_factor", priv->cfg.averaging_factor); } diff --git a/units/digital_in/_din_settings.c b/units/digital_in/_din_settings.c index 9c152ec..40d03d5 100644 --- a/units/digital_in/_din_settings.c +++ b/units/digital_in/_din_settings.c @@ -92,24 +92,24 @@ void DIn_writeIni(Unit *unit, IniWriter *iw) iw_entry(iw, "port", "%c", priv->port_name); iw_comment(iw, "Pins (comma separated, supports ranges)"); - iw_entry(iw, "pins", cfg_pinmask_encode(priv->pins, unit_tmp512, 0)); + iw_entry_s(iw, "pins", cfg_pinmask_encode(priv->pins, unit_tmp512, 0)); iw_comment(iw, "Pins with pull-up"); - iw_entry(iw, "pull-up", cfg_pinmask_encode(priv->pullup, unit_tmp512, 0)); + iw_entry_s(iw, "pull-up", cfg_pinmask_encode(priv->pullup, unit_tmp512, 0)); iw_comment(iw, "Pins with pull-down"); - iw_entry(iw, "pull-down", cfg_pinmask_encode(priv->pulldown, unit_tmp512, 0)); + iw_entry_s(iw, "pull-down", cfg_pinmask_encode(priv->pulldown, unit_tmp512, 0)); iw_cmt_newline(iw); iw_comment(iw, "Trigger pins activated by rising/falling edge"); - iw_entry(iw, "trig-rise", cfg_pinmask_encode(priv->trig_rise, unit_tmp512, 0)); - iw_entry(iw, "trig-fall", cfg_pinmask_encode(priv->trig_fall, unit_tmp512, 0)); + iw_entry_s(iw, "trig-rise", cfg_pinmask_encode(priv->trig_rise, unit_tmp512, 0)); + iw_entry_s(iw, "trig-fall", cfg_pinmask_encode(priv->trig_fall, unit_tmp512, 0)); iw_comment(iw, "Trigger pins auto-armed by default"); - iw_entry(iw, "auto-trigger", cfg_pinmask_encode(priv->def_auto, unit_tmp512, 0)); + iw_entry_s(iw, "auto-trigger", cfg_pinmask_encode(priv->def_auto, unit_tmp512, 0)); iw_comment(iw, "Triggers hold-off time (ms)"); - iw_entry(iw, "hold-off", "%d", (int)priv->trig_holdoff); + iw_entry_d(iw, "hold-off", priv->trig_holdoff); #if PLAT_NO_FLOATING_INPUTS iw_comment(iw, "NOTE: Pins use pull-up by default.\r\n"); diff --git a/units/digital_out/_dout_settings.c b/units/digital_out/_dout_settings.c index 61844fe..f792153 100644 --- a/units/digital_out/_dout_settings.c +++ b/units/digital_out/_dout_settings.c @@ -72,11 +72,11 @@ void DOut_writeIni(Unit *unit, IniWriter *iw) iw_entry(iw, "port", "%c", priv->port_name); iw_comment(iw, "Pins (comma separated, supports ranges)"); - iw_entry(iw, "pins", cfg_pinmask_encode(priv->pins, unit_tmp512, 0)); + iw_entry_s(iw, "pins", cfg_pinmask_encode(priv->pins, unit_tmp512, 0)); iw_comment(iw, "Initially high pins"); - iw_entry(iw, "initial", cfg_pinmask_encode(priv->initial, unit_tmp512, 0)); + iw_entry_s(iw, "initial", cfg_pinmask_encode(priv->initial, unit_tmp512, 0)); iw_comment(iw, "Open-drain pins"); - iw_entry(iw, "open-drain", cfg_pinmask_encode(priv->open_drain, unit_tmp512, 0)); + iw_entry_s(iw, "open-drain", cfg_pinmask_encode(priv->open_drain, unit_tmp512, 0)); } diff --git a/units/fcap/_fcap_settings.c b/units/fcap/_fcap_settings.c index 477c1ae..37ddfdc 100644 --- a/units/fcap/_fcap_settings.c +++ b/units/fcap/_fcap_settings.c @@ -92,20 +92,20 @@ void UFCAP_writeIni(Unit *unit, IniWriter *iw) iw_cmt_newline(iw); iw_comment(iw, "Active level or edge (0-low,falling; 1-high,rising)"); - iw_entry(iw, "active-level", "%d", (int)priv->conf.active_level); + iw_entry_d(iw, "active-level", priv->conf.active_level); iw_comment(iw, "Input filtering (0-15)"); - iw_entry(iw, "input-filter", "%d", (int)priv->conf.dfilter); + iw_entry_d(iw, "input-filter", priv->conf.dfilter); iw_comment(iw, "Pulse counter pre-divider (1,2,4,8)"); - iw_entry(iw, "direct-presc", "%d", (int)priv->conf.direct_presc); + iw_entry_d(iw, "direct-presc", priv->conf.direct_presc); iw_comment(iw, "Pulse counting interval (ms)"); - iw_entry(iw, "direct-time", "%d", (int)priv->conf.direct_msec); + iw_entry_d(iw, "direct-time", priv->conf.direct_msec); iw_cmt_newline(iw); iw_comment(iw, "Mode on startup: N-none, I-indirect, D-direct, F-free count"); - iw_entry(iw, "initial-mode", cfg_enum4_encode(priv->conf.startmode, + iw_entry_s(iw, "initial-mode", cfg_enum4_encode(priv->conf.startmode, OPMODE_IDLE, "N", OPMODE_INDIRECT_CONT, "I", OPMODE_DIRECT_CONT, "D", diff --git a/units/i2c/_i2c_settings.c b/units/i2c/_i2c_settings.c index ceed318..c87fff8 100644 --- a/units/i2c/_i2c_settings.c +++ b/units/i2c/_i2c_settings.c @@ -74,7 +74,7 @@ void UI2C_writeIni(Unit *unit, IniWriter *iw) struct priv *priv = unit->data; iw_comment(iw, "Peripheral number (I2Cx)"); - iw_entry(iw, "device", "%d", (int)priv->periph_num); + iw_entry_d(iw, "device", priv->periph_num); iw_comment(iw, "Pin mappings (SCL,SDA)"); #if GEX_PLAT_F072_DISCOVERY @@ -89,15 +89,15 @@ void UI2C_writeIni(Unit *unit, IniWriter *iw) #else #error "BAD PLATFORM!" #endif - iw_entry(iw, "remap", "%d", (int)priv->remap); + iw_entry_d(iw, "remap", priv->remap); iw_cmt_newline(iw); iw_comment(iw, "Speed: 1-Standard, 2-Fast, 3-Fast+"); - iw_entry(iw, "speed", "%d", (int)priv->speed); + iw_entry_d(iw, "speed", priv->speed); iw_comment(iw, "Analog noise filter enable (Y,N)"); - iw_entry(iw, "analog-filter", str_yn(priv->anf)); + iw_entry_s(iw, "analog-filter", str_yn(priv->anf)); iw_comment(iw, "Digital noise filter bandwidth (0-15)"); - iw_entry(iw, "digital-filter", "%d", (int)priv->dnf); + iw_entry_d(iw, "digital-filter", priv->dnf); } diff --git a/units/neopixel/_npx_settings.c b/units/neopixel/_npx_settings.c index 3299d52..cf0045a 100644 --- a/units/neopixel/_npx_settings.c +++ b/units/neopixel/_npx_settings.c @@ -54,8 +54,8 @@ void Npx_writeIni(Unit *unit, IniWriter *iw) struct priv *priv = unit->data; iw_comment(iw, "Data pin"); - iw_entry(iw, "pin", cfg_pinrsc_encode(priv->cfg.pin)); + iw_entry_s(iw, "pin", cfg_pinrsc_encode(priv->cfg.pin)); iw_comment(iw, "Number of pixels"); - iw_entry(iw, "pixels", "%d", priv->cfg.pixels); + iw_entry_d(iw, "pixels", priv->cfg.pixels); } diff --git a/units/sipo/_sipo_settings.c b/units/sipo/_sipo_settings.c index c7f3c4a..c915705 100644 --- a/units/sipo/_sipo_settings.c +++ b/units/sipo/_sipo_settings.c @@ -98,19 +98,19 @@ void USIPO_writeIni(Unit *unit, IniWriter *iw) struct priv *priv = unit->data; iw_comment(iw, "Shift pin & its active edge (1-rising,0-falling)"); - iw_entry(iw, "shift-pin", cfg_pinrsc_encode(priv->cfg.pin_shift)); - iw_entry(iw, "shift-pol", "%d", priv->cfg.shift_pol); + iw_entry_s(iw, "shift-pin", cfg_pinrsc_encode(priv->cfg.pin_shift)); + iw_entry_d(iw, "shift-pol", priv->cfg.shift_pol); iw_comment(iw, "Store pin & its active edge"); - iw_entry(iw, "store-pin", cfg_pinrsc_encode(priv->cfg.pin_store)); - iw_entry(iw, "store-pol", "%d", priv->cfg.store_pol); + iw_entry_s(iw, "store-pin", cfg_pinrsc_encode(priv->cfg.pin_store)); + iw_entry_d(iw, "store-pol", priv->cfg.store_pol); iw_comment(iw, "Clear pin & its active level"); - iw_entry(iw, "clear-pin", cfg_pinrsc_encode(priv->cfg.pin_clear)); - iw_entry(iw, "clear-pol", "%d", priv->cfg.clear_pol); + iw_entry_s(iw, "clear-pin", cfg_pinrsc_encode(priv->cfg.pin_clear)); + iw_entry_d(iw, "clear-pol", priv->cfg.clear_pol); iw_comment(iw, "Data port and pins"); iw_entry(iw, "data-port", "%c", priv->cfg.data_pname); - iw_entry(iw, "data-pins", cfg_pinmask_encode(priv->cfg.data_pins, unit_tmp512, true)); + iw_entry_s(iw, "data-pins", cfg_pinmask_encode(priv->cfg.data_pins, unit_tmp512, true)); } diff --git a/units/spi/_spi_settings.c b/units/spi/_spi_settings.c index f9ece2f..314de96 100644 --- a/units/spi/_spi_settings.c +++ b/units/spi/_spi_settings.c @@ -98,7 +98,7 @@ void USPI_writeIni(Unit *unit, IniWriter *iw) struct priv *priv = unit->data; iw_comment(iw, "Peripheral number (SPIx)"); - iw_entry(iw, "device", "%d", (int)priv->periph_num); + iw_entry_d(iw, "device", priv->periph_num); // TODO show a legend for peripherals and remaps iw_comment(iw, "Pin mappings (SCK,MISO,MOSI)"); @@ -114,28 +114,28 @@ void USPI_writeIni(Unit *unit, IniWriter *iw) #else #error "BAD PLATFORM!" #endif - iw_entry(iw, "remap", "%d", (int)priv->remap); + iw_entry_d(iw, "remap", priv->remap); iw_cmt_newline(iw); iw_comment(iw, "Prescaller: 2,4,8,...,256"); - iw_entry(iw, "prescaller", "%d", (int)priv->prescaller); + iw_entry_d(iw, "prescaller", priv->prescaller); iw_comment(iw, "Clock polarity: 0,1 (clock idle level)"); - iw_entry(iw, "cpol", "%d", (int)priv->cpol); + iw_entry_d(iw, "cpol", priv->cpol); iw_comment(iw, "Clock phase: 0,1 (active edge, 0-first, 1-second)"); - iw_entry(iw, "cpha", "%d", (int)priv->cpha); + iw_entry_d(iw, "cpha", priv->cpha); iw_comment(iw, "Transmit only, disable MISO"); - iw_entry(iw, "tx-only", str_yn(priv->tx_only)); + iw_entry_s(iw, "tx-only", str_yn(priv->tx_only)); iw_comment(iw, "Bit order (LSB or MSB first)"); - iw_entry(iw, "first-bit", cfg_enum2_encode((uint32_t) priv->lsb_first, 0, "MSB", 1, "LSB")); + iw_entry_s(iw, "first-bit", cfg_enum2_encode((uint32_t) priv->lsb_first, 0, "MSB", 1, "LSB")); iw_cmt_newline(iw); iw_comment(iw, "SS port name"); iw_entry(iw, "port", "%c", priv->ssn_port_name); iw_comment(iw, "SS pins (comma separated, supports ranges)"); - iw_entry(iw, "pins", cfg_pinmask_encode(priv->ssn_pins, unit_tmp512, 0)); + iw_entry_s(iw, "pins", cfg_pinmask_encode(priv->ssn_pins, unit_tmp512, 0)); } diff --git a/units/touch/_touch_core.c b/units/touch/_touch_core.c index 7d25922..dc46e15 100644 --- a/units/touch/_touch_core.c +++ b/units/touch/_touch_core.c @@ -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 diff --git a/units/touch/_touch_settings.c b/units/touch/_touch_settings.c index a213e51..eb80015 100644 --- a/units/touch/_touch_settings.c +++ b/units/touch/_touch_settings.c @@ -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)); } } diff --git a/units/touch/unit_touch.c b/units/touch/unit_touch.c index a7d9a7e..a40e48f 100644 --- a/units/touch/unit_touch.c +++ b/units/touch/unit_touch.c @@ -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<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<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++) { diff --git a/units/usart/_usart_settings.c b/units/usart/_usart_settings.c index dcd2ff9..cdeaa4f 100644 --- a/units/usart/_usart_settings.c +++ b/units/usart/_usart_settings.c @@ -156,7 +156,7 @@ void UUSART_writeIni(Unit *unit, IniWriter *iw) struct priv *priv = unit->data; iw_comment(iw, "Peripheral number (UARTx 1-4)"); - iw_entry(iw, "device", "%d", (int)priv->periph_num); + iw_entry_d(iw, "device", priv->periph_num); iw_comment(iw, "Pin mappings (TX,RX,CK,CTS,RTS/DE)"); #if GEX_PLAT_F072_DISCOVERY @@ -173,41 +173,41 @@ void UUSART_writeIni(Unit *unit, IniWriter *iw) #else #error "BAD PLATFORM!" #endif - iw_entry(iw, "remap", "%d", (int)priv->remap); + iw_entry_d(iw, "remap", priv->remap); iw_cmt_newline(iw); - iw_comment(iw, "Baud rate in bps (eg. 9600, 115200)"); // TODO examples/range - iw_entry(iw, "baud-rate", "%d", (int)priv->baudrate); + iw_comment(iw, "Baud rate in bps (eg. 9600)"); + iw_entry_d(iw, "baud-rate", priv->baudrate); iw_comment(iw, "Parity type (NONE, ODD, EVEN)"); - iw_entry(iw, "parity", cfg_enum3_encode(priv->parity, + iw_entry_s(iw, "parity", cfg_enum3_encode(priv->parity, 0, "NONE", 1, "ODD", 2, "EVEN")); iw_comment(iw, "Number of stop bits (0.5, 1, 1.5, 2)"); - iw_entry(iw, "stop-bits", cfg_enum4_encode(priv->stopbits, + iw_entry_s(iw, "stop-bits", cfg_enum4_encode(priv->stopbits, 0, "0.5", 1, "1", 2, "1.5", 3, "2")); iw_comment(iw, "Bit order (LSB or MSB first)"); - iw_entry(iw, "first-bit", cfg_enum2_encode((uint32_t) priv->lsb_first, + iw_entry_s(iw, "first-bit", cfg_enum2_encode((uint32_t) priv->lsb_first, 0, "MSB", 1, "LSB")); iw_comment(iw, "Word width (7,8,9) - including parity bit if used"); - iw_entry(iw, "word-width", "%d", (int)priv->width); + iw_entry_d(iw, "word-width", (int)priv->width); iw_comment(iw, "Enabled lines (RX,TX,RXTX)"); - iw_entry(iw, "direction", cfg_enum3_encode(priv->direction, + iw_entry_s(iw, "direction", cfg_enum3_encode(priv->direction, 1, "RX", 2, "TX", 3, "RXTX")); iw_comment(iw, "Hardware flow control (NONE, RTS, CTS, FULL)"); - iw_entry(iw, "hw-flow-control", cfg_enum4_encode(priv->hw_flow_control, + iw_entry_s(iw, "hw-flow-control", cfg_enum4_encode(priv->hw_flow_control, 0, "NONE", 1, "RTS", 2, "CTS", @@ -215,19 +215,19 @@ void UUSART_writeIni(Unit *unit, IniWriter *iw) iw_cmt_newline(iw); iw_comment(iw, "Generate serial clock (Y,N)"); - iw_entry(iw, "clock-output", str_yn(priv->clock_output)); - iw_comment(iw, "Output clock polarity: 0,1 (clock idle level)"); - iw_entry(iw, "cpol", "%d", (int)priv->cpol); - iw_comment(iw, "Output clock phase: 0,1 (active edge, 0-first, 1-second)"); - iw_entry(iw, "cpha", "%d", (int)priv->cpha); + iw_entry_s(iw, "clock-output", str_yn(priv->clock_output)); + iw_comment(iw, "Clock polarity: 0,1"); + iw_entry_d(iw, "cpol", priv->cpol); + iw_comment(iw, "Clock phase: 0,1"); + iw_entry_d(iw, "cpha", priv->cpha); iw_cmt_newline(iw); iw_comment(iw, "Generate RS485 Driver Enable signal (Y,N) - uses RTS pin"); - iw_entry(iw, "de-output", str_yn(priv->de_output)); + iw_entry_s(iw, "de-output", str_yn(priv->de_output)); iw_comment(iw, "DE active level: 0,1"); - iw_entry(iw, "de-polarity", "%d", (int)(priv->de_polarity)); + iw_entry_d(iw, "de-polarity", (priv->de_polarity)); iw_comment(iw, "DE assert time (0-31)"); - iw_entry(iw, "de-assert-time", "%d", (int)(priv->de_assert_time)); + iw_entry_d(iw, "de-assert-time", (priv->de_assert_time)); iw_comment(iw, "DE clear time (0-31)"); - iw_entry(iw, "de-clear-time", "%d", (int)(priv->de_clear_time)); + iw_entry_d(iw, "de-clear-time", (priv->de_clear_time)); } diff --git a/utils/ini_writer.c b/utils/ini_writer.c index 2a9a4e6..e3a52cb 100644 --- a/utils/ini_writer.c +++ b/utils/ini_writer.c @@ -119,6 +119,25 @@ void iw_entry(IniWriter *iw, const char *key, const char *format, ...) iw_newline(iw); // one newline after entry } +void iw_entry_s(IniWriter *iw, const char *key, const char *value) +{ + if (iw->count == 0) return; + iw_string(iw, key); + iw_string(iw, "="); + iw_string(iw, value); + iw_newline(iw); +} + +void iw_entry_d(IniWriter *iw, const char *key, int32_t value) +{ + if (iw->count == 0) return; + iw_string(iw, key); + iw_string(iw, "="); + uint32_t len = (int)fixup_snprintf(&iwbuffer[0], IWBUFFER_LEN, "%d", value); + iw_buff(iw, (uint8_t *) iwbuffer, len); + iw_newline(iw); +} + uint32_t iw_measure_total(void (*handler)(IniWriter *), uint32_t tag) { IniWriter iw = iw_init(NULL, 0xFFFFFFFF, 1); diff --git a/utils/ini_writer.h b/utils/ini_writer.h index c9b8cfa..28cc109 100644 --- a/utils/ini_writer.h +++ b/utils/ini_writer.h @@ -126,6 +126,9 @@ __attribute__((format(printf,2,3))); void iw_entry(IniWriter *iw, const char *key, const char *format, ...) __attribute__((format(printf,3,4))); +void iw_entry_s(IniWriter *iw, const char *key, const char *value); +void iw_entry_d(IniWriter *iw, const char *key, int32_t value); + /** * Measure total ini writer length using a dummy write *