summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/i2c-tools/picodlp-control/Config.h41
-rw-r--r--packages/i2c-tools/picodlp-control/Crc8.c149
-rw-r--r--packages/i2c-tools/picodlp-control/Crc8.h54
-rw-r--r--packages/i2c-tools/picodlp-control/DumpMem.c93
-rw-r--r--packages/i2c-tools/picodlp-control/DumpMem.h49
-rw-r--r--packages/i2c-tools/picodlp-control/Log.c335
-rw-r--r--packages/i2c-tools/picodlp-control/Log.h232
-rw-r--r--packages/i2c-tools/picodlp-control/i2c-api.c522
-rw-r--r--packages/i2c-tools/picodlp-control/i2c-api.h143
-rw-r--r--packages/i2c-tools/picodlp-control/i2c-dev.h400
-rw-r--r--packages/i2c-tools/picodlp-control/i2c-io-api.h52
-rw-r--r--packages/i2c-tools/picodlp-control/i2c-io.h220
-rw-r--r--packages/i2c-tools/picodlp-control/i2c.c710
-rw-r--r--packages/i2c-tools/picodlp-control/i2c.h135
-rwxr-xr-xpackages/i2c-tools/picodlp-control/picodlp-control47
-rw-r--r--packages/i2c-tools/picodlp-control/picodlp-control.c109
-rw-r--r--packages/i2c-tools/picodlp-control_0.1.bb9
17 files changed, 3007 insertions, 293 deletions
diff --git a/packages/i2c-tools/picodlp-control/Config.h b/packages/i2c-tools/picodlp-control/Config.h
new file mode 100644
index 0000000000..83bb46de84
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/Config.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file Config.h
+*
+* @brief Global Configuration information.
+*
+****************************************************************************/
+
+#if !defined( CONFIG_H )
+#define CONFIG_H /**< Include Guard */
+
+/* ---- Include Files ---------------------------------------------------- */
+
+/* ---- Constants and Types ---------------------------------------------- */
+
+/**
+ * Sets Logging parameters
+ */
+
+#define CFG_LOG_TO_BUFFER 0
+
+#define CFG_CRC8BLOCK 1
+
+/** @} */
+
+#endif // CONFIG_H
+
diff --git a/packages/i2c-tools/picodlp-control/Crc8.c b/packages/i2c-tools/picodlp-control/Crc8.c
new file mode 100644
index 0000000000..87dcf5c2f4
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/Crc8.c
@@ -0,0 +1,149 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file Crc8.c
+*
+* @brief This file contains the definition of the CRC-8 algorithim
+* used by SMBus
+*
+*
+*****************************************************************************/
+
+/* ---- Include Files ----------------------------------------------------- */
+
+#include "Config.h"
+
+#include "Crc8.h"
+
+#include "Log.h"
+
+/* ---- Public Variables -------------------------------------------------- */
+/* ---- Private Constants and Types --------------------------------------- */
+/* ---- Private Variables ------------------------------------------------- */
+/* ---- Private Function Prototypes --------------------------------------- */
+/* ---- Functions --------------------------------------------------------- */
+
+/****************************************************************************/
+/**
+* Calculates the CRC-8 used as part of SMBus.
+*
+* CRC-8 is defined to be x^8 + x^2 + x + 1
+*
+* To use this function use the following template:
+*
+* crc = Crc8( crc, data );
+*/
+
+#if 0 // Traditional implementation
+
+#define POLYNOMIAL (0x1070U << 3)
+
+unsigned char Crc8( unsigned char inCrc, unsigned char inData )
+{
+ int i;
+ unsigned short data;
+
+ data = inCrc ^ inData;
+ data <<= 8;
+
+ for ( i = 0; i < 8; i++ )
+ {
+ if (( data & 0x8000 ) != 0 )
+ {
+ data = data ^ POLYNOMIAL;
+ }
+ data = data << 1;
+ }
+
+#if 0
+#if defined( LogBuf2 )
+ LogBuf2( "Crc8: data:0x%02x crc:0x%02x\n", inData, (unsigned char)( data >> 8 ));
+#else
+
+ Log( "Crc8: data:0x%02x crc:0x%02x\n", inData, (unsigned char)( data >> 8 ));
+#endif
+
+#endif
+
+
+ return (unsigned char)( data >> 8 );
+
+} // Crc8
+
+#else // Optimized for 8 bit CPUs (0x22 bytes on ATMega128 versus 0x30 for above version)
+
+unsigned char Crc8( unsigned char inCrc, unsigned char inData )
+{
+ unsigned char i;
+ unsigned char data;
+
+ data = inCrc ^ inData;
+
+ for ( i = 0; i < 8; i++ )
+ {
+ if (( data & 0x80 ) != 0 )
+ {
+ data <<= 1;
+ data ^= 0x07;
+ }
+ else
+ {
+ data <<= 1;
+ }
+ }
+
+#if 0
+#if defined( LogBuf2 )
+ LogBuf2( "Crc8: data:0x%02x crc:0x%02x\n", inData, data );
+#else
+
+ Log( "Crc8: data:0x%02x crc:0x%02x\n", inData, data );
+#endif
+
+#endif
+
+
+ return data;
+
+} // Crc8
+
+#endif
+
+
+#if defined( CFG_CRC8BLOCK )
+
+/****************************************************************************/
+/**
+* Calculates the CRC-8 used as part of SMBus over a block of memory.
+*/
+
+uint8_t Crc8Block( uint8_t crc, uint8_t *data, uint8_t len )
+{
+ while ( len > 0 )
+ {
+ crc = Crc8( crc, *data++ );
+ len--;
+ }
+
+ return crc;
+
+} // Crc8Block
+
+#endif // CFG_CRC8BLOCK
+
+/** @} */
+
+
diff --git a/packages/i2c-tools/picodlp-control/Crc8.h b/packages/i2c-tools/picodlp-control/Crc8.h
new file mode 100644
index 0000000000..2d1f74b82c
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/Crc8.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file Crc8.h
+*
+* @brief This file contains the definition of the CRC-8 algorithim
+* used by SMBus
+*
+****************************************************************************/
+
+#if !defined( CRC8_H )
+#define CRC_H ///< Include Guard
+
+/* ---- Include Files ----------------------------------------------------- */
+
+#include <inttypes.h>
+
+#if defined( __cplusplus )
+extern "C"
+{
+#endif
+
+
+/* ---- Constants and Types ---------------------------------------------- */
+/* ---- Variable Externs ------------------------------------------------- */
+/* ---- Function Prototypes ---------------------------------------------- */
+
+uint8_t Crc8( uint8_t crc, uint8_t data );
+
+uint8_t Crc8Block( uint8_t crc, uint8_t *data, uint8_t len );
+
+
+#if defined( __cplusplus )
+}
+#endif
+
+
+/** @} */
+
+#endif // CRC8_H
+
diff --git a/packages/i2c-tools/picodlp-control/DumpMem.c b/packages/i2c-tools/picodlp-control/DumpMem.c
new file mode 100644
index 0000000000..e13e94b0f8
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/DumpMem.c
@@ -0,0 +1,93 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file DumpMem.c
+*
+* @brief Memmory dump routine
+*
+****************************************************************************/
+
+// ---- Include Files -------------------------------------------------------
+
+#include <inttypes.h>
+#include "DumpMem.h"
+#include "Log.h"
+
+// ---- Public Variables ----------------------------------------------------
+// ---- Private Constants and Types -----------------------------------------
+// ---- Private Variables ---------------------------------------------------
+// ---- Private Function Prototypes -----------------------------------------
+// ---- Functions -----------------------------------------------------------
+
+/**************************************************************************/
+/**
+* Dumps a page of output for debugging purposes.
+*/
+
+void DumpMem( const char *prefix, unsigned address, const void *inData, unsigned numBytes )
+{
+ const uint8_t *data = (const uint8_t *)inData;
+ unsigned byteOffset;
+
+ if ( numBytes == 0 )
+ {
+ Log( "%s: No data\n", prefix );
+ return;
+ }
+
+#define LINE_WIDTH 16
+
+ for ( byteOffset = 0; byteOffset < numBytes; byteOffset += LINE_WIDTH )
+ {
+ unsigned i;
+
+ Log( "%s: %04x: ", prefix, address + byteOffset );
+
+ for ( i = 0; i < LINE_WIDTH; i++ )
+ {
+ if (( byteOffset + i ) < numBytes )
+ {
+ Log( "%02.2X ", data[ byteOffset + i ] );
+ }
+ else
+ {
+ Log( " " );
+ }
+ }
+ for ( i = 0; i < LINE_WIDTH; i++ )
+ {
+ if (( byteOffset + i ) < numBytes )
+ {
+ unsigned char ch = data[ byteOffset + i ];
+ if (( ch < ' ' ) || ( ch > '~' ))
+ {
+ Log( "." );
+ }
+ else
+ {
+ Log( "%c", ch );
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ Log( "\n" );
+ }
+
+} // DumpMem
+
diff --git a/packages/i2c-tools/picodlp-control/DumpMem.h b/packages/i2c-tools/picodlp-control/DumpMem.h
new file mode 100644
index 0000000000..5d536f49e8
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/DumpMem.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file DumpMem.h
+*
+* @brief Debug routine for dumping memory
+*
+****************************************************************************/
+
+#if !defined( DUMPMEM_H )
+#define DUMPMEM_H ///< Include Guard
+
+// ---- Include Files -------------------------------------------------------
+
+/**
+ * @addtogroup Log
+ * @{
+ */
+
+#if defined( __cplusplus )
+extern "C"
+{
+#endif
+
+
+void DumpMem( const char *prefix, unsigned address, const void *data, unsigned numBytes );
+
+#if defined( __cplusplus )
+}
+#endif
+
+
+/** @} */
+
+#endif // DUMPMEM_H
+
diff --git a/packages/i2c-tools/picodlp-control/Log.c b/packages/i2c-tools/picodlp-control/Log.c
new file mode 100644
index 0000000000..e32783391b
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/Log.c
@@ -0,0 +1,335 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file Log.cpp
+*
+* @brief This file contains the implementation of the logging functions.
+*
+****************************************************************************/
+
+// ---- Include Files -------------------------------------------------------
+
+#include "Log.h"
+
+#if CFG_LOG_USE_STDIO
+# include <stdio.h>
+#else
+
+# include "Str.h"
+# include "UART.h"
+#endif
+
+
+// ---- Public Variables ----------------------------------------------------
+// ---- Private Constants and Types -----------------------------------------
+
+#if defined( AVR )
+
+#undef Log
+#undef LogError
+#undef vLog
+
+#define Log Log_P
+#define LogError LogError_P
+#define vLog vLog_P
+#define LogBuf LogBuf_P
+
+#define char prog_char
+
+#else
+
+
+#define PSTR(str) str
+
+int gVerbose = 0;
+int gDebug = 0;
+int gQuiet = 0;
+
+#endif
+
+
+#if CFG_LOG_TO_BUFFER
+
+volatile LOG_Buffer_t LOG_gBuffer;
+
+#endif
+
+
+// ---- Private Variables ---------------------------------------------------
+
+#if CFG_LOG_USE_STDIO
+
+FILE *gLogFs = NULL;
+
+#endif
+
+
+// ---- Private Function Prototypes -----------------------------------------
+
+// ---- Functions -----------------------------------------------------------
+
+/**
+ * @addtogroup Log
+ * @{
+ */
+
+#if !defined( AVR )
+
+void DefaultLogFunc( int logLevel, const char *fmt, va_list args )
+{
+ FILE *fs;
+
+ if ( gQuiet && ( logLevel == LOG_LEVEL_NORMAL ))
+ {
+ return;
+ }
+
+ if ( gLogFs == NULL )
+ {
+ fs = stderr;
+ }
+ else
+ {
+ fs = gLogFs;
+ }
+
+ if ( logLevel == LOG_LEVEL_ERROR )
+ {
+ fprintf( fs, "ERROR: " );
+ }
+ vfprintf( fs, fmt, args );
+ fflush( fs );
+
+} // DefaultLogFunc
+
+static LogFunc_t gLogFunc = DefaultLogFunc;
+
+void SetLogFunc( LogFunc_t logFunc )
+{
+
+ gLogFunc = logFunc;
+
+} // SetLogFunc
+
+#endif
+
+
+//***************************************************************************
+/**
+* Sets the logging stream
+*/
+
+#if CFG_LOG_USE_STDIO
+void LogInit( FILE *logFs )
+{
+ gLogFs = logFs;
+
+} // LogInit
+
+#else
+
+
+static int LogToUartFunc( void *outParm, int ch )
+{
+ UART0_PutChar( ch );
+
+ return 1;
+}
+#endif
+
+
+//***************************************************************************
+/**
+* Logs a string using printf like semantics
+*/
+
+void Log
+(
+ const char *fmt, ///< printf style format specifier
+ ... ///< variable list of arguments
+)
+{
+ va_list args;
+
+ va_start( args, fmt );
+ vLog( fmt, args );
+ va_end( args );
+}
+
+//***************************************************************************
+/**
+* Logs a string using printf like semantics
+*/
+
+void vLog
+(
+ const char *fmt, ///< printf style format specified
+ va_list args ///< variable list of arguments
+)
+{
+ // For now we call printf directly. A better way would be to install
+ // a callback which does the real work
+
+#if defined( AVR )
+# if CFG_LOG_USE_STDIO
+ if ( gLogFs != NULL )
+ {
+ vfprintf_P( gLogFs, fmt, args );
+ }
+# else
+
+ vStrXPrintf_P( LogToUartFunc, NULL, fmt, args );
+# endif
+
+#else
+
+ if ( gLogFunc != NULL )
+ {
+ gLogFunc( LOG_LEVEL_NORMAL, fmt, args );
+ }
+#endif
+
+}
+
+#if !defined( AVR )
+
+//***************************************************************************
+/**
+* Logs an error.
+*/
+
+void vLogError
+(
+ const char *fmt, ///< printf style format specified
+ va_list args ///< variable list of arguments
+)
+{
+ if ( gLogFunc != NULL )
+ {
+ gLogFunc( LOG_LEVEL_ERROR, fmt, args );
+ }
+}
+
+#endif
+
+
+/***************************************************************************/
+/**
+* Logs an error
+*/
+
+void LogError
+(
+ const char *fmt, ///< printf style format specifier
+ ... ///< variable list of arguments
+)
+{
+ va_list args;
+
+#if defined( AVR )
+ //Log( "ERROR: " );
+ //Log_P( PSTR( "ERROR: " ));
+
+ va_start( args, fmt );
+ vLog( fmt, args );
+ va_end( args );
+#else
+
+ va_start( args, fmt );
+ vLogError( fmt, args );
+ va_end( args );
+#endif
+
+
+} // LogError
+
+/***************************************************************************/
+/**
+* Logs an entry to the log buffer
+*/
+
+#if CFG_LOG_TO_BUFFER
+
+void LogBuf( const char *fmt, uint8_t arg1, uint8_t arg2 LOG_EXTRA_PARAMS_DECL )
+{
+#if defined( AVR )
+ uint8_t sreg = SREG;
+ cli();
+#endif
+
+
+ if ( CBUF_IsFull( LOG_gBuffer ))
+ {
+ volatile LOG_Entry_t *entry = CBUF_GetLastEntryPtr( LOG_gBuffer );
+
+ entry->fmt = PSTR( "*** Lost Messages ***\n" );
+ }
+ else
+ {
+ volatile LOG_Entry_t *entry = CBUF_GetPushEntryPtr( LOG_gBuffer );
+
+ entry->fmt = fmt;
+ entry->param1 = arg1;
+ entry->param2 = arg2;
+
+#if CFG_LOG_EXTRA_PARAMS
+ entry->param3 = arg3;
+ entry->param4 = arg4;
+#endif
+
+
+ CBUF_AdvancePushIdx( LOG_gBuffer );
+ }
+
+#if defined( AVR )
+ SREG = sreg;
+#endif
+
+
+} // LogBuf
+
+#endif // CFG_LOG_TO_BUFFER
+
+/***************************************************************************/
+/**
+* Dumps any unlogged entries from the log buffer
+*/
+
+#if CFG_LOG_TO_BUFFER
+
+void LogBufDump( void )
+{
+ while ( !CBUF_IsEmpty( LOG_gBuffer ))
+ {
+ volatile LOG_Entry_t *entry = CBUF_GetPopEntryPtr( LOG_gBuffer );
+
+#if CFG_LOG_EXTRA_PARAMS
+ Log( entry->fmt, entry->param1, entry->param2, entry->param3, entry->param4 );
+#else
+
+ Log( entry->fmt, entry->param1, entry->param2 );
+#endif
+
+
+ CBUF_AdvancePopIdx( LOG_gBuffer );
+ }
+
+} // LogBufDump
+
+#endif // CFG_LOG_TO_BUFFER
+
+/** @} */
+
diff --git a/packages/i2c-tools/picodlp-control/Log.h b/packages/i2c-tools/picodlp-control/Log.h
new file mode 100644
index 0000000000..d12d482fc6
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/Log.h
@@ -0,0 +1,232 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file Log.h
+*
+* @brief Contains some logging macros.
+*
+****************************************************************************/
+/**
+* @defgroup Log Logging
+*
+* @brief Provides a common interface for logging.
+*
+****************************************************************************/
+
+#if !defined( LOG_H )
+#define LOG_H ///< Include Guard
+
+// ---- Include Files -------------------------------------------------------
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#if !defined( CONFIG_H )
+# include "Config.h"
+#endif
+
+#if !defined( CFG_LOG_USE_STDIO )
+# define CFG_LOG_USE_STDIO 1
+#endif
+
+
+#if defined( AVR )
+# include <avr/pgmspace.h>
+# include <avr/interrupt.h>
+#endif
+
+
+#if CFG_LOG_TO_BUFFER
+# if !defined( CBUF_H )
+# include "CBUF.h"
+# endif
+
+#endif
+
+
+
+/**
+ * @addtogroup Log
+ * @{
+ */
+
+#if !defined( CFG_LOG_ENABLED )
+# define CFG_LOG_ENABLED 1
+#endif
+
+
+#if !CFG_LOG_ENABLED
+
+#define Log( fmt, args... )
+#define LogError( fmt, args... )
+
+#else
+
+
+#if defined( __cplusplus )
+extern "C"
+{
+#endif
+
+
+/***************************************************************************
+*
+* Log Buffer support
+*/
+
+#if CFG_LOG_TO_BUFFER
+
+#if defined( AVR )
+
+typedef struct
+{
+ const prog_char *fmt;
+ uint8_t param1;
+ uint8_t param2;
+#if CFG_LOG_EXTRA_PARAMS
+ uint8_t param3;
+ uint8_t param4;
+#endif
+
+
+} LOG_Entry_t;
+
+#if CFG_LOG_EXTRA_PARAMS
+# define LOG_EXTRA_PARAMS_DECL , uint8_t arg3, uint8_t arg4
+# define LOG_EXTRA_PARAMS , 0, 0
+#else
+
+# define LOG_EXTRA_PARAMS_DECL
+# define LOG_EXTRA_PARAMS
+#endif
+
+
+void LogBuf_P( const prog_char *fmt, uint8_t arg1, uint8_t arg2 LOG_EXTRA_PARAMS_DECL );
+
+#define LogBuf0( fmt ) LogBuf_P( PSTR( fmt ), 0, 0 LOG_EXTRA_PARAMS )
+#define LogBuf1( fmt, arg1 ) LogBuf_P( PSTR( fmt ), arg1, 0 LOG_EXTRA_PARAMS )
+#define LogBuf2( fmt, arg1, arg2 ) LogBuf_P( PSTR( fmt ), arg1, arg2 LOG_EXTRA_PARAMS )
+
+#if CFG_LOG_EXTRA_PARAMS
+#define LogBuf3( fmt, arg1, arg2, arg3 ) LogBuf_P( PSTR( fmt ), arg1, arg2, arg3, 0 )
+#define LogBuf4( fmt, arg1, arg2, arg3, arg4 ) LogBuf_P( PSTR( fmt ), arg1, arg2, arg3, arg4 )
+#endif
+
+
+#else
+
+
+typedef struct
+{
+ const char *fmt;
+ uint8_t param1;
+ uint8_t param2;
+
+} LOG_Entry_t;
+
+void LogBuf( const char *fmt, uint8_t arg1, uint8_t arg2 );
+
+#define LogBuf0( fmt, arg1 ) LogBuf( fmt, 0, 0 )
+#define LogBuf1( fmt, arg1 ) LogBuf( fmt, arg1, 0 )
+#define LogBuf2( fmt, arg1, arg2 ) LogBuf( fmt, arg1, arg2 )
+
+#endif // AVR
+
+#if ( CFG_LOG_NUM_BUFFER_ENTRIES > 128 )
+typedef uint16_t LOG_BufferIdx_t;
+#else
+
+typedef uint8_t LOG_BufferIdx_t;
+#endif
+
+
+typedef struct
+{
+ LOG_BufferIdx_t m_getIdx;
+ LOG_BufferIdx_t m_putIdx;
+ LOG_Entry_t m_entry[ CFG_LOG_NUM_BUFFER_ENTRIES ];
+
+} LOG_Buffer_t;
+
+extern volatile LOG_Buffer_t LOG_gBuffer;
+
+#define LOG_gBuffer_SIZE ( sizeof( LOG_gBuffer.m_entry ) / sizeof( LOG_gBuffer.m_entry[ 0 ] ))
+
+void LogBufDump( void );
+
+#endif // CFG_LOG_TO_BUFFER
+
+/***************************************************************************
+*
+* Regular logging support
+*/
+
+#if CFG_LOG_USE_STDIO
+extern FILE *gLogFs;
+
+void LogInit( FILE *logFs );
+#endif
+
+
+#if defined( AVR )
+
+void Log_P( const prog_char *fmt, ... );
+void LogError_P( const prog_char *fmt, ... );
+void vLog_P( const prog_char *fmt, va_list args );
+
+#define Log( fmt, args... ) Log_P( PSTR( fmt ), ## args )
+#define LogError( fmt, args... ) LogError_P( PSTR( fmt ), ## args )
+#define vLog( fmt, va_list, args ) vLog_P( PSTR( fmt ), args )
+
+#else // AVR
+
+#define LOG_LEVEL_NORMAL 0
+#define LOG_LEVEL_ERROR 1
+
+typedef void (*LogFunc_t)( int logLevel, const char *fmt, va_list args );
+
+extern int gVerbose;
+extern int gDebug;
+extern int gQuiet;
+
+void Log( const char *fmt, ... );
+void LogError( const char *fmt, ... );
+void vLog( const char *fmt, va_list args );
+void vLogError( const char *fmt, va_list args );
+
+#define Log_P( fmt, args... ) Log( fmt, ## args )
+#define LogError_P( fmt, args... ) LogError( fmt, ## args )
+#define vLog_P( fmt, args ) vLog( fmt, args )
+
+#define LogDebug( fmt, args... ) do { if ( gDebug ) { Log( fmt, ## args ); }} while (0)
+#define LogVerbose( fmt, args... ) do { if ( gVerbose ) { Log( fmt, ## args ); }} while (0)
+
+void SetLogFunc( LogFunc_t logFunc );
+void DefaultLogFunc( int logLevel, const char *fmt, va_list args );
+
+#endif // AVR
+
+#if defined( __cplusplus )
+}
+#endif
+
+
+#endif // CFG_LOG_ENABLED
+
+/** @} */
+
+#endif // LOG_H
+
diff --git a/packages/i2c-tools/picodlp-control/i2c-api.c b/packages/i2c-tools/picodlp-control/i2c-api.c
new file mode 100644
index 0000000000..cfc41565a4
--- /dev/null
+++ b/packages/i2c-tools/picodlp-control/i2c-api.c
@@ -0,0 +1,522 @@
+/****************************************************************************
+*
+* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* Alternatively, this software may be distributed under the terms of BSD
+* license.
+*
+* See README and COPYING for more details.
+*
+****************************************************************************/
+/**
+*
+* @file i2c-api.c
+*
+* @brief This file contains the implementation for performing I2C operations
+* on the gumstix.
+*
+****************************************************************************/
+
+// ---- Include Files -------------------------------------------------------
+
+#include <string.h>
+#include <errno.h>
+
+#include "i2c.h"
+#include "i2c-dev.h"
+#include "i2c-api.h"
+
+#include "Crc8.h"
+#include "DumpMem.h"
+#include "Log.h"
+
+// ---- Public Variables ----------------------------------------------------
+
+// ---- Private Constants and Types -----------------------------------------
+
+// ---- Private Variables ---------------------------------------------------
+
+static I2C_Addr_t gI2cAddr;
+static int gUseCrc;
+
+// ---- Private Function Prototypes -----------------------------------------
+
+// ---- Functions -----------------------------------------------------------
+
+//***************************************************************************
+/**
+*
+* Sets the I2C address that we'll be communicating with, as well as whether
+* the device uses smbus PEC (CRC).
+*/
+
+void I2cSetSlaveAddress( int i2cDev, I2C_Addr_t i2cAddr, int useCrc )
+{
+ gI2cAddr = i2cAddr;
+ gUseCrc = useCrc;
+
+ LogDebug( "----- I2cSetSlaveAddress i2cAddr:0x%02x useCrc:%d -----\n",
+ i2cAddr, useCrc );
+
+ // Indicate which slave we wish to speak to
+
+ if ( ioctl( i2cDev, I2C_SLAVE, gI2cAddr ) < 0 )
+ {
+ LogError( "I2cSetSlaveAddress: Error trying to set slave address to 0x%02x (%d %s)\n",
+ gI2cAddr, errno, strerror( errno ));
+ }
+
+ // We do the CRC calculation ourself, so we don't need to tell the driver
+ // that we're using it.
+
+#if 0
+ // Indicate that we use PEC (aka CRCs)
+
+ if ( ioctl( i2cDev, I2C_PEC, 1 ) < 0 )
+ {
+ LogError( "I2cSetSlaveAddress: Error trying to set PEC mode\n" );
+ }
+#endif
+
+} // I2cSetSlaveAddress
+
+//***************************************************************************
+/**
+* Transfer data to/from an i2c device.
+*
+* This function implements the equivalent of the smbus functions using
+* I2C_RDWR.
+*
+* The PXA driver doesn't support the smbus transfers.
+*
+* This function can perform the following SMBUS transactions:
+*
+* Write Byte: wrLen == 1, rdLen == 0
+* Read Byte: wrLen == 0, rdLen == 1
+* Write Word: wrLen == 2, rdLen == 0
+* Read Word: wrLen == 0, rdLen == 2
+* Process Call: wrLen == 2, rdLen == 2
+* Write Block: wrLen == 0x80 + numBytes, rdLen == 0
+* Read Block: wrLen == 0, rdLen == 0x80 + numBytes
+* Process Block: wrLen == 0x80 + numBytes, rdLen == 0x80 + numBytes
+*/
+
+int I2cTransfer
+(
+ int i2cDev, ///< Handle to i2c-dev file
+ uint8_t cmd, ///< Command to send
+ const void *wrData, ///< Data to write
+ uint8_t wrLen, ///< Number of bytes to write (or in 0x80 for a block write)
+ void *rdData, ///< Place to store data read
+ uint8_t rdLen, ///< Number of bytes to read (or in 0x80 for a block read)
+ uint8_t *bytesReadp ///< Place to store number of bytes read
+)
+{
+ struct i2c_rdwr_ioctl_data rdwr;
+ struct i2c_msg msg[ 2 ];
+ uint8_t wrBuf[ I2C_MAX_DATA_LEN + 3 ]; // +1 for cmd, +1 for le