feat: add ++dmm_loop cmd

++dmm_loop <0|1> to disable the HP3478A DMM loop, if for some reason the
DMM app loop is interfering with the GPIB bus when used as a USB-GPIB
controller
This commit is contained in:
2025-12-04 18:26:02 +06:00
parent 329a648f9c
commit fb6c3cbb7b
2 changed files with 37 additions and 16 deletions

View File

@@ -30,7 +30,7 @@
#define MENU_COMMIT_DELAY_MS 2400 // Time to hold before entering mode #define MENU_COMMIT_DELAY_MS 2400 // Time to hold before entering mode
#define MENU_SUBLAYER_DELAY_MS 500 // Time to "hover" before dots start #define MENU_SUBLAYER_DELAY_MS 500 // Time to "hover" before dots start
#define MENU_DEBOUNCE_MS 100 // Button press dead-time #define MENU_DEBOUNCE_MS 100 // Button press dead-time
#define MENU_LOCKOUT_MS 1000 // How long to ignore SRQ for after exiting menu #define MENU_LOCKOUT_MS 200 // How long to ignore SRQ for after exiting menu
// Polling // Polling
#define POLL_INTERVAL_MS 100 // 10Hz polling when in Passthrough #define POLL_INTERVAL_MS 100 // 10Hz polling when in Passthrough
@@ -76,6 +76,7 @@
#define BUZZER_CHIRP_HZ 3000 #define BUZZER_CHIRP_HZ 3000
#define BUZZER_CHIRP_MS 75 #define BUZZER_CHIRP_MS 75
#define BUZZER_CONT_HZ 2500 #define BUZZER_CONT_HZ 2500
#define BUZZER_ONLINE_TUNE 0 // todo: add to conf
// #define LOCAL_COMMIT 1 // #define LOCAL_COMMIT 1

38
main.c
View File

@@ -65,6 +65,7 @@ typedef enum {
CMD_ADDR, // Set GPIB primary address CMD_ADDR, // Set GPIB primary address
CMD_MODE, // Set Controller vs Device mode (we're always the controller) CMD_MODE, // Set Controller vs Device mode (we're always the controller)
CMD_TIMEOUT, // Set read timeouts CMD_TIMEOUT, // Set read timeouts
CMD_DMM_LOOP, // Toggle extra HP3478A features
// Data transport/formatting // Data transport/formatting
CMD_READ, // Read data from bus CMD_READ, // Read data from bus
@@ -273,7 +274,8 @@ typedef struct {
uint8_t dmm_online : 1; uint8_t dmm_online : 1;
uint8_t has_saved_state : 1; uint8_t has_saved_state : 1;
uint8_t tone_timer_pending : 1; uint8_t tone_timer_pending : 1;
uint8_t reserved : 2; uint8_t dmm_loop : 1;
uint8_t reserved : 1;
uint32_t usb_timeout_cycles; // calculated from sys_cfg.usb_timeout_target_ms uint32_t usb_timeout_cycles; // calculated from sys_cfg.usb_timeout_target_ms
@@ -346,6 +348,7 @@ static const cmd_entry_t COMMAND_TABLE[] = {
{"mode", CMD_MODE}, // 0=Device, 1=Controller {"mode", CMD_MODE}, // 0=Device, 1=Controller
{"tmo", CMD_TIMEOUT}, // Set read timeout {"tmo", CMD_TIMEOUT}, // Set read timeout
{"read_tmo_ms", CMD_TIMEOUT}, {"read_tmo_ms", CMD_TIMEOUT},
{"dmm_loop", CMD_DMM_LOOP}, // Toggle extra feats
// Protocol/formatting // Protocol/formatting
{"auto", CMD_AUTO}, // Auto-read data after write {"auto", CMD_AUTO}, // Auto-read data after write
@@ -608,6 +611,8 @@ inline static void config_apply_to_app(void) {
app.usb_timeout_cycles = app.usb_timeout_cycles =
((FUNCONF_SYSTEM_CORE_CLOCK / 1000 * sys_cfg.usb_timeout_target_ms) / ((FUNCONF_SYSTEM_CORE_CLOCK / 1000 * sys_cfg.usb_timeout_target_ms) /
CYCLES_PER_LOOP); CYCLES_PER_LOOP);
app.dmm_loop = 1; // again, preferably read from config if someone wants this
// to be persistent
} }
static void config_reset_defaults(void) { static void config_reset_defaults(void) {
@@ -1929,12 +1934,11 @@ static void handle_env_sensor(void) {
uint32_t now = millis(); uint32_t now = millis();
if ((now - app.env_last_read) >= sys_cfg.env_sensor_read_interval_ms) { if (((now - app.env_last_read) >= sys_cfg.env_sensor_read_interval_ms) &&
if (aht20_read(&app.current_env) == AHT20_OK) { aht20_read(&app.current_env) == AHT20_OK) {
app.env_last_read = now; app.env_last_read = now;
} }
} }
}
// helper to write text to HP3478A display // helper to write text to HP3478A display
static void dmm_display(const char* text, const char* mode) { static void dmm_display(const char* text, const char* mode) {
@@ -2765,6 +2769,7 @@ static void cmd_help(void) {
" ++eor <0-7> Read Stop: 0:CRLF ... 7:EOI-Only\r\n" " ++eor <0-7> Read Stop: 0:CRLF ... 7:EOI-Only\r\n"
" ++eot_enable <B> Append extra char to read output\r\n" " ++eot_enable <B> Append extra char to read output\r\n"
" ++eot_char <dec> The char to append\r\n" " ++eot_char <dec> The char to append\r\n"
" ++dmm_loop <0|1> Toggle HP3478A loop, if it conflicts w/ GPIB bus\r\n"
"\r\n" "\r\n"
"[System Configuration]\r\n" "[System Configuration]\r\n"
" ++config List all configurable parameters\r\n" " ++config List all configurable parameters\r\n"
@@ -2808,10 +2813,12 @@ static void cmd_status(void) {
"EOR : %d\r\n" "EOR : %d\r\n"
"EOI : %d\r\n" "EOI : %d\r\n"
"EOT : %s (%d)\r\n" "EOT : %s (%d)\r\n"
"SRQ : %d\r\n", "SRQ : %d\r\n"
"DMM_LOOP : %d\r\n",
sys_cfg.target_addr, sys_cfg.gpib_timeout_ms, sys_cfg.auto_read, sys_cfg.target_addr, sys_cfg.gpib_timeout_ms, sys_cfg.auto_read,
sys_cfg.eos_mode, sys_cfg.eor_mode, sys_cfg.eoi_assert, sys_cfg.eos_mode, sys_cfg.eor_mode, sys_cfg.eoi_assert,
sys_cfg.eot_enable ? "ON" : "OFF", sys_cfg.eot_char, srq); sys_cfg.eot_enable ? "ON" : "OFF", sys_cfg.eot_char, srq,
app.dmm_loop);
usb_send_text(scratch.cmd.fmt_buf); usb_send_text(scratch.cmd.fmt_buf);
} }
@@ -2948,6 +2955,16 @@ static void process_command(void) {
} }
break; break;
case CMD_DMM_LOOP:
if (*p_args) {
app.dmm_loop = (atoi(p_args) ? true : false);
exit_to_passthrough();
gpib_interface_clear();
} else {
usb_send_text(app.dmm_loop ? "1\r\n" : "0\r\n");
}
break;
case CMD_SAVECFG: case CMD_SAVECFG:
config_save(); config_save();
break; break;
@@ -3277,7 +3294,7 @@ do_read_operation: {
} }
} }
static void app_loop(void) { static void dmm_loop(void) {
uint32_t now = millis(); uint32_t now = millis();
if (app.tone_timer_pending) { if (app.tone_timer_pending) {
@@ -3322,8 +3339,9 @@ static void app_loop(void) {
gpib_interface_clear(); gpib_interface_clear();
app.dmm_online = true; app.dmm_online = true;
#if defined(BUZZER_ONLINE_TUNE) && BUZZER_ONLINE_TUNE
play_tune(ONLINE_NOTES); play_tune(ONLINE_NOTES);
#endif
gpib_send(sys_cfg.dmm_addr, gpib_send(sys_cfg.dmm_addr,
HP3478A_CMD_MASK_BTN_ONLY HP3478A_CMD_SRQ_CLEAR); HP3478A_CMD_MASK_BTN_ONLY HP3478A_CMD_SRQ_CLEAR);
gpib_go_to_local(sys_cfg.dmm_addr); gpib_go_to_local(sys_cfg.dmm_addr);
@@ -3408,7 +3426,9 @@ int main() {
while (1) { while (1) {
handle_usb_state(); handle_usb_state();
usb_process_tx(); usb_process_tx();
app_loop(); if (app.dmm_loop) {
dmm_loop();
}
handle_env_sensor(); handle_env_sensor();
if (app.usb_online) { if (app.usb_online) {