en:pfw:i2c_device-drivers
                Table of Contents
I2C device drivers
The idea for I2C device drivers
There are lots of chips available using the I2C-protocol. These examples use the I2C implementation as described here. All of them need a specific device driver. To name some: sensors, memory, clocks, I/O, etc. Here you can add any driver you like to share. Preferably written in Generic Forth. But as we embrace the differences, you may also add them in a new folder for your own dialect !
I2C drivers
      EDMP ( ea -- )       - Dump EEPROM memory from address ea
      SHOW ( -- )          - Show string stored in EEPROM
APDS ( -- ) - Show light and infrared light data
      PCA-ON ( -- )        - Activate PCA9632 LED power switch 
      >ON    ( b -- )      - (De)activate LED power output modes
      ALARM  ( -- )        - Give every 10 seconds text string alarm signal
      TIMER  ( s m -- )    - Give every s seconds and m minutes a text string
      CLOCK  ( -- )        - Show an RTC each second on a new line, first set the RTC!
      RUNNER1 ( -- )       - Running light on the output chip 
      RUNNER2 ( -- )       - Same running light with delay timing using the input chip
      SHOW    ( -- )       - Copy input chip data to output chip 
ANALOG ( +n -- ) - Convert ADC input +n, output to a DAC and type on screen
      8-Bit ADC/DAC
TEMPERATURE2 ( -- ) - Read & show 9-bit temperature continuously
TMP75-DEMO ( -- ) - Read & show temperature continuously
- More on OLEDs ; OLED drivers, character sets, etc.
 - More on LCD's ; LCD drivers, character sets, etc.
 - Scanner ; Scan your I2C network for connected devices
 
APDS9300 driver in pseudo code
Using the I2C driver as presented I2C, The I2C protocol
Function: {AP-ADDR  ( reg +n -- )
  29  perform device! perform {i2c-write  or reg with 80 bus!
Function: APDS@     ( reg -- byte )
  1  perform {ap-addr perform i2c}
  perform {i2c-read  perform bus@  perform i2c}
Function: APDS!     ( byte reg -- )
  2  perform {ap-addr  perform bus!  perform i2c}
Function: APDS-ON   ( -- )     3 0   perform apds!
Function: APDS-ON   ( -- )     3 0   perform apds!
Function: LIGHT     ( -- u )   0C  do apds@  100 times  0D  do apds@  or
Function: IR        ( -- u )   0E  do apds@  100 times  0F  do apds@  or
      The tiny APDS9300
APDS9300 in Generic Forth
hex
: {AP-ADDR  ( reg +n -- )   29 device!  {i2c-write  80 or bus! ;
: APDS@     ( reg -- b )    1 {ap-addr i2c}  1 {i2c-read  bus@ i2c} ;
: APDS!     ( b reg -- )    2 {ap-addr  bus! i2c} ;
: APDS-ON   ( -- )          3 0 apds! ;
: APDS-OFF  ( -- )          0 0 apds! ;
: LIGHT     ( -- u )        0C apds@  0D apds@  b+b ;
: IR        ( -- u )        0E apds@  0F apds@  b+b ;
Implementations
Have a look in this directory for Generic Forth implementations. Or in the sub directories for implementations for different systems.
en/pfw/i2c_device-drivers.txt · Last modified: 2023-09-04 18:15 by uho
                
                