[Armadeus-commitlog] SF.net SVN: armadeus: [623] trunk
Brought to you by:
sszy
|
From: <th...@us...> - 2007-08-17 17:21:50
|
Revision: 623
http://armadeus.svn.sourceforge.net/armadeus/?rev=623&view=rev
Author: thom25
Date: 2007-08-17 10:21:47 -0700 (Fri, 17 Aug 2007)
Log Message:
-----------
add CH7024 tool
Modified Paths:
--------------
trunk/buildroot/target/device/armadeus/Config.in
Added Paths:
-----------
trunk/target/packages/ch7024ctrl/
trunk/target/packages/ch7024ctrl/Makefile
trunk/target/packages/ch7024ctrl/ch7024.c
trunk/target/packages/ch7024ctrl/ch7024.h
Modified: trunk/buildroot/target/device/armadeus/Config.in
===================================================================
--- trunk/buildroot/target/device/armadeus/Config.in 2007-08-09 22:43:03 UTC (rev 622)
+++ trunk/buildroot/target/device/armadeus/Config.in 2007-08-17 17:21:47 UTC (rev 623)
@@ -61,6 +61,13 @@
source package/max5821ctrl/Config.in
comment "---"
+config BR2_ARMADEUS_PACKAGE
+ bool "armadeus packages"
+ default n
+ depends BR2_TARGET_ARMADEUS
+ source package/ch7024ctrl/Config.in
+ comment "---"
+
config BR2_PACKAGE_LINUX
bool "linux"
default n
Added: trunk/target/packages/ch7024ctrl/Makefile
===================================================================
--- trunk/target/packages/ch7024ctrl/Makefile (rev 0)
+++ trunk/target/packages/ch7024ctrl/Makefile 2007-08-17 17:21:47 UTC (rev 623)
@@ -0,0 +1,59 @@
+#
+# Makefile for the Armadeus SVIDEO controler CH7024
+#
+
+CFLAGS = -Wall -O
+
+INCLUDES =
+
+PWD := $(shell pwd)
+
+#HEADERS =
+
+SOURCES = ch7024.c
+OBJECTS = ch7024.o
+
+TARGET = ch7024
+
+
+####### Implicit rules
+
+.SUFFIXES: .cpp .cxx .cc .C .c
+
+.cpp.o:
+ $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
+
+.cxx.o:
+ $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
+
+.cc.o:
+ $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
+
+.C.o:
+ $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
+
+.c.o:
+ $(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
+
+
+####### Build rules
+
+
+$(TARGET): $(OBJECTS) Makefile $(HEADERS)
+ @echo
+ @echo "Building I2C dac test programm..."
+ $(CC) $(OBJECTS) $(CFLAGS) $(INCLUDES) -o $(TARGET)
+
+
+all: $(TARGET)
+
+clean:
+ -rm -f $(TARGET)
+ -rm -f *.o *~ core
+
+ch7024.o: ch7024.c ch7024.h Makefile
+ @echo
+ $(CC) -c $(CFLAGS) $(INCLUDES) ch7024.c
+
+
+
Added: trunk/target/packages/ch7024ctrl/ch7024.c
===================================================================
--- trunk/target/packages/ch7024ctrl/ch7024.c (rev 0)
+++ trunk/target/packages/ch7024ctrl/ch7024.c 2007-08-17 17:21:47 UTC (rev 623)
@@ -0,0 +1,264 @@
+/*
+** THE ARMADEUS PROJECT
+**
+** Copyright (C) year The source forge armadeus project team
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** ch7024: manage the Svideo output controller CH7024
+**
+** author: th...@us...
+*/
+
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <linux/i2c.h> // seems to make trouble during compiling ....
+#include <linux/i2c-dev.h>
+
+#include <sys/ioctl.h>
+#include "ch7024.h"
+//#define DEBUG_CH7024 1
+
+#define VERSION 0.1f
+#define CONF_FILE "ch7024.conf"
+#define MAX_DUMP_LINE 100
+/****************************************************************************************************************************/
+
+/* MENU */
+void usage()
+{
+ printf ("\nCH7024 utility ver %0.1f. Armadeus\n", VERSION);
+ printf ("q: quit\n");
+ printf ("m: modify\n");
+ printf ("d: dump all\n");
+ printf ("s: save\n");
+ printf ("l: load\n");
+ printf ("other: menu\n");
+}
+
+/* Read a byte on the I2C bus
+ @param fd: file descriptor of the device
+ @param reg: registre to access
+ @param buf: buffer used to store the result
+ @return : -1 in case of error otherwise 0
+ */
+int read_byte( int fd, unsigned char reg, unsigned char *buf )
+{
+ struct i2c_msg msg = { CH7024_I2C_SLAVE_ADDR, 0, 1, buf };
+ struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
+
+ buf[0] = reg; // select reg to read
+ if ( ioctl( fd, I2C_RDWR, &rdwr ) < 0 ){
+ printf("Write error\n");
+ return -1;
+ }
+ msg.flags = I2C_M_RD; // read
+
+ if ( ioctl( fd, I2C_RDWR, &rdwr ) < 0 ){
+ printf("Read error\n");
+ return -1;
+ }
+ return 0;
+}
+
+/* Write a byte on the I2C bus
+ @param fd: file descriptor of the device
+ @param reg: registre to access
+ @param value: value to write
+ @return : -1 in case of error otherwise 0
+ */
+int write_byte(int fd, unsigned char reg, unsigned char value)
+{
+ unsigned char buf[2] = {reg,value};
+ struct i2c_msg msg = { CH7024_I2C_SLAVE_ADDR, 0, sizeof(buf), buf };
+ struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
+
+#ifdef DEBUG_CH7024
+ printf("write ref %02X value %02X\n",reg, value);
+#endif
+ if ( ioctl( fd, I2C_RDWR, &rdwr ) < 0 ){
+ printf("Write error\n");
+ return -1;
+ }
+ return 0;
+}
+
+/* dump the register values on the screen if destFile is NULL or in a file
+ @param string: string to dump
+ @param destFile: file in which to write
+ */
+ void dump2Output(char* string, FILE* destFile)
+{
+ if( destFile == NULL )
+ printf("%s", string);
+ else
+ fprintf(destFile,"%s", string);
+}
+
+/* dump the register values on the screen if destFile is NULL or in a file
+ @param fd: file descriptor of the CH7024
+ @param destFile: file in which to write if used otherwise ""
+ */
+void dump(int fd, FILE* destFile)
+{
+ int i,j, address;
+ unsigned char buf[2];
+ char dumpString[MAX_DUMP_LINE];
+
+ if( destFile == NULL )
+ printf("Ad:Va\tRe:Va\tRe:Va\tRe:Va\n");
+ for( i = 0; i<14; i++ ){
+ for( j = 0; j<4; j++ ){
+ address = i*4+j;
+ if( !read_byte( fd, address, buf ) ){
+ sprintf( dumpString, "%02X:%02X\t", address, buf[0] );
+ dump2Output( dumpString, destFile );
+ }
+ }
+ dump2Output( "\n", destFile );
+ }
+ if( !read_byte( fd, DAC_TRIMMING_CMD, buf ) ){
+ sprintf( dumpString, "%02X:%02X\t", DAC_TRIMMING_CMD, buf[0] );
+ dump2Output( dumpString, destFile );
+ }
+ if( !read_byte( fd, DATA_IO_CMD, buf ) ){
+ sprintf( dumpString, "%02X:%02X\t", DATA_IO_CMD, buf[0] );
+ dump2Output( dumpString, destFile );
+ }
+ if( !read_byte( fd, ATTACHED_DISPLAY, buf ) ){
+ sprintf( dumpString, "%02X:%02X\n", ATTACHED_DISPLAY, buf[0] );
+ dump2Output( dumpString, destFile );
+ }
+}
+
+/* load the CH7024 registers with the values contained in the given file
+ @param fd: file descriptor of the CH7024
+ @param fileName: file containing the values. If "" then the name has to be entered
+ */
+void load( int fd, char* fileName )
+{
+ char line[MAX_DUMP_LINE];
+ FILE *fd_conf = NULL;
+ int addr1, addr2, addr3, addr4;
+ int val1, val2, val3, val4;
+ int nb;
+
+ if( strlen(fileName) == 0 ){
+ printf("Enter file name: ");
+ gets(fileName);
+ }
+ if ((fd_conf = fopen(fileName,"r")) < 0){
+ perror("Open error: ");
+ exit (1);
+ }
+ while(fgets(line, MAX_DUMP_LINE, fd_conf) != NULL){
+ nb = sscanf(line,"%2X%*c%2X%2X%*c%2X%2X%*c%2X%2X%*c%2X",
+ &addr1,&val1,&addr2,&val2,&addr3,&val3,&addr4,&val4 );
+ if(nb>=2)
+ write_byte (fd, addr1, val1);
+ if(nb>=4)
+ write_byte (fd, addr2, val2);
+ if(nb>=6)
+ write_byte (fd, addr3, val3);
+ if(nb>=8)
+ write_byte (fd, addr4, val4);
+ }
+ if(fd_conf != NULL)
+ fclose(fd_conf);
+}
+
+
+int main(int argc, char *argv[])
+{
+ int fd; // CH7024 file descriptor
+ FILE *fd_conf = NULL; // config file
+ char string[10]; // user input string
+ unsigned char buf[2]; // buf to store I2C command/data
+ int regAddr;
+ int regValue;
+
+ if ( argc >2 ){ // too many args
+ usage();
+ exit(1);
+ }
+
+ // open I2C /dev
+ if ((fd = open("/dev/i2c-0",O_RDWR)) < 0){
+ perror("Open error: ");
+ exit (1);
+ }
+
+ // configure I2C_SLAVE
+ if ( ioctl(fd ,/*I2C_SLAVE*/ 0x703, CH7024_I2C_SLAVE_ADDR) < 0){
+ perror("Ioctl error: ");
+ exit (1);
+ }
+
+ // check CH7024 presence
+ if( !read_byte( fd, DEVICE_ID_CMD, buf ) ){
+ if( buf[0] != CH7024_ID ){
+ printf("CH7024 found. Exit\n");
+ exit(1);
+ }
+ }
+
+ if ( argc == 2 ){ // read data from file
+ load(fd,argv[1]);
+ exit(0);
+ }
+
+ usage();
+ while(1){
+ gets(string);
+ if(string[0] == 'q') // Exit
+ exit(0);
+ else if (string[0] == 'm'){ // Modify registers
+ printf("reg addr (hex without 0x): ");
+ gets(string);
+ sscanf(string,"%2x", ®Addr);
+ printf("reg value (hex without 0x): ");
+ gets(string);
+ sscanf(string,"%2x", ®Value);
+ write_byte (fd, regAddr, regValue);
+ }
+ else if (string[0] == 'd') // Dump to screen
+ dump(fd,fd_conf);
+ else if (string[0] == 's'){ // Save to file
+ if ((fd_conf = fopen(CONF_FILE,"w")) < 0){
+ perror("Open error: ");
+ exit (1);
+ }
+ dump(fd,fd_conf);
+ if(fd_conf != NULL)
+ fclose(fd_conf);
+ }
+ else if (string[0] == 'l'){ // load from file
+ load(fd,"");
+ }
+ else
+ usage();
+ };
+
+ if(fd >= 0)
+ close(fd);
+
+ exit (0);
+}
Added: trunk/target/packages/ch7024ctrl/ch7024.h
===================================================================
--- trunk/target/packages/ch7024ctrl/ch7024.h (rev 0)
+++ trunk/target/packages/ch7024ctrl/ch7024.h 2007-08-17 17:21:47 UTC (rev 623)
@@ -0,0 +1,219 @@
+/*
+** THE ARMADEUS PROJECT
+**
+** Copyright (C) year The source forge armadeus project team
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** File : ch7024.h
+**
+** author: th...@us...
+*/
+
+
+// I2C slave Adresses
+
+#define CH7024_I2C_SLAVE_ADDR 0x76
+
+
+// command bytes
+#define DEVICE_ID_CMD 0x00
+#define REVISION_ID_CMD 0x01
+#define PAGE_SELECT_CMD 0X02
+#define RESET_CMD 0x03
+#define POWER_STATE_CMD 0x04
+#define TV_HUE_CMD 0x05
+#define TV_SAT_CMD 0x06
+#define TV_CONTRAST_CMD 0x07
+#define TV_BRIGHTNESS_CMD 0x08
+#define TV_SHARPNESS_CMD 0x09
+#define VIDEO_OUTPUT_FORMAT_CMD 0x0A
+#define CRYSTAL_CMD 0x0B
+#define INPUT_DATA_FORMAT1_CMD 0x0C
+#define INPUT_DATA_FORMAT2_CMD 0x0D
+#define SYNC_CMD 0x0E
+#define TV_FILTER1_CMD 0x0F
+#define TV_FILTER2_CMD 0x10
+#define INPUT_TIMING1_CMD 0x11
+#define INPUT_TIMING2_CMD 0x12
+#define INPUT_TIMING3_CMD 0x13
+#define INPUT_TIMING4_CMD 0x14
+#define INPUT_TIMING5_CMD 0x15
+#define INPUT_TIMING6_CMD 0x16
+#define INPUT_TIMING7_CMD 0x17
+#define INPUT_TIMING8_CMD 0x18
+#define INPUT_TIMING9_CMD 0x19
+#define INPUT_TIMING10_CMD 0x1A
+#define INPUT_TIMING11_CMD 0x1B
+#define BURST_AMPLITUDE_CMD 0x1C
+#define CLOCK_TREE_CMD 0x1D
+#define OUTPUT_TIMING1_CMD 0x1E
+#define OUTPUT_TIMING2_CMD 0x1F
+#define TV_VERTICAL_POS1_CMD 0x20
+#define TV_VERTICAL_POS2_CMD 0x21
+#define TV_HORIZONTAL_POS1_CMD 0x22
+#define TV_HORIZONTAL_POS2_CMD 0x23
+#define PCLK_CLOCK_DIVIDER1_CMD 0x24
+#define PCLK_CLOCK_DIVIDER2_CMD 0x25
+#define PCLK_CLOCK_DIVIDER3_CMD 0x26
+#define PCLK_CLOCK_DIVIDER4_CMD 0x27
+#define CLOCK_DIVIDER_NUM1_CMD 0x28
+#define CLOCK_DIVIDER_NUM2_CMD 0x29
+#define CLOCK_DIVIDER_NUM3_CMD 0x2A
+#define CLOCK_DIVIDER_DEN1_CMD 0x2B
+#define CLOCK_DIVIDER_DEN2_CMD 0x2C
+#define CLOCK_DIVIDER_DEN3_CMD 0x2D
+#define CLOCK_DIVIDER_INT_CMD 0x2E
+#define PLL_RATIO1_CMD 0x2F
+#define PLL_RATIO2_CMD 0x30
+#define PLL_RATIO3_CMD 0x31
+#define FSCI_ADJUSTMENT1_CMD 0x32
+#define FSCI_ADJUSTMENT2_CMD 0x33
+#define SUB_CARRIER_FREQ1_CMD 0x34
+#define SUB_CARRIER_FREQ2_CMD 0x35
+#define SUB_CARRIER_FREQ3_CMD 0x36
+#define SUB_CARRIER_FREQ4_CMD 0x37
+#define DAC_TRIMMING_CMD 0x62
+#define DATA_IO_CMD 0x63
+#define ATTACHED_DISPLAY 0x7E
+#define CBCR_INPUT_SWITCH_CMD 0x10 // second page
+
+
+#define CH7024_ID 0x45
+#define PAGE_SELECT_0 0
+#define PAGE_SELECT_1 1
+#define DAC_OUTPUT_OFF (0<<4)
+#define DAC_OUTPUT_CVBS (1<<4)
+#define DAC_OUTPUT_SVIDEO (2<<4)
+#define OUTPUT_FORMAT__NTSC_M 0
+#define OUTPUT_FORMAT__NTSC_J 1
+#define OUTPUT_FORMAT__NTSC_443 2
+#define OUTPUT_FORMAT__PAL 3
+#define OUTPUT_FORMAT__PAL_M 4
+#define OUTPUT_FORMAT__PAL_N 5
+#define OUTPUT_FORMAT__PAL_NC 6
+#define OUTPUT_FORMAT__PAL_60 7
+
+
+
+
+
+typedef struct
+{
+ unsigned char resetib : 1;
+ unsigned char resetdb : 1;
+ unsigned char spare : 8;
+} reset_reg;
+
+typedef struct
+{
+ unsigned char fdp : 1;
+ unsigned char reserved : 1;
+ unsigned char ppdac : 2;
+ unsigned char spare : 8;
+} powerState_reg;
+
+typedef struct
+{
+ unsigned char vos : 4;
+ unsigned char dacsw : 2;
+ unsigned char svideo : 1;
+ unsigned char tv_bp : 1;
+} videoOutputFormat_reg;
+
+typedef struct
+{
+ unsigned char xtal : 4;
+ unsigned char spare : 3;
+ unsigned char xtalsel : 1;
+} crystal_reg;
+
+typedef struct
+{
+ unsigned char multi : 1;
+ unsigned char spare : 5;
+ unsigned char dcksel : 1;
+ unsigned char ducvbs : 1;
+} inputDataFormat1_reg;
+
+typedef struct
+{
+ unsigned char idf : 3;
+ unsigned char swap : 3;
+ unsigned char reverse : 1;
+ unsigned char high : 1;
+} inputDataFormat2_reg;
+
+typedef struct
+{
+ unsigned char diffen : 1;
+ unsigned char syo : 1;
+ unsigned char vpo : 1;
+ unsigned char hpo : 1;
+ unsigned char flds : 1;
+ unsigned char fldsen : 1;
+ unsigned char des : 1;
+ unsigned char pouten : 1;
+} sync_reg;
+
+typedef struct
+{
+ unsigned char ycv : 2;
+ unsigned char ysv : 2;
+ unsigned char cbw : 1;
+ unsigned char cfbp : 1;
+ unsigned char cfrb : 1;
+ unsigned char xch : 1;
+} tvFiler1_reg;
+
+typedef struct
+{
+ unsigned char aff : 3;
+ unsigned char spare : 5;
+} tvFiler2_reg;
+
+typedef struct
+{
+ unsigned char hai : 3;
+ unsigned char hti : 3;
+ unsigned char reserved : 1;
+ unsigned char hvauto : 1;
+} inputTiming1_reg;
+
+typedef struct
+{
+ unsigned char ho : 3;
+ unsigned char hw : 2;
+ unsigned char spare : 3;
+} inputTiming4_reg;
+
+typedef struct
+{
+ unsigned char ho : 2;
+ unsigned char vti : 2;
+ unsigned char vo : 2;
+ unsigned char spare : 2;
+} inputTiming7_reg;
+
+typedef struct
+{
+ unsigned char dotcr13 : 1;
+ unsigned char bsdadj : 3;
+ unsigned char aciv : 1;
+ unsigned char spare : 3;
+} burstAmplitude_reg;
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|