// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BV4206 is the GPIO IC // This is a library of words inteded for this IC it is an I2C // device. The user should set the device address // using the word 4205-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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // HISTORY: // Now uses common file bvsys.flb // 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 // #URL-Lib "http://pin1.org/forthlib/flb/I2C/bvsys.flb" // CONSTANTS: // device variable is in bvsys.lib // These are simple commands following the device commands. : a1 { pin io -- } device s 1 sb pin sb io sb p ; // set input or output : a2 { pin value -- } device s 2 sb pin sb value sb p ; // set pin high or low : a3 ( chan -- pinVal ) device s 3 sb sb device 1+ rs rl p ; // read pin : a4 ( 0|1 -- ) device s 4 sb sb p ; // set/clear weak pull ups // : a10 ( 0|1 -- ) device s &10 sb sb p ; // timer o/p control : a11 ( val -- ) device s &11 sb sb p ; // timer pre-scale value : a12 ( val -- ) device s &12 sb sb p ; // timer value : a13 ( -- val ) device s &13 sb device 1+ rs rl p ; // read timer value : a14 ( 0|1 -- ) device s &14 sb sb p ; // timer source : a15 ( 0|1 -- ) device s &15 sb sb p ; // timer external i/p control // : a20 ( 0|1 -- ) device s &20 sb sb p ; // PWM activate : a21 { width16 -- } device s &21 sb // PWM pulse width 16 bit value width16 8 rshift &ff and sb // high width16 &ff and sb // low p ; // use this first to establish i2C address : 4206-default ( -- f/t ) &42 bv-init i2cfull ; : st &42 bv-init i2cfull . ;