Pico I2S/RTC super-HAT


Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9805
Posted: 02:14pm 04 Feb 2025      

VGA is 16 instructions and uses a couple of DMA channels
I2S is 7 instructions, doesn't use DMA, but uses a combined TX FIFO

; ============================================================================
;                           QVGA PIO (16 instructions)
; ============================================================================
; Control word (right shifted):
;  - bit 0..26 (27 bits) loop counter N
;  - bit 27..31 (5 bits) jump address

.program qvga
.side_set 2 ; HSYNC and VSYNC output (2 bits)
.define NOSYNC 0 ; no sync, output image or blanking
.define HSYNC 1 ; HSYNC pulse (or CSYNC pulse)
.define VSYNC 2 ; VSYNC pulse
.define VHSYNC 3 ; HSYNC and VSYNC pulse
.define BPP 4 ; number of bits per pixel

; ===== [3 instructions] HSYNC pulse, N=delay in clock cycles - 3
; starts HSYNC at time 0

public hsync:
jmp x--,hsync side HSYNC ; [N+1] loop
public entry: ; program entry point
out x,27 side HSYNC ; [1] get next loop counter N
out pc,5 side HSYNC ; [1] jump to next function

; ===== [3 instructions] VSYNC pulse, N=delay in clock cycles - 3
; starts VSYNC at time 0

public vsync:
jmp x--,vsync side VSYNC ; [N+1] loop
out x,27 side VSYNC ; [1] get next loop counter N
out pc,5 side VSYNC ; [1] jump to next function

; ===== [3 instructions] VSYNC and HSYNC pulse, N=delay in clock cycles - 3
; starts HSYNC and VSYNC at time 0

public vhsync:
jmp x--,vhsync side VHSYNC ; [N+1] loop
out x,27 side VHSYNC ; [1] get next loop counter N
out pc,5 side VHSYNC ; [1] jump to next function

; ===== [4 instructions] DARK pulse, N=delay in clock cycles - 4
; sets blanking at time 0, starts NOSYNC at time 0

public dark:
mov pins,null side NOSYNC ; [1] dark output
dark_loop:
jmp x--,dark_loop side NOSYNC ; [N+1] loop
.wrap_target ; wrap jump target
out x,27 side NOSYNC ; [1] get next loop counter N
out pc,5 side NOSYNC ; [1] jump to next function

; ===== [3 instructions] output pixels at 5 clocks per pixel, N=number of pixels-2
; number of pixels must be multiple of: 1 at BP=32, 2 at BPP=16, 4 at BPP=8, 8 at BPP=4, 16 at BPP=2, 32 at BPP=1
; Output first pixel at time 0

public output:
out pins,BPP side NOSYNC [2] ; [3] output pixel
jmp x--,output side NOSYNC [1] ; [2] loop (N+1 pixels)
out pins,BPP side NOSYNC [2] ; [3] output pixel
.wrap ; wrap jump to .wrap_target



           0xe03e, //  0: set    x, 30           side 0    
           0x8880, //  1: pull   noblock         side 1    
           0x6001, //  2: out    pins, 1         side 0    
           0x0842, //  3: jmp    x--, 2          side 1    
           0xf03e, //  4: set    x, 30           side 2    
           0x9880, //  5: pull   noblock         side 3    
           0x7001, //  6: out    pins, 1         side 2    
           0x1846, //  7: jmp    x--, 6          side 3  

PIO assemble 1
.program i2s
.side set 2
.wrap target
.line 20
Set x,30 side 0
Pull noblock side 1
.label loop1
Out pins,1 side 0
Jmp x--,loop1 side 1
Set x,30 side 2
Pull noblock side 3
.label loop2
Out pins,1 side 2
Jmp x--,loop2 side 3
.wrap
.end program list

Edited 2025-02-05 01:21 by matherp