' RJA using cheezus's port of FSRW to view VGA bmp files 'sends some diagnostic info out over serial port CON 'RJA: new for real P2 - you can use different xdiv and xmul to set clock frequency: /10*125 -> 250 MHz _XTALFREQ = 20_000_000 ' crystal frequency _XDIV = 2 ' crystal divider to give 1MHz _XMUL = 25 ' crystal / div * mul _XDIVP = 1 ' crystal / div * mul /divp to give _CLKFREQ (1,2,4..30) _XOSC = %10 'OSC ' %00=OFF, %01=OSC, %10=15pF, %11=30pF _XSEL = %11 'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms) _XPPPP = ((_XDIVP>>1) + 15) & $F ' 1->15, 2->0, 4->1, 6->2...30->14 _CLOCKFREQ = _XTALFREQ / _XDIV * _XMUL / _XDIVP ' internal clock frequency _SETFREQ = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2 ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00 ' setup oscillator _ENAFREQ = _SETFREQ + _XSEL ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss ' enable oscillator CON '' SD Card PIN SETTINGS ' P2-ES SD CARD miso = 58 mosi = 59 cs = 60 clk = 61 CON 'VGA settings intensity = 80 '0..128 fclk = _CLOCKFREQ*1.0 fpix = 25_000_000.0 fset = (fpix / fclk * 2.0) * float($4000_0000) vga_basepin =8 '0 vsync =vga_basepin+4 'vsync pin CON 'serial settings RXPIN=63 ' Prop pins used for comms TXPIN=62 ' for regular terminal Baudrate = 115200'230400 ' baud rate for serial communications obj ser: "spin\SmartSerial.spin" sd: "fsrw.spin2" var byte tbuf[20] 'byte bigbuf[8192/1] 'byte image[308_278] 'buffer to store image pub Main | r, s, bytes,cog, p 'First, set the P2 clock clkset(_SETFREQ, _CLOCKFREQ) coginit(1,@VgaOrigin, 0) 'start VGA driver in cog#1 (will restart later) 'Start up serial comms ser.start(RXPIN,TXPIN,0,BaudRate) 'open comm port 'wait a few seconds for terminal to get ready repeat r from 2 to 1 waitcnt(cnt+clkfreq) ser.dec(r) ser.tx(13) ser.str(string("Attempting to Mount SD.", 13)) 'Try to mount a few times then give up if not successful repeat 10 waitcnt(cnt+clkfreq/2) r:=sd.mount_explicit(MISO, CLK, MOSI, CS) if r<0 sd.release() 'see if this helps next attempt else quit 'escape from repeat loop if mounted if r<0 ser.str(string("Unable to mount after several tries. Giving up. Try removing card for a second.", 13)) repeat ser.str(string("SD Mounted.", 13)) 'Load bmp file r:=sd.popen(string("bitmap2.bmp"),"r") if r<0 ser.str(string("Cannot open file..", 13)) repeat ser.str(string("File Open.", 13)) s:=sd.fsize() 'size of file ser.str(string("File Size= ")) ser.dec(s) ser.tx(13) p:=@BitmapFile'image'BitmapFile sd.pread(p,s) 'read in file ser.str(string("Read complete. Re-starting VGA")) 're-start VGA coginit(1,@VgaOrigin, 0)'@image) 'start VGA driver in cog#1 repeat DAT 'VGA Driver VgaOrigin org ' ' ' Setup mov ptrb,##BitmapFile'ptra mov ptra, ptrb'##BitmapFile add ptra,##$36 rdfast #0,ptra 'rdfast #0,##$1000-$400 'load .bmp palette into lut rep @.end,#$100 rflong y shl y,#8 wrlut y,x add x,#1 .end mov ptra, ptrb'##BitmapFile add ptra,##$436 rdfast ##640*480/64,ptra 'set rdfast to wrap on bitmap setxfrq ##round(fset) 'set transfer frequency to 25MHz 'the next 4 lines may be commented out to bypass level scaling setcy ##intensity << 24 'r set colorspace for rgb setci ##intensity << 16 'g setcq ##intensity << 08 'b setcmod #%01_0_000_0 'enable colorspace conversion 'RJA dacmodes changed for real P2 cogid x99 shl x99, #8 or dacmode_s, x99 or dacmode_c, x99 'RJA dacmodes changed for real P2 wrpin dacmode_s,#0+VGA_Basepin 'enable dac modes in pins 0..3 wrpin dacmode_c,#1+VGA_Basepin wrpin dacmode_c,#2+VGA_Basepin wrpin dacmode_c,#3+VGA_Basepin 'setnib dira,#$f,#0 'RJA: New for real P2 drvl #0+VGA_Basepin drvl #1+VGA_Basepin drvl #2+VGA_Basepin drvl #3+VGA_Basepin ' ' Field loop ' field mov x,#33 'top blanks call #blank mov x,#480 'set visible lines line call #hsync 'do horizontal sync xcont m_rf,#0 'visible line djnz x,#line 'another line? mov x,#10 'bottom blanks call #blank drvnot #vsync 'sync on mov x,#2 'sync blanks call #blank drvnot #vsync 'sync off jmp #field 'loop ' ' ' Subroutines ' blank call #hsync 'blank lines xcont m_vi,#0 _ret_ djnz x,#blank hsync xcont m_bs,#0 'horizontal sync xcont m_sn,#1 _ret_ xcont m_bv,#0 ' ' ' Initialized data ' 'RJA: New dacmodes for real P2 dacmode_s long %0000_0000_000_1011000000000_01_00000_0 'hsync is 123-ohm, 3.3V dacmode_c long %0000_0000_000_1011100000000_01_00000_0 'R/G/B are 75-ohm, 2.0V m_bs long $7F010000+16 'before sync m_sn long $7F010000+96 'sync m_bv long $7F010000+48 'before visible m_vi long $7F010000+640 'visible m_rf long $7F080000+640 'visible rlong 8bpp lut x long 0 y long 0 x99 long 0 ' ' ' Bitmap ' orgh BitmapFile 'something to show before load is complete and also storage for bitmap file "TestPat1.bmp" '640 x 480, 8bpp bitmap byte 0[100] 'a little padding just in case metadata makes SD file bigger