[openfirmware] [commit] r2880 - cpu/arm/olpc dev/olpc dev/olpc/cafecamera dev/olpc/mmp2camera dev/olpc/viacamera

repository service svn at openfirmware.info
Sat Feb 25 17:55:47 CET 2012


Author: wmb
Date: Sat Feb 25 17:55:45 2012
New Revision: 2880
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2880

Log:
OLPC - all versions - support new SETi image sensor.

Added:
   dev/olpc/imagesensor.fth
   dev/olpc/seti.fth
Modified:
   cpu/arm/olpc/smbus.fth
   dev/olpc/cafecamera/cafecamera.bth
   dev/olpc/cafecamera/cafecamera.fth
   dev/olpc/cafecamera/platform.fth
   dev/olpc/cameratest.fth
   dev/olpc/mmp2camera/ccic.fth
   dev/olpc/mmp2camera/loadpkg.fth
   dev/olpc/mmp2camera/platform.fth
   dev/olpc/mmp2camera/smbus.fth
   dev/olpc/ov7670.fth
   dev/olpc/viacamera/camera.fth
   dev/olpc/viacamera/loadpkg.fth
   dev/olpc/viacamera/platform.fth
   dev/olpc/viacamera/smbus.fth

Modified: cpu/arm/olpc/smbus.fth
==============================================================================
--- cpu/arm/olpc/smbus.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ cpu/arm/olpc/smbus.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -15,40 +15,51 @@
 : smb-data-dir-out  ( -- )  smb-data-gpio# gpio-dir-out  ;
 : smb-data-dir-in  ( -- )  smb-data-gpio# gpio-dir-in  ;
 
+: smb-start ( -- )  smb-clk-hi  smb-data-hi  smb-data-lo smb-clk-lo  ;
+: smb-stop  ( -- )  smb-clk-lo  smb-data-lo  smb-clk-hi  smb-data-hi  ;
+
 h# 3500 constant smb-clk-timeout-us
 \ Slave can flow control by holding CLK low temporarily
 : smb-wait-clk-hi  ( -- )
    smb-clk-timeout-us 0  do
       smb-clk@  if  smb-dly  unloop exit  then  1 us
    loop
+   smb-stop
    true abort" I2C clock stuck low"
 ;
 : smb-data-hi-w  ( -- )  smb-data-hi  smb-wait-clk-hi  ;
 
+[ifdef] notdef
 h# 3500 constant smb-data-timeout-us
 : smb-wait-data-hi  ( -- )
    smb-data-timeout-us 0  do
       smb-data@  if  unloop exit  then  1 us
    loop
+   smb-stop
    true abort" I2C data stuck low"
 ;
+[then]
 
 : smb-restart  ( -- )
    smb-clk-hi  smb-data-lo  smb-clk-lo
 ;
 
-: smb-start ( -- )  smb-clk-hi  smb-data-hi  smb-data-lo smb-clk-lo  ;
-: smb-stop  ( -- )  smb-clk-lo  smb-data-lo  smb-clk-hi  smb-data-hi  ;
-
 : smb-get-ack  ( -- )
    smb-data-dir-in
    smb-data-hi
    smb-clk-hi smb-wait-clk-hi  
-   smb-data@  \ drop		\ SCCB generates an don't care bit
-   if  smb-stop  true abort" I2c NAK" then
-   smb-clk-lo
-\   smb-wait-data-hi
-   smb-data-dir-out
+   smb-data@           ( nak? )
+
+   smb-clk-lo          ( nak? )
+
+\ Empirically, the Omnivision image sensor sometimes fails to
+\ release the ACK until the next clock, so smb-wait-data-hi
+\ causes spurious failures.
+\  smb-wait-data-hi
+
+   smb-data-dir-out    ( nak? )
+
+   if  smb-stop  true abort" I2c NAK"  then
 ;
 : smb-bit  ( flag -- )
    if  smb-data-hi  else  smb-data-lo  then

Modified: dev/olpc/cafecamera/cafecamera.bth
==============================================================================
--- dev/olpc/cafecamera/cafecamera.bth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/cafecamera/cafecamera.bth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -10,7 +10,9 @@
 FCode-version2
 
 fload ${BP}/dev/olpc/cafecamera/platform.fth
-fload ${BP}/dev/olpc/ov7670.fth
+fload ${BP}/dev/olpc/imagesensor.fth
+fload ${BP}/dev/olpc/seti.fth
+fload ${BP}/dev/olpc/ov7670.fth		\ Load last; most likely to be present
 fload ${BP}/dev/olpc/cafecamera/cafecamera.fth
 fload ${BP}/dev/olpc/cameratest.fth
 

Modified: dev/olpc/cafecamera/cafecamera.fth
==============================================================================
--- dev/olpc/cafecamera/cafecamera.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/cafecamera/cafecamera.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -65,7 +65,7 @@
 : ctlr-stop   ( -- )  3c dup cl@ 1 invert and swap cl!  ;	\ Stop the whole thing
 
 : read-setup  ( -- )
-   camera-config
+   true camera-config   \ Always use RGB
    ctlr-config
    3f 30 cl!				\ Clear pending interrupts
    ctlr-start
@@ -107,11 +107,6 @@
    5 ms
    40 dup cl@ 1000.0000 or swap cl!		\ power off
 ;
-: init  ( -- )
-   (init)
-   power-up
-   camera-init
-;
 
 
 \ =============================  read operation ==============================
@@ -207,8 +202,9 @@
 
 : open  ( -- flag )
    map-regs
-   init
-   ov7670-detected? 0=  if  unmap-regs false exit  then
+   (init)
+   power-up
+   sensor-found? 0=  if  unmap-regs false exit  then
    alloc-dma-bufs
    read-setup
    true

Modified: dev/olpc/cafecamera/platform.fth
==============================================================================
--- dev/olpc/cafecamera/platform.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/cafecamera/platform.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -37,7 +37,8 @@
 \   4 my-w@  6 invert and  4 my-w!  \ No need to turn it off
 ;
 
-h# 42 2 << constant ov-sid
+h# 42 value camera-smb-slave
+: camera-smb-on  ( -- )  ;
 
 : clr-smb-intr  ( -- )  7.0000 30 cl!  ;
 : smbus-wait  ( -- )
@@ -45,9 +46,11 @@
    1 ms				\ 20 usec delay
 ;
 
+: set-slave  ( -- )  camera-smb-slave 2 lshift  87.fc01 or b8 cl!  ;	\ TWSI control 0: id, 8-bit, clk
+
 : ov@  ( reg -- data )
    clr-smb-intr
-   ov-sid 87.fc01 or b8 cl!	\ TWSI control 0: id, 8-bit, clk
+   set-slave
    bc cl@ drop			\ Force write
    d# 16 << 100.0000 or bc cl!	\ TWSI control 1: read, reg
    smbus-wait
@@ -56,7 +59,7 @@
 
 : ov!  ( data reg -- )
    clr-smb-intr
-   ov-sid 8.7fc01 or b8 cl!	\ TWSI control 0: id, 8-bit, clk
+   set-slave
    bc cl@ drop			\ Force write
    d# 16 << or bc cl!		\ TWSI control 1: read, reg
    2 ms

Modified: dev/olpc/cameratest.fth
==============================================================================
--- dev/olpc/cameratest.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/cameratest.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -8,9 +8,13 @@
 \ Thanks to Cortland Setlow (AKA Blaketh) for the autobrightness code
 \ and the full-screen + mirrored display.
 
+[ifdef] notdef
+\ This seemed like a good idea but in practice it was found to be confusing
 : autobright  ( -- )
    read-agc 3 + 3 rshift  h# f min  " bright!" " $call-screen" evaluate
 ;
+[then]
+
 : full-brightness  ( -- )  h# f " bright!" " $call-screen" evaluate  ;
 
 : timeout-read  ( adr len timeout -- actual )
@@ -40,14 +44,15 @@
    open 0=  if  true exit  then
    d# 300 ms
    start-display
-   unmirrored  resync                                   ( )
+   false set-mirrored  resync                           ( )
    shoot-still  ?dup  if  stop-display close exit  then	( error? )
    d# 1,000 ms
-   mirrored  resync  shoot-movie  full-brightness	( error? )
+   true set-mirrored  resync  shoot-movie  full-brightness	( error? )
    stop-display close					( error? )
    ?dup  0=  if  confirm-selftest?  then		( error? )
 ;
 
+[ifdef] notdef
 : xselftest  ( -- error? )
    open 0=  if  true exit  then
    h# 10 0 do
@@ -56,6 +61,7 @@
    loop
    0 close					( error? )
 ;
+[then]
 
 \ LICENSE_BEGIN
 \ Copyright (c) 2009 FirmWorks

Added: dev/olpc/imagesensor.fth
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dev/olpc/imagesensor.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -0,0 +1,14 @@
+purpose: Interface layer to image sensor chips
+
+\ Each sensor chip driver must define sensor-found? , chaining to the
+\ previous definition if that sensor chip is not detected.  If the
+\ chip is detected, the driver must set camera-config and set-mirrored
+\ to implementations suitable for that chip.
+
+defer camera-config  ( ycrcb? -- )
+defer set-mirrored   ( mirrored? -- )
+
+\ Redefine to add a new sensor
+: sensor-found?  ( -- flag )
+   false
+;

Modified: dev/olpc/mmp2camera/ccic.fth
==============================================================================
--- dev/olpc/mmp2camera/ccic.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/mmp2camera/ccic.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -46,6 +46,8 @@
 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
 
+0 value use-ycrcb?
+
 : setup-image  ( -- )
    VGA_WIDTH 2*  h# 24 cl!	\ 640*2 stride, UV stride in high bits = 0
 
@@ -69,7 +71,7 @@
 : ctlr-stop   ( -- )  h# 3c dup cl@  1 invert and  swap cl!  ;	\ Disable
 
 : read-setup  ( -- )
-   camera-config
+   use-ycrcb? camera-config
    ctlr-config
      \ Clear all interrupts
    interrupts-on          \ Enable frame done interrupts
@@ -99,12 +101,6 @@
    sensor-power-off
 ;
 
-: init  ( -- )
-   power-on
-   camera-smb-setup  smb-on
-   camera-init
-;
-
 
 \ =============================  read operation ==============================
 
@@ -145,9 +141,9 @@
 
 : open  ( -- flag )
    my-address my-space  h# 1000  " map-in" $call-parent  to camera-base
-   init
+   power-on
+   sensor-found?  0=  if  false exit  then
    my-args " yuv" $=  to use-ycrcb?
-   ov7670-detected? 0=  if  false exit  then
    alloc-dma-bufs
    read-setup
    true

Modified: dev/olpc/mmp2camera/loadpkg.fth
==============================================================================
--- dev/olpc/mmp2camera/loadpkg.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/mmp2camera/loadpkg.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -23,7 +23,11 @@
 [then]
 
    fload ${BP}/dev/olpc/mmp2camera/platform.fth
+   fload ${BP}/dev/olpc/imagesensor.fth
+   warning @ warning off
    fload ${BP}/dev/olpc/ov7670.fth
+   fload ${BP}/dev/olpc/seti.fth		\ Load last; most likely to be present
+   warning !
    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 Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/mmp2camera/platform.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -4,14 +4,16 @@
 headers
 hex
 
+0 value camera-smb-slave
 : camera-smb-setup  ( -- )
    1 to smb-dly-us
 \+ olpc-cl2   d# 108 to smb-clock-gpio#
 \+ olpc-cl2   d# 109 to smb-data-gpio#
 \+ olpc-cl3   d#   4 to smb-clock-gpio#
 \+ olpc-cl3   d#   5 to smb-data-gpio#
-   h# 42 to smb-slave
+   camera-smb-slave to smb-slave
 ;
+: camera-smb-on  ( -- )  camera-smb-setup  smb-on  ;
 : ov@  ( reg -- data )  camera-smb-setup  smb-byte@  ;
 : ov!  ( data reg -- )  camera-smb-setup  smb-byte!  ;
 

Modified: dev/olpc/mmp2camera/smbus.fth
==============================================================================
--- dev/olpc/mmp2camera/smbus.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/mmp2camera/smbus.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -1,54 +1,56 @@
 4 value smb-dly-us
-: smb-dly  smb-dly-us us  ;
 
+0 value smb-clock-gpio#
 0 value smb-data-gpio#
-0 value smb-clk-gpio#
 
+: smb-dly  smb-dly-us us  ;
 : smb-data-hi  ( -- )  smb-data-gpio# gpio-set  smb-dly  ;
 : smb-data-lo  ( -- )  smb-data-gpio# gpio-clr  smb-dly  ;
-: smb-clk-hi  ( -- )  smb-clk-gpio# gpio-set  smb-dly  ;
-: smb-clk-lo  ( -- )  smb-clk-gpio# gpio-clr  smb-dly  ;
+: smb-clk-hi  ( -- )  smb-clock-gpio# gpio-set  smb-dly  ;
+: smb-clk-lo  ( -- )  smb-clock-gpio# gpio-clr  smb-dly  ;
 : smb-data@  ( -- flag )  smb-data-gpio# gpio-pin@  ;
-: smb-clk@  ( -- )  smb-clk-gpio#  gpio-pin@  ;
+: smb-clk@  ( -- flag )  smb-clock-gpio# gpio-pin@  ;
 : smb-off  ( -- )  smb-data-gpio# gpio-dir-in  ;
-: smb-on  ( -- )  smb-data-gpio# gpio-dir-out  smb-clk-gpio# gpio-dir-out  ;
+: smb-on  ( -- )  smb-data-gpio# gpio-dir-out  smb-clock-gpio# gpio-dir-out  ;
 : smb-data-dir-out  ( -- )  smb-data-gpio# gpio-dir-out  ;
 : smb-data-dir-in  ( -- )  smb-data-gpio# gpio-dir-in  ;
 
+: smb-start ( -- )  smb-clk-hi  smb-data-hi  smb-data-lo smb-clk-lo  ;
+: smb-stop  ( -- )  smb-clk-lo  smb-data-lo  smb-clk-hi  smb-data-hi  ;
+
 h# 3500 constant smb-clk-timeout-us
 \ Slave can flow control by holding CLK low temporarily
 : smb-wait-clk-hi  ( -- )
    smb-clk-timeout-us 0  do
       smb-clk@  if  smb-dly  unloop exit  then  1 us
    loop
+   smb-stop
    true abort" I2C clock stuck low"
 ;
 : smb-data-hi-w  ( -- )  smb-data-hi  smb-wait-clk-hi  ;
 
+[ifdef] notdef
 h# 3500 constant smb-data-timeout-us
 : smb-wait-data-hi  ( -- )
    smb-data-timeout-us 0  do
       smb-data@  if  unloop exit  then  1 us
    loop
+   smb-stop
    true abort" I2C data stuck low"
 ;
+[then]
 
 : smb-restart  ( -- )
    smb-clk-hi  smb-data-lo  smb-clk-lo
 ;
 
-: smb-start ( -- )  smb-clk-hi  smb-data-hi  smb-data-lo smb-clk-lo  ;
-: smb-stop  ( -- )  smb-clk-lo  smb-data-lo  smb-clk-hi  smb-data-hi  ;
-
 : smb-get-ack  ( -- )
    smb-data-dir-in
    smb-data-hi
    smb-clk-hi smb-wait-clk-hi  
-   smb-data@  \ drop		\ SCCB generates an don't care bit
-   if  smb-stop  smb-data-dir-out  true abort" I2c NAK" then
-   smb-clk-lo
-\   smb-wait-data-hi
-   smb-data-dir-out
+   smb-data@ cmb-clk-low       ( nak? )
+   smb-data-dir-out            ( nak? )
+   if  smb-stop  true abort" I2c NAK"  then
 ;
 : smb-bit  ( flag -- )
    if  smb-data-hi  else  smb-data-lo  then

Modified: dev/olpc/ov7670.fth
==============================================================================
--- dev/olpc/ov7670.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/ov7670.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -1,26 +1,41 @@
 \ 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          ( )
+: 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
 ;
 
-0 value use-ycrcb?
+\ VGA RGB565
+: ov7670-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
 
-false value ov7670-detected?
+   \ 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
+;
+
+: ov7670-config  ( ycrcb? -- )
+   >r                           ( r: ycrcb? )
 
-: ((camera-init)  ( -- )
    80 12 ov!  2 ms		\ reset (reads back different)
    01 11 ov!			\ 30 fps
    04 3a ov!			\ UYVY or VYUY
@@ -121,9 +136,60 @@
    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
+   ( r: ycrcb? )  r>  0=  if  ov7670-rgb565  then   ( )  \ Possibly switch to RGB mode
+
+   d# 490 d# 10 d# 14 d# 158 set-hw	\ VGA window info
+;
+
+: ov7670-set-mirrored  ( mirrored? -- )
+   h# 1e ov@  h# 20                     ( mirrored? reg-value bit )
+   rot  if  or  else  invert and  then  ( reg-value' )
+   h# 1e ov!
+;
+
+: probe-ov7670  ( -- found? )
+   h# 42 to camera-smb-slave    ( )   \ Omnivision SMB ID
+   camera-smb-on
+
+   \ Try to read a byte of the manufacturing ID.  If the read fails,
+   \ the device is not present or not responding.
+   h# 1d ['] ov@ catch  if      ( x )
+      drop                      ( )
+      false exit                ( -- false )
+   then                         ( id-low )
+
+   \ Otherwise there is something at that SMB address; verify that
+   \ it has the correct ID.
+
+   h# 1c ov@  h# 0b ov@  h# 0a ov@  bljoin h# 7673.7fa2 <>   if     \ ProdID.MfgID
+      false exit                ( -- false )
+   then                         ( )
+
+   " OV7670" " sensor" string-property
+
+   ['] ov7670-set-mirrored to set-mirrored
+   ['] ov7670-config       to camera-config
+   true
+;
+
+\ Chain of sensor recognizers
+: sensor-found?  ( -- flag )
+   probe-ov7670  if  true exit  then
+   sensor-found?
+;
+
+\ The rest is for debugging and testing
+[ifdef] notdef
+
+\ 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          ( )
 ;
 
 : config-check  ( -- )
@@ -211,35 +277,6 @@
    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 )
@@ -252,22 +289,6 @@
    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
@@ -283,9 +304,8 @@
       cr
    h# 10 +loop
 ;
+[then]
 
-: 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

Added: dev/olpc/seti.fth
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dev/olpc/seti.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -0,0 +1,319 @@
+purpose: Driver for SETi image sensor 
+
+hex
+: seti-config  ( ycrcb? -- )
+   >r               ( r: ycrcb? )
+
+   \ SNR
+   00 00 ov!
+   00 04 ov!
+   03 05 ov!
+\   33 07 ov!
+   32 07 ov!
+   34 10 ov!
+   27 11 ov!
+   21 12 ov!
+   c6 16 ov!
+   aa 17 ov!
+
+   00 20 ov!         \ P_BNKT
+   01 21 ov!         \ P_HBNKT
+   01 22 ov!         \ P_ROWFIL
+   01 23 ov!         \ P_VBNKT
+
+   \ AE
+   01 00 ov!
+   14 11 ov!         \ 6fps at lowlux
+   78 12 ov!         \ D65 target 0x74
+   78 13 ov!         \ CWF target 0x74
+   78 14 ov!         \ A target   0x74
+   08 1E ov!         \ ini gain  0x08
+   7d 34 ov!
+   60 40 ov!         \ Max x8
+
+   d4 70 ov!         \ anti-sat on
+   07 74 ov!         \ anti-sat ini
+   69 79 ov!         \ anti-sat 
+   
+   \ AWB
+   02 00 ov!
+   d0 10 ov!
+   c0 11 ov!
+   80 12 ov!
+   7f 13 ov!
+   7f 14 ov!
+   fe 15 ov!         \ R gain Top
+   80 16 ov!         \ R gain bottom 
+   cb 17 ov!         \ B gain Top
+   70 18 ov!         \ B gain bottom 0x80
+   94 19 ov!         \ Cr top value 0x90
+   6c 1a ov!         \ Cr bottom value 0x70
+   94 1b ov!         \ Cb top value 0x90
+   6c 1c ov!         \ Cb bottom value 0x70
+   94 1d ov!         \ 0xa0
+   6c 1e ov!         \ 0x60
+   e8 20 ov!         \ AWB luminous top value
+   30 21 ov!         \ AWB luminous bottom value 0x20
+   a4 22 ov!
+   20 23 ov!
+   20 24 ov!
+   0f 26 ov!
+   01 27 ov!         \ BRTSRT
+   b4 28 ov!         \ BRTRGNTOP result 0xad
+   b0 29 ov!         \ BRTRGNBOT 
+   92 2a ov!         \ BRTBGNTOP result 0x90
+   8e 2b ov!         \ BRTBGNBOT
+   88 2c ov!         \ RGAINCONT
+   88 2d ov!         \ BGAINCONT
+
+   00 30 ov!
+   10 31 ov!
+   00 32 ov!
+   10 33 ov!
+   02 34 ov!
+   76 35 ov!
+   01 36 ov!
+   d6 37 ov!
+   01 40 ov!
+   04 41 ov!
+   08 42 ov!
+   10 43 ov!
+   12 44 ov!
+   35 45 ov!
+   64 46 ov!
+   33 50 ov!
+   20 51 ov!
+   e5 52 ov!
+   fb 53 ov!
+   13 54 ov!
+   26 55 ov!
+   07 56 ov!
+   f5 57 ov!
+   ea 58 ov!
+   21 59 ov!
+
+   88 62 ov!         \ G gain
+
+   b3 63 ov!         \ R D30 to D20
+   c3 64 ov!         \ B D30 to D20
+   b3 65 ov!         \ R D20 to D30
+   c3 66 ov!         \ B D20 to D30
+
+   dd 67 ov!         \ R D65 to D30
+   a0 68 ov!         \ B D65 to D30
+   dd 69 ov!         \ R D30 to D65
+   a0 6a ov!         \ B D30 to D65
+
+   \ IDP
+   03 00 ov!
+   ff 10 ov!
+   0d 11 ov!
+   cb 12 ov!
+   04 14 ov!         \ don't change
+
+   \ DPCNR
+\   28 17 ov!        \DPCNRCTRL
+   00 18 ov!         \ DPTHR
+   56 19 ov!         \ C DP Number ( Normal [7:6] Dark [5:4] ) | [3:0] DPTHRMIN
+   56 1A ov!         \ G DP Number ( Normal [7:6] Dark [5:4] ) | [3:0] DPTHRMAX
+   12 1B ov!         \ DPTHRSLP( [7:4] @ Normal | [3:0] @ Dark )
+   04 1C ov!         \ NRTHR
+   00 1D ov!         \ [5:0] NRTHRMIN 0x48
+   00 1E ov!         \ [5:0] NRTHRMAX 0x48
+   08 1F ov!         \ NRTHRSLP( [7:4] @ Normal | [3:0] @ Dark )  0x2f
+   04 20 ov!         \ IllumiInfo STRTNOR
+   0f 21 ov!         \ IllumiInfo STRTDRK
+
+   \  Gamma
+   00 30 ov!         \ 0x0
+   04 31 ov!         \ 0x3
+   0b 32 ov!         \ 0xb
+   24 33 ov!         \ 0x1f
+   49 34 ov!         \ 0x43
+   66 35 ov!         \ 0x5f
+   7c 36 ov!         \ 0x74
+   8d 37 ov!         \ 0x85
+   9b 38 ov!         \ 0x94
+   aa 39 ov!         \ 0xA2
+   b6 3a ov!         \ 0xAF
+   ca 3b ov!         \ 0xC6
+   dc 3c ov!         \ 0xDB
+   ef 3d ov!         \ 0xEF
+   f8 3e ov!         \ 0xF8
+   ff 3f ov!         \ 0xFF
+
+   \ Shading Register Setting
+   11 40 ov!
+   11 41 ov!
+   22 42 ov!
+   33 43 ov!
+   44 44 ov!
+   55 45 ov!
+   12 46 ov!         \ left R gain[7:4], right R gain[3:0]
+   20 47 ov!         \ top R gain[7:4], bottom R gain[3:0]
+   01 48 ov!         \ left Gr gain[7:4], right Gr gain[3:0] 0x21
+   20 49 ov!         \ top Gr gain[7:4], bottom Gr gain[3:0]
+   01 4a ov!         \ left Gb gain[7:4], right Gb gain[3:0] 0x02
+   20 4b ov!         \ top Gb gain[7:4], bottom Gb gain[3:0]
+   01 4c ov!         \ left B gain[7:4], right B gain[3:0]
+   00 4d ov!         \ top B gain[7:4], bottom B gain[3:0]
+   04 4e ov!         \ X-axis center high[3:2], Y-axis center high[1:0]
+   50 4f ov!         \ X-axis center low[7:0] 0x50
+   d0 50 ov!         \ Y-axis center low[7:0] 0xf6
+   80 51 ov!         \ Shading Center Gain
+   00 52 ov!         \ Shading R Offset
+   00 53 ov!         \ Shading Gr Offset
+   00 54 ov!         \ Shading Gb Offset
+   00 55 ov!         \ Shading B Offset
+
+   \ Interpolation
+   57 60 ov!         \ INT outdoor condition
+   ff 61 ov!         \ INT normal condition
+
+   77 62 ov!         \ ASLPCTRL 7:4 GE, 3:0 YE
+   38 63 ov!         \ YDTECTRL (YE) [7] fixed,
+   38 64 ov!         \ GPEVCTRL (GE) [7] fixed,
+
+   0c 66 ov!         \ SATHRMIN
+   ff 67 ov!
+   04 68 ov!         \ SATHRSRT
+   08 69 ov!         \ SATHRSLP
+
+   af 6a ov!         \ PTDFATHR [7] fixed, [5:0] value
+   78 6b ov!         \ PTDLOTHR [6] fixed, [5:0] value
+
+   84 6d ov!         \ YFLTCTRL
+
+   \  Color matrix (D65) - Daylight
+   42 71 ov!         \ 0x40
+   bf 72 ov!         \ 0xb9
+   00 73 ov!         \ 0x07
+   0f 74 ov!         \ 0x15
+   31 75 ov!         \ 0x21
+   00 76 ov!         \ 0x0a
+   00 77 ov!         \ 0xf8
+   bc 78 ov!         \ 0xc5
+   44 79 ov!         \ 0x46
+
+   \  Color matrix (D30) - CWF
+   56 7a ov!         \ 0x3a
+   bf 7b ov!         \ 0xcd
+   eb 7c ov!         \ 0xfa
+   1a 7d ov!         \ 0x12
+   22 7e ov!         \ 0x2c
+   04 7f ov!         \ 0x02
+   dc 80  ov!        \ 0xf7
+   c9 81 ov!         \ 0xc7
+   5b 82 ov!         \ 0x42
+
+   \ Color matrix (D20) - A
+   4d 83 ov!         \ 0x38
+   c0 84 ov!         \ 0xc4
+   f3 85 ov!         \ 0x04
+   18 86 ov!         \ 0x07
+   24 87 ov!         \ 0x25
+   04 88 ov!         \ 0x14
+   e0 89 ov!         \ 0xf0
+   cb 8a ov!         \ 0xc2
+   55 8b ov!         \ 0x4f
+
+   10 8c ov!         \ CMA select
+
+   a4 8d ov!         \ programmable edge
+   06 8e ov!         \ PROGEVAL
+   00 8f ov!         \ Cb/Cr coring
+
+   15 90 ov!         \ GEUGAIN
+   15 91 ov!         \ GEUGAIN
+   f0 92 ov!         \ Ucoring [7:4] max, [3:0] min
+   00 94 ov!         \ Uslope (1/128)
+   f0 96 ov!         \ Dcoring [7:4] max, [3:0] min
+   00 98 ov!         \ Dslope (1/128)
+
+   08 9a ov!
+   18 9b ov!
+
+   0c 9f ov!         \ YEUGAIN
+   0c a0 ov!         \ YEUGAIN
+   33 a1 ov!         \ Yecore [7:4]upper [3:0]down
+
+   10 a9 ov!         \ Cr saturation 0x12
+   10 aa ov!         \ Cb saturation 0x12
+   82 ab ov!         \ Brightness
+   40 ae ov!         \ Hue
+   86 af ov!         \ Hue
+   10 b9 ov!         \ 0x20 lowlux color
+   20 ba ov!         \ 0x10 lowlux color
+
+   \ inverse color space conversion
+   40 cc ov!
+   00 cd ov!
+   58 ce ov!
+   40 cf ov!
+   ea d0 ov!
+   d3 d1 ov!
+   40 d2 ov!
+   6f d3 ov!
+   00 d4 ov!
+
+   \  ee nr
+   08 d9 ov!
+   1f da ov!
+   05 db ov!
+   08 dc ov!
+   3c dd ov!
+   fb de ov!         \ NOIZCTRL
+
+   \ dark offset
+   10 df ov!
+   60 e0 ov!
+   90 e1 ov!
+   08 e2 ov!
+   0a e3 ov!
+
+   \ memory speed
+   15 e5 ov!
+   20 e6 ov!
+   04 e7 ov!
+
+   \ Sensor On
+   00 00 ov!
+   05 03 ov!
+
+                 
+   ( r: ycrcb? )  r>  0=  if    ( )
+      03 00 ov!  \ IDP
+      cb 12 ov!  \ RGB565 setting (same as yCrCb setting?)
+   then
+;
+
+: seti-set-mirrored  ( mirrored? -- )
+   0 0 ov!  4 ov@  1                       ( mirrored? reg-value bit )
+   rot  if  or  else  invert and  then     ( reg-value' )
+   4 ov!
+;
+
+: probe-seti  ( -- found? )
+   h# 66 to camera-smb-slave  ( )
+   camera-smb-on              ( )
+
+   \ Try to read a byte of the manufacturing ID.  If the read fails,
+   \ the device is not present or not responding.
+   1 ['] ov@ catch  if        ( x )
+      drop                    ( )
+      false exit              ( -- false )
+   then                       ( regval )
+   drop  \ XXX Should compare with the SETi ID
+
+   " SETi-xxx" " sensor" string-property
+
+   ['] seti-set-mirrored to set-mirrored
+   ['] seti-config       to camera-config
+   true
+;
+
+\ Chain of sensor recognizers
+: sensor-found?  ( -- flag )
+   probe-seti  if  true exit  then
+   sensor-found?
+;

Modified: dev/olpc/viacamera/camera.fth
==============================================================================
--- dev/olpc/viacamera/camera.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/viacamera/camera.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -57,8 +57,10 @@
 : ctlr-start  ( -- )  310 dup cl@ 1 or swap cl!  ;		\ Start the whole thing
 : ctlr-stop   ( -- )  310 dup cl@ 1 invert and swap cl!  ;	\ Stop the whole thing
 
+0 value use-ycrcb?
+
 : read-setup  ( -- )
-   camera-config
+   use-ycrcb? camera-config
    ctlr-config
    83 300 cl!				\ Clear pending interrupts
    1000.0000 200 cl!			\ Allow CAP0 end interrupt
@@ -104,7 +106,6 @@
    (init)
    power-up
    camera-smb-setup  smb-on
-   camera-init
 ;
 
 
@@ -154,7 +155,7 @@
 : open  ( -- flag )
    init
    my-args " yuv" $=  to use-ycrcb?
-   ov7670-detected? 0=  if  false exit  then
+   sensor-found? 0=  if  false exit  then
    alloc-dma-bufs
    read-setup
    true

Modified: dev/olpc/viacamera/loadpkg.fth
==============================================================================
--- dev/olpc/viacamera/loadpkg.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/viacamera/loadpkg.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -30,7 +30,11 @@
    [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}/dev/olpc/imagesensor.fth
+   warning @ warning off
+   fload ${BP}/dev/olpc/seti.fth
+   fload ${BP}/dev/olpc/ov7670.fth	\ Load last; most likely to be present
+   warning !
    fload ${BP}/cpu/x86/ycrcbtorgb.fth             \ Color space conversion
    fload ${BP}/dev/olpc/viacamera/camera.fth
    fload ${BP}/dev/olpc/cameratest.fth

Modified: dev/olpc/viacamera/platform.fth
==============================================================================
--- dev/olpc/viacamera/platform.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/viacamera/platform.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -11,10 +11,11 @@
 : 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  ;
+0 value camera-smb-slave
+: camera-smb-setup  ( -- )  sccb-port to smb-port  camera-smb-slave to smb-slave  ;
+: camera-smb-on  ( -- )  camera-smb-setup  smb-on  ;
 : ov@  ( reg -- data )  camera-smb-setup  smb-byte@  ;
 : ov!  ( data reg -- )  camera-smb-setup  smb-byte!  ;
 

Modified: dev/olpc/viacamera/smbus.fth
==============================================================================
--- dev/olpc/viacamera/smbus.fth	Fri Feb 24 07:40:33 2012	(r2879)
+++ dev/olpc/viacamera/smbus.fth	Sat Feb 25 17:55:45 2012	(r2880)
@@ -46,10 +46,8 @@
 : smb-get-ack  ( -- )
    smb-data-hi
    smb-clk-hi smb-wait-clk-hi  
-   smb-data@  \ drop		\ SCCB generates an don't care bit
+   smb-data@ smb-clk-lo       ( nak? )
    if  smb-stop  true abort" I2c NAK" then
-   smb-clk-lo
-\   smb-wait-data-hi
 ;
 : smb-bit  ( flag -- )
    if  smb-data-hi  else  smb-data-lo  then



More information about the openfirmware mailing list