Commit 87fba8d6 authored by schneider's avatar schneider
Browse files

fix(pmic): Check pmic interrupt state from application context

Closes #13
parent d19fa787
......@@ -51,7 +51,7 @@
#include "msc.h"
#include "descriptors.h"
#include "mscmem.h"
#include "card10.h"
/***** Definitions *****/
#define EVENT_ENUM_COMP MAXUSB_NUM_EVENTS
......@@ -212,6 +212,8 @@ void run_usbmsc(void)
printf("Remote Wakeup\n");
}
}
card10_poll();
}
}
......
......@@ -7,6 +7,8 @@
#include "api/dispatcher.h"
#include "card10.h"
extern TaskHandle_t dispatcher_task_id;
/*
......@@ -39,6 +41,10 @@ void post_idle_sleep(TickType_t xExpectedIdleTime)
if (api_dispatcher_poll_once()) {
xTaskNotifyGive(dispatcher_task_id);
}
// Do card10 house keeping. E.g. polling the i2c devices if they triggered an interrupt
// TODO: Do this in a more task fokused way (high/low ISR)
card10_poll();
}
void vApplicationGetIdleTaskMemory(
......
......@@ -185,3 +185,7 @@ void core1_stop(void) {
MXC_GCR->perckcn1 |= MXC_F_GCR_PERCKCN1_CPU1;
}
void card10_poll(void)
{
pmic_poll();
}
......@@ -12,4 +12,5 @@ void card10_diag(void);
void core1_start(void);
void core1_stop(void);
void card10_poll(void);
#endif
......@@ -9,11 +9,14 @@ static const gpio_cfg_t pmic_interrupt_pin = {
PORT_0, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
};
static pmic_button_callback_fn pmic_button_callback = NULL;
static volatile bool interrupt_pending;
void pmic_init(void)
{
uint8_t didm = MAX77650_getDIDM();
uint8_t cid = MAX77650_getChipID();
interrupt_pending = false;
printf("MAX7765x DIDM: 0x%02x CID: 0x%02x\n", didm, cid);
MAX77650_setIP_SBB0(0b11); //Limit switch current of SBB0 to 500mA for noise reduction
......@@ -99,6 +102,14 @@ void pmic_init(void)
static void pmic_interrupt_callback(void*_)
{
interrupt_pending = true;
}
void pmic_poll(void)
{
if(interrupt_pending) {
/* There might be a race condition here. Don't care ATM. */
interrupt_pending = false;
uint8_t int_flag = MAX77650_getINT_GLBL();
if (int_flag & (MAX77650_INT_nEN_R | MAX77650_INT_nEN_F)) {
......@@ -107,6 +118,7 @@ static void pmic_interrupt_callback(void*_)
}
}
/* TODO: Other pmic interrupts */
}
}
void pmic_set_button_callback(pmic_button_callback_fn cb)
......
......@@ -6,6 +6,7 @@
void pmic_init(void);
void pmic_set_led(uint8_t led, uint8_t val);
void pmic_poll(void);
typedef void (*pmic_button_callback_fn)(bool falling);
void pmic_set_button_callback(pmic_button_callback_fn cb);
......
Supports Markdown
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