summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/lradc-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 13:36:23 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 16:10:52 +0200
commit55e01b8de46555929f62a9eb762d7791786ccc58 (patch)
tree71c657f38d4d5c461803caf8bda362728284fa01 /firmware/target/arm/imx233/lradc-imx233.c
parent01216c5ad3f2996d16cd7279387d2df859ec019b (diff)
downloadrockbox-55e01b8de46555929f62a9eb762d7791786ccc58.tar.gz
rockbox-55e01b8de46555929f62a9eb762d7791786ccc58.tar.bz2
rockbox-55e01b8de46555929f62a9eb762d7791786ccc58.zip
imx233: enhance lradc driver with touchscreen specific stuff
Change-Id: I83759a00257274c0cbde5a78306256abd2c83800
Diffstat (limited to 'firmware/target/arm/imx233/lradc-imx233.c')
-rw-r--r--firmware/target/arm/imx233/lradc-imx233.c80
1 files changed, 77 insertions, 3 deletions
diff --git a/firmware/target/arm/imx233/lradc-imx233.c b/firmware/target/arm/imx233/lradc-imx233.c
index 4d309b0875..e6a3738b9c 100644
--- a/firmware/target/arm/imx233/lradc-imx233.c
+++ b/firmware/target/arm/imx233/lradc-imx233.c
@@ -22,6 +22,7 @@
#include "system-target.h"
#include "lradc-imx233.h"
#include "kernel-imx233.h"
+#include "stdlib.h"
/* channels */
static struct channel_arbiter_t channel_arbiter;
@@ -30,6 +31,34 @@ static struct channel_arbiter_t delay_arbiter;
/* battery is very special, dedicate a channel and a delay to it */
static int battery_chan;
static int battery_delay_chan;
+/* irq callbacks */
+static lradc_irq_fn_t irq_cb[HW_LRADC_NUM_CHANNELS];
+
+#define define_cb(x) \
+ void INT_LRADC_CH##x(void) \
+ { \
+ INT_LRADC_CH(x); \
+ }
+
+void INT_LRADC_CH(int chan)
+{
+ if(irq_cb[chan])
+ irq_cb[chan](chan);
+}
+
+define_cb(0)
+define_cb(1)
+define_cb(2)
+define_cb(3)
+define_cb(4)
+define_cb(5)
+define_cb(6)
+define_cb(7)
+
+void imx233_lradc_set_channel_irq_callback(int channel, lradc_irq_fn_t cb)
+{
+ irq_cb[channel] = cb;
+}
void imx233_lradc_setup_channel(int channel, bool div2, bool acc, int nr_samples, int src)
{
@@ -54,9 +83,28 @@ void imx233_lradc_setup_delay(int dchan, int trigger_lradc, int trigger_delays,
delay << HW_LRADC_DELAYx__DELAY_BP;
}
-void imx233_lradc_kick_channel(int channel)
+void imx233_lradc_clear_channel_irq(int channel)
{
__REG_CLR(HW_LRADC_CTRL1) = HW_LRADC_CTRL1__LRADCx_IRQ(channel);
+}
+
+bool imx233_lradc_read_channel_irq(int channel)
+{
+ return HW_LRADC_CTRL1 & HW_LRADC_CTRL1__LRADCx_IRQ(channel);
+}
+
+void imx233_lradc_enable_channel_irq(int channel, bool enable)
+{
+ if(enable)
+ __REG_SET(HW_LRADC_CTRL1) = HW_LRADC_CTRL1__LRADCx_IRQ_EN(channel);
+ else
+ __REG_CLR(HW_LRADC_CTRL1) = HW_LRADC_CTRL1__LRADCx_IRQ_EN(channel);
+ imx233_lradc_clear_channel_irq(channel);
+}
+
+void imx233_lradc_kick_channel(int channel)
+{
+ imx233_lradc_clear_channel_irq(channel);
__REG_SET(HW_LRADC_CTRL0) = HW_LRADC_CTRL0__SCHEDULE(channel);
}
@@ -68,7 +116,7 @@ void imx233_lradc_kick_delay(int dchan)
void imx233_lradc_wait_channel(int channel)
{
/* wait for completion */
- while(!(HW_LRADC_CTRL1 & HW_LRADC_CTRL1__LRADCx_IRQ(channel)))
+ while(!imx233_lradc_read_channel_irq(channel))
yield();
}
@@ -185,7 +233,7 @@ int imx233_lradc_sense_ext_temperature(int chan, int sensor)
/* disable sensor current */
imx233_lradc_set_temp_isrc(sensor, HW_LRADC_CTRL2__TEMP_ISRC__0uA);
- return (b - a) / EXT_TEMP_ACC_COUNT;
+ return (abs(b - a) / EXT_TEMP_ACC_COUNT) * 1104 / 1000;
}
void imx233_lradc_setup_battery_conversion(bool automatic, unsigned long scale_factor)
@@ -203,6 +251,32 @@ int imx233_lradc_read_battery_voltage(void)
return __XTRACT(HW_LRADC_CONVERSION, SCALED_BATT_VOLTAGE);
}
+void imx233_lradc_setup_touch(bool xminus_enable, bool yminus_enable,
+ bool xplus_enable, bool yplus_enable, bool touch_detect)
+{
+ __FIELD_SET_CLR(HW_LRADC_CTRL0, XMINUS_ENABLE, xminus_enable);
+ __FIELD_SET_CLR(HW_LRADC_CTRL0, YMINUS_ENABLE, yminus_enable);
+ __FIELD_SET_CLR(HW_LRADC_CTRL0, XPLUS_ENABLE, xplus_enable);
+ __FIELD_SET_CLR(HW_LRADC_CTRL0, YPLUS_ENABLE, yplus_enable);
+ __FIELD_SET_CLR(HW_LRADC_CTRL0, TOUCH_DETECT_ENABLE, touch_detect);
+}
+
+void imx233_lradc_enable_touch_detect_irq(bool enable)
+{
+ __FIELD_SET_CLR(HW_LRADC_CTRL1, TOUCH_DETECT_IRQ_EN, enable);
+ imx233_lradc_clear_touch_detect_irq();
+}
+
+void imx233_lradc_clear_touch_detect_irq(void)
+{
+ __REG_CLR(HW_LRADC_CTRL1) = HW_LRADC_CTRL1__TOUCH_DETECT_IRQ;
+}
+
+bool imx233_lradc_read_touch_detect(void)
+{
+ return HW_LRADC_STATUS & HW_LRADC_STATUS__TOUCH_DETECT_RAW;
+}
+
void imx233_lradc_init(void)
{
arbiter_init(&channel_arbiter, HW_LRADC_NUM_CHANNELS);