DPC Module:DPC Console under Linux

From LEXWiKi

(Difference between revisions)
Jump to: navigation, search
Line 53: Line 53:
typedef unsigned short WORD;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned int DWORD;
-
#define m_SMBusMapIoAddr 0x0500
+
#define g_SMBusMapIoAddr 0x0500
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
-
#define HST_STS 0x00 // SMBus Host Status Register Offset
+
#define SMBHSTSTS 0x00 // SMBus Host Status Register Offset
-
#define HST_CNT 0x02 // SMBus Host Contorl Register Offset
+
#define SMBHSTCNT 0x02 // SMBus Host Contorl Register Offset
-
#define HST_CMD 0x03 // SMBus Host Command Register Offset
+
#define SMBHSTCMD 0x03 // SMBus Host Command Register Offset
-
#define XMIT_SLVA 0x04 // SMBus Host Address Register Offset
+
#define SMBHSTADD 0x04 // SMBus Host Address Register Offset
-
#define HST_D0 0x05 // SMBus Host Data0 Register Offset
+
#define SMBHSTDAT0 0x05 // SMBus Host Data0 Register Offset
 +
 
 +
#define SMBHSTCNT_START 0x40 // SMBus Host Contorl -> 0100 0000 Start
 +
#define SMBHSTCNT_BYTE 0x08 // SMBus Host Contorl -> 0000 1000 Byte Data
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
-
#define SADD 0xb0
+
#define DPC_ADD 0xb0
-
#define PWMFeq 0x01
+
#define PWMFeq 0x01
-
#define PWMDuty 0x02
+
#define PWMDuty 0x02
=== SMBusIoWrite ===
=== SMBusIoWrite ===
-
void SMBusIoWrite(BYTE byteOffset,BYTE byteData)
+
void SMBusIoWrite(BYTE byteOffset, BYTE byteData)
{
{
-
outb( byteData , m_SMBusMapIoAddr + byteOffset);
+
outb( byteData , (g_SMBusMapIoAddr + byteOffset) );
}
}
Line 75: Line 78:
{
{
DWORD dwAddrVal;
DWORD dwAddrVal;
-
dwAddrVal = inb(m_SMBusMapIoAddr + byteOffset);
+
dwAddrVal = inb((g_SMBusMapIoAddr + byteOffset));
return (BYTE)(dwAddrVal & 0x0FF);
return (BYTE)(dwAddrVal & 0x0FF);
 +
}
 +
 +
=== SMBus_WriteByte ===
 +
bool SMBus_WriteByte(BYTE byteSlave, BYTE pCmd, BYTE pByte)
 +
{
 +
SMBusIoWrite(SMBHSTADD , byteSlave & ~1 );
 +
SMBusIoWrite(SMBHSTCMD , pCmd );
 +
SMBusIoWrite(SMBHSTDAT0 , pByte );
 +
SMBusIoWrite(SMBHSTCNT , SMBHSTCNT_START | SMBHSTCNT_BYTE);
 +
return true;
}
}
=== SetDutyCycle ===
=== SetDutyCycle ===
-
void SetDutyCycle(gint iDutyValue)
+
void SetDutyCycle(gint nDutyValue)
{
{
-
DWORD dwPortVal;
+
SMBus_WriteByte( DPC_ADD, PWMDuty, (BYTE)nDutyValue );
-
SMBusIoWrite(HST_STS, 0xFE);
+
-
SMBusIoWrite(XMIT_SLVA, SADD);
+
-
SMBusIoWrite(HST_CMD, PWMDuty);
+
-
dwPortVal = SMBusIoRead (HST_STS);
+
-
dwPortVal = dwPortVal & 0x01;
+
-
SMBusIoWrite(HST_D0, iDutyValue);
+
-
SMBusIoWrite(HST_CNT, 0x48);
+
}
}
=== SetFrequency ===
=== SetFrequency ===
-
void SetFrequency(gint iFrequency)
+
void SetFrequency(gint nFrequency)
{
{
-
DWORD dwPortVal;
+
SMBus_WriteByte( DPC_ADD, PWMFeq, (BYTE)nFrequency );
-
SMBusIoWrite(HST_STS, 0xFE);
+
-
SMBusIoWrite(XMIT_SLVA, SADD);
+
-
SMBusIoWrite(HST_CMD, PWMFeq);
+
-
dwPortVal = SMBusIoRead (HST_STS);
+
-
dwPortVal = dwPortVal & 0x01;
+
-
SMBusIoWrite(HST_D0, iFrequency);
+
-
SMBusIoWrite(HST_CNT, 0x48);
+
}
}

Revision as of 10:39, 29 May 2020

Contents

The Sample code source you can download form

Binary file:
???DPCv4.2.2W_bin.zip
???DPC_LightSensor_4.2.2W_bin.zip

How to compile source code

  • Compile source code with Code::Blocks.
    1. Download and install the Code::Block with command "apt-get install codeblocks".
    2. Open an exist project(DPC_Console.cbp) in Code::Blocks, click the compile button.


  • Compile source code with "make"
    1. cd DPC_Console
    2. key in command "make".
   Before you make it, you need to install : "make" "make-guile" "pkg-config" "gcc" "gtk2.0"

How to use the DPC console application

  1. Install resource before execute application. ".\install.sh"
  2. Execute the application. ".\DPC_Console".
    Image:DPC_Info_1.jpg
  3. Set brightness from 10 to 100 with command "-d". Ex: Set brightness 50 with command "-d50".
  4. Select panel what you try to adjust with command "-t". Ex: Select 200 Hz with command "-t0".
    (0 = 200 Hz, 1 = 275 Hz, 2 = 380 Hz, 3 = 20 Hz, 4 = 25 Hz)
  5. Select range what you add / subtract brightness with command "-r". Ex: Select 10 Sz with command "-r4".
    (0 = 1 Sz, 1 = 2 Sz, 2 = 3 Sz, 3 = 5 Sz, 4 = 10 Sz)
  6. Dump DPC information with command "-i".
  7. Print DPC help menu with command "-h".
  8. Step add / subtract brightness with keyboard : "Up arrow key" / "Down arrow key".
  9. Turn off screen backlight with command "-f". Duty cycle value will be modify to 0.
  10. Default hot key to turn on screen backlight. With hot key "Ctrl + n". Duty cycle value will be modify to 50.
  11. Quit DPC application with command "Exit".

How to use light sensor module

  1. Print light sensor help menu with command "-hl".
  2. Turn on/off light sensor to modify duty cycle value automaticaly. With command "-la". Ex: Turn off light sensor active with command "-la0".
    (0 = Off, 1 = On)
    Attention: If active light sensor module, GPIO module will be turned off.
  3. Select light sensor mode with command "-lm". Ex: Select ALS mode with command "-lm0".
    (0 = Measures ALS continuously, 1 = Measures IR continuously)
  4. Select light sensor range with command "-lr". Ex: Select range 1000 with command "-lr0".
    (0 = 1000, 1 = 4000, 2 = 16000, 3 = 64000)
  5. Turn on/off using custom bounding range with command "-lc". Ex: Turn on custom bounding range with command "-lc1".
    (0 = Use, 1 = Not use)
  6. Set a custom value for light sensor maximum range with command "-lmax". Ex: Set 100 for maximum range with command "-lmax9".
    (0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100)
  7. Set a custom value for light sensor median range with command "-lmed". Ex: Set 50 for median range with command "-lmed4".
    (0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100)
  8. Set a custom value for light sensor minimum range with command "-lmin". Ex: Set 10 for minimum range with command "-lmin0".
    (0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100)

How to use GPIO module

  1. Print GPIO module help menu with command "-hg".
  2. Turn on/off GPIO module to modify duty cycle value. With command "-ga". Ex: Turn off GPIO active with command "-ga0".
    (0 = Off, 1 = On)
    Attention: If active GPIO module, light sensor module will be turned off.

Sample code Introduction

Define SMBus register

 typedef unsigned char  BYTE;
 typedef unsigned short WORD;
 typedef unsigned int   DWORD;
 #define g_SMBusMapIoAddr 0x0500
 //----------------------------------------------------------------------------------
 #define SMBHSTSTS     0x00	// SMBus Host Status        Register Offset
 #define SMBHSTCNT     0x02	// SMBus Host Contorl       Register Offset
 #define SMBHSTCMD     0x03	// SMBus Host Command 	    Register Offset
 #define SMBHSTADD     0x04	// SMBus Host Address	    Register Offset
 #define SMBHSTDAT0    0x05	// SMBus Host Data0         Register Offset
 #define SMBHSTCNT_START 0x40   // SMBus Host Contorl -> 0100 0000 Start
 #define SMBHSTCNT_BYTE  0x08   // SMBus Host Contorl -> 0000 1000 Byte Data
 //----------------------------------------------------------------------------------
 #define DPC_ADD       0xb0
 #define PWMFeq        0x01
 #define PWMDuty       0x02

SMBusIoWrite

 void SMBusIoWrite(BYTE byteOffset, BYTE byteData)
 {
     outb( byteData , (g_SMBusMapIoAddr + byteOffset) );
 }

SMBusIoRead

 BYTE SMBusIoRead(BYTE byteOffset)
 {
     DWORD dwAddrVal;
     dwAddrVal = inb((g_SMBusMapIoAddr + byteOffset));
     return (BYTE)(dwAddrVal & 0x0FF);
 }

SMBus_WriteByte

 bool SMBus_WriteByte(BYTE byteSlave, BYTE pCmd, BYTE pByte)
 {
     SMBusIoWrite(SMBHSTADD  , byteSlave & ~1 );
     SMBusIoWrite(SMBHSTCMD  , pCmd );
     SMBusIoWrite(SMBHSTDAT0 , pByte );
     SMBusIoWrite(SMBHSTCNT  , SMBHSTCNT_START | SMBHSTCNT_BYTE);
     return true;
 }

SetDutyCycle

 void SetDutyCycle(gint nDutyValue)
 {
     SMBus_WriteByte( DPC_ADD, PWMDuty, (BYTE)nDutyValue );
 }

SetFrequency

 void SetFrequency(gint nFrequency)
 {
     SMBus_WriteByte( DPC_ADD, PWMFeq, (BYTE)nFrequency );
 }
Personal tools