From: Dennis Ruffer [mailto:[email protected]]  Sent: Saturday, May 7, 2016
6:53 PM
>From: Bernd Paysan [mailto:[email protected]] Sent: Saturday, May 7, 2016
2:46 PM
>>>Am Freitag, 6. Mai 2016, 15:14:54 CEST schrieb Dennis Ruffer:
>>>> Does anyone have an I2C framework on gforth that I can "borrow"?
>>> 
>>>> I see that unix/serial.fs has most of the pieces, but it would be 
>>> easier if someone had already tested the ioctl I2C_RDWR interface.
>>> 
>>> Thanks for whatever pointers anyone can provide.
>>
>>I haven't tried yet, but one of my ARM boards actually has something
hooked up to the i2c bus, so I could try...
>
>I'll have to do something with some open hardware design then and post it.
>Maybe the Raspberry Pi has something.

Here's a start, but this one gives:

pi@raspberrypi:~/Documents/Forth $ gforth i2c.fs

in file included from *OS command line*:-1
i2c.fs:26: Undefined word
    >>>O_RDWR<<< open throw
Backtrace:
$B68FBEDC throw
$B6908600 no.extensions
$B68FDE10 compiler-notfound1

But when I used r/w, I got:
pi@raspberrypi:~/Documents/Forth $ gforth i2c.fs
Gforth 0.7.2, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
i2c-detect
/home/pi/.gforth/libcc-named/.libs/i2c.so.0: undefined symbol:
gforth_c_open_ann_n
:1: Invalid name argument
>>>i2c-detect<<<
Backtrace:
$B69CF7D8 throw
$B69CF900 link-wrapper-function
$B69D0730 open
$B69D080C open-i2c-dev

It's been a while since I've gotten this deep, so excuse my ignorance.

But help please. ;)

DaR

\ I2C interface for Gforth under Unix

\ WARNING! This program can confuse your I2C bus, cause data loss and worse!

\ I started with the following tutorial:
\ https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial
\ http://wiringpi.com/download-and-install/
\ https://fossies.org/dox/i2c-tools-3.1.2/i2cdetect_8c_source.html
\ 
http://askubuntu.com/questions/625523/libtool-installed-but-not-on-path-after-installation

\ Then took the following from unix/serial.fs

c-library i2c
    \c #include <sys/ioctl.h>
    \c #include <stdio.h>
    \c #include <fcntl.h>

    c-function ioctl ioctl n n a -- n ( fd cmd ptr -- n )
    c-function open open a n n -- n ( path flags mode -- fd )
    c-function read read n a n -- n ( fd addr u -- u' )
    c-function write write n a n -- n ( fd addr u -- u' )
    c-function close close n -- n ( fd -- r )
end-c-library

: open-i2c-dev ( a # -- handle )
    O_RDWR open throw
;

: close-i2c-dev ( handle -- )
    close throw
;

0x0705 constant I2C-FUNCS \ Get the adapter functionality mask

variable buss
variable func

: i2c-detect ( -- )
    s" /dev/i2c-1" open-i2c-dev dup buss !
    dup I2C-FUNCS func ioctl 0<
    if  close-i2c-dev
        1 abort" IOCTL I2C_FUNCS Failed."
    else  close-i2c-dev
    then
;

Reply via email to