@@ -252,8 +252,8 @@ static ALWAYS_INLINE void pin_swdio_out_disable(const struct device *dev)
252252 pin_delay_asm(delay); \
253253 } while (0)
254254
255- static int sw_sequence (const struct device * dev , uint32_t count ,
256- const uint8_t * data )
255+ static int sw_output_sequence (const struct device * dev , uint32_t count ,
256+ const uint8_t * data )
257257{
258258 struct sw_cfg_data * sw_data = dev -> data ;
259259 unsigned int key ;
@@ -285,6 +285,37 @@ static int sw_sequence(const struct device *dev, uint32_t count,
285285 return 0 ;
286286}
287287
288+ static int sw_input_sequence (const struct device * dev , uint32_t count ,
289+ uint8_t * data )
290+ {
291+ struct sw_cfg_data * sw_data = dev -> data ;
292+ unsigned int key ;
293+ uint32_t val = 0U ; /* current byte */
294+ uint32_t n = 8U ; /* bit counter */
295+ uint32_t bit ;
296+
297+ LOG_DBG ("reading %u bits" , count );
298+ key = irq_lock ();
299+
300+ pin_swdio_out_disable (dev );
301+ while (count -- ) {
302+ if (n == 0U ) {
303+ * data ++ = val ;
304+ val = 0 ;
305+ n = 8U ;
306+ }
307+ SW_READ_BIT (dev , bit , sw_data -> clock_delay );
308+ LOG_DBG ("Read bit: %d" , bit );
309+ val = (val << 1 | bit );
310+ n -- ;
311+ }
312+
313+ * data = val ; /* write last byte */
314+ irq_unlock (key );
315+
316+ return 0 ;
317+ }
318+
288319static ALWAYS_INLINE void sw_cycle_turnaround (const struct device * dev )
289320{
290321 struct sw_cfg_data * sw_data = dev -> data ;
@@ -653,7 +684,8 @@ static int sw_gpio_init(const struct device *dev)
653684}
654685
655686static struct swdp_api swdp_bitbang_api = {
656- .swdp_sequence = sw_sequence ,
687+ .swdp_output_sequence = sw_output_sequence ,
688+ .swdp_input_sequence = sw_input_sequence ,
657689 .swdp_transfer = sw_transfer ,
658690 .swdp_set_pins = sw_set_pins ,
659691 .swdp_get_pins = sw_get_pins ,
@@ -669,7 +701,7 @@ static struct swdp_api swdp_bitbang_api = {
669701 (NULL))
670702
671703#define SW_DEVICE_DEFINE (n ) \
672- BUILD_ASSERT((DT_INST_NODE_HAS_PROP(n, dout_gpios)) == \
704+ BUILD_ASSERT((DT_INST_NODE_HAS_PROP(n, dout_gpios)) == \
673705 (DT_INST_NODE_HAS_PROP(n, dnoe_gpios)), \
674706 "Either the dout-gpios or dnoe-gpios property is missing."); \
675707 \
0 commit comments