Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
9152e208
Commit
9152e208
authored
Aug 05, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished the fuel gauge driver. *Needs testing* with real battery: charge state, remaining time.
parent
f735d785
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
23 deletions
+26
-23
max17047.c
sw/common/drivers/max17047.c
+20
-15
max17047.h
sw/common/drivers/max17047.h
+6
-8
No files found.
sw/common/drivers/max17047.c
View file @
9152e208
...
...
@@ -90,37 +90,35 @@ uint16_t max17047_get_status(void)
uint16_t
max17047_get_voltage
(
void
)
{
uint16_t
vcell
;
uint16_t
tmp
;
max17047_read_reg
(
MAX17047_REG_VCELL
,
2
,
(
uint8_t
*
)
&
vcell
);
max17047_read_reg
(
MAX17047_REG_VCELL
,
2
,
(
uint8_t
*
)
&
tmp
);
// convert to mV
vcell
>>=
3
;
vcell
*=
5
;
uint32_t
volt
=
tmp
*
80
>>
10
;
return
vcell
;
return
(
uint16_t
)
volt
;
}
u
int16_t
max17047_get_current
(
void
)
int16_t
max17047_get_current
(
void
)
{
uint16_t
current
;
int16_t
tmp
;
max17047_read_reg
(
MAX17047_REG_CURRENT
,
2
,
(
uint8_t
*
)
&
current
);
max17047_read_reg
(
MAX17047_REG_CURRENT
,
2
,
(
uint8_t
*
)
&
tmp
);
// convert to mA
// TODO
uint32_t
curr
=
tmp
*
160
>>
10
;
return
curr
ent
;
return
curr
;
}
int8_t
max17047_get_temperature
(
void
)
{
// TODO requires configuration of TOFF and TGAIN registers
uint8_t
temperature
[
2
];
max17047_read_reg
(
MAX17047_REG_TEMPERATURE
,
2
,
temperature
);
return
temperature
[
0
];
return
temperature
[
1
];
}
uint8_t
max17047_get_charge
(
void
)
...
...
@@ -129,12 +127,19 @@ uint8_t max17047_get_charge(void)
max17047_read_reg
(
MAX17047_REG_SOC_REP
,
2
,
charge
);
return
charge
[
0
];
return
charge
[
1
];
}
uint16_t
max17047_get_time_left
(
void
)
{
// TODO see what is missing?
return
0
;
uint16_t
time
;
max17047_read_reg
(
MAX17047_REG_TIME_TO_EMPTY
,
2
,
&
time
);
// convert to minutes
time
>>=
5
;
time
*=
3
;
return
time
;
}
sw/common/drivers/max17047.h
View file @
9152e208
...
...
@@ -32,9 +32,6 @@
// Two-wire protocol address
#define MAX17047_ADDRESS 0x6C
// Sense resistor value (milliohm)
#define MAX17047_SENS_RES 10
// Register addresses
#define MAX17047_REG_STATUS 0x00
#define MAX17047_REG_VALRT_TH 0x01
...
...
@@ -141,7 +138,7 @@ uint8_t max17047_write_reg(uint8_t address, uint8_t length, uint8_t* buffer);
/**
* @brief Reads the status.
* @return Status of max17047.
* @return Status of max17047.
Check MAX170474_STS_xxx defines for details.
*/
uint16_t
max17047_get_status
(
void
);
...
...
@@ -152,10 +149,11 @@ uint16_t max17047_get_status(void);
uint16_t
max17047_get_voltage
(
void
);
/**
* @brief Reads current from the battery.
* @return Current (in milliampers).
* @brief Reads current drawn from the battery.
* @return Current (in milliampers). Negative values represent discharging,
* positive values represent charging.
*/
u
int16_t
max17047_get_current
(
void
);
int16_t
max17047_get_current
(
void
);
/**
* @brief Reads temperature sensor.
...
...
@@ -164,7 +162,7 @@ uint16_t max17047_get_current(void);
int8_t
max17047_get_temperature
(
void
);
/**
* @brief Reads
the current
state of charge.
* @brief Reads state of charge.
* @return State of charge (expressed as percentage: 0-100).
*/
uint8_t
max17047_get_charge
(
void
);
...
...
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