This allows to drive MCU RST lines or similar with the ch341a during a flashrom run. CS1 is active low and CS2 is active high; note that the tristate state is a weak pullup, thus using CS2 would need an external pull-down.
Signed-off-by: Urja Rannikko urjaman@gmail.com --- ch341a_spi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/ch341a_spi.c b/ch341a_spi.c index 6eb2804..7e5d577 100644 --- a/ch341a_spi.c +++ b/ch341a_spi.c @@ -303,8 +303,12 @@ static uint8_t swap_byte(uint8_t x) static int32_t enable_pins(bool enable) { uint8_t buf[] = { + /* We provide CS1 as "nACT" and CS2 as "ACT" during operation for ISP + * designs to drive eg. reset lines, meaning CS1 is driven low during + * flashrom run and CS2 high. Note that the tristate state is a weak + * pullup, thus using CS2 needs an external pull-down. */ CH341A_CMD_UIO_STREAM, - CH341A_CMD_UIO_STM_OUT | 0x37, // CS high (all of them), SCK=0, DOUT*=1 + CH341A_CMD_UIO_STM_OUT | (enable ? 0x35 : 0x33), // SCK=0, DOUT*=1 CH341A_CMD_UIO_STM_DIR | (enable ? 0x3F : 0x00), // Interface output enable / disable CH341A_CMD_UIO_STM_END, }; @@ -327,11 +331,11 @@ static void pluck_cs(uint8_t *ptr) stored_delay_us = 0; } *ptr++ = CH341A_CMD_UIO_STREAM; - *ptr++ = CH341A_CMD_UIO_STM_OUT | 0x37; /* deasserted */ + *ptr++ = CH341A_CMD_UIO_STM_OUT | 0x35; /* deasserted */ int i; for (i = 0; i < delay_cnt; i++) - *ptr++ = CH341A_CMD_UIO_STM_OUT | 0x37; /* "delay" */ - *ptr++ = CH341A_CMD_UIO_STM_OUT | 0x36; /* asserted */ + *ptr++ = CH341A_CMD_UIO_STM_OUT | 0x35; /* "delay" */ + *ptr++ = CH341A_CMD_UIO_STM_OUT | 0x34; /* asserted */ *ptr++ = CH341A_CMD_UIO_STM_END; }