aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/common/lib/hardware/i2c-eeprom.frt
blob: 746893335e5a61c4aa6e10a0590f92e69ea7f6e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
\
\ Basic Access to I2C EEPROM 
\
\ useful words are
\ [¢]@i2c.ee/[c]!i2c.ee
\ See cookbook for further information

#require i2c.frt

: i2c.ee.send-addr ( n -- )
  dup >< i2c.tx ( high byte ) i2c.tx ( low byte )
  \ no stop condition
;

\ The write methods do not wait afterwards!
\ at least 5ms have to pass
: c!i2c.ee ( c addr hwid -- )
  i2c.begin
    i2c.ee.send-addr 
    i2c.tx 
  i2c.end
;

: !i2c.ee ( c addr hwid -- )
  i2c.begin
    i2c.ee.send-addr 
    dup >< i2c.tx i2c.tx 
  i2c.end
;

: c@i2c.ee ( addr hwid -- c )
  dup i2c.begin
    swap i2c.ee.send-addr 
    i2c.start     \ repeated start
    i2c.rd i2c.tx \ hwid for reading
    i2c.rx
  i2c.end
;

: @i2c.ee ( addr hwid -- n )
  dup i2c.begin
    swap i2c.ee.send-addr 
    i2c.start     \ repeated start
    i2c.rd i2c.tx \ hwid for reading
    i2c.rx >< i2c.rxn or
  i2c.end
;