// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BV4219 Graphic display // This is a library of words inteded for this device it is an I2C // device. The user should set the device address // using the word 4219-init and supplying a device address. // This will load as a stand alone file or can be used as a library // providing the parent file includes the files in the REQUIRES // section // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // REQUIRES: // #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=0 // #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb" sid=101 // #URL-Lib "http://pin1.org/forthlib/flb/I2C/i2c.flb" sid=103 // CONSTANTS: // This variable is used to hold the I2C address of the device // it can be chaned to a constant if required. integer device // These are simple commands following the device commands. : a1 ( on/off -- ) device s 1 sb sb p ; // turn display on or off, 1=on : a2 ( -- cmd ) device s 2 sb sb p ; // sends command to display : a3 ( -- byte ) device s 3 sb sb p ; // write byte : a4 { bytes -- } device s 4 sb // reads bytes on display device 1+ rs bytes 1- for rn next rl p ; : a6 ( 1|0 -- ) device s 6 sb sb p ; // back light on/off : a5 ( -- ) device s 5 sb p ; // reset : a7 ( x -- ) device s 7 sb sb p ; // set x position : a8 ( r -- ) device s 8 sb sb p ; // set r position : a9 { x r b -- } device s 9 sb x sb r sb b sb p ; // plce byte : aa { x y b -- } device s &a sb x sb y sb b sb p ; // plce byte : a10 ( byte -- ) device s &10 sb sb p ; // fills display with byte : pixon { x y -- } // on is white device s &11 sb x sb y sb 1 sb p ; // turns on pixel : pixoff { x y -- } // on is white device s &11 sb x sb y sb 0 sb p ; // turns on pixel : dhl { x y l -- } device s &12 sb x sb y sb l sb p ; // draw horizontal line : dhli { x y l -- } device s &13 sb x sb y sb l sb p ; // draw horizontal line : dvl { x y l -- } device s &14 sb x sb y sb l sb p ; // draw veritcal line : dvli { x y l -- } device s &15 sb x sb y sb l sb p ; // draw veritcal line : dbnf { x y xl yl -- } device s &16 sb x sb y sb xl sb yl sb p ; // draw box no fill : dbwf { x y xl yl -- } device s &18 sb x sb y sb xl sb yl sb p ; // draw box with fill : a20 ( char -- ) device s &20 sb sb p ; // send white character : a21 ( char -- ) device s &21 sb sb p ; // send dark character : a22 ( udf -- ) device s &22 sb sb p ; // send white udf from eeprom : a23 ( udf -- ) device s &23 sb sb p ; // send dark udf from eeprom : a25 { r c -- } device s &25 sb r sb c sb p ; // text cursor position : a27 ( -- x ) device s &27 sb device 1+ rs rl p ; // gets x pos : a28 ( -- r ) device s &28 sb device 1+ rs rl p ; // gest r pos // send string to text terminated with 0, do not exceed 32 charaters : send-text { addr --- } device s &20 sb // device and command begin addr c@ 0 <> while addr c@ sb 1 +> addr repeat p // stop ; // a55 will test if device is working and return t/f : a55 ( -- t/f ) device s &55 sb device 1+ rs rn 1 = rn 2 = and rl 3 = and p ; // read eeprom // # number of bytes to read and // from is starting address of eeprom : a90 ( #, from -- values ) device s &90 sb sb device 1+ rs 1- for rn next rl p ; // write all of the byts that are on the stack to eerpm // starting at address start. Note start has to be last value on stack : a91 ( [ .. ] start -- ) device s &91 sb sb depth for sb next p ; : a93 ( -- x ) device s &93 sb device 1+ rs rl p ; // end of eerpom : a94 ( -- ) device s &94 sb p ; // sleep : a95 ( -- ) device s &95 sb p ; // reset : a96 ( -- ) device s &96 sb &55 sb &aa sb p ; // restore factory defaults // imediately sets new i2c address to eeprom : a99 ( new -- ) device s &99 sb dup sb &55 sb &aa sb device sb => device p ; : aa0 ( -- ver. ) device s &a0 sb device 1+ rs rn . ." ." rl emit p ; // use this first to establish i2C address if device and // to initialise i2c system with default speed, if sucess requirn -1 : 4219-init ( device -- -1|0 ) => device i2-init a55 ; : i2cslow ( -- ) 100000 i2speed ; // sets i2c to slow speed : i2cfull ( -- ) 400000 i2speed ; // sets i2c to full speed : 4219-default 66 4219-init i2cfull ;