Commit 98f36877 authored by Projects's avatar Projects

charger: Interrupt driven status update.

parent 3923d5ed
/*
* 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);
}
/*
* 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 */
......@@ -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;
};
......
......@@ -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 \
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment