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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
55 deletions
+54
-55
batteryReading.c
...ryChargerReading/batteryReadingComponent/batteryReading.c
+54
-55
No files found.
samples/tutorials/hardwareInterfaces/i2c/BatteryChargerReading/batteryReadingComponent/batteryReading.c
View file @
7ebbff9e
...
...
@@ -13,7 +13,7 @@
#include "interfaces.h"
#include <linux/i2c-dev-user.h>
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-
//* Static functions
//--------------------------------------------------------------------------------------------------
...
...
@@ -66,6 +66,7 @@ static int I2cAccessBusAddr
if
(
ioctl
(
fd
,
I2C_SLAVE_FORCE
,
i2cAddr
)
<
0
)
{
LE_ERROR
(
"Could not set address to 0x%02x: %s"
,
i2cAddr
,
strerror
(
errno
));
close
(
fd
);
return
LE_FAULT
;
}
...
...
@@ -130,39 +131,40 @@ static le_result_t SmbusReadReg
static
le_result_t
SmbusWriteReg
(
uint8_t
i2cBus
,
////< I2C bus to perform the write on
uint8_t
i2cAddr
,
////< I2C device
address
uint8_t
i2cAddr
,
////< I2C device address
uint8_t
reg
,
////< Register within the I2C device to write to
uint8_t
data
////< Data to write to the given register
)
{
int
i2cFd
=
I2cAccessBusAddr
(
i2cBus
,
i2cAddr
);
int
i2cFd
=
I2cAccessBusAddr
(
i2cBus
,
i2cAddr
);
if
(
i2cFd
==
LE_FAULT
)
{
LE_ERROR
(
"failed to open i2c bus %d for access to address %d"
,
i2cBus
,
i2cAddr
);
return
LE_FAULT
;
}
if
(
i2cFd
==
LE_FAULT
)
{
LE_ERROR
(
"failed to open i2c bus %d for access to address %d"
,
i2cBus
,
i2cAddr
);
return
LE_FAULT
;
}
le_result_t
result
;
le_result_t
result
;
const
int
writeResult
=
i2c_smbus_write_byte_data
(
i2cFd
,
reg
,
data
);
if
(
writeResult
<
0
)
{
LE_ERROR
(
"smbus write failed with error %d"
,
writeResult
);
result
=
LE_FAULT
;
}
else
{
LE_DEBUG
(
"SMBUS Write addr 0x%x, reg=0x%x, data=0x%x"
,
i2cAddr
,
reg
,
data
);
result
=
LE_OK
;
}
const
int
writeResult
=
i2c_smbus_write_byte_data
(
i2cFd
,
reg
,
data
);
if
(
writeResult
<
0
)
{
LE_ERROR
(
"smbus write failed with error %d"
,
writeResult
);
result
=
LE_FAULT
;
}
else
{
LE_DEBUG
(
"SMBUS Write addr 0x%x, reg=0x%x, data=0x%x"
,
i2cAddr
,
reg
,
data
);
result
=
LE_OK
;
}
close
(
i2cFd
);
close
(
i2cFd
);
return
result
;
return
result
;
}
/**-----------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Enables I2C Switch.
* 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.
...
...
@@ -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
...
...
@@ -193,65 +194,64 @@ static void ReadBatteryChargerRegister
void
)
{
// read all ten registers of Battery charger with i2c address 0x71
uint8_t
R
egisterReading
;
// read all ten registers of Battery charger with i2c address 0x6B
uint8_t
r
egisterReading
;
SmbusReadReg
(
0
,
0x6B
,
0x00
,
&
R
egisterReading
);
LE_DEBUG
(
"Input Source Control value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x00
,
&
r
egisterReading
);
LE_DEBUG
(
"Input Source Control value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x01
,
&
R
egisterReading
);
LE_DEBUG
(
"Power-On Configuration Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x01
,
&
r
egisterReading
);
LE_DEBUG
(
"Power-On Configuration Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x02
,
&
R
egisterReading
);
LE_DEBUG
(
"Charge Current Control Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x02
,
&
r
egisterReading
);
LE_DEBUG
(
"Charge Current Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x03
,
&
R
egisterReading
);
LE_DEBUG
(
"
Pre-Charge/Termination Current Control Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x03
,
&
r
egisterReading
);
LE_DEBUG
(
"
Pre-Charge/Termination Current Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x04
,
&
R
egisterReading
);
LE_DEBUG
(
"Charge Voltage Control Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x04
,
&
r
egisterReading
);
LE_DEBUG
(
"Charge Voltage Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x05
,
&
R
egisterReading
);
LE_DEBUG
(
"Charge Termination/Timer Control Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x05
,
&
r
egisterReading
);
LE_DEBUG
(
"Charge Termination/Timer Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x06
,
&
R
egisterReading
);
LE_DEBUG
(
"Thermal Regulation Control Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x06
,
&
r
egisterReading
);
LE_DEBUG
(
"Thermal Regulation Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x07
,
&
R
egisterReading
);
LE_DEBUG
(
"Misc Operation Control Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x07
,
&
r
egisterReading
);
LE_DEBUG
(
"Misc Operation Control Register value is %d"
,
r
egisterReading
);
sleep
(
1
);
SmbusReadReg
(
0
,
0x6B
,
0x08
,
&
R
egisterReading
);
LE_DEBUG
(
"System Status Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x08
,
&
r
egisterReading
);
LE_DEBUG
(
"System Status Register value is %d"
,
r
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x09
,
&
R
egisterReading
);
LE_DEBUG
(
"Fault Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x09
,
&
r
egisterReading
);
LE_DEBUG
(
"Fault Register value is %d"
,
r
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x0A
,
&
R
egisterReading
);
LE_DEBUG
(
"Vendor / Part / Revision Status Register value is %d"
,
R
egisterReading
);
SmbusReadReg
(
0
,
0x6B
,
0x0A
,
&
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
(
void
...
...
@@ -260,16 +260,15 @@ static void OutputBatteryChargerVoltage
uint8_t
OutputVoltage
;
SmbusWriteReg
(
0
,
0x6B
,
0x04
,
0xBA
);
SmbusReadReg
(
0
,
0x6B
,
0x04
,
&
OutputVoltage
);
SmbusReadReg
(
0
,
0x6B
,
0x04
,
&
OutputVoltage
);
LE_DEBUG
(
"Output voltage is set to %d"
,
OutputVoltage
);
}
//--------------------------------------------------------------------------------------------------
/**
* Main program starts below
*
*/
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-
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