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
98f36877
Commit
98f36877
authored
Dec 09, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
charger: Interrupt driven status update.
parent
3923d5ed
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
0 deletions
+129
-0
charger.c
sw/common/drivers/charger.c
+55
-0
charger.h
sw/common/drivers/charger.h
+48
-0
event.h
sw/common/event.h
+12
-0
Makefile
sw/freewatch/Makefile
+1
-0
irq_dispatcher.c
sw/freewatch/src/irq_dispatcher.c
+11
-0
main.c
sw/freewatch/src/main.c
+2
-0
No files found.
sw/common/drivers/charger.c
0 → 100644
View file @
98f36877
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* 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 3
* 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, you may find one here:
* http://www.gnu.org/licenses/gpl-3.0-standalone.html
* or you may search the http://www.gnu.org website for the version 3 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Charger driver (bq24072).
*/
#include "charger.h"
#include <em_gpio.h>
// Charger detected (active low)
#define BC_CHG_PORT gpioPortE
#define BC_CHG_PIN 9
// Power good (active low)
#define BC_PGOOD_PORT gpioPortA
#define BC_PGOOD_PIN 15
void
charger_init
(
void
)
{
GPIO_PinModeSet
(
BC_CHG_PORT
,
BC_CHG_PIN
,
gpioModeInputPull
,
1
);
GPIO_PinModeSet
(
BC_PGOOD_PORT
,
BC_PGOOD_PIN
,
gpioModeInputPull
,
1
);
GPIO_IntConfig
(
BC_CHG_PORT
,
BC_CHG_PIN
,
true
,
true
,
true
);
GPIO_IntConfig
(
BC_PGOOD_PORT
,
BC_PGOOD_PIN
,
true
,
true
,
true
);
}
int
charger_power_good
(
void
)
{
return
!
GPIO_PinInGet
(
BC_PGOOD_PORT
,
BC_PGOOD_PIN
);
}
int
charger_active
(
void
)
{
return
!
GPIO_PinInGet
(
BC_CHG_PORT
,
BC_CHG_PIN
);
}
sw/common/drivers/charger.h
0 → 100644
View file @
98f36877
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* 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 3
* 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, you may find one here:
* http://www.gnu.org/licenses/gpl-3.0-standalone.html
* or you may search the http://www.gnu.org website for the version 3 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Charger driver (bq24072).
*/
#ifndef CHARGER_H
#define CHARGER_H
/**
* @brief Initializes I/O interrupts to indicate the charger state changes.
*/
void
charger_init
(
void
);
/**
* @brief Returns the Power Good flag state.
* @return 0 when the flag is not active, >0 otherwise.
*/
int
charger_power_good
(
void
);
/**
* @brief Returns true if charger is charging.
* @return 0 if charger is not active, >0 otherwise.
*/
int
charger_active
(
void
);
#endif
/* CHARGER_H */
sw/common/event.h
View file @
98f36877
...
...
@@ -38,6 +38,7 @@ enum event_type {
SENSOR_INT
,
RTC_TICK
,
BATTERY_STATUS
,
CHARGER
,
GPS_TICK
,
GPS_OFF
};
...
...
@@ -52,6 +53,16 @@ enum button_name {
BUT_BR
// bottom right
};
/**
* Battery charger states.
*/
enum
charger_state
{
CHARGING
,
NOT_CHARGING
,
POWER_GOOD
,
POWER_BAD
};
/**
* Sensor interrupts.
*/
...
...
@@ -78,6 +89,7 @@ struct event {
enum
button_name
button
;
enum
sensor_type
sensor
;
struct
battery_info
battery
;
enum
charger_state
charger
;
}
data
;
};
...
...
sw/freewatch/Makefile
View file @
98f36877
...
...
@@ -162,6 +162,7 @@ C_SRC += \
../common/drivers/vibra.c
\
../common/drivers/lsm303c.c
\
../common/drivers/gps.c
\
../common/drivers/charger.c
\
../common/gfx/font_helv11.c
\
../common/gfx/font_helv17.c
\
../common/gfx/font_helv17b.c
\
...
...
sw/freewatch/src/irq_dispatcher.c
View file @
98f36877
...
...
@@ -29,6 +29,7 @@
#include <event.h>
#include <drivers/rtc.h>
#include <drivers/charger.h>
#include <em_gpio.h>
#include <em_burtc.h>
...
...
@@ -66,6 +67,16 @@ static portBASE_TYPE gpio_irq_dispatcher(uint32_t flags)
evt
.
data
.
button
=
BUT_BR
;
break
;
case
(
1
<<
9
):
// PE9
evt
.
type
=
CHARGER
;
evt
.
data
.
charger
=
charger_active
()
?
CHARGING
:
NOT_CHARGING
;
break
;
case
(
1
<<
15
):
// PA15
evt
.
type
=
CHARGER
;
evt
.
data
.
charger
=
charger_power_good
()
?
POWER_GOOD
:
POWER_BAD
;
break
;
// Sensors
// There is a conflict with the bottom-left button interrupt
// case (1 << 6): // PA6
...
...
sw/freewatch/src/main.c
View file @
98f36877
...
...
@@ -39,6 +39,7 @@
#include <drivers/rtc.h>
#include <drivers/vibra.h>
#include <drivers/gps.h>
#include <drivers/charger.h>
#include <gfx/ui.h>
#include <apps/app_list.h>
...
...
@@ -93,6 +94,7 @@ int main(void)
battery_monitor_init
();
state_init
();
gpsbkgnd_init
();
charger_init
();
// Initialize SLEEP driver, no callbacks are used
SLEEP_Init
(
NULL
,
NULL
);
...
...
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