BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mangoh-drivers
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
mangoh-drivers
Commits
7ebbff9e
Commit
7ebbff9e
authored
Nov 22, 2016
by
David Frey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup formatting/naming of battery charger demo
parent
28531fa7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
47 deletions
+46
-47
batteryReading.c
...ryChargerReading/batteryReadingComponent/batteryReading.c
+46
-47
No files found.
samples/tutorials/hardwareInterfaces/i2c/BatteryChargerReading/batteryReadingComponent/batteryReading.c
View file @
7ebbff9e
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#include "interfaces.h"
#include "interfaces.h"
#include <linux/i2c-dev-user.h>
#include <linux/i2c-dev-user.h>
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-
//* Static functions
//* Static functions
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
...
@@ -66,6 +66,7 @@ static int I2cAccessBusAddr
...
@@ -66,6 +66,7 @@ static int I2cAccessBusAddr
if
(
ioctl
(
fd
,
I2C_SLAVE_FORCE
,
i2cAddr
)
<
0
)
if
(
ioctl
(
fd
,
I2C_SLAVE_FORCE
,
i2cAddr
)
<
0
)
{
{
LE_ERROR
(
"Could not set address to 0x%02x: %s"
,
i2cAddr
,
strerror
(
errno
));
LE_ERROR
(
"Could not set address to 0x%02x: %s"
,
i2cAddr
,
strerror
(
errno
));
close
(
fd
);
return
LE_FAULT
;
return
LE_FAULT
;
}
}
...
@@ -135,34 +136,35 @@ static le_result_t SmbusWriteReg
...
@@ -135,34 +136,35 @@ static le_result_t SmbusWriteReg
uint8_t
data
////< Data to write to the given register
uint8_t
data
////< Data to write to the given register
)
)
{
{
int
i2cFd
=
I2cAccessBusAddr
(
i2cBus
,
i2cAddr
);
int
i2cFd
=
I2cAccessBusAddr
(
i2cBus
,
i2cAddr
);
if
(
i2cFd
==
LE_FAULT
)
if
(
i2cFd
==
LE_FAULT
)
{
{
LE_ERROR
(
"failed to open i2c bus %d for access to address %d"
,
i2cBus
,
i2cAddr
);
LE_ERROR
(
"failed to open i2c bus %d for access to address %d"
,
i2cBus
,
i2cAddr
);
return
LE_FAULT
;
return
LE_FAULT
;
}
}
le_result_t
result
;
le_result_t
result
;
const
int
writeResult
=
i2c_smbus_write_byte_data
(
i2cFd
,
reg
,
data
);
const
int
writeResult
=
i2c_smbus_write_byte_data
(
i2cFd
,
reg
,
data
);
if
(
writeResult
<
0
)
if
(
writeResult
<
0
)
{
{
LE_ERROR
(
"smbus write failed with error %d"
,
writeResult
);
LE_ERROR
(
"smbus write failed with error %d"
,
writeResult
);
result
=
LE_FAULT
;
result
=
LE_FAULT
;
}
}
else
else
{
{
LE_DEBUG
(
"SMBUS Write addr 0x%x, reg=0x%x, data=0x%x"
,
i2cAddr
,
reg
,
data
);
LE_DEBUG
(
"SMBUS Write addr 0x%x, reg=0x%x, data=0x%x"
,
i2cAddr
,
reg
,
data
);
result
=
LE_OK
;
result
=
LE_OK
;
}
}
close
(
i2cFd
);
close
(
i2cFd
);
return
result
;
return
result
;
}
}
/**-----------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Enables I2C Switch.
* Enables I2C Switch.
* This switch is used on mangoh to provide buffering on the i2c lines.
* This switch is used on mangoh to provide buffering on the i2c lines.
* If this is not enabled then you cannot access the Battery charger.
* If this is not enabled then you cannot access the Battery charger.
...
@@ -184,8 +186,7 @@ static void EnableI2cBus
...
@@ -184,8 +186,7 @@ static void EnableI2cBus
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
/**
* This functions reads and prints all the registers on an SMBUS write of a 1 byte register
* Reads and prints all the registers on an SMBUS write of a 1 byte register
*
*/
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
static
void
ReadBatteryChargerRegister
static
void
ReadBatteryChargerRegister
...
@@ -193,65 +194,64 @@ static void ReadBatteryChargerRegister
...
@@ -193,65 +194,64 @@ static void ReadBatteryChargerRegister
void
void
)
)
{
{
// read all ten registers of Battery charger with i2c address 0x71
// read all ten registers of Battery charger with i2c address 0x6B
uint8_t
R
egisterReading
;
uint8_t
r
egisterReading
;
SmbusReadReg
(
0
,
0x6B
,
0x00
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x00
,
&
r
egisterReading
);
LE_DEBUG
(
"Input Source Control value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Input Source Control value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x01
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x01
,
&
r
egisterReading
);
LE_DEBUG
(
"Power-On Configuration Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Power-On Configuration Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x02
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x02
,
&
r
egisterReading
);
LE_DEBUG
(
"Charge Current Control Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Charge Current Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x03
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x03
,
&
r
egisterReading
);
LE_DEBUG
(
"
Pre-Charge/Termination Current Control Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"
Pre-Charge/Termination Current Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x04
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x04
,
&
r
egisterReading
);
LE_DEBUG
(
"Charge Voltage Control Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Charge Voltage Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x05
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x05
,
&
r
egisterReading
);
LE_DEBUG
(
"Charge Termination/Timer Control Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Charge Termination/Timer Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x06
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x06
,
&
r
egisterReading
);
LE_DEBUG
(
"Thermal Regulation Control Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Thermal Regulation Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x07
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x07
,
&
r
egisterReading
);
LE_DEBUG
(
"Misc Operation Control Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Misc Operation Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x08
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x08
,
&
r
egisterReading
);
LE_DEBUG
(
"System Status Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"System Status Register value is %d"
,
r
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x09
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x09
,
&
r
egisterReading
);
LE_DEBUG
(
"Fault Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Fault Register value is %d"
,
r
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x0A
,
&
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x0A
,
&
r
egisterReading
);
LE_DEBUG
(
"Vendor / Part / Revision Status Register value is %d"
,
R
egisterReading
);
LE_DEBUG
(
"Vendor / Part / Revision Status Register value is %d"
,
r
egisterReading
);
}
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
/**
* This function changes battery charger output voltage and reads back register
* Changes battery charger output voltage and reads back register.
*
*/
*/
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-
static
void
OutputBatteryChargerVoltage
static
void
OutputBatteryChargerVoltage
(
(
void
void
...
@@ -267,9 +267,8 @@ static void OutputBatteryChargerVoltage
...
@@ -267,9 +267,8 @@ static void OutputBatteryChargerVoltage
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
/**
* Main program starts below
* Main program starts below
*
*/
*/
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-
COMPONENT_INIT
COMPONENT_INIT
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment