Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# po1030.c

    00001 /*! \file po1030.h \brief PO1030 Imager Interface Driver. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'po1030.h'
    00005 // Title        : PO1030 Imager Interface Driver
    00006 // Author       : Pascal Stang - Copyright (C) 2006
    00007 // Created      : 2006.02.01
    00008 // Revised      : 2006.02.01
    00009 // Version      : 0.1
    00010 // Target MCU   : ARM processors
    00011 // Editor Tabs  : 4
    00012 //
    00013 // NOTE: This code is currently below version 1.0, and therefore is considered
    00014 // to be lacking in some functionality or documentation, or may not be fully
    00015 // tested.  Nonetheless, you can expect most functions to work.
    00016 //
    00017 // This code is distributed under the GNU Public License
    00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00019 //
    00020 //*****************************************************************************
    00021
    00022 #include "at91sam7s64.h"
    00023 #include "global.h"
    00024 #include "i2c.h"
    00025 #include "po1030.h"
    00026
    00027 // functions
    00028
    00029 void po1030Init(void)
    00030 {
    00031
    00032 }
    00033
    00034 u16 po1030GetID(void)
    00035 {
    00036     return po1030RegRead(PO1030_REG_DEVID);
    00037 }
    00038
    00039 // read/write register
    00040 u16 po1030RegRead(u08 regaddr)
    00041 {
    00042     u08 packet[2];
    00043     // set the register to access
    00044     packet[0] = (regaddr & PO1030_REG_MASK);
    00045     i2cMasterSend(PO1030_I2C_BASE_ADDR, 1, &packet[0]);
    00046     // read the value
    00047     if(regaddr&PO1030_REG_16BIT)
    00048     {
    00049         i2cMasterReceive(PO1030_I2C_BASE_ADDR, 2, &packet[0]);
    00050         // return value
    00051         return (packet[0]<<8)|packet[1];
    00052     }
    00053     else
    00054     {
    00055         i2cMasterReceive(PO1030_I2C_BASE_ADDR, 1, &packet[0]);
    00056         // return value
    00057         return packet[0];
    00058     }
    00059 }
    00060
    00061 void po1030RegWrite(u08 regaddr, u16 value)
    00062 {
    00063     u08 packet[3];
    00064     // set the register to access
    00065     packet[0] = (regaddr & PO1030_REG_MASK);
    00066     // read the value
    00067     if(regaddr&PO1030_REG_16BIT)
    00068     {
    00069         // set value to write
    00070         packet[1] = (value>>8);
    00071         packet[2] = (value);
    00072         // write the value
    00073         i2cMasterSend(PO1030_I2C_BASE_ADDR, 3, &packet[0]);
    00074     }
    00075     else
    00076     {
    00077         // set value to write
    00078         packet[1] = (value);
    00079         // write the value
    00080         i2cMasterSend(PO1030_I2C_BASE_ADDR, 2, &packet[0]);
    00081     }
    00082 }
    00083
    00084
    00085