mail.coreboot.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
List overview
Download
openfirmware
October 2011
----- 2024 -----
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
openfirmware@openfirmware.info
1 participants
103 discussions
Start a n
N
ew thread
[commit] r2558 - dev/olpc/cafecamera
by repository service
01 Oct '11
01 Oct '11
Author: wmb Date: Sat Oct 1 19:45:39 2011 New Revision: 2558 URL:
http://tracker.coreboot.org/trac/openfirmware/changeset/2558
Log: OLPC XO-1 - Changed camera driver to use the shared common code for the Omnivision sensor and the selftest infrastructure. Added: dev/olpc/cafecamera/platform.fth Modified: dev/olpc/cafecamera/cafecamera.bth dev/olpc/cafecamera/cafecamera.fth Modified: dev/olpc/cafecamera/cafecamera.bth ============================================================================== --- dev/olpc/cafecamera/cafecamera.bth Sat Oct 1 19:44:26 2011 (r2557) +++ dev/olpc/cafecamera/cafecamera.bth Sat Oct 1 19:45:39 2011 (r2558) @@ -9,7 +9,10 @@ FCode-version2 +fload ${BP}/dev/olpc/cafecamera/platform.fth +fload ${BP}/dev/olpc/ov7670.fth fload ${BP}/dev/olpc/cafecamera/cafecamera.fth +fload ${BP}/dev/olpc/cameratest.fth end0 Modified: dev/olpc/cafecamera/cafecamera.fth ============================================================================== --- dev/olpc/cafecamera/cafecamera.fth Sat Oct 1 19:44:26 2011 (r2557) +++ dev/olpc/cafecamera/cafecamera.fth Sat Oct 1 19:45:39 2011 (r2558) @@ -1,331 +1,6 @@ \ See license at end of file purpose: Driver for the CMOS camera -headers -hex - -" camera" device-name -" olpc,camera" model -" camera" device-type -" olpc,camera" " compatible" string-property -" OV7670" " sensor" string-property - -h# 4000 constant /regs - -my-address my-space encode-phys - 0 encode-int encode+ h# 0 encode-int encode+ - -my-address my-space h# 200.0010 + encode-phys encode+ - 0 encode-int encode+ /regs encode-int encode+ - -" reg" property - - -: my-w@ ( offset -- w ) my-space + " config-w@" $call-parent ; -: my-w! ( w offset -- ) my-space + " config-w!" $call-parent ; - -0 instance value chip - -: cl! ( l adr -- ) chip + rl! ; -: cl@ ( adr -- l ) chip + rl@ ; - -: map-regs ( -- ) - 0 0 h# 0200.0010 my-space + /regs " map-in" $call-parent to chip - 4 my-w@ 6 or 4 my-w! -; - -: unmap-regs ( -- ) - chip /regs " map-out" $call-parent -\ 4 my-w@ 6 invert and 4 my-w! \ No need to turn it off -; - -\ ======================= OV7670 SMBUS operations ========================== - -\ cafe_smbus_xfer - -h# 42 2 << constant ov-sid - -: clr-smb-intr ( -- ) 7.0000 30 cl! ; -: smbus-wait ( -- ) - begin 28 cl@ 7.0000 and until - 1 ms \ 20 usec delay -; - -: ov@ ( reg -- data ) - clr-smb-intr - ov-sid 87.fc01 or b8 cl! \ TWSI control 0: id, 8-bit, clk - bc cl@ drop \ Force write - d# 16 << 100.0000 or bc cl! \ TWSI control 1: read, reg - smbus-wait - bc cl@ ff and -; - -: ov! ( data reg -- ) - clr-smb-intr - ov-sid 8.7fc01 or b8 cl! \ TWSI control 0: id, 8-bit, clk - bc cl@ drop \ Force write - d# 16 << or bc cl! \ TWSI control 1: read, reg - 2 ms - smbus-wait - bc cl@ drop -; - -: ovc ( val adr -- ) - 2dup ov@ ( val reg# val actual ) - tuck <> if ( val reg# actual ) - ." Bad camera I2C value at " swap 2 u.r ( val actual ) - ." expected " swap 2 u.r ." got " 2 u.r cr ( ) - else ( val reg# actual ) - 3drop ( ) - then ( ) -; - -\ ============================= camera operations ============================= - -false value ov7670-detected? - -: ((camera-init) ( -- ) - 80 12 ov! \ reset (reads back different) - 01 11 ov! \ 30 fps - 04 3a ov! \ UYVY or VYUY - 00 12 ov! \ VGA - - \ Hardware window - 13 17 ov! \ Horiz start high bits - 01 18 ov! \ Horiz stop high bits - b6 32 ov! \ HREF pieces - 0a 19 ov! \ Vert start high bits - 7a 1a ov! \ Vert stop high bits - 0a 03 ov! \ GAIN, VSTART, VSTOP pieces - - \ Mystery scaling numbers - 00 0c ov! \ Control 3 - 00 3e ov! \ Control 14 - 3a 70 ov! 35 71 ov! 11 72 ov! f0 73 ov! - 02 a2 ov! - 00 15 ov! \ Control 10 - - \ Gamma curve values - 20 7a ov! 10 7b ov! 1e 7c ov! 35 7d ov! - 5a 7e ov! 69 7f ov! 76 80 ov! 80 81 ov! - 88 82 ov! 8f 83 ov! 96 84 ov! a3 85 ov! - af 86 ov! c4 87 ov! d7 88 ov! e8 89 ov! - - \ AGC and AEC parameters - e0 13 ov! \ Control 8 - 00 00 ov! \ Gain lower 8 bits - 40 0d ov! \ Control 4 magic reserved bit - 18 14 ov! \ Control 9: 4x gain + magic reserved bit - 05 a5 ov! \ 50hz banding step limit - 07 ab ov! \ 60hz banding step limit - 95 24 ov! \ AGC upper limit - 33 25 ov! \ AGC lower limit - e3 24 ov! \ AGC/AEC fast mode op region - 78 9f ov! \ Hist AEC/AGC control 1 - 68 a0 ov! \ Hist AEC/AGC control 2 - 03 a1 ov! \ Magic - d8 a6 ov! \ Hist AEC/AGC control 3 - d8 a7 ov! \ Hist AEC/AGC control 4 - f0 a8 ov! \ Hist AEC/AGC control 5 - 90 a9 ov! \ Hist AEC/AGC control 6 - 94 aa ov! \ Hist AEC/AGC control 7 - e5 13 ov! \ Control 8 - - \ Mostly magic - 61 0e ov! 4b 0f ov! 02 16 ov! 07 1e ov! - 02 21 ov! 91 22 ov! 07 29 ov! 0b 33 ov! - 0b 35 ov! 1d 37 ov! 71 38 ov! 2a 39 ov! - 78 3c ov! 40 4d ov! 20 4e ov! 00 69 ov! - 4a 6b ov! 10 74 ov! 4f 8d ov! 00 8e ov! - 00 8f ov! 00 90 ov! 00 91 ov! 00 96 ov! - 00 9a ov! 84 b0 ov! 0c b1 ov! 0e b2 ov! - 82 b3 ov! 0a b8 ov! - - \ More magic, some of which tweaks white balance - 0a 43 ov! f0 44 ov! 34 45 ov! 58 46 ov! - 28 47 ov! 3a 48 ov! 88 59 ov! 88 5a ov! - 44 5b ov! 67 5c ov! 49 5d ov! 0e 5e ov! - 0a 6c ov! 55 6d ov! 11 6e ov! - 9f 6f ov! \ 9e for advance AWB - 40 6a ov! - 40 01 ov! \ Blue gain - 60 02 ov! \ Red gain - e7 13 ov! \ Control 8 - - \ Matrix coefficients - 80 4f ov! 80 50 ov! 00 51 ov! 22 52 ov! - 5e 53 ov! 80 54 ov! 9e 58 ov! - - 08 41 ov! \ AWB gain enable - 00 3f ov! \ Edge enhancement factor - 05 75 ov! e1 76 ov! 00 4c ov! 01 77 ov! - c3 3d ov! \ Control 13 - 09 4b ov! 60 c9 ov! \ Reads back differently - 38 41 ov! \ Control 16 - 40 56 ov! - - 11 34 ov! - 12 3b ov! \ Control 11 - 88 a4 ov! 00 96 ov! 30 97 ov! 20 98 ov! - 30 99 ov! 84 9a ov! 29 9b ov! 03 9c ov! - 5c 9d ov! 3f 9e ov! 04 78 ov! - - \ Extra-weird stuff. Some sort of multiplexor register - 01 79 ov! f0 c8 ov! - 0f 79 ov! 00 c8 ov! - 10 79 ov! 7e c8 ov! - 0a 79 ov! 80 c8 ov! - 0b 79 ov! 01 c8 ov! - 0c 79 ov! 0f c8 ov! - 0d 79 ov! 20 c8 ov! - 09 79 ov! 80 c8 ov! - 02 79 ov! c0 c8 ov! - 03 79 ov! 40 c8 ov! - 05 79 ov! 30 c8 ov! - 26 79 ov! - - \ OVT says that rewrite this works around a bug in 565 mode. - \ The symptom of the bug is red and green speckles in the image. - 01 11 ov! \ 30 fps def 80 -; - -: config-check ( -- ) - 01 11 ovc \ 30 fps - 04 3a ovc \ UYVY or VYUY - ( 00 12 ovc ) \ VGA - - \ Hardware window - 13 17 ovc \ Horiz start high bits - 01 18 ovc \ Horiz stop high bits - b6 32 ovc \ HREF pieces - ( 0a 19 ovc ) \ Vert start high bits - 7a 1a ovc \ Vert stop high bits - 0a 03 ovc \ GAIN, VSTART, VSTOP pieces - - \ Mystery scaling numbers - 00 0c ovc \ Control 3 - 00 3e ovc \ Control 14 - 3a 70 ovc 35 71 ovc 11 72 ovc f0 73 ovc - 02 a2 ovc - 00 15 ovc \ Control 10 - - \ Gamma curve values - 20 7a ovc 10 7b ovc 1e 7c ovc 35 7d ovc - 5a 7e ovc 69 7f ovc 76 80 ovc 80 81 ovc - 88 82 ovc 8f 83 ovc 96 84 ovc a3 85 ovc - af 86 ovc c4 87 ovc d7 88 ovc e8 89 ovc - - \ AGC and AEC parameters - ( e0 13 ovc ) \ Control 8 - ( 00 00 ovc ) \ Gain lower 8 bits - 40 0d ovc \ Control 4 magic reserved bit - ( 18 14 ovc ) \ Control 9: 4x gain + magic reserved bit - 05 a5 ovc \ 50hz banding step limit - 07 ab ovc \ 60hz banding step limit - ( 95 24 ovc ) \ AGC upper limit - 33 25 ovc \ AGC lower limit - e3 24 ovc \ AGC/AEC fast mode op region - 78 9f ovc \ Hist AEC/AGC control 1 - 68 a0 ovc \ Hist AEC/AGC control 2 - 03 a1 ovc \ Magic - d8 a6 ovc \ Hist AEC/AGC control 3 - d8 a7 ovc \ Hist AEC/AGC control 4 - f0 a8 ovc \ Hist AEC/AGC control 5 - 90 a9 ovc \ Hist AEC/AGC control 6 - 94 aa ovc \ Hist AEC/AGC control 7 - ( e5 13 ovc ) \ Control 8 - - \ Mostly magic - 61 0e ovc 4b 0f ovc 02 16 ovc 07 1e ovc - 02 21 ovc 91 22 ovc 07 29 ovc 0b 33 ovc - 0b 35 ovc 1d 37 ovc 71 38 ovc 2a 39 ovc - 78 3c ovc 40 4d ovc 20 4e ovc 00 69 ovc - 4a 6b ovc 10 74 ovc 4f 8d ovc 00 8e ovc - 00 8f ovc 00 90 ovc 00 91 ovc 00 96 ovc - ( 00 9a ovc ) 84 b0 ovc 0c b1 ovc 0e b2 ovc - 82 b3 ovc 0a b8 ovc - - \ More magic, some of which tweaks white balance - 0a 43 ovc f0 44 ovc 34 45 ovc 58 46 ovc - 28 47 ovc 3a 48 ovc 88 59 ovc 88 5a ovc - 44 5b ovc 67 5c ovc 49 5d ovc 0e 5e ovc - 0a 6c ovc 55 6d ovc 11 6e ovc - 9f 6f ovc \ 9e for advance AWB - ( 40 6a ovc ) - ( 40 01 ovc ) \ Blue gain - ( 60 02 ovc ) \ Red gain - e7 13 ovc \ Control 8 - - \ Matrix coefficients - b3 4f ovc b3 50 ovc 00 51 ovc 3d 52 ovc - a7 53 ovc e4 54 ovc 9e 58 ovc - - \ 08 41 ovc \ AWB gain enable - ( 00 3f ovc ) \ Edge enhancement factor - 05 75 ovc e1 76 ovc ( 00 4c ovc ) 01 77 ovc - c0 3d ovc \ Control 13 - 09 4b ovc ( 60 c9 ovc ) - 38 41 ovc \ Control 16 - 40 56 ovc - - 11 34 ovc - 12 3b ovc \ Control 11 - 88 a4 ovc 00 96 ovc 30 97 ovc 20 98 ovc - 30 99 ovc 84 9a ovc 29 9b ovc 03 9c ovc - 5c 9d ovc 3f 9e ovc 04 78 ovc - -; - -: camera-init ( -- ) - false to ov7670-detected? - ((camera-init) - 1d ov@ 1c ov@ bwjoin 7fa2 <> if exit then \ Manufacturing ID - b ov@ a ov@ bwjoin 7673 <> if exit then \ Product ID - true to ov7670-detected? -; - -\ VGA RGB565 -: init-rgb565 ( -- ) - 04 12 ov! \ VGA, RGB565 - 00 8c ov! \ No RGB444 - 00 04 ov! \ Control 1 - 10 40 ov! \ RGB565 output - 38 14 ov! \ 16x gain ceiling - b3 4f ov! \ v-red - b3 50 ov! \ v-green - 00 51 ov! \ v-blue - 3d 52 ov! \ u-red - a7 53 ov! \ u-green - e4 54 ov! \ u-blue - c0 3d ov! \ Gamma enable, UV saturation auto adjust -; - -: read-agc ( -- n ) - 3 ov@ h# c0 and 2 lshift 0 ov@ or -; - -: read-aec ( -- n ) - 7 ov@ h# 3f and d# 10 lshift - h# 10 ov@ 2 lshift or - 4 ov@ 3 and or -; - -: set-hw ( vstop vstart hstop hstart -- ) - dup 3 >> 17 ov! \ Horiz start high bits - over 3 >> 18 ov! \ Horiz stop high bits - 32 ov@ swap 7 and or swap 7 and 3 << or 10 ms 32 ov! \ Horiz bottom bits - - dup 2 >> 19 ov! \ Vert start high bits - over 2 >> 1a ov! \ Vert start high bits - 03 ov@ swap 3 and or swap 3 and 2 << or 10 ms 03 ov! \ Vert bottom bits -; - -: camera-config ( -- ) - ((camera-init) - init-rgb565 - d# 490 d# 10 d# 14 d# 158 set-hw \ VGA window info -; - \ ============================= cafe operations ============================== d# 640 constant VGA_WIDTH @@ -444,15 +119,21 @@ 0 value buf-mask 0 value buf-act : /string ( adr len n -- adr' len' ) tuck - -rot + swap ; + +\ Advance next-buf - modulo #dma-bufs - by the number of bits set in buf-mask : +next-buf ( buf-mask -- ) 0 swap ( cnt buf-mask ) - 3 0 do dup 1 and rot + swap 1 >> loop drop - next-buf + #dma-bufs mod to next-buf + #dma-bufs 0 do ( cnt buf-mask ) + dup 1 and ( cnt buf-mask bit ) + rot + ( buf-mask cnt' ) + swap 1 >> ( cnt buf-mask' ) + loop drop ( cnt ) + next-buf + #dma-bufs mod to next-buf ( ) ; : buf-done? ( -- buf-mask ) 28 cl@ 2f 30 cl! 7 and ; -: read-buf ( adr len i -- adr' len' ) +: read-buf ( adr len buf# -- adr' len' ) 1 over << buf-mask and 0= if drop exit then - ( adr len i ) + ( adr len buf# ) 'dma-buf 2 pick 2 pick ( adr len dma-buf adr len ) /dma-buf min dup >r move r> ( adr len len' ) buf-act over + to buf-act ( adr len len' ) @@ -469,12 +150,60 @@ buf-mask +next-buf ; +0 value snap-next-buf +: snap-buf-done? ( -- false | buf true ) + 1 snap-next-buf lshift ( bitmask ) + dup h# 28 cl@ and if ( bitmask ) + h# 38 or h# 30 cl! ( ) \ Clear interrupts + snap-next-buf dup 1+ #dma-bufs mod to snap-next-buf ( buf# ) + 'dma-buf true ( buf true ) + else ( bitmask ) + drop false ( flag ) + then +; + +: resync ( -- ) + \ Wait for the current frame to be ready + begin snap-buf-done? until drop + + \ Ack any buffers that are already ready + begin snap-buf-done? while drop repeat + + \ Now when the next buffer is ready, it will be fresh +; + +\ Clear out any stale buffers +: xresync ( -- ) + \ Ack pending end-of-frames until there are none + begin h# 28 cl@ 7 and dup while h# 30 cl! repeat drop + + \ Now wait for a frame to become ready and set snap-next-buf to point to it + begin h# 28 cl@ 7 and dup 0= while drop repeat ( mask ) + 3 0 do + dup 1 and if + i to snap-next-buf + unloop exit + then + 2/ + loop + 0 to snap-next-buf +; + external : write ( adr len -- actual ) 2drop 0 ; : read ( adr len -- actual ) buf-done? ?dup if (read) else 2drop 0 then ; +: snap ( timeout -- true | buf false ) + 0 do + snap-buf-done? if ( buf ) + false unloop exit ( -- buf false ) + then + 1 ms + loop + true +; : open ( -- flag ) map-regs @@ -492,93 +221,13 @@ unmap-regs ; -\ ============================= selftest operation =========================== - -d# 10,000 constant movie-time -0 constant test-x -0 constant test-y - -\ Thanks to Cortland Setlow (AKA Blaketh) for the autobrightness code -\ and the full-screen + mirrored display. - -: autobright ( -- ) - read-agc 3 + 3 rshift h# f min " bright!" " $call-screen" evaluate -; -: full-brightness ( -- ) h# f " bright!" " $call-screen" evaluate ; - -: display-frame ( adr -- ) -\ test-x test-y VGA_WIDTH VGA_HEIGHT " draw-rectangle" " $call-screen" evaluate +: display-frame ( buf -- ) " expand-to-screen" " $call-screen" evaluate -\ autobright -; - -: timeout-read ( adr len timeout -- actual ) - >r 0 -rot r> 0 ?do ( actual adr len ) - 2dup read ?dup if 3 roll drop -rot leave then - 1 ms - loop 2drop -; - -: shoot-movie ( -- error? ) - /dma-buf #dma-bufs * dup dma-alloc swap ( adr len ) - get-msecs movie-time + -rot ( timeout adr len ) - begin - 2dup read ?dup 0> if ( timeout adr len actual ) - VGA_WIDTH VGA_HEIGHT * 2* / 0 ?do over display-frame loop - else - 1 ms - then ( timeout adr len ) - get-msecs 3 pick u> - until ( timeout adr len ) - dma-free drop false ( error? ) -; - -: shoot-still ( -- error? ) - /dma-buf dup dma-alloc tuck ( adr len adr ) - /dma-buf d# 1,000 timeout-read 0> if ( adr len ) - over display-frame - false - else - true - then ( adr len error? ) - -rot dma-free ( error? ) -; - -: mirrored ( -- ) h# 1e ov@ h# 20 or h# 1e ov! ; -: unmirrored ( -- ) h# 1e ov@ h# 20 invert and h# 1e ov! ; - -: selftest ( -- error? ) - open 0= if true exit then - unmirrored shoot-still ?dup if close exit then ( error? ) - d# 1,000 ms - mirrored shoot-movie full-brightness ( error? ) - close ( error? ) -; - -: dump-regs ( run# -- ) - 0 d# 16 " at-xy" eval - ." Pass " .d - key upc h# 47 = if ." Good" else ." Bad" then cr \ 47 is G - - ." 0 1 2 3 4 5 6 7 8 9 a b c d e f" cr - ." -----------------------------------------------" cr - h# ca 0 do - i 2 u.r ." : " - i h# 10 bounds do - i h# ca < if i ov@ 3 u.r then - loop - cr - h# 10 +loop -; - -: xselftest ( -- error? ) - open 0= if true exit then - h# 10 0 do - shoot-still drop d# 500 ms camera-config config-check - i dump-regs - loop - 0 close ( error? ) +\ test-x test-y VGA_WIDTH VGA_HEIGHT " draw-rectangle" " $call-screen" evaluate ; +: start-display ( -- ) ; +: stop-display ( -- ) ; +false constant camera-blocked? \ Do this at probe time to make sure the camera power is off map-regs Added: dev/olpc/cafecamera/platform.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ dev/olpc/cafecamera/platform.fth Sat Oct 1 19:45:39 2011 (r2558) @@ -0,0 +1,94 @@ +\ See license at end of file +purpose: Platform specifics for OLPC Camera on XO-1 + +headers +hex + +" camera" device-name +" olpc,camera" model +" camera" device-type +" olpc,camera" " compatible" string-property + +h# 4000 constant /regs + +my-address my-space encode-phys + 0 encode-int encode+ h# 0 encode-int encode+ + +my-address my-space h# 200.0010 + encode-phys encode+ + 0 encode-int encode+ /regs encode-int encode+ + +" reg" property + +: my-w@ ( offset -- w ) my-space + " config-w@" $call-parent ; +: my-w! ( w offset -- ) my-space + " config-w!" $call-parent ; + +0 instance value chip + +: cl! ( l adr -- ) chip + rl! ; +: cl@ ( adr -- l ) chip + rl@ ; + +: map-regs ( -- ) + 0 0 h# 0200.0010 my-space + /regs " map-in" $call-parent to chip + 4 my-w@ 6 or 4 my-w! +; + +: unmap-regs ( -- ) + chip /regs " map-out" $call-parent +\ 4 my-w@ 6 invert and 4 my-w! \ No need to turn it off +; + +h# 42 2 << constant ov-sid + +: clr-smb-intr ( -- ) 7.0000 30 cl! ; +: smbus-wait ( -- ) + begin 28 cl@ 7.0000 and until + 1 ms \ 20 usec delay +; + +: ov@ ( reg -- data ) + clr-smb-intr + ov-sid 87.fc01 or b8 cl! \ TWSI control 0: id, 8-bit, clk + bc cl@ drop \ Force write + d# 16 << 100.0000 or bc cl! \ TWSI control 1: read, reg + smbus-wait + bc cl@ ff and +; + +: ov! ( data reg -- ) + clr-smb-intr + ov-sid 8.7fc01 or b8 cl! \ TWSI control 0: id, 8-bit, clk + bc cl@ drop \ Force write + d# 16 << or bc cl! \ TWSI control 1: read, reg + 2 ms + smbus-wait + bc cl@ drop +; + +\ This must be headerless so evaluate won't find this version +headerless +: confirm-selftest? ( -- flag ) " confirm-selftest?" evaluate ; +headers + +\ LICENSE_BEGIN +\ Copyright (c) 2011 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
1
0
0
0
[commit] r2557 - cpu/x86 dev/olpc/viacamera
by repository service
01 Oct '11
01 Oct '11
Author: wmb Date: Sat Oct 1 19:44:26 2011 New Revision: 2557 URL:
http://tracker.coreboot.org/trac/openfirmware/changeset/2557
Log: OLPC XO-1.5 - Changed camera driver to use the shared common code for the Omnivision sensor and the selftest infrastructure. Added: cpu/x86/ycrcbtorgb.fth - copied unchanged from r2553, dev/olpc/viacamera/ycrcbtorgb.fth dev/olpc/viacamera/platform.fth Deleted: dev/olpc/viacamera/ycrcbtorgb.fth Modified: dev/olpc/viacamera/camera.fth dev/olpc/viacamera/loadpkg.fth dev/olpc/viacamera/smbus.fth Copied: cpu/x86/ycrcbtorgb.fth (from r2553, dev/olpc/viacamera/ycrcbtorgb.fth) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/x86/ycrcbtorgb.fth Sat Oct 1 19:44:26 2011 (r2557, copy of r2553, dev/olpc/viacamera/ycrcbtorgb.fth) @@ -0,0 +1,141 @@ +\ See license at end of file +purpose: Color space conversion from YCbCr to RGB + +\ R = clip (Y + 1.402 * Cr) +\ G = clip (Y - 0.344 * Cb - 0.714 * Cr) +\ B = clip (Y + 1.772 * Cb) + +\ This is for full-range YCbCr, where the Y anc Cb/Cr values ranges from 0-255. +\ For restricted-range YCbCr (16 <= Y <= 235, 16 <= Cr,Cb <= 240), the Y value +\ would need to be adjusted to Ysc = (Y - 16) * 1.164 (1.164 = 298 / 256 = 149 / 128) +\ and the multipliers change from (1.402, -0.343, -0.711, 1.765) to (1.596, -0.392, -0.813, 2.017) + +code ycrcb444>rgb888 ( y cr cb -- r g b ) + \ y: 8 [sp] + \ u: 4 [sp] = Cr + \ v: 0 [sp] = Cb + + d# 128 # 0 [sp] sub \ convert Cb to signed + d# 128 # 4 [sp] sub \ convert Cr to signed + 8 [sp] bx mov \ Get Y into register + + d# 90 # 4 [sp] ax imul-imm \ Multiply Cr by 1.402 * 64 (actually 1.406) + d# 6 # ax sar \ Scale down by 64 + bx ax add \ Add to Y + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + ax 8 [sp] mov \ Put R in place on stack + + d# -46 # 4 [sp] ax imul-imm \ Multiply Cr by -0.714 * 64 (actually -0.719) + d# 6 # ax sar \ Scale down by 64 + ax cx mov + d# -22 # 0 [sp] ax imul-imm \ Multiply Cr by -0.344 * 64 (actually -0.344) + d# 6 # ax sar \ Scale down by 64 + ax cx add + bx cx add \ Now we have G + 0< if cx cx xor then \ Clip to 0 + d# 255 # cx cmp > if d# 255 # cx mov then \ Clip to 255 + + d# 113 # 0 [sp] ax imul-imm \ Multiply Cr by 1.772 * 64 (actually 1.766) + d# 6 # ax sar \ Scale down by 64 + bx ax add \ Add to Y + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + ax 0 [sp] mov \ Put B in place on stack + + cx 4 [sp] mov \ Put G in place on stack +c; + + +\ This version operates on pixel values in memory +\ Src bytes are Cb Y1 Cr Y2 (2 pixels) +\ Dst bytes are R G B A R G B A (2 pixels) + +code ycbcr422>rgba8888 ( src dst count -- ) + 4 [sp] di xchg \ di: dst + 8 [sp] si xchg \ si: src + + ax push ax push \ Space on stack for Cr and Cb values + + begin + \ src: Cb Y1 Cr Y2 dst: R1 G1 B1 A1 R2 G2 B2 A2 + ax ax xor al lods d# 128 # ax sub ax 0 [sp] mov \ Get Cb, make signed, save on stack + ax ax xor al lods ax bx mov \ Get Y1, save in BX + ax ax xor al lods d# 128 # ax sub ax 4 [sp] mov \ Get Cr, make signed, save on stack + + d# 90 # 4 [sp] ax imul-imm \ Multiply Cr by 1.402 * 64 (actually 1.406) + d# 6 # ax sar \ Scale down by 64 + bx ax add \ Add to Y + + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + al stos \ Output R + + d# -46 # 4 [sp] ax imul-imm \ Multiply Cr by -0.714 * 64 (actually -0.719) + d# 6 # ax sar \ Scale down by 64 + ax dx mov + d# -22 # 0 [sp] ax imul-imm \ Multiply Cr by -0.344 * 64 (actually -0.344) + d# 6 # ax sar \ Scale down by 64 + dx ax add + bx ax add \ Now we have G + + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + al stos \ Output G + + d# 113 # 0 [sp] ax imul-imm \ Multiply Cr by 1.772 * 64 (actually 1.766) + d# 6 # ax sar \ Scale down by 64 + bx ax add \ Add to Y + + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + al stos \ Output B + d# 255 # al mov + al stos \ Output A + + ax ax xor al lods ax bx mov \ Get Y2 into BX + + d# 90 # 4 [sp] ax imul-imm \ Multiply Cr by 1.402 * 64 (actually 1.406) + d# 6 # ax sar \ Scale down by 64 + bx ax add \ Add to Y + + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + al stos \ Output R + + d# -46 # 4 [sp] ax imul-imm \ Multiply Cr by -0.714 * 64 (actually -0.719) + d# 6 # ax sar \ Scale down by 64 + ax dx mov + d# -22 # 0 [sp] ax imul-imm \ Multiply Cr by -0.344 * 64 (actually -0.344) + d# 6 # ax sar \ Scale down by 64 + dx ax add + bx ax add \ Now we have G + + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + al stos \ Output G + + d# 113 # 0 [sp] ax imul-imm \ Multiply Cr by 1.772 * 64 (actually 1.766) + d# 6 # ax sar \ Scale down by 64 + bx ax add \ Add to Y + + 0< if ax ax xor then \ Clip to 0 + d# 255 # ax cmp > if d# 255 # ax mov then \ Clip to 255 + + al stos \ Output B + d# 255 # al mov + al stos \ Output A + + 8 [sp] dec + 0= until + + d# 12 [sp] sp lea \ Clean stack, removing Cr, Cb, and count values + di pop \ Restore EDI + si pop \ Restore ESI +c; Modified: dev/olpc/viacamera/camera.fth ============================================================================== --- dev/olpc/viacamera/camera.fth Sat Oct 1 19:32:47 2011 (r2556) +++ dev/olpc/viacamera/camera.fth Sat Oct 1 19:44:26 2011 (r2557) @@ -4,284 +4,6 @@ headers hex -" OV7670" " sensor" string-property - -: cl! ( l adr -- ) " mmio-base" $call-parent + rl! ; -: cl@ ( adr -- l ) " mmio-base" $call-parent + rl@ ; - -\ ======================= OV7670 SMBUS operations ========================== - -h# 42 constant ov-sid -h# 31 constant sccb-port - -: sccb-setup ( -- ) sccb-port to smb-port ov-sid to smb-slave ; -: ov@ ( reg -- data ) sccb-setup smb-byte@ ; -: ov! ( data reg -- ) sccb-setup smb-byte! ; - -: ovc ( val adr -- ) - 2dup ov@ ( val reg# val actual ) - tuck <> if ( val reg# actual ) - ." Bad camera I2C value at " swap 2 u.r ( val actual ) - ." expected " swap 2 u.r ." got " 2 u.r cr ( ) - else ( val reg# actual ) - 3drop ( ) - then ( ) -; - -\ ============================= camera operations ============================= - -0 value use-ycrcb? - -false value ov7670-detected? - -: ((camera-init) ( -- ) - 80 12 ov! 2 ms \ reset (reads back different) - 01 11 ov! \ 30 fps - 04 3a ov! \ UYVY or VYUY - 00 12 ov! \ VGA - - \ Hardware window - 13 17 ov! \ Horiz start high bits - 01 18 ov! \ Horiz stop high bits - b6 32 ov! \ HREF pieces - 02 19 ov! \ Vert start high bits - !! 02 - 7a 1a ov! \ Vert stop high bits - 0a 03 ov! \ GAIN, VSTART, VSTOP pieces - - \ Mystery scaling numbers - 00 0c ov! \ Control 3 - 00 3e ov! \ Control 14 - 3a 70 ov! 35 71 ov! 11 72 ov! f0 73 ov! - 02 a2 ov! - 00 15 ov! \ Control 10 - - \ Gamma curve values - 20 7a ov! 10 7b ov! 1e 7c ov! 35 7d ov! - 5a 7e ov! 69 7f ov! 76 80 ov! 80 81 ov! - 88 82 ov! 8f 83 ov! 96 84 ov! a3 85 ov! - af 86 ov! c4 87 ov! d7 88 ov! e8 89 ov! - - \ AGC and AEC parameters - e0 13 ov! \ Control 8 - 00 00 ov! \ Gain lower 8 bits !! Linux then sets REG_AECH to 0 - 00 10 ov! - 40 0d ov! \ Control 4 magic reserved bit - 18 14 ov! \ Control 9: 4x gain + magic reserved bit - 05 a5 ov! \ 50hz banding step limit - 07 ab ov! \ 60hz banding step limit - 95 24 ov! \ AGC upper limit - 33 25 ov! \ AGC lower limit - e3 24 ov! \ AGC/AEC fast mode op region - 78 9f ov! \ Hist AEC/AGC control 1 - 68 a0 ov! \ Hist AEC/AGC control 2 - 03 a1 ov! \ Magic - d8 a6 ov! \ Hist AEC/AGC control 3 - d8 a7 ov! \ Hist AEC/AGC control 4 - f0 a8 ov! \ Hist AEC/AGC control 5 - 90 a9 ov! \ Hist AEC/AGC control 6 - 94 aa ov! \ Hist AEC/AGC control 7 - e5 13 ov! \ Control 8 - - \ Mostly magic - 61 0e ov! 4b 0f ov! 02 16 ov! 07 1e ov! - 02 21 ov! 91 22 ov! 07 29 ov! 0b 33 ov! - 0b 35 ov! 1d 37 ov! 71 38 ov! 2a 39 ov! - 78 3c ov! 40 4d ov! 20 4e ov! 00 69 ov! - 4a 6b ov! 10 74 ov! 4f 8d ov! 00 8e ov! - 00 8f ov! 00 90 ov! 00 91 ov! 00 96 ov! - 00 9a ov! 84 b0 ov! 0c b1 ov! 0e b2 ov! - 82 b3 ov! 0a b8 ov! - - \ More magic, some of which tweaks white balance - 0a 43 ov! f0 44 ov! 34 45 ov! 58 46 ov! - 28 47 ov! 3a 48 ov! 88 59 ov! 88 5a ov! - 44 5b ov! 67 5c ov! 49 5d ov! 0e 5e ov! - 0a 6c ov! 55 6d ov! 11 6e ov! - 9f 6f ov! \ 9e for advance AWB - 40 6a ov! - 40 01 ov! \ Blue gain - 60 02 ov! \ Red gain - e7 13 ov! \ Control 8 - - \ Matrix coefficients - 80 4f ov! 80 50 ov! 00 51 ov! 22 52 ov! - 5e 53 ov! 80 54 ov! 9e 58 ov! - - 08 41 ov! \ AWB gain enable - 00 3f ov! \ Edge enhancement factor - 05 75 ov! e1 76 ov! 00 4c ov! 01 77 ov! - c3 3d ov! \ Control 13 - 09 4b ov! 60 c9 ov! \ Reads back differently - 38 41 ov! \ Control 16 - 40 56 ov! - - 11 34 ov! - 12 3b ov! \ Control 11 - 88 a4 ov! 00 96 ov! 30 97 ov! 20 98 ov! - 30 99 ov! 84 9a ov! 29 9b ov! 03 9c ov! - 4c 9d ov! 3f 9e ov! 04 78 ov! - - \ Extra-weird stuff. Some sort of multiplexor register - 01 79 ov! f0 c8 ov! - 0f 79 ov! 00 c8 ov! - 10 79 ov! 7e c8 ov! - 0a 79 ov! 80 c8 ov! - 0b 79 ov! 01 c8 ov! - 0c 79 ov! 0f c8 ov! - 0d 79 ov! 20 c8 ov! - 09 79 ov! 80 c8 ov! - 02 79 ov! c0 c8 ov! - 03 79 ov! 40 c8 ov! - 05 79 ov! 30 c8 ov! - 26 79 ov! - - \ OVT says that rewrite this works around a bug in 565 mode. - \ The symptom of the bug is red and green speckles in the image. -\ 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this -; - -: config-check ( -- ) - 01 11 ovc \ 30 fps - 04 3a ovc \ UYVY or VYUY - ( 00 12 ovc ) \ VGA - - \ Hardware window - 13 17 ovc \ Horiz start high bits - 01 18 ovc \ Horiz stop high bits - b6 32 ovc \ HREF pieces - 02 19 ovc \ Vert start high bits - 7a 1a ovc \ Vert stop high bits - 0a 03 ovc \ GAIN, VSTART, VSTOP pieces - - \ Mystery scaling numbers - 00 0c ovc \ Control 3 - 00 3e ovc \ Control 14 - 3a 70 ovc 35 71 ovc 11 72 ovc f0 73 ovc - 02 a2 ovc - 00 15 ovc \ Control 10 - - \ Gamma curve values - 20 7a ovc 10 7b ovc 1e 7c ovc 35 7d ovc - 5a 7e ovc 69 7f ovc 76 80 ovc 80 81 ovc - 88 82 ovc 8f 83 ovc 96 84 ovc a3 85 ovc - af 86 ovc c4 87 ovc d7 88 ovc e8 89 ovc - - \ AGC and AEC parameters - ( e0 13 ovc ) \ Control 8 - ( 00 00 ovc ) \ Gain lower 8 bits - ( 00 10 ovc ) \ Automatic exposure control 9:2 - 40 0d ovc \ Control 4 magic reserved bit - ( 18 14 ovc ) \ Control 9: 4x gain + magic reserved bit - 05 a5 ovc \ 50hz banding step limit - 07 ab ovc \ 60hz banding step limit - ( 95 24 ovc ) \ AGC upper limit - 33 25 ovc \ AGC lower limit - e3 24 ovc \ AGC/AEC fast mode op region - 78 9f ovc \ Hist AEC/AGC control 1 - 68 a0 ovc \ Hist AEC/AGC control 2 - 03 a1 ovc \ Magic - d8 a6 ovc \ Hist AEC/AGC control 3 - d8 a7 ovc \ Hist AEC/AGC control 4 - f0 a8 ovc \ Hist AEC/AGC control 5 - 90 a9 ovc \ Hist AEC/AGC control 6 - 94 aa ovc \ Hist AEC/AGC control 7 - ( e5 13 ovc ) \ Control 8 - - \ Mostly magic - 61 0e ovc 4b 0f ovc 02 16 ovc 07 1e ovc - 02 21 ovc 91 22 ovc 07 29 ovc 0b 33 ovc - 0b 35 ovc 1d 37 ovc 71 38 ovc 2a 39 ovc - 78 3c ovc 40 4d ovc 20 4e ovc 00 69 ovc - 4a 6b ovc 10 74 ovc 4f 8d ovc 00 8e ovc - 00 8f ovc 00 90 ovc 00 91 ovc 00 96 ovc - ( 00 9a ovc ) 84 b0 ovc 0c b1 ovc 0e b2 ovc - 82 b3 ovc 0a b8 ovc - - \ More magic, some of which tweaks white balance - 0a 43 ovc f0 44 ovc 34 45 ovc 58 46 ovc - 28 47 ovc 3a 48 ovc 88 59 ovc 88 5a ovc - 44 5b ovc 67 5c ovc 49 5d ovc 0e 5e ovc - 0a 6c ovc 55 6d ovc 11 6e ovc - 9f 6f ovc \ 9e for advance AWB - ( 40 6a ovc ) - ( 40 01 ovc ) \ Blue gain - ( 60 02 ovc ) \ Red gain - e7 13 ovc \ Control 8 - - \ Matrix coefficients - b3 4f ovc b3 50 ovc 00 51 ovc 3d 52 ovc - a7 53 ovc e4 54 ovc 9e 58 ovc - - \ 08 41 ovc \ AWB gain enable - ( 00 3f ovc ) \ Edge enhancement factor - 05 75 ovc e1 76 ovc ( 00 4c ovc ) 01 77 ovc - c0 3d ovc \ Control 13 - 09 4b ovc ( 60 c9 ovc ) - 38 41 ovc \ Control 16 - 40 56 ovc - - 11 34 ovc - 12 3b ovc \ Control 11 - 88 a4 ovc 00 96 ovc 30 97 ovc 20 98 ovc - 30 99 ovc 84 9a ovc 29 9b ovc 03 9c ovc - 5c 9d ovc 3f 9e ovc 04 78 ovc - -; - -: camera-init ( -- ) - false to ov7670-detected? - ((camera-init) - 1d ov@ 1c ov@ bwjoin 7fa2 <> if exit then \ Manufacturing ID - b ov@ a ov@ bwjoin 7673 <> if exit then \ Product ID - true to ov7670-detected? -; - -\ VGA RGB565 -: init-rgb565 ( -- ) - 04 12 ov! \ VGA, RGB565 - 00 8c ov! \ No RGB444 - 00 04 ov! \ Control 1: CCIR601 (H/VSYNC framing) - 10 40 ov! \ RGB565 output - 38 14 ov! \ 16x gain ceiling - b3 4f ov! \ v-red - b3 50 ov! \ v-green - 00 51 ov! \ v-blue - 3d 52 ov! \ u-red - a7 53 ov! \ u-green - e4 54 ov! \ u-blue - c0 3d ov! \ Gamma enable, UV saturation auto adjust - - \ OVT says that rewrite this works around a bug in 565 mode. - \ The symptom of the bug is red and green speckles in the image. - 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this -; - -: read-agc ( -- n ) - 3 ov@ h# c0 and 2 lshift 0 ov@ or -; - -: read-aec ( -- n ) - 7 ov@ h# 3f and d# 10 lshift - h# 10 ov@ 2 lshift or - 4 ov@ 3 and or -; - -: set-hw ( vstop vstart hstop hstart -- ) - dup 3 >> 17 ov! \ Horiz start high bits - over 3 >> 18 ov! \ Horiz stop high bits - 32 ov@ swap 7 and or swap 7 and 3 << or 10 ms 32 ov! \ Horiz bottom bits - - dup 2 >> 19 ov! \ Vert start high bits - over 2 >> 1a ov! \ Vert start high bits - 03 ov@ swap 3 and or swap 3 and 2 << or 10 ms 03 ov! \ Vert bottom bits -; - -: camera-config ( -- ) - ((camera-init) - use-ycrcb? 0= if init-rgb565 then - d# 490 d# 10 d# 14 d# 158 set-hw \ VGA window info -; - \ ========================== video capture operations ========================== d# 640 constant VGA_WIDTH @@ -381,7 +103,7 @@ : init ( -- ) (init) power-up - sccb-setup smb-on + camera-smb-setup smb-on camera-init ; @@ -396,6 +118,8 @@ then ; +: resync ( -- ) ; + : snap ( timeout -- true | adr false ) 0 do buf-done? if @@ -413,6 +137,14 @@ 300 cl@ 83 or 300 cl! \ Clear interrupts ; +: start-display ( -- ) ; +: stop-display ( -- ) ; +: camera-blocked? ( -- flag ) + serial-enabled? dup if + ." The serial port is in use so the camera cannot be used" cr + then +; + external : read ( adr len -- actual ) @@ -437,18 +169,6 @@ \ ============================= selftest operation =========================== -d# 5,000 constant movie-time -0 constant test-x -0 constant test-y - -\ Thanks to Cortland Setlow (AKA Blaketh) for the autobrightness code -\ and the full-screen + mirrored display. - -: autobright ( -- ) - read-agc 3 + 3 rshift h# f min " bright!" $call-parent -; -: full-brightness ( -- ) h# f " bright!" $call-parent ; - : display-ycrcb-frame ( adr -- ) temp-buf VGA_WIDTH VGA_HEIGHT * ycbcr422>rgba8888 temp-buf VGA_WIDTH 4* ( src-adr src-pitch ) @@ -462,72 +182,7 @@ : display-frame ( adr -- ) use-ycrcb? if display-ycrcb-frame else display-rgb-frame then -\ autobright ; -: timeout-read ( adr len timeout -- actual ) - >r 0 -rot r> 0 ?do ( actual adr len ) - 2dup read ?dup if 3 roll drop -rot leave then - 1 ms - loop 2drop -; - -: shoot-still ( -- error? ) - d# 1000 snap if true exit then ( adr ) - display-frame - false -; - -: shoot-movie ( -- error? ) - get-msecs movie-time + ( timeout ) - begin ( timeout ) - shoot-still if drop true exit then ( timeout ) - dup get-msecs - 0<= ( timeout reached ) - until ( timeout ) - drop false -; - -: mirrored ( -- ) h# 1e ov@ h# 20 or h# 1e ov! ; -: unmirrored ( -- ) h# 1e ov@ h# 20 invert and h# 1e ov! ; - -: selftest ( -- error? ) - serial-enabled? if - ." The serial port is in use so the camera cannot be used" cr - false exit - then - open 0= if true exit then - d# 300 ms - unmirrored shoot-still ?dup if close exit then ( error? ) - d# 1,000 ms - mirrored shoot-movie full-brightness ( error? ) - close ( error? ) - ?dup 0= if confirm-selftest? then ( error? ) -; - -: dump-regs ( run# -- ) - 0 d# 16 " at-xy" eval - ." Pass " .d - key upc h# 47 = if ." Good" else ." Bad" then cr \ 47 is G - - ." 0 1 2 3 4 5 6 7 8 9 a b c d e f" cr - ." -----------------------------------------------" cr - h# ca 0 do - i 2 u.r ." : " - i h# 10 bounds do - i h# ca < if i ov@ 3 u.r then - loop - cr - h# 10 +loop -; - -: xselftest ( -- error? ) - open 0= if true exit then - h# 10 0 do - shoot-still drop d# 500 ms camera-config config-check - i dump-regs - loop - 0 close ( error? ) -; - \ LICENSE_BEGIN \ Copyright (c) 2009 FirmWorks Modified: dev/olpc/viacamera/loadpkg.fth ============================================================================== --- dev/olpc/viacamera/loadpkg.fth Sat Oct 1 19:32:47 2011 (r2556) +++ dev/olpc/viacamera/loadpkg.fth Sat Oct 1 19:44:26 2011 (r2557) @@ -26,10 +26,14 @@ new-device " camera" device-name 0 0 reg \ A reg property makes "test-all" consider this device - fload ${BP}/dev/olpc/viacamera/smbus.fth - fload ${BP}/dev/olpc/viacamera/ycrcbtorgb.fth + [ifndef] seq! : seq! 3c4 pc! 3c5 pc! ; [then] + [ifndef] seq@ : seq@ 3c4 pc! 3c5 pc@ ; [then] + fload ${BP}/dev/olpc/viacamera/smbus.fth \ Bit-banging SMBUS driver + fload ${BP}/dev/olpc/viacamera/platform.fth + fload ${BP}/dev/olpc/ov7670.fth + fload ${BP}/cpu/x86/ycrcbtorgb.fth \ Color space conversion fload ${BP}/dev/olpc/viacamera/camera.fth + fload ${BP}/dev/olpc/cameratest.fth finish-device device-end - Added: dev/olpc/viacamera/platform.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ dev/olpc/viacamera/platform.fth Sat Oct 1 19:44:26 2011 (r2557) @@ -0,0 +1,43 @@ +\ See license at end of file +purpose: Platform specifics for OLPC Camera on XO-1.5 + +h# 26 constant dcon-port +: dcon-setup ( -- ) dcon-port to smb-port h# 1a to smb-slave ; +: smb-init ( -- ) dcon-setup smb-on smb-pulses ; + +: dcon@ ( reg# -- word ) dcon-setup smb-word@ ; +: dcon! ( word reg# -- ) dcon-setup smb-word! ; + +: cl! ( l adr -- ) " mmio-base" $call-parent + rl! ; +: cl@ ( adr -- l ) " mmio-base" $call-parent + rl@ ; + +h# 42 constant ov-sid +h# 31 constant sccb-port + +: camera-smb-setup ( -- ) sccb-port to smb-port ov-sid to smb-slave ; +: ov@ ( reg -- data ) camera-smb-setup smb-byte@ ; +: ov! ( data reg -- ) camera-smb-setup smb-byte! ; + +\ LICENSE_BEGIN +\ Copyright (c) 2011 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END Modified: dev/olpc/viacamera/smbus.fth ============================================================================== --- dev/olpc/viacamera/smbus.fth Sat Oct 1 19:32:47 2011 (r2556) +++ dev/olpc/viacamera/smbus.fth Sat Oct 1 19:44:26 2011 (r2557) @@ -1,10 +1,4 @@ -[ifndef] seq! -: seq! 3c4 pc! 3c5 pc! ; -[then] - -[ifndef] seq@ -: seq@ 3c4 pc! 3c5 pc@ ; -[then] +\ 0 value smb-port @@ -123,10 +117,3 @@ : smb-pulses ( -- ) d# 32 0 do smb-clk-lo smb-clk-hi loop ; - -h# 26 constant dcon-port -: dcon-setup ( -- ) dcon-port to smb-port h# 1a to smb-slave ; -: smb-init ( -- ) dcon-setup smb-on smb-pulses ; - -: dcon@ ( reg# -- word ) dcon-setup smb-word@ ; -: dcon! ( word reg# -- ) dcon-setup smb-word! ;
1
0
0
0
[commit] r2556 - in dev/olpc: . mmp2camera
by repository service
01 Oct '11
01 Oct '11
Author: wmb Date: Sat Oct 1 19:32:47 2011 New Revision: 2556 URL:
http://tracker.coreboot.org/trac/openfirmware/changeset/2556
Log: OLPC XO-1.75 - trac #11236 - Added YCrCb (YUV) support to the XO-1.75 camera test, in the process factoring out the Omnivision sensor code and the base selftest infrastructure into separate files so that XO-1, XO-1.5, and XO-1.75 don't have to duplicate that code. This addresses the stated request of 11236, but does not really change the underlying reality with respect to testing H/VSYNC, since the XO-1.75 camera test has always used CCIR601 separate-sync-lines signaling instead of CCIR656 in-stream sync. Added: dev/olpc/cameratest.fth dev/olpc/ov7670.fth Modified: dev/olpc/mmp2camera/ccic.fth dev/olpc/mmp2camera/loadpkg.fth dev/olpc/mmp2camera/platform.fth Added: dev/olpc/cameratest.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ dev/olpc/cameratest.fth Sat Oct 1 19:32:47 2011 (r2556) @@ -0,0 +1,82 @@ +\ See license at end of file +purpose: Common code for OLPC Camera selftest + +d# 5,000 constant movie-time +0 constant test-x +0 constant test-y + +\ Thanks to Cortland Setlow (AKA Blaketh) for the autobrightness code +\ and the full-screen + mirrored display. + +: autobright ( -- ) + read-agc 3 + 3 rshift h# f min " bright!" " $call-screen" evaluate +; +: full-brightness ( -- ) h# f " bright!" " $call-screen" evaluate ; + +: timeout-read ( adr len timeout -- actual ) + >r 0 -rot r> 0 ?do ( actual adr len ) + 2dup read ?dup if 3 roll drop -rot leave then + 1 ms + loop 2drop +; + +: shoot-still ( -- error? ) + d# 1000 snap if true exit then ( buf ) + display-frame ( autobright ) + false +; + +: shoot-movie ( -- error? ) + get-msecs movie-time + ( timeout ) + begin ( timeout ) + shoot-still if drop true exit then ( timeout ) + dup get-msecs - 0<= ( timeout reached ) + until ( timeout ) + drop false +; + +: selftest ( -- error? ) + camera-blocked? if false exit then + open 0= if true exit then + d# 300 ms + start-display + unmirrored resync ( ) + shoot-still ?dup if stop-display close exit then ( error? ) + d# 1,000 ms + mirrored resync shoot-movie full-brightness ( error? ) + stop-display close ( error? ) + ?dup 0= if confirm-selftest? then ( error? ) +; + +: xselftest ( -- error? ) + open 0= if true exit then + h# 10 0 do + shoot-still drop d# 500 ms camera-config config-check + i dump-regs + loop + 0 close ( error? ) +; + +\ LICENSE_BEGIN +\ Copyright (c) 2009 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END Modified: dev/olpc/mmp2camera/ccic.fth ============================================================================== --- dev/olpc/mmp2camera/ccic.fth Fri Sep 30 03:30:43 2011 (r2555) +++ dev/olpc/mmp2camera/ccic.fth Sat Oct 1 19:32:47 2011 (r2556) @@ -1,5 +1,12 @@ +\ See license at end of file +purpose: Driver for OLPC camera connected to Marvell MMP2 CCIC port + \ ========================== video capture operations ========================== +0 value camera-base +: cl! ( l adr -- ) camera-base + rl! ; +: cl@ ( adr -- l ) camera-base + rl@ ; + d# 640 constant VGA_WIDTH d# 480 constant VGA_HEIGHT @@ -36,18 +43,16 @@ \ 0100.0000 for HSYNC active low \ 0080.0000 for VSYNC falling edge h# 0000.0000 constant polarities -h# 20 constant rgb-sensor -h# 080 constant rgb-fb -h# 00 constant rgb-endian \ 0c bits +h# 0.8000 constant ycrcb4:2:2-format \ YCrCb input and output, 422 packed format (8000), no swapping +h# a0 constant rgb-format \ RGB input (20) and output (80), no swapping -\ VGA RGB565 : setup-image ( -- ) VGA_WIDTH 2* h# 24 cl! \ 640*2 stride, UV stride in high bits = 0 VGA_WIDTH 2* VGA_HEIGHT wljoin h# 34 cl! \ Image size register 0 0 wljoin h# 38 cl! \ Image offset - polarities rgb-fb or rgb-sensor or rgb-endian or h# 3c cl! \ CTRL0 + use-ycrcb? if ycrcb4:2:2-format else rgb-format then polarities or h# 3c cl! \ CTRL0 ; : interrupts-off ( -- ) 0 h# 2c cl! h# ffffffff h# 30 cl! ; @@ -96,7 +101,7 @@ : init ( -- ) power-on - ov-smb-setup smb-on + camera-smb-setup smb-on camera-init ; @@ -114,6 +119,7 @@ then ; +: resync ( -- ) ; : snap ( timeout -- true | buf# false ) 0 do @@ -140,21 +146,24 @@ : open ( -- flag ) my-address my-space h# 1000 " map-in" $call-parent to camera-base init + my-args " yuv" $= to use-ycrcb? ov7670-detected? 0= if false exit then alloc-dma-bufs read-setup true ; +\ There are no pin conflicts on this platform, so the camera can't be blocked +false constant camera-blocked? + : start-display ( -- ) - 0 'dma-buf-phys VGA_WIDTH VGA_HEIGHT " start-video" $call-screen + 0 'dma-buf-phys VGA_WIDTH VGA_HEIGHT use-ycrcb? " start-video" $call-screen ; : stop-display ( -- ) " stop-video" $call-screen ; : close ( -- ) - stop-display ctlr-stop interrupts-off power-off @@ -165,17 +174,28 @@ \ ============================= selftest operation =========================== -d# 5,000 constant movie-time -0 constant test-x -0 constant test-y - \ Thanks to Cortland Setlow (AKA Blaketh) for the autobrightness code -\ and the full-screen + mirrored display. -: autobright ( -- ) - read-agc 3 + 3 rshift h# f min " bright!" $call-screen +[ifdef] notdef \ Unnecessary, since that we don't use 24bpp +VGA_WIDTH value rect-w +VGA_HEIGHT value rect-h + +d# 1200 3 * value dst-pitch +d# 1200 VGA_WIDTH - 2/ value dst-x +d# 800 VGA_HEIGHT - 2/ value dst-y + +VGA_WIDTH 2* value src-pitch + +: >dst-adr ( adr -- adr' ) dst-y dst-pitch * dst-x + 3 * + ; + +: copy16>24 ( src-adr dst-base -- ) + >dst-adr ( src-adr dst-adr ) + rect-h 0 ?do ( src-adr dst-adr ) + 2dup rect-w copy16>24-line ( scr-adr dst-adr ) + swap src-pitch + swap dst-pitch + ( scr-adr' dst-adr' ) + loop ( src-adr dst-adr ) + 2drop ( ) ; -: full-brightness ( -- ) h# f " bright!" $call-screen ; code copy16>24-line ( src-adr dst-adr #pixels -- ) mov r2,tos \ #pixels in r2 @@ -199,93 +219,11 @@ decs r2,1 0= until c; +[then] -VGA_WIDTH value rect-w -VGA_HEIGHT value rect-h - -d# 1200 3 * value dst-pitch -d# 1200 VGA_WIDTH - 2/ value dst-x -d# 800 VGA_HEIGHT - 2/ value dst-y - -: >dst-adr ( adr -- adr' ) dst-y dst-pitch * dst-x + 3 * + ; - -VGA_WIDTH 2* value src-pitch - -: copy16>24 ( src-adr dst-base -- ) - >dst-adr ( src-adr dst-adr ) - rect-h 0 ?do ( src-adr dst-adr ) - 2dup rect-w copy16>24-line ( scr-adr dst-adr ) - swap src-pitch + swap dst-pitch + ( scr-adr' dst-adr' ) - loop ( src-adr dst-adr ) - 2drop ( ) -; - -: display-frame ( buf# -- ) +: display-frame ( buf -- ) 'dma-buf-phys " set-video-dma-adr" $call-screen \ 'dma-buf fb-pa copy16>24 -\ autobright -; - -: timeout-read ( adr len timeout -- actual ) - >r 0 -rot r> 0 ?do ( actual adr len ) - 2dup read ?dup if 3 roll drop -rot leave then - 1 ms - loop 2drop -; - -: shoot-still ( -- error? ) - d# 1000 snap if true exit then ( buf# ) - display-frame - false -; - -: shoot-movie ( -- error? ) - get-msecs movie-time + ( timeout ) - begin ( timeout ) - shoot-still if drop true exit then ( timeout ) - dup get-msecs - 0<= ( timeout reached ) - until ( timeout ) - drop false -; - -: mirrored ( -- ) h# 1e ov@ h# 20 or h# 1e ov! ; -: unmirrored ( -- ) h# 1e ov@ h# 20 invert and h# 1e ov! ; - -: selftest ( -- error? ) - open 0= if true exit then - d# 300 ms - start-display - unmirrored shoot-still ?dup if close exit then ( error? ) - d# 1,000 ms - mirrored shoot-movie full-brightness ( error? ) - close ( error? ) - ?dup 0= if confirm-selftest? then ( error? ) -; - -: dump-regs ( run# -- ) - 0 d# 16 " at-xy" eval - ." Pass " .d - key upc h# 47 = if ." Good" else ." Bad" then cr \ 47 is G - - ." 0 1 2 3 4 5 6 7 8 9 a b c d e f" cr - ." -----------------------------------------------" cr - h# ca 0 do - i 2 u.r ." : " - i h# 10 bounds do - i h# ca < if i ov@ 3 u.r then - loop - cr - h# 10 +loop -; - -: xselftest ( -- error? ) - open 0= if true exit then - - h# 10 0 do - shoot-still drop d# 500 ms camera-config config-check - i dump-regs - loop - 0 close ( error? ) ; \ LICENSE_BEGIN Modified: dev/olpc/mmp2camera/loadpkg.fth ============================================================================== --- dev/olpc/mmp2camera/loadpkg.fth Fri Sep 30 03:30:43 2011 (r2555) +++ dev/olpc/mmp2camera/loadpkg.fth Sat Oct 1 19:32:47 2011 (r2556) @@ -23,8 +23,7 @@ [then] fload ${BP}/dev/olpc/mmp2camera/platform.fth - fload ${BP}/dev/olpc/mmp2camera/ov.fth + fload ${BP}/dev/olpc/ov7670.fth fload ${BP}/dev/olpc/mmp2camera/ccic.fth + fload ${BP}/dev/olpc/cameratest.fth end-package - - Modified: dev/olpc/mmp2camera/platform.fth ============================================================================== --- dev/olpc/mmp2camera/platform.fth Fri Sep 30 03:30:43 2011 (r2555) +++ dev/olpc/mmp2camera/platform.fth Sat Oct 1 19:32:47 2011 (r2556) @@ -1,17 +1,17 @@ \ See license at end of file -purpose: Driver for OLPC camera connected to Via VX855 Video Capture Port +purpose: Platform specifics for OLPC camera connected to Marvell MMP2 CMOS Camera Interface Controller (CCIC) headers hex -" OV7670" " sensor" string-property - -: ov-smb-setup ( -- ) +: camera-smb-setup ( -- ) 1 to smb-dly-us d# 108 to smb-clock-gpio# d# 109 to smb-data-gpio# h# 42 to smb-slave ; +: ov@ ( reg -- data ) camera-smb-setup smb-byte@ ; +: ov! ( data reg -- ) camera-smb-setup smb-byte! ; : reset-sensor ( -- ) d# 102 gpio-clr 1 ms d# 102 gpio-set ; @@ -27,6 +27,26 @@ \ PIXMCLK on GPIO69, PIXCLK on GPIO70, PIXDATA[7:0] on GPIO[59:66] \ CAM_SCL on GPIO108, CAM_SDA on GPIO109 (bitbang) -0 value camera-base -: cl! ( l adr -- ) camera-base + rl! ; -: cl@ ( adr -- l ) camera-base + rl@ ; +\ LICENSE_BEGIN +\ Copyright (c) 2011 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END Added: dev/olpc/ov7670.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ dev/olpc/ov7670.fth Sat Oct 1 19:32:47 2011 (r2556) @@ -0,0 +1,312 @@ +\ See license at end of file +purpose: Omnivision OV7670 image sensor driver + +" OV7670" " sensor" string-property + +\ ============================= camera operations ============================= + +\ Check for the expected value +: ovc ( val adr -- ) + 2dup ov@ ( val reg# val actual ) + tuck <> if ( val reg# actual ) + ." Bad camera I2C value at " swap 2 u.r ( val actual ) + ." expected " swap 2 u.r ." got " 2 u.r cr ( ) + else ( val reg# actual ) + 3drop ( ) + then ( ) +; + +0 value use-ycrcb? + +false value ov7670-detected? + +: ((camera-init) ( -- ) + 80 12 ov! 2 ms \ reset (reads back different) + 01 11 ov! \ 30 fps + 04 3a ov! \ UYVY or VYUY + 00 12 ov! \ VGA + + \ Hardware window + 13 17 ov! \ Horiz start high bits + 01 18 ov! \ Horiz stop high bits + b6 32 ov! \ HREF pieces + 02 19 ov! \ Vert start high bits + 7a 1a ov! \ Vert stop high bits + 0a 03 ov! \ GAIN, VSTART, VSTOP pieces + + \ Mystery scaling numbers + 00 0c ov! \ Control 3 + 00 3e ov! \ Control 14 + 3a 70 ov! 35 71 ov! 11 72 ov! f0 73 ov! + 02 a2 ov! + 00 15 ov! \ Control 10 + + \ Gamma curve values + 20 7a ov! 10 7b ov! 1e 7c ov! 35 7d ov! + 5a 7e ov! 69 7f ov! 76 80 ov! 80 81 ov! + 88 82 ov! 8f 83 ov! 96 84 ov! a3 85 ov! + af 86 ov! c4 87 ov! d7 88 ov! e8 89 ov! + + \ AGC and AEC parameters + e0 13 ov! \ Control 8 + 00 00 ov! \ Gain lower 8 bits !! Linux then sets REG_AECH to 0 + 00 10 ov! + 40 0d ov! \ Control 4 magic reserved bit + 18 14 ov! \ Control 9: 4x gain + magic reserved bit + 05 a5 ov! \ 50hz banding step limit + 07 ab ov! \ 60hz banding step limit + 95 24 ov! \ AGC upper limit + 33 25 ov! \ AGC lower limit + e3 24 ov! \ AGC/AEC fast mode op region + 78 9f ov! \ Hist AEC/AGC control 1 + 68 a0 ov! \ Hist AEC/AGC control 2 + 03 a1 ov! \ Magic + d8 a6 ov! \ Hist AEC/AGC control 3 + d8 a7 ov! \ Hist AEC/AGC control 4 + f0 a8 ov! \ Hist AEC/AGC control 5 + 90 a9 ov! \ Hist AEC/AGC control 6 + 94 aa ov! \ Hist AEC/AGC control 7 + e5 13 ov! \ Control 8 + + \ Mostly magic + 61 0e ov! 4b 0f ov! 02 16 ov! 07 1e ov! + 02 21 ov! 91 22 ov! 07 29 ov! 0b 33 ov! + 0b 35 ov! 1d 37 ov! 71 38 ov! 2a 39 ov! + 78 3c ov! 40 4d ov! 20 4e ov! 00 69 ov! + 4a 6b ov! 10 74 ov! 4f 8d ov! 00 8e ov! + 00 8f ov! 00 90 ov! 00 91 ov! 00 96 ov! + 00 9a ov! 84 b0 ov! 0c b1 ov! 0e b2 ov! + 82 b3 ov! 0a b8 ov! + + \ More magic, some of which tweaks white balance + 0a 43 ov! f0 44 ov! 34 45 ov! 58 46 ov! + 28 47 ov! 3a 48 ov! 88 59 ov! 88 5a ov! + 44 5b ov! 67 5c ov! 49 5d ov! 0e 5e ov! + 0a 6c ov! 55 6d ov! 11 6e ov! + 9f 6f ov! \ 9e for advance AWB + 40 6a ov! + 40 01 ov! \ Blue gain + 60 02 ov! \ Red gain + e7 13 ov! \ Control 8 + + \ Matrix coefficients + 80 4f ov! 80 50 ov! 00 51 ov! 22 52 ov! + 5e 53 ov! 80 54 ov! 9e 58 ov! + + 08 41 ov! \ AWB gain enable + 00 3f ov! \ Edge enhancement factor + 05 75 ov! e1 76 ov! 00 4c ov! 01 77 ov! + c3 3d ov! \ Control 13 + 09 4b ov! 60 c9 ov! \ Reads back differently + 38 41 ov! \ Control 16 + 40 56 ov! + + 11 34 ov! + 12 3b ov! \ Control 11 + 88 a4 ov! 00 96 ov! 30 97 ov! 20 98 ov! + 30 99 ov! 84 9a ov! 29 9b ov! 03 9c ov! + 4c 9d ov! 3f 9e ov! 04 78 ov! + + \ Extra-weird stuff. Some sort of multiplexor register + 01 79 ov! f0 c8 ov! + 0f 79 ov! 00 c8 ov! + 10 79 ov! 7e c8 ov! + 0a 79 ov! 80 c8 ov! + 0b 79 ov! 01 c8 ov! + 0c 79 ov! 0f c8 ov! + 0d 79 ov! 20 c8 ov! + 09 79 ov! 80 c8 ov! + 02 79 ov! c0 c8 ov! + 03 79 ov! 40 c8 ov! + 05 79 ov! 30 c8 ov! + 26 79 ov! + + \ OVT says that rewrite this works around a bug in 565 mode. + \ The symptom of the bug is red and green speckles in the image. +\ 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this +; + +: config-check ( -- ) + 01 11 ovc \ 30 fps + 04 3a ovc \ UYVY or VYUY + ( 00 12 ovc ) \ VGA + + \ Hardware window + 13 17 ovc \ Horiz start high bits + 01 18 ovc \ Horiz stop high bits + b6 32 ovc \ HREF pieces + 02 19 ovc \ Vert start high bits + 7a 1a ovc \ Vert stop high bits + 0a 03 ovc \ GAIN, VSTART, VSTOP pieces + + \ Mystery scaling numbers + 00 0c ovc \ Control 3 + 00 3e ovc \ Control 14 + 3a 70 ovc 35 71 ovc 11 72 ovc f0 73 ovc + 02 a2 ovc + 00 15 ovc \ Control 10 + + \ Gamma curve values + 20 7a ovc 10 7b ovc 1e 7c ovc 35 7d ovc + 5a 7e ovc 69 7f ovc 76 80 ovc 80 81 ovc + 88 82 ovc 8f 83 ovc 96 84 ovc a3 85 ovc + af 86 ovc c4 87 ovc d7 88 ovc e8 89 ovc + + \ AGC and AEC parameters + ( e0 13 ovc ) \ Control 8 + ( 00 00 ovc ) \ Gain lower 8 bits + ( 00 10 ovc ) \ Automatic exposure control 9:2 + 40 0d ovc \ Control 4 magic reserved bit + ( 18 14 ovc ) \ Control 9: 4x gain + magic reserved bit + 05 a5 ovc \ 50hz banding step limit + 07 ab ovc \ 60hz banding step limit + ( 95 24 ovc ) \ AGC upper limit + 33 25 ovc \ AGC lower limit + e3 24 ovc \ AGC/AEC fast mode op region + 78 9f ovc \ Hist AEC/AGC control 1 + 68 a0 ovc \ Hist AEC/AGC control 2 + 03 a1 ovc \ Magic + d8 a6 ovc \ Hist AEC/AGC control 3 + d8 a7 ovc \ Hist AEC/AGC control 4 + f0 a8 ovc \ Hist AEC/AGC control 5 + 90 a9 ovc \ Hist AEC/AGC control 6 + 94 aa ovc \ Hist AEC/AGC control 7 + ( e5 13 ovc ) \ Control 8 + + \ Mostly magic + 61 0e ovc 4b 0f ovc 02 16 ovc 07 1e ovc + 02 21 ovc 91 22 ovc 07 29 ovc 0b 33 ovc + 0b 35 ovc 1d 37 ovc 71 38 ovc 2a 39 ovc + 78 3c ovc 40 4d ovc 20 4e ovc 00 69 ovc + 4a 6b ovc 10 74 ovc 4f 8d ovc 00 8e ovc + 00 8f ovc 00 90 ovc 00 91 ovc 00 96 ovc + ( 00 9a ovc ) 84 b0 ovc 0c b1 ovc 0e b2 ovc + 82 b3 ovc 0a b8 ovc + + \ More magic, some of which tweaks white balance + 0a 43 ovc f0 44 ovc 34 45 ovc 58 46 ovc + 28 47 ovc 3a 48 ovc 88 59 ovc 88 5a ovc + 44 5b ovc 67 5c ovc 49 5d ovc 0e 5e ovc + 0a 6c ovc 55 6d ovc 11 6e ovc + 9f 6f ovc \ 9e for advance AWB + ( 40 6a ovc ) + ( 40 01 ovc ) \ Blue gain + ( 60 02 ovc ) \ Red gain + e7 13 ovc \ Control 8 + + \ Matrix coefficients + b3 4f ovc b3 50 ovc 00 51 ovc 3d 52 ovc + a7 53 ovc e4 54 ovc 9e 58 ovc + + \ 08 41 ovc \ AWB gain enable + ( 00 3f ovc ) \ Edge enhancement factor + 05 75 ovc e1 76 ovc ( 00 4c ovc ) 01 77 ovc + c0 3d ovc \ Control 13 + 09 4b ovc ( 60 c9 ovc ) + 38 41 ovc \ Control 16 + 40 56 ovc + + 11 34 ovc + 12 3b ovc \ Control 11 + 88 a4 ovc 00 96 ovc 30 97 ovc 20 98 ovc + 30 99 ovc 84 9a ovc 29 9b ovc 03 9c ovc + 5c 9d ovc 3f 9e ovc 04 78 ovc + +; + +: camera-init ( -- ) + false to ov7670-detected? + ((camera-init) + 1d ov@ 1c ov@ bwjoin 7fa2 <> if exit then \ Manufacturing ID + b ov@ a ov@ bwjoin 7673 <> if exit then \ Product ID + true to ov7670-detected? +; + +\ VGA RGB565 +: init-rgb565 ( -- ) + 04 12 ov! \ VGA, RGB565 + 00 8c ov! \ No RGB444 + 00 04 ov! \ Control 1: CCIR601 (H/VSYNC framing) + 10 40 ov! \ RGB565 output + 38 14 ov! \ 16x gain ceiling + b3 4f ov! \ v-red + b3 50 ov! \ v-green + 00 51 ov! \ v-blue + 3d 52 ov! \ u-red + a7 53 ov! \ u-green + e4 54 ov! \ u-blue + c0 3d ov! \ Gamma enable, UV saturation auto adjust + + \ OVT says that rewrite this works around a bug in 565 mode. + \ The symptom of the bug is red and green speckles in the image. + 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this +; + +: read-agc ( -- n ) + 3 ov@ h# c0 and 2 lshift 0 ov@ or +; + +: read-aec ( -- n ) + 7 ov@ h# 3f and d# 10 lshift + h# 10 ov@ 2 lshift or + 4 ov@ 3 and or +; + +: set-hw ( vstop vstart hstop hstart -- ) + dup 3 >> 17 ov! \ Horiz start high bits + over 3 >> 18 ov! \ Horiz stop high bits + 32 ov@ swap 7 and or swap 7 and 3 << or 10 ms 32 ov! \ Horiz bottom bits + + dup 2 >> 19 ov! \ Vert start high bits + over 2 >> 1a ov! \ Vert start high bits + 03 ov@ swap 3 and or swap 3 and 2 << or 10 ms 03 ov! \ Vert bottom bits +; + +: camera-config ( -- ) + ((camera-init) + use-ycrcb? 0= if init-rgb565 then + d# 490 d# 10 d# 14 d# 158 set-hw \ VGA window info +; + +: dump-regs ( run# -- ) + 0 d# 16 " at-xy" eval + ." Pass " .d + key upc h# 47 = if ." Good" else ." Bad" then cr \ 47 is G + + ." 0 1 2 3 4 5 6 7 8 9 a b c d e f" cr + ." -----------------------------------------------" cr + h# ca 0 do + i 2 u.r ." : " + i h# 10 bounds do + i h# ca < if i ov@ 3 u.r then + loop + cr + h# 10 +loop +; + +: mirrored ( -- ) h# 1e ov@ h# 20 or h# 1e ov! ; +: unmirrored ( -- ) h# 1e ov@ h# 20 invert and h# 1e ov! ; + +\ LICENSE_BEGIN +\ Copyright (c) 2011 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
1
0
0
0
← Newer
1
...
8
9
10
11
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
Results per page:
10
25
50
100
200