Changeset 2880
- Timestamp:
- Feb 25, 2012 5:55:45 PM (16 months ago)
- Files:
-
- 2 added
- 14 edited
-
cpu/arm/olpc/smbus.fth (modified) (4 diffs)
-
dev/olpc/cafecamera/cafecamera.bth (modified) (1 diff)
-
dev/olpc/cafecamera/cafecamera.fth (modified) (3 diffs)
-
dev/olpc/cafecamera/platform.fth (modified) (3 diffs)
-
dev/olpc/cameratest.fth (modified) (3 diffs)
-
dev/olpc/imagesensor.fth (added)
-
dev/olpc/mmp2camera/ccic.fth (modified) (4 diffs)
-
dev/olpc/mmp2camera/loadpkg.fth (modified) (1 diff)
-
dev/olpc/mmp2camera/platform.fth (modified) (2 diffs)
-
dev/olpc/mmp2camera/smbus.fth (modified) (4 diffs)
-
dev/olpc/ov7670.fth (modified) (5 diffs)
-
dev/olpc/seti.fth (added)
-
dev/olpc/viacamera/camera.fth (modified) (3 diffs)
-
dev/olpc/viacamera/loadpkg.fth (modified) (1 diff)
-
dev/olpc/viacamera/platform.fth (modified) (1 diff)
-
dev/olpc/viacamera/smbus.fth (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cpu/arm/olpc/smbus.fth
r2726 r2880 16 16 : smb-data-dir-in ( -- ) smb-data-gpio# gpio-dir-in ; 17 17 18 : smb-start ( -- ) smb-clk-hi smb-data-hi smb-data-lo smb-clk-lo ; 19 : smb-stop ( -- ) smb-clk-lo smb-data-lo smb-clk-hi smb-data-hi ; 20 18 21 h# 3500 constant smb-clk-timeout-us 19 22 \ Slave can flow control by holding CLK low temporarily … … 22 25 smb-clk@ if smb-dly unloop exit then 1 us 23 26 loop 27 smb-stop 24 28 true abort" I2C clock stuck low" 25 29 ; 26 30 : smb-data-hi-w ( -- ) smb-data-hi smb-wait-clk-hi ; 27 31 32 [ifdef] notdef 28 33 h# 3500 constant smb-data-timeout-us 29 34 : smb-wait-data-hi ( -- ) … … 31 36 smb-data@ if unloop exit then 1 us 32 37 loop 38 smb-stop 33 39 true abort" I2C data stuck low" 34 40 ; 41 [then] 35 42 36 43 : smb-restart ( -- ) … … 38 45 ; 39 46 40 : smb-start ( -- ) smb-clk-hi smb-data-hi smb-data-lo smb-clk-lo ;41 : smb-stop ( -- ) smb-clk-lo smb-data-lo smb-clk-hi smb-data-hi ;42 43 47 : smb-get-ack ( -- ) 44 48 smb-data-dir-in 45 49 smb-data-hi 46 50 smb-clk-hi smb-wait-clk-hi 47 smb-data@ \ drop \ SCCB generates an don't care bit 48 if smb-stop true abort" I2c NAK" then 49 smb-clk-lo 50 \ smb-wait-data-hi 51 smb-data-dir-out 51 smb-data@ ( nak? ) 52 53 smb-clk-lo ( nak? ) 54 55 \ Empirically, the Omnivision image sensor sometimes fails to 56 \ release the ACK until the next clock, so smb-wait-data-hi 57 \ causes spurious failures. 58 \ smb-wait-data-hi 59 60 smb-data-dir-out ( nak? ) 61 62 if smb-stop true abort" I2c NAK" then 52 63 ; 53 64 : smb-bit ( flag -- ) -
dev/olpc/cafecamera/cafecamera.bth
r2558 r2880 11 11 12 12 fload ${BP}/dev/olpc/cafecamera/platform.fth 13 fload ${BP}/dev/olpc/ov7670.fth 13 fload ${BP}/dev/olpc/imagesensor.fth 14 fload ${BP}/dev/olpc/seti.fth 15 fload ${BP}/dev/olpc/ov7670.fth \ Load last; most likely to be present 14 16 fload ${BP}/dev/olpc/cafecamera/cafecamera.fth 15 17 fload ${BP}/dev/olpc/cameratest.fth -
dev/olpc/cafecamera/cafecamera.fth
r2558 r2880 66 66 67 67 : read-setup ( -- ) 68 camera-config68 true camera-config \ Always use RGB 69 69 ctlr-config 70 70 3f 30 cl! \ Clear pending interrupts … … 108 108 40 dup cl@ 1000.0000 or swap cl! \ power off 109 109 ; 110 : init ( -- )111 (init)112 power-up113 camera-init114 ;115 110 116 111 … … 208 203 : open ( -- flag ) 209 204 map-regs 210 init 211 ov7670-detected? 0= if unmap-regs false exit then 205 (init) 206 power-up 207 sensor-found? 0= if unmap-regs false exit then 212 208 alloc-dma-bufs 213 209 read-setup -
dev/olpc/cafecamera/platform.fth
r2558 r2880 38 38 ; 39 39 40 h# 42 2 << constant ov-sid 40 h# 42 value camera-smb-slave 41 : camera-smb-on ( -- ) ; 41 42 42 43 : clr-smb-intr ( -- ) 7.0000 30 cl! ; … … 46 47 ; 47 48 49 : set-slave ( -- ) camera-smb-slave 2 lshift 87.fc01 or b8 cl! ; \ TWSI control 0: id, 8-bit, clk 50 48 51 : ov@ ( reg -- data ) 49 52 clr-smb-intr 50 ov-sid 87.fc01 or b8 cl! \ TWSI control 0: id, 8-bit, clk53 set-slave 51 54 bc cl@ drop \ Force write 52 55 d# 16 << 100.0000 or bc cl! \ TWSI control 1: read, reg … … 57 60 : ov! ( data reg -- ) 58 61 clr-smb-intr 59 ov-sid 8.7fc01 or b8 cl! \ TWSI control 0: id, 8-bit, clk62 set-slave 60 63 bc cl@ drop \ Force write 61 64 d# 16 << or bc cl! \ TWSI control 1: read, reg -
dev/olpc/cameratest.fth
r2556 r2880 9 9 \ and the full-screen + mirrored display. 10 10 11 [ifdef] notdef 12 \ This seemed like a good idea but in practice it was found to be confusing 11 13 : autobright ( -- ) 12 14 read-agc 3 + 3 rshift h# f min " bright!" " $call-screen" evaluate 13 15 ; 16 [then] 17 14 18 : full-brightness ( -- ) h# f " bright!" " $call-screen" evaluate ; 15 19 … … 41 45 d# 300 ms 42 46 start-display 43 unmirrored resync( )47 false set-mirrored resync ( ) 44 48 shoot-still ?dup if stop-display close exit then ( error? ) 45 49 d# 1,000 ms 46 mirrored resync shoot-movie full-brightness ( error? )50 true set-mirrored resync shoot-movie full-brightness ( error? ) 47 51 stop-display close ( error? ) 48 52 ?dup 0= if confirm-selftest? then ( error? ) 49 53 ; 50 54 55 [ifdef] notdef 51 56 : xselftest ( -- error? ) 52 57 open 0= if true exit then … … 57 62 0 close ( error? ) 58 63 ; 64 [then] 59 65 60 66 \ LICENSE_BEGIN -
dev/olpc/mmp2camera/ccic.fth
r2556 r2880 47 47 h# a0 constant rgb-format \ RGB input (20) and output (80), no swapping 48 48 49 0 value use-ycrcb? 50 49 51 : setup-image ( -- ) 50 52 VGA_WIDTH 2* h# 24 cl! \ 640*2 stride, UV stride in high bits = 0 … … 70 72 71 73 : read-setup ( -- ) 72 camera-config74 use-ycrcb? camera-config 73 75 ctlr-config 74 76 \ Clear all interrupts … … 98 100 h# 40 cl@ h# 1000.0000 or h# 40 cl! \ Disable pads 99 101 sensor-power-off 100 ;101 102 : init ( -- )103 power-on104 camera-smb-setup smb-on105 camera-init106 102 ; 107 103 … … 146 142 : open ( -- flag ) 147 143 my-address my-space h# 1000 " map-in" $call-parent to camera-base 148 init 144 power-on 145 sensor-found? 0= if false exit then 149 146 my-args " yuv" $= to use-ycrcb? 150 ov7670-detected? 0= if false exit then151 147 alloc-dma-bufs 152 148 read-setup -
dev/olpc/mmp2camera/loadpkg.fth
r2556 r2880 24 24 25 25 fload ${BP}/dev/olpc/mmp2camera/platform.fth 26 fload ${BP}/dev/olpc/imagesensor.fth 27 warning @ warning off 26 28 fload ${BP}/dev/olpc/ov7670.fth 29 fload ${BP}/dev/olpc/seti.fth \ Load last; most likely to be present 30 warning ! 27 31 fload ${BP}/dev/olpc/mmp2camera/ccic.fth 28 32 fload ${BP}/dev/olpc/cameratest.fth -
dev/olpc/mmp2camera/platform.fth
r2741 r2880 5 5 hex 6 6 7 0 value camera-smb-slave 7 8 : camera-smb-setup ( -- ) 8 9 1 to smb-dly-us … … 11 12 \+ olpc-cl3 d# 4 to smb-clock-gpio# 12 13 \+ olpc-cl3 d# 5 to smb-data-gpio# 13 h# 42to smb-slave14 camera-smb-slave to smb-slave 14 15 ; 16 : camera-smb-on ( -- ) camera-smb-setup smb-on ; 15 17 : ov@ ( reg -- data ) camera-smb-setup smb-byte@ ; 16 18 : ov! ( data reg -- ) camera-smb-setup smb-byte! ; -
dev/olpc/mmp2camera/smbus.fth
r1992 r2880 1 1 4 value smb-dly-us 2 3 0 value smb-clock-gpio# 4 0 value smb-data-gpio# 5 2 6 : smb-dly smb-dly-us us ; 3 4 0 value smb-data-gpio#5 0 value smb-clk-gpio#6 7 7 : smb-data-hi ( -- ) smb-data-gpio# gpio-set smb-dly ; 8 8 : smb-data-lo ( -- ) smb-data-gpio# gpio-clr smb-dly ; 9 : smb-clk-hi ( -- ) smb-cl k-gpio# gpio-set smb-dly ;10 : smb-clk-lo ( -- ) smb-cl k-gpio# gpio-clr smb-dly ;9 : smb-clk-hi ( -- ) smb-clock-gpio# gpio-set smb-dly ; 10 : smb-clk-lo ( -- ) smb-clock-gpio# gpio-clr smb-dly ; 11 11 : smb-data@ ( -- flag ) smb-data-gpio# gpio-pin@ ; 12 : smb-clk@ ( -- ) smb-clk-gpio#gpio-pin@ ;12 : smb-clk@ ( -- flag ) smb-clock-gpio# gpio-pin@ ; 13 13 : smb-off ( -- ) smb-data-gpio# gpio-dir-in ; 14 : smb-on ( -- ) smb-data-gpio# gpio-dir-out smb-cl k-gpio# gpio-dir-out ;14 : smb-on ( -- ) smb-data-gpio# gpio-dir-out smb-clock-gpio# gpio-dir-out ; 15 15 : smb-data-dir-out ( -- ) smb-data-gpio# gpio-dir-out ; 16 16 : smb-data-dir-in ( -- ) smb-data-gpio# gpio-dir-in ; 17 18 : smb-start ( -- ) smb-clk-hi smb-data-hi smb-data-lo smb-clk-lo ; 19 : smb-stop ( -- ) smb-clk-lo smb-data-lo smb-clk-hi smb-data-hi ; 17 20 18 21 h# 3500 constant smb-clk-timeout-us … … 22 25 smb-clk@ if smb-dly unloop exit then 1 us 23 26 loop 27 smb-stop 24 28 true abort" I2C clock stuck low" 25 29 ; 26 30 : smb-data-hi-w ( -- ) smb-data-hi smb-wait-clk-hi ; 27 31 32 [ifdef] notdef 28 33 h# 3500 constant smb-data-timeout-us 29 34 : smb-wait-data-hi ( -- ) … … 31 36 smb-data@ if unloop exit then 1 us 32 37 loop 38 smb-stop 33 39 true abort" I2C data stuck low" 34 40 ; 41 [then] 35 42 36 43 : smb-restart ( -- ) … … 38 45 ; 39 46 40 : smb-start ( -- ) smb-clk-hi smb-data-hi smb-data-lo smb-clk-lo ;41 : smb-stop ( -- ) smb-clk-lo smb-data-lo smb-clk-hi smb-data-hi ;42 43 47 : smb-get-ack ( -- ) 44 48 smb-data-dir-in 45 49 smb-data-hi 46 50 smb-clk-hi smb-wait-clk-hi 47 smb-data@ \ drop \ SCCB generates an don't care bit 48 if smb-stop smb-data-dir-out true abort" I2c NAK" then 49 smb-clk-lo 50 \ smb-wait-data-hi 51 smb-data-dir-out 51 smb-data@ cmb-clk-low ( nak? ) 52 smb-data-dir-out ( nak? ) 53 if smb-stop true abort" I2c NAK" then 52 54 ; 53 55 : smb-bit ( flag -- ) -
dev/olpc/ov7670.fth
r2556 r2880 2 2 purpose: Omnivision OV7670 image sensor driver 3 3 4 " OV7670" " sensor" string-property5 6 4 \ ============================= camera operations ============================= 7 5 8 \ Check for the expected value 9 : ovc ( val adr -- ) 10 2dup ov@ ( val reg# val actual ) 11 tuck <> if ( val reg# actual ) 12 ." Bad camera I2C value at " swap 2 u.r ( val actual ) 13 ." expected " swap 2 u.r ." got " 2 u.r cr ( ) 14 else ( val reg# actual ) 15 3drop ( ) 16 then ( ) 17 ; 18 19 0 value use-ycrcb? 20 21 false value ov7670-detected? 22 23 : ((camera-init) ( -- ) 6 : set-hw ( vstop vstart hstop hstart -- ) 7 dup 3 >> 17 ov! \ Horiz start high bits 8 over 3 >> 18 ov! \ Horiz stop high bits 9 32 ov@ swap 7 and or swap 7 and 3 << or 10 ms 32 ov! \ Horiz bottom bits 10 11 dup 2 >> 19 ov! \ Vert start high bits 12 over 2 >> 1a ov! \ Vert start high bits 13 03 ov@ swap 3 and or swap 3 and 2 << or 10 ms 03 ov! \ Vert bottom bits 14 ; 15 16 \ VGA RGB565 17 : ov7670-rgb565 ( -- ) 18 04 12 ov! \ VGA, RGB565 19 00 8c ov! \ No RGB444 20 00 04 ov! \ Control 1: CCIR601 (H/VSYNC framing) 21 10 40 ov! \ RGB565 output 22 38 14 ov! \ 16x gain ceiling 23 b3 4f ov! \ v-red 24 b3 50 ov! \ v-green 25 00 51 ov! \ v-blue 26 3d 52 ov! \ u-red 27 a7 53 ov! \ u-green 28 e4 54 ov! \ u-blue 29 c0 3d ov! \ Gamma enable, UV saturation auto adjust 30 31 \ OVT says that rewrite this works around a bug in 565 mode. 32 \ The symptom of the bug is red and green speckles in the image. 33 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this 34 ; 35 36 : ov7670-config ( ycrcb? -- ) 37 >r ( r: ycrcb? ) 38 24 39 80 12 ov! 2 ms \ reset (reads back different) 25 40 01 11 ov! \ 30 fps … … 122 137 26 79 ov! 123 138 124 \ OVT says that rewrite this works around a bug in 565 mode. 125 \ The symptom of the bug is red and green speckles in the image. 126 \ 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this 139 ( r: ycrcb? ) r> 0= if ov7670-rgb565 then ( ) \ Possibly switch to RGB mode 140 141 d# 490 d# 10 d# 14 d# 158 set-hw \ VGA window info 142 ; 143 144 : ov7670-set-mirrored ( mirrored? -- ) 145 h# 1e ov@ h# 20 ( mirrored? reg-value bit ) 146 rot if or else invert and then ( reg-value' ) 147 h# 1e ov! 148 ; 149 150 : probe-ov7670 ( -- found? ) 151 h# 42 to camera-smb-slave ( ) \ Omnivision SMB ID 152 camera-smb-on 153 154 \ Try to read a byte of the manufacturing ID. If the read fails, 155 \ the device is not present or not responding. 156 h# 1d ['] ov@ catch if ( x ) 157 drop ( ) 158 false exit ( -- false ) 159 then ( id-low ) 160 161 \ Otherwise there is something at that SMB address; verify that 162 \ it has the correct ID. 163 164 h# 1c ov@ h# 0b ov@ h# 0a ov@ bljoin h# 7673.7fa2 <> if \ ProdID.MfgID 165 false exit ( -- false ) 166 then ( ) 167 168 " OV7670" " sensor" string-property 169 170 ['] ov7670-set-mirrored to set-mirrored 171 ['] ov7670-config to camera-config 172 true 173 ; 174 175 \ Chain of sensor recognizers 176 : sensor-found? ( -- flag ) 177 probe-ov7670 if true exit then 178 sensor-found? 179 ; 180 181 \ The rest is for debugging and testing 182 [ifdef] notdef 183 184 \ Check for the expected value 185 : ovc ( val adr -- ) 186 2dup ov@ ( val reg# val actual ) 187 tuck <> if ( val reg# actual ) 188 ." Bad camera I2C value at " swap 2 u.r ( val actual ) 189 ." expected " swap 2 u.r ." got " 2 u.r cr ( ) 190 else ( val reg# actual ) 191 3drop ( ) 192 then ( ) 127 193 ; 128 194 … … 212 278 30 99 ovc 84 9a ovc 29 9b ovc 03 9c ovc 213 279 5c 9d ovc 3f 9e ovc 04 78 ovc 214 215 ;216 217 : camera-init ( -- )218 false to ov7670-detected?219 ((camera-init)220 1d ov@ 1c ov@ bwjoin 7fa2 <> if exit then \ Manufacturing ID221 b ov@ a ov@ bwjoin 7673 <> if exit then \ Product ID222 true to ov7670-detected?223 ;224 225 \ VGA RGB565226 : init-rgb565 ( -- )227 04 12 ov! \ VGA, RGB565228 00 8c ov! \ No RGB444229 00 04 ov! \ Control 1: CCIR601 (H/VSYNC framing)230 10 40 ov! \ RGB565 output231 38 14 ov! \ 16x gain ceiling232 b3 4f ov! \ v-red233 b3 50 ov! \ v-green234 00 51 ov! \ v-blue235 3d 52 ov! \ u-red236 a7 53 ov! \ u-green237 e4 54 ov! \ u-blue238 c0 3d ov! \ Gamma enable, UV saturation auto adjust239 240 \ OVT says that rewrite this works around a bug in 565 mode.241 \ The symptom of the bug is red and green speckles in the image.242 01 11 ov! \ 30 fps def 80 !! Linux doesn't do this243 280 ; 244 281 … … 251 288 h# 10 ov@ 2 lshift or 252 289 4 ov@ 3 and or 253 ;254 255 : set-hw ( vstop vstart hstop hstart -- )256 dup 3 >> 17 ov! \ Horiz start high bits257 over 3 >> 18 ov! \ Horiz stop high bits258 32 ov@ swap 7 and or swap 7 and 3 << or 10 ms 32 ov! \ Horiz bottom bits259 260 dup 2 >> 19 ov! \ Vert start high bits261 over 2 >> 1a ov! \ Vert start high bits262 03 ov@ swap 3 and or swap 3 and 2 << or 10 ms 03 ov! \ Vert bottom bits263 ;264 265 : camera-config ( -- )266 ((camera-init)267 use-ycrcb? 0= if init-rgb565 then268 d# 490 d# 10 d# 14 d# 158 set-hw \ VGA window info269 290 ; 270 291 … … 284 305 h# 10 +loop 285 306 ; 286 287 : mirrored ( -- ) h# 1e ov@ h# 20 or h# 1e ov! ; 288 : unmirrored ( -- ) h# 1e ov@ h# 20 invert and h# 1e ov! ; 307 [then] 308 289 309 290 310 \ LICENSE_BEGIN -
dev/olpc/viacamera/camera.fth
r2557 r2880 58 58 : ctlr-stop ( -- ) 310 dup cl@ 1 invert and swap cl! ; \ Stop the whole thing 59 59 60 0 value use-ycrcb? 61 60 62 : read-setup ( -- ) 61 camera-config63 use-ycrcb? camera-config 62 64 ctlr-config 63 65 83 300 cl! \ Clear pending interrupts … … 105 107 power-up 106 108 camera-smb-setup smb-on 107 camera-init108 109 ; 109 110 … … 155 156 init 156 157 my-args " yuv" $= to use-ycrcb? 157 ov7670-detected? 0= if false exit then158 sensor-found? 0= if false exit then 158 159 alloc-dma-bufs 159 160 read-setup -
dev/olpc/viacamera/loadpkg.fth
r2557 r2880 31 31 fload ${BP}/dev/olpc/viacamera/smbus.fth \ Bit-banging SMBUS driver 32 32 fload ${BP}/dev/olpc/viacamera/platform.fth 33 fload ${BP}/dev/olpc/ov7670.fth 33 fload ${BP}/dev/olpc/imagesensor.fth 34 warning @ warning off 35 fload ${BP}/dev/olpc/seti.fth 36 fload ${BP}/dev/olpc/ov7670.fth \ Load last; most likely to be present 37 warning ! 34 38 fload ${BP}/cpu/x86/ycrcbtorgb.fth \ Color space conversion 35 39 fload ${BP}/dev/olpc/viacamera/camera.fth -
dev/olpc/viacamera/platform.fth
r2557 r2880 12 12 : cl@ ( adr -- l ) " mmio-base" $call-parent + rl@ ; 13 13 14 h# 42 constant ov-sid15 14 h# 31 constant sccb-port 16 15 17 : camera-smb-setup ( -- ) sccb-port to smb-port ov-sid to smb-slave ; 16 0 value camera-smb-slave 17 : camera-smb-setup ( -- ) sccb-port to smb-port camera-smb-slave to smb-slave ; 18 : camera-smb-on ( -- ) camera-smb-setup smb-on ; 18 19 : ov@ ( reg -- data ) camera-smb-setup smb-byte@ ; 19 20 : ov! ( data reg -- ) camera-smb-setup smb-byte! ; -
dev/olpc/viacamera/smbus.fth
r2557 r2880 47 47 smb-data-hi 48 48 smb-clk-hi smb-wait-clk-hi 49 smb-data@ \ drop \ SCCB generates an don't care bit49 smb-data@ smb-clk-lo ( nak? ) 50 50 if smb-stop true abort" I2c NAK" then 51 smb-clk-lo52 \ smb-wait-data-hi53 51 ; 54 52 : smb-bit ( flag -- )
Note: See TracChangeset
for help on using the changeset viewer.
