From fb93abea9e78ac0e9b9e824fe1d4a38f79152516 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 26 Apr 2021 12:10:54 +0100 Subject: [PATCH] New firmware command CMD_GET_PIN to read an interface pin's voltage level. --- inc/cdc_acm_protocol.h | 5 ++++- src/f1/floppy.c | 5 +++++ src/f7/floppy.c | 14 ++++++++++++++ src/floppy.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/inc/cdc_acm_protocol.h b/inc/cdc_acm_protocol.h index 0fcbe3e..9b032aa 100644 --- a/inc/cdc_acm_protocol.h +++ b/inc/cdc_acm_protocol.h @@ -67,7 +67,10 @@ #define CMD_SOURCE_BYTES 18 /* CMD_SINK_BYTES, length=6. Argument is gw_sink_source_bytes. */ #define CMD_SINK_BYTES 19 -#define CMD_MAX 19 +/* CMD_GET_PIN, length=3, pin#. Successful ACK is followed by pin-level byte + * (1=High, 0=Low). Unsupported pin returns ACK_BAD_PIN and no pin level. */ +#define CMD_GET_PIN 20 +#define CMD_MAX 20 /* diff --git a/src/f1/floppy.c b/src/f1/floppy.c index c37d132..e12dae3 100644 --- a/src/f1/floppy.c +++ b/src/f1/floppy.c @@ -173,6 +173,11 @@ static uint8_t drive_motor(uint8_t nr, bool_t on) return ACK_OKAY; } +static uint8_t mcu_get_floppy_pin(unsigned int pin, uint8_t *p_level) +{ + return ACK_BAD_PIN; +} + static uint8_t set_user_pin(unsigned int pin, unsigned int level) { if (pin != 2) diff --git a/src/f7/floppy.c b/src/f7/floppy.c index 03aed2e..6281272 100644 --- a/src/f7/floppy.c +++ b/src/f7/floppy.c @@ -265,6 +265,20 @@ static uint8_t drive_motor(uint8_t nr, bool_t on) } +static uint8_t mcu_get_floppy_pin(unsigned int pin, uint8_t *p_level) +{ + switch (gw_info.hw_submodel) { + case F7SM_v3: + case F7SM_lightning_plus: + if (pin == 34) { + *p_level = gpio_read_pin(gpioc, 2); + return ACK_OKAY; + } + break; + } + return ACK_BAD_PIN; +} + static uint8_t set_user_pin(unsigned int pin, unsigned int level) { const struct pin_mapping *upin; diff --git a/src/floppy.c b/src/floppy.c index e669dcb..b6721e1 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -296,6 +296,26 @@ static bool_t set_bus_type(uint8_t type) return TRUE; } +static uint8_t get_floppy_pin(unsigned int pin, uint8_t *p_level) +{ + uint8_t rc = ACK_OKAY; + switch (pin) { + case 8: + *p_level = get_index(); + break; + case 26: + *p_level = get_trk0(); + break; + case 28: + *p_level = get_wrprot(); + break; + default: + rc = mcu_get_floppy_pin(pin, p_level); + break; + } + return rc; +} + static void floppy_reset(void) { floppy_state = ST_inactive; @@ -1262,6 +1282,15 @@ static void process_command(void) u_buf[1] = set_user_pin(pin, level); goto out; } + case CMD_GET_PIN: { + uint8_t pin = u_buf[2]; + if (len != 3) + goto bad_command; + u_buf[1] = get_floppy_pin(pin, &u_buf[2]); + if (u_buf[1] == ACK_OKAY) + resp_sz += 1; + goto out; + } case CMD_RESET: { if (len != 2) goto bad_command;