// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BVSYS - // All of the I2C devices 'BV'xx share a set of common system // commands for changing the device address, inspecting the // EEPROM etc. This library contains those commands rather // than repeating them in each of the individual libraries. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 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 is a variable so that it can be changed outside this // library, the downside is that it MUST be initialised before // using the library integer device // ============== system ===================================== // 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 // the device will return -1 : bv-init ( device -- -1|0 ) => device i2-init a55 ; : i2cslow ( -- ) 100000 i2speed ; // sets i2c to slow speed : i2cfull ( -- ) 400000 i2speed ; // sets i2c to full speed