In article ,   
   Waldek Hebisch wrote:   
   >albert@spenarnc.xs4all.nl wrote:   
   >> In article ,   
   >> Waldek Hebisch wrote:   
   >>>   
   >>>which outputs bits to data register. To get actual output one   
   >>>need to set direction register and associate PIN with GPIO function.   
   >>   
   >> I defined set-function by ( fun# gpio#)   
   >> and redefine fun# that I always 0 for input , -1 for output.   
   >> This make a 1602 driver almost portable except for defining   
   >> the port numbers/   
   >   
   >One pin may have several functions, not only GPIO. Do you mean   
   >that you change numbering of functions so that 0 is GPIO input,   
   >-1 is GPIO output and other functions get other numbers?   
      
   GA13 is pin 0x1D. That is never changed.   
   29 CONSTANT GA13   
   0 GA13 set-function / OR   
   -1 GA13 set-function /OR   
      
   In the following example I use PB0. This is directly   
   reference in the doc. Function 5 couples PB0 to UART2.   
   This is documented also.   
   "$20 CONSTANT PB0 7 PB0 setfunction"   
   This is all it takes. Screw linux protections and   
   abstraction layers.   
   Now it boils down to finding out how the UART works.   
   Note that 32 uS is the period I want for a midi signal.   
      
   We Forthers don't have to rely on Linux kernel gurus,   
   but we need documentation.   
      
   ----------------------------   
      
   \ $Id: uart.frt,v 1.4 2023/04/19 20:09:55 albert Exp albert $   
   \ Copyright (2023): Albert van der Horst {by GNU Public License}   
   WANT $-PREFIX   
   WANT setfunction   
   DECIMAL \ All other via prefixes   
   $20 CONSTANT PB0 7 PB0 setfunction \ PB0 coupled to UART2   
   \ Common   
   VMA-IO @ $00,1000 + CONSTANT CCU-BASE   
   CCU-BASE $090C + CONSTANT UART_BGR_REG   
   \ Reset all uarts and start the clocks.   
   -1 UART_BGR_REG L!   
      
   VMA-IO @ $50,0000 + CONSTANT UART-BASE   
   UART-BASE $0000 + CONSTANT UART0   
   UART-BASE $0400 + CONSTANT UART1   
   UART-BASE $0800 + CONSTANT UART2   
   UART-BASE $0C00 + CONSTANT UART3   
      
   UART2 CONSTANT UART   
   : >DLL 0 + ; : >DLH 4 + ;   
   : >THR 0 + ; : >LCR $0C + ;   
   : >FCR 8 + ;   
   \ : >LSR 14 + ; : >HALT $0A4 + ;   
   \ %0000,0100,0000,0100 UART_BGR_REG BIS \ alternative only UART2.   
   \ 9.2.4.1   
   \ 24 Mhz default, leave it alone.   
   \ clock setting, break, don't care, parity, stop bit, bitlength   
   %1,0,00,0,0,00 UART >LCR BIS   
   \ The divider for a midi signal is 48 (24Mhz/48*16 ~ 32 uS)   
   48 UART >DLL L! 0 UART >DLH L!   
   %1,0,00,0,0,00 UART >LCR BIC   
      
   \ clock set, break, parity aux, parity, stop bit, bitlength   
    %0,0,00,0,0,11 UART >LCR L!   
    1 UART >FCR BIS \ Enable fifo.   
   \ --------- API ------------   
   \ Start a break for indefinite time.   
   : break %0,1,00,0,0,00 UART >LCR BIS ;   
   \ Transmit a byte .   
   : TRANSMIT-U UART >THR L! ;   
      
   \ --------- Tests and checks. ------------   
   : test BEGIN $0AA TRANSMIT-U KEY? UNTIL ;   
   : test2 0 DO $0AA TRANSMIT-U 1 MS LOOP ;   
   : rdump BEGIN DUP H. SPACE DUP L@ H. CR 4 + KEY &Q = UNTIL ;   
      
   \ Toggle break fast n times.   
   : breaky >R %0,1,00,0,0,00 UART >LCR   
    R> 0 DO 2DUP BIS 2DUP BIC LOOP   
    2DROP ;   
   --------------------------------------------------------------   
   [If I make an UART and object, it becomes infinitely more   
   elegant.   
      
   \ Usage : you have to look up port PB0   
   $20 CONSTANT PB0 7 PB0 set-function \ PB0 coupled to UART2   
   2 NEW-UART midi-port 31,125 baudrate fifo-on   
   ]   
      
   >   
   >--   
   > Waldek Hebisch   
   --   
   Temu exploits Christians: (Disclaimer, only 10 apostles)   
   Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall   
   Art For Home, Office And Garden Decor - Perfect For Windows, Bars,   
   And Gifts For Friends Family And Colleagues.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|