diff options
author | Mitch Bradley <wmb@firmworks.com> | 2016-12-02 10:12:29 -1000 |
---|---|---|
committer | Mitch Bradley <wmb@firmworks.com> | 2016-12-02 10:12:29 -1000 |
commit | 38867bf9b034f88ff50964e2d00b7c6556ee2ae5 (patch) | |
tree | 53260ea8b0facfb8352c01e4cc374e4f0257306f | |
parent | 4a588eb7d2b3ac53c23e13730d7f193b6e4c1f14 (diff) | |
parent | 10c35052f686feaa31d63b03173ef44fae2b2593 (diff) | |
download | cforth-38867bf9b034f88ff50964e2d00b7c6556ee2ae5.tar.gz |
Merge branch 'master' of https://github.com/MitchBradley/cforth
-rw-r--r-- | src/app/esp8266/ds1307.fth | 30 | ||||
-rw-r--r-- | src/app/esp8266/tsl2561.fth | 43 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/app/esp8266/ds1307.fth b/src/app/esp8266/ds1307.fth new file mode 100644 index 0000000..0b5c1e4 --- /dev/null +++ b/src/app/esp8266/ds1307.fth @@ -0,0 +1,30 @@ +\ Driver for DS1307 RTC + +$68 value ds-slave + +: ds-read-setup ( reg# -- ) + ds-slave i2c-start-write abort" ds1307 fail write" + false ds-slave i2c-start-read abort" ds1307 fail read" +; + +$9 buffer: ds + +: ds-read ( -- ) + 0 ds-read-setup + ds 8 0 do + false i2c-byte@ over c! 1+ + loop + true i2c-byte@ swap c! +; + +: .ds + ds-read + ds 9 cdump +; + +: ds-set ( cc yy mm dd ww hh mm ss -- ) + 0 ds-slave i2c-start-write abort" ds1307 fail write" + 8 0 do i2c-byte! drop loop + $90 i2c-byte! drop \ sqwe 1hz + i2c-stop +; diff --git a/src/app/esp8266/tsl2561.fth b/src/app/esp8266/tsl2561.fth new file mode 100644 index 0000000..cdd954f --- /dev/null +++ b/src/app/esp8266/tsl2561.fth @@ -0,0 +1,43 @@ +\ Driver for TSL2561 light-to-digital converter + +$39 constant tsl2561-slave + +: power! ( b -- ) a0 tsl2561-slave i2c-b! abort" no ack" ; +\ : power@ ( -- b ) a0 tsl2561-slave true i2c-b@ ; +: power-on 3 power! ; +\ : power-off 0 power! ; +\ : power-on? power@ 3 and 3 = ; + +: timing! ( timing -- ) a1 tsl2561-slave i2c-b! abort" no ack" ; +\ : timing@ ( -- timing ) a1 tsl2561-slave true i2c-b@ ; +\ : integ-13.7ms 0 ; +\ : integ-101ms 1 ; +: integ-402ms 2 ; +\ : integ-manual 3 ; + +\ : +gain-low ; +: +gain-high 10 or ; + +: timing-on integ-402ms +gain-high timing! ; + +\ manual integration +\ (the adc shadow register is not updated until manual integration ends) +\ : manual-on timing@ 8 or timing! ; +\ : manual-off timing@ 8 invert and timing! ; +\ : timing-manual integ-manual +gain-high timing! ; + +: adc0@ ( -- adc0 ) ac tsl2561-slave true i2c-le-w@ ; +: adc1@ ( -- adc1 ) ae tsl2561-slave true i2c-le-w@ ; + +: adc@ ( -- adc0 adc1 ) + ac tsl2561-slave i2c-start-write abort" no ack" + true tsl2561-slave i2c-start-read abort" no ack" + 0 i2c-byte@ + 0 i2c-byte@ bwjoin + 0 i2c-byte@ + 1 i2c-byte@ bwjoin +; + +: init-tsl2561 power-on timing-on ; + +: watch-tsl2561 init-tsl2561 begin adc@ .d .d cr #100 ms key? until ; |