In article <nnd$14ef56f1$51a862bc@47e2c85bbc07e978>,
none) (albert <albert@cherry.> wrote:
>In article <
3d1b59d5-8ed3-4c5b...@googlegroups.com>,
>Christof Eberspaecher <
chwe...@gmail.com> wrote:
>>none albert schrieb am Dienstag, 5. Juli 2022 um 20:55:45 UTC+2:
>>> In article <
ca1bcf8a-624e-46e0...@googlegroups.com>,
>>> Christof Eberspaecher <
chwe...@gmail.com> wrote:
>>> >Hi,
>>> >the actual raspberry os does no longer support wiringPi, which was a
>>way to access GPIO under GForth as described here:
>>> >
https://forums.raspberrypi.com/viewtopic.php?t=207597
>>> >Is there now another (easy) way?
>>> >Thanks in advance! Christof
>>> An alternative is ciforth
>>> lina.html on my site below.
>>>
>>> WANT set-function gpio-on
>>> 18 CONSTANT #LED
>>> _output #LED set-function
>>> #LED gpio-on
>>> #LED gpio-off
>>>
>>> Tested on raspberry 1, 32 bit version.
>>>
>>> Groetjes Albert
>>Thank you, Albert!
>>WANT seems to work after 1 LOAD, but says: ... not present but wanted.
>(Oh yes.)
>>I did not find the docu for gpio.
>>The source seems to be in screen 146 for raspi1 but I was not able to
>>get it to work.
>>I am astonished, that you can just @ and ! in linux? I got a
>>"Speicherzugriffsfehler" crash even with sudo.
>>Christof
>
>You can io with @ and !. That is memory mapped io.
>Mostly however you must use C@ and C!.
>On a 64 bit system you have to occasionally use L@ and L!
>(32 bit io).
>
>I added gpio for a demonstration of led display, I admit that
>the library is poorly documented.
>
>Can you send the whole log via e-mail ?
>
>Groetjes Albert
I've analysed it. There was nothing wrong with the code per
se, but the conditional compilation system prevented it
from being loaded (defect in ?RP1).
You can download version 5.4.1 from lina.html on my site below.
I tested it with the control of an 2x16 display (1602)
on a raspberry pi 1. (32 bit arm7)
-------- 8< ---------------- 8< ----------
\ $Id: lcd1602.frt,v 1.2 2019/04/16 12:48:02 albert Exp albert $
\ Copyright (2012): Albert van der Horst {by GNU Public License}
\ HCC Forth gg: Egel project 12 for the Raspberry pi.
\ After the 8051 and MSP430 implementations of Willem Ouwerkerk.
\ This is a driver for the 1602A display : 16 by 2 char's.
\ The following is a direct connection to the raspberry pi 1 revision 1
\ descr color 1602 pi name gpio#
\ ground black 1 2
\ Vdd red 2 6
\ RS brown 4 3 SDA 0 (pi 1 rev. 1)
\ RW orange 5 5 SCL 1 (pi 1 rev. 1)
\ E grey 6 7 GPCLK0 4
\
\ DB4 yellow 11 15 GPIO 22
\ DB5 green 12 16 GPIO 23
\ DB6 blue 13 18 GPIO 24
\ DB7 purple 14 22 GPIO 25
\
\
WANT BOUNDS
WANT gpio-on set-function _on
DECIMAL
0 CONSTANT RS \ brown 4 3 SDA
1 CONSTANT RW \ orange 5 5 SCL
4 CONSTANT EN \ grey 6 7 GPCLK0
22 CONSTANT DB4 \ yellow 11 15
23 CONSTANT DB5 \ green 12 16
24 CONSTANT DB6 \ blue 13 18
25 CONSTANT DB7 \ purple 14 22
\ Display variables
16 CONSTANT c/l
VARIABLE cursor
HEX
0F DB4 LSHIFT CONSTANT DB4-7
\ Set all bit used to output. Tell
: init
_output RS set-function _output EN set-function
_output RW set-function
DB4 4 + DB4 DO _output I set-function LOOP
RW gpio-off \ Always write
;
: command-mode RS gpio-off ;
: char-mode RS gpio-on ;
: enable-pulse EN gpio-on 1 MS EN gpio-off 1 MS ;
\ Output nibble .
: nibble>lcd DB4 LSHIFT DUP _on P! INVERT DB4-7 AND _off P!
enable-pulse ;
\ Output nibble . Alternative implementation.
\ : nibble>lcd' DB4-7 _off BIS DB4 LSHIFT _on BIS
\ enable-pulse ;
\ Send byte to LCD
\ Depending on mode it is interpreted as a char or a command.
\ This assumes 4 bits mode!
: lcd-byte DUP 4 RSHIFT nibble>lcd nibble>lcd ;
\ Send instruction .
: lcd-instr command-mode lcd-byte ;
\ Make LCD clean and set cursor in upper left corner.
: lcd-page 1 lcd-instr 0 cursor ! 2 MS ;
\ After calling this it should be possible to send char's to the display
: lcd-setup
init \ Basic io interpretation
3 0 DO 03 lcd-instr 5 MS LOOP \ And set 8 bits interface mode
02 lcd-instr \ Finally set 4 bits interface mode.
28 lcd-instr \ 4 bit interf. 2 lines, 5*7 bits char.
08 lcd-instr lcd-page \ Display cursor, empty screen
06 lcd-instr \ Display direction from left to right
0C lcd-instr \ Display on & cursor on
;
\ Type sc to the display.
: lcd-type char-mode DUP cursor +!
BOUNDS ?DO I C@ lcd-byte LOOP ;
: lcd-emit ( char -- ) DSP@ 1 lcd-type DROP ;
: lcd-space ( -- ) BL lcd-emit ;
: lcd-spaces ( u -- ) 0 ?DO lcd-space LOOP ;
\ Like `CR but for lcd.
: lcd-cr
c/l cursor @ < IF \ Cursor at line 2 ?
80 lcd-instr 0 cursor ! \ Yes, to line 1
ELSE
C0 lcd-instr c/l cursor ! \ No, to line 2
THEN ;
: demo1 ( -- )
lcd-setup
" Hi Forth" lcd-type lcd-cr \ Test LCD
" users..." lcd-type ;
: demo2 ( -- )
lcd-setup
"arm ciforth lina" lcd-type lcd-cr \ Test LCD
"Egel A.D. MMXIX" lcd-type ;
DECIMAL
-------- 8< ---------------- 8< ----------
You are not obliged to use _on and _off that allows to
turn several io-bits on and off at the same time.
You can get by with
_output _input set-function gpio-on gpio-off
that can serve as a model that applies widely, I think.
You can use set-function to set a port to e.g. analogue
to digital conversion. That requires consulting the manual,
but it should be straightforward.