| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | .program dco | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  |     set x, 0 | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  |     set y, 0 | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  | .wrap_target        //                                              CYCLES | 
					
						
							|  |  |  |     pull            // load full 32-bit register.                   1c | 
					
						
							|  |  |  |     out y, 8        // load 8-bit delay value.                      2c | 
					
						
							|  |  |  |     mov x, y        // copy value in order to do next PI cycle.     3c | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  | LOOP0: | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  |     jmp x-- LOOP0   // do exactly X*CPU CLK delay.                  4c+x | 
					
						
							|  |  |  |     set pins, 1 [3] // set output high.                             5c+x | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  | LOOP1: | 
					
						
							|  |  |  |     jmp y-- LOOP1   // do exactly X*CPU CLK delay.                  8c+x | 
					
						
							|  |  |  |     set pins, 0     // set output high.                             9c+x | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  |     // RPix: The next sections repeat aforementioned algo 3 times. | 
					
						
							|  |  |  |     out y, 8 | 
					
						
							|  |  |  |     mov x, y [1] | 
					
						
							|  |  |  | LOOP2: | 
					
						
							|  |  |  |     jmp x-- LOOP2 | 
					
						
							|  |  |  |     set pins, 1 [3] | 
					
						
							|  |  |  | LOOP3: | 
					
						
							|  |  |  |     jmp y-- LOOP3 | 
					
						
							|  |  |  |     set pins, 0 | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     out y, 8 | 
					
						
							|  |  |  |     mov x, y [1] | 
					
						
							|  |  |  | LOOP4: | 
					
						
							|  |  |  |     jmp x-- LOOP4 | 
					
						
							|  |  |  |     set pins, 1 [3] | 
					
						
							|  |  |  | LOOP5: | 
					
						
							|  |  |  |     jmp y-- LOOP5 | 
					
						
							|  |  |  |     set pins, 0 | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  |     out y, 8 | 
					
						
							|  |  |  |     mov x, y [1] | 
					
						
							|  |  |  | LOOP6: | 
					
						
							|  |  |  |     jmp x-- LOOP6 | 
					
						
							|  |  |  |     set pins, 1 [3] | 
					
						
							|  |  |  | LOOP7: | 
					
						
							|  |  |  |     jmp y-- LOOP7 | 
					
						
							|  |  |  |     set pins, 0 | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .wrap | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % c-sdk { | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define PIOASM_DELAY_CYCLES 5 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | static inline void dco_program_init(PIO pio, uint sm, uint offset, uint pin) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     pio_sm_config c = dco_program_get_default_config(offset); | 
					
						
							|  |  |  |     sm_config_set_out_pins(&c, pin, 1); | 
					
						
							|  |  |  |     pio_gpio_init(pio, pin); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  |     //sm_config_set_out_shift(&c, true, true, 32);           // Autopull. | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  |     sm_config_set_clkdiv_int_frac(&c, 1u, 0u); | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pio_sm_init(pio, sm, offset, &c); | 
					
						
							|  |  |  |     pio_sm_set_enabled(pio, sm, true); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-03 23:54:39 +00:00
										 |  |  | // | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | static inline void dco_program_puts(PIO pio, uint sm, const uint32_t *s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-11-07 00:07:42 +00:00
										 |  |  |     pio_sm_put_blocking(pio, sm, s[0]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[1]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[2]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[3]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[4]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[5]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[6]); | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, s[7]); | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 20:36:35 +00:00
										 |  |  | static inline void dco_program_puts1w(PIO pio, uint sm, const uint32_t val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     pio_sm_put_blocking(pio, sm, val); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-01 23:41:14 +00:00
										 |  |  | %} |