summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-16 16:43:05 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-16 16:57:54 +0200
commitd815cf3c79321eb5db66cd18a77e3713943560a8 (patch)
treea7305ac2a115bdec7b713e05a4b291b3224ab0c0 /firmware
parent8517cf8bed758120bdf95b5880d17ac277d21d74 (diff)
downloadrockbox-d815cf3c79321eb5db66cd18a77e3713943560a8.tar.gz
rockbox-d815cf3c79321eb5db66cd18a77e3713943560a8.tar.bz2
rockbox-d815cf3c79321eb5db66cd18a77e3713943560a8.zip
imx233: rewrite lradc using new register headers
Change-Id: I06e4467c0ffe33145e6192528b074a23a8df67cc
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/arm/imx233/adc-imx233.c4
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c2
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c2
-rw-r--r--firmware/target/arm/imx233/lradc-imx233.c115
-rw-r--r--firmware/target/arm/imx233/lradc-imx233.h129
-rw-r--r--firmware/target/arm/imx233/sansa-fuzeplus/adc-fuzeplus.c2
-rw-r--r--firmware/target/arm/imx233/touchscreen-imx233.c6
7 files changed, 99 insertions, 161 deletions
diff --git a/firmware/target/arm/imx233/adc-imx233.c b/firmware/target/arm/imx233/adc-imx233.c
index 2d2f0de517..9b5af82d5d 100644
--- a/firmware/target/arm/imx233/adc-imx233.c
+++ b/firmware/target/arm/imx233/adc-imx233.c
@@ -51,10 +51,10 @@ static short adc_read_virtual(int c)
return imx233_lradc_read_battery_voltage();
case IMX233_ADC_VDDIO:
/* VddIO pin has a builtin 2:1 divide */
- return adc_read_physical(HW_LRADC_CHANNEL_VDDIO, false);
+ return adc_read_physical(LRADC_SRC_VDDIO, false);
case IMX233_ADC_VDD5V:
/* Vdd5V pin has a builtin 4:1 divide */
- return adc_read_physical(HW_LRADC_CHANNEL_5V, false) * 2;
+ return adc_read_physical(LRADC_SRC_5V, false) * 2;
case IMX233_ADC_DIE_TEMP:
{
// don't block on second channel otherwise we might deadlock !
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c
index 50ed498cc6..9ec641be88 100644
--- a/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c
+++ b/firmware/target/arm/imx233/creative-zenxfi2/adc-zenxfi2.c
@@ -26,7 +26,7 @@ int imx233_adc_mapping[] =
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
- [ADC_5V] = HW_LRADC_CHANNEL_5V,
+ [ADC_5V] = IMX233_ADC_VDD5V,
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
};
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c
index 6671c7202e..919e55200b 100644
--- a/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c
+++ b/firmware/target/arm/imx233/creative-zenxfi3/adc-zenxfi3.c
@@ -26,7 +26,7 @@ int imx233_adc_mapping[] =
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
- [ADC_5V] = HW_LRADC_CHANNEL_5V,
+ [ADC_5V] = IMX233_ADC_VDD5V,
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
};
diff --git a/firmware/target/arm/imx233/lradc-imx233.c b/firmware/target/arm/imx233/lradc-imx233.c
index e6a3738b9c..4fe05f36f7 100644
--- a/firmware/target/arm/imx233/lradc-imx233.c
+++ b/firmware/target/arm/imx233/lradc-imx233.c
@@ -32,7 +32,7 @@ static struct channel_arbiter_t delay_arbiter;
static int battery_chan;
static int battery_delay_chan;
/* irq callbacks */
-static lradc_irq_fn_t irq_cb[HW_LRADC_NUM_CHANNELS];
+static lradc_irq_fn_t irq_cb[LRADC_NUM_CHANNELS];
#define define_cb(x) \
void INT_LRADC_CH##x(void) \
@@ -62,55 +62,51 @@ void imx233_lradc_set_channel_irq_callback(int channel, lradc_irq_fn_t cb)
void imx233_lradc_setup_channel(int channel, bool div2, bool acc, int nr_samples, int src)
{
- __REG_CLR(HW_LRADC_CHx(channel)) = HW_LRADC_CHx__NUM_SAMPLES_BM | HW_LRADC_CHx__ACCUMULATE;
- __REG_SET(HW_LRADC_CHx(channel)) = nr_samples << HW_LRADC_CHx__NUM_SAMPLES_BP |
- acc << HW_LRADC_CHx__ACCUMULATE;
+ HW_LRADC_CHn_CLR(channel) = BM_OR2(LRADC_CHn, NUM_SAMPLES, ACCUMULATE);
+ HW_LRADC_CHn_SET(channel) = BF_OR2(LRADC_CHn, NUM_SAMPLES(nr_samples), ACCUMULATE(acc));
if(div2)
- __REG_SET(HW_LRADC_CTRL2) = HW_LRADC_CTRL2__DIVIDE_BY_TWO(channel);
+ BF_SETV(LRADC_CTRL2, DIVIDE_BY_TWO, 1 << channel);
else
- __REG_CLR(HW_LRADC_CTRL2) = HW_LRADC_CTRL2__DIVIDE_BY_TWO(channel);
- __REG_CLR(HW_LRADC_CTRL4) = HW_LRADC_CTRL4__LRADCxSELECT_BM(channel);
- __REG_SET(HW_LRADC_CTRL4) = src << HW_LRADC_CTRL4__LRADCxSELECT_BP(channel);
+ BF_CLRV(LRADC_CTRL2, DIVIDE_BY_TWO, 1 << channel);
+ HW_LRADC_CTRL4_CLR = BM_LRADC_CTRL4_LRADCxSELECT(channel);
+ HW_LRADC_CTRL4_SET = src << BP_LRADC_CTRL4_LRADCxSELECT(channel);
}
void imx233_lradc_setup_delay(int dchan, int trigger_lradc, int trigger_delays,
int loop_count, int delay)
{
- HW_LRADC_DELAYx(dchan) =
- trigger_lradc << HW_LRADC_DELAYx__TRIGGER_LRADCS_BP |
- trigger_delays << HW_LRADC_DELAYx__TRIGGER_DELAYS_BP |
- loop_count << HW_LRADC_DELAYx__LOOP_COUNT_BP |
- delay << HW_LRADC_DELAYx__DELAY_BP;
+ HW_LRADC_DELAYn(dchan) = BF_OR4(LRADC_DELAYn, TRIGGER_LRADCS(trigger_lradc),
+ TRIGGER_DELAYS(trigger_delays), LOOP_COUNT(loop_count), DELAY(delay));
}
void imx233_lradc_clear_channel_irq(int channel)
{
- __REG_CLR(HW_LRADC_CTRL1) = HW_LRADC_CTRL1__LRADCx_IRQ(channel);
+ BF_CLR(LRADC_CTRL1, LRADCx_IRQ(channel));
}
bool imx233_lradc_read_channel_irq(int channel)
{
- return HW_LRADC_CTRL1 & HW_LRADC_CTRL1__LRADCx_IRQ(channel);
+ return BF_RD(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);
+ BF_SET(LRADC_CTRL1, LRADCx_IRQ_EN(channel));
else
- __REG_CLR(HW_LRADC_CTRL1) = HW_LRADC_CTRL1__LRADCx_IRQ_EN(channel);
+ BF_CLR(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);
+ BF_SETV(LRADC_CTRL0, SCHEDULE, 1 << channel);
}
void imx233_lradc_kick_delay(int dchan)
{
- __REG_SET(HW_LRADC_DELAYx(dchan)) = HW_LRADC_DELAYx__KICK;
+ BF_SETn(LRADC_DELAYn, dchan, KICK);
}
void imx233_lradc_wait_channel(int channel)
@@ -122,12 +118,12 @@ void imx233_lradc_wait_channel(int channel)
int imx233_lradc_read_channel(int channel)
{
- return __XTRACT_EX(HW_LRADC_CHx(channel), HW_LRADC_CHx__VALUE);
+ return BF_RDn(LRADC_CHn, channel, VALUE);
}
void imx233_lradc_clear_channel(int channel)
{
- __REG_CLR(HW_LRADC_CHx(channel)) = HW_LRADC_CHx__VALUE_BM;
+ BF_CLRn(LRADC_CHn, channel, VALUE);
}
int imx233_lradc_acquire_channel(int timeout)
@@ -162,10 +158,10 @@ void imx233_lradc_reserve_delay(int channel)
int imx233_lradc_sense_die_temperature(int nmos_chan, int pmos_chan)
{
- imx233_lradc_setup_channel(nmos_chan, false, false, 0, HW_LRADC_CHANNEL_NMOS_THIN);
- imx233_lradc_setup_channel(pmos_chan, false, false, 0, HW_LRADC_CHANNEL_PMOS_THIN);
+ imx233_lradc_setup_channel(nmos_chan, false, false, 0, LRADC_SRC_NMOS_THIN);
+ imx233_lradc_setup_channel(pmos_chan, false, false, 0, LRADC_SRC_PMOS_THIN);
// mux sensors
- __REG_CLR(HW_LRADC_CTRL2) = HW_LRADC_CTRL2__TEMPSENSE_PWD;
+ BF_CLR(LRADC_CTRL2, TEMPSENSE_PWD);
imx233_lradc_clear_channel(nmos_chan);
imx233_lradc_clear_channel(pmos_chan);
// schedule both channels
@@ -175,7 +171,7 @@ int imx233_lradc_sense_die_temperature(int nmos_chan, int pmos_chan)
imx233_lradc_wait_channel(nmos_chan);
imx233_lradc_wait_channel(pmos_chan);
// mux sensors
- __REG_SET(HW_LRADC_CTRL2) = HW_LRADC_CTRL2__TEMPSENSE_PWD;
+ BF_SET(LRADC_CTRL2, TEMPSENSE_PWD);
// do the computation
int diff = imx233_lradc_read_channel(nmos_chan) - imx233_lradc_read_channel(pmos_chan);
// return diff * 1.012 / 4
@@ -187,19 +183,19 @@ static void imx233_lradc_set_temp_isrc(int sensor, int value)
{
if(sensor < 0 || sensor > 1)
panicf("imx233_lradc_set_temp_isrc: invalid sensor");
- unsigned mask = HW_LRADC_CTRL2__TEMP_ISRCx_BM(sensor);
- unsigned bp = HW_LRADC_CTRL2__TEMP_ISRCx_BP(sensor);
- unsigned en = HW_LRADC_CTRL2__TEMP_SENSOR_IENABLEx(sensor);
+ unsigned mask = sensor ? BM_LRADC_CTRL2_TEMP_ISRC0 : BM_LRADC_CTRL2_TEMP_ISRC1;
+ unsigned bp = sensor ? BP_LRADC_CTRL2_TEMP_ISRC0 : BP_LRADC_CTRL2_TEMP_ISRC1;
+ unsigned en = sensor ? BM_LRADC_CTRL2_TEMP_SENSOR_IENABLE0 : BM_LRADC_CTRL2_TEMP_SENSOR_IENABLE1;
- __REG_CLR(HW_LRADC_CTRL2) = mask;
- __REG_SET(HW_LRADC_CTRL2) = value << bp;
+ HW_LRADC_CTRL2_CLR = mask;
+ HW_LRADC_CTRL2_SET = value << bp;
if(value != 0)
{
- __REG_SET(HW_LRADC_CTRL2) = en;
+ HW_LRADC_CTRL2_SET = en;
udelay(100);
}
else
- __REG_CLR(HW_LRADC_CTRL2) = en;
+ HW_LRADC_CTRL2_CLR = en;
}
int imx233_lradc_sense_ext_temperature(int chan, int sensor)
@@ -208,7 +204,7 @@ int imx233_lradc_sense_ext_temperature(int chan, int sensor)
/* setup channel */
imx233_lradc_setup_channel(chan, false, false, 0, sensor);
/* set current source to 300µA */
- imx233_lradc_set_temp_isrc(sensor, HW_LRADC_CTRL2__TEMP_ISRC__300uA);
+ imx233_lradc_set_temp_isrc(sensor, BV_LRADC_CTRL2_TEMP_ISRC0__300);
/* read value and accumulate */
int a = 0;
for(int i = 0; i < EXT_TEMP_ACC_COUNT; i++)
@@ -220,7 +216,7 @@ int imx233_lradc_sense_ext_temperature(int chan, int sensor)
}
/* setup channel for small accumulation */
/* set current source to 20µA */
- imx233_lradc_set_temp_isrc(sensor, HW_LRADC_CTRL2__TEMP_ISRC__20uA);
+ imx233_lradc_set_temp_isrc(sensor, BV_LRADC_CTRL2_TEMP_ISRC0__20);
/* read value */
int b = 0;
for(int i = 0; i < EXT_TEMP_ACC_COUNT; i++)
@@ -231,72 +227,75 @@ int imx233_lradc_sense_ext_temperature(int chan, int sensor)
b += imx233_lradc_read_channel(chan);
}
/* disable sensor current */
- imx233_lradc_set_temp_isrc(sensor, HW_LRADC_CTRL2__TEMP_ISRC__0uA);
+ imx233_lradc_set_temp_isrc(sensor, BV_LRADC_CTRL2_TEMP_ISRC0__ZERO);
return (abs(b - a) / EXT_TEMP_ACC_COUNT) * 1104 / 1000;
}
void imx233_lradc_setup_battery_conversion(bool automatic, unsigned long scale_factor)
{
- __REG_CLR(HW_LRADC_CONVERSION) = HW_LRADC_CONVERSION__SCALE_FACTOR_BM;
- __REG_SET(HW_LRADC_CONVERSION) = scale_factor;
+ BF_CLR(LRADC_CONVERSION, SCALE_FACTOR);
+ BF_SETV(LRADC_CONVERSION, SCALE_FACTOR, scale_factor);
if(automatic)
- __REG_SET(HW_LRADC_CONVERSION) = HW_LRADC_CONVERSION__AUTOMATIC;
+ BF_SET(LRADC_CONVERSION, AUTOMATIC);
else
- __REG_CLR(HW_LRADC_CONVERSION) = HW_LRADC_CONVERSION__AUTOMATIC;
+ BF_CLR(LRADC_CONVERSION, AUTOMATIC);
}
int imx233_lradc_read_battery_voltage(void)
{
- return __XTRACT(HW_LRADC_CONVERSION, SCALED_BATT_VOLTAGE);
+ return BF_RD(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);
+ HW_LRADC_CTRL0_CLR = BM_OR5(LRADC_CTRL0, XMINUS_ENABLE, YMINUS_ENABLE,
+ XPLUS_ENABLE, YPLUS_ENABLE, TOUCH_DETECT_ENABLE);
+ HW_LRADC_CTRL0_SET = BF_OR5(LRADC_CTRL0, XMINUS_ENABLE(xminus_enable),
+ YMINUS_ENABLE(yminus_enable), XPLUS_ENABLE(xplus_enable),
+ YPLUS_ENABLE(yplus_enable), 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);
+ if(enable)
+ BF_SET(LRADC_CTRL1, TOUCH_DETECT_IRQ_EN);
+ else
+ BF_CLR(LRADC_CTRL1, TOUCH_DETECT_IRQ_EN);
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;
+ BF_CLR(LRADC_CTRL1, TOUCH_DETECT_IRQ);
}
bool imx233_lradc_read_touch_detect(void)
{
- return HW_LRADC_STATUS & HW_LRADC_STATUS__TOUCH_DETECT_RAW;
+ return BF_RD(LRADC_STATUS, TOUCH_DETECT_RAW);
}
void imx233_lradc_init(void)
{
- arbiter_init(&channel_arbiter, HW_LRADC_NUM_CHANNELS);
- arbiter_init(&delay_arbiter, HW_LRADC_NUM_DELAYS);
+ arbiter_init(&channel_arbiter, LRADC_NUM_CHANNELS);
+ arbiter_init(&delay_arbiter, LRADC_NUM_DELAYS);
// enable block
imx233_reset_block(&HW_LRADC_CTRL0);
// disable ground ref
- __REG_CLR(HW_LRADC_CTRL0) = HW_LRADC_CTRL0__ONCHIP_GROUNDREF;
+ BF_CLR(LRADC_CTRL0, ONCHIP_GROUNDREF);
// disable temperature sensors
- __REG_CLR(HW_LRADC_CTRL2) = HW_LRADC_CTRL2__TEMP_SENSOR_IENABLE0 |
- HW_LRADC_CTRL2__TEMP_SENSOR_IENABLE1;
- __REG_SET(HW_LRADC_CTRL2) = HW_LRADC_CTRL2__TEMPSENSE_PWD;
+ BF_CLR(LRADC_CTRL2, TEMP_SENSOR_IENABLE0);
+ BF_CLR(LRADC_CTRL2, TEMP_SENSOR_IENABLE1);
+ BF_SET(LRADC_CTRL2, TEMPSENSE_PWD);
// set frequency
- __REG_CLR(HW_LRADC_CTRL3) = HW_LRADC_CTRL3__CYCLE_TIME_BM;
- __REG_SET(HW_LRADC_CTRL3) = HW_LRADC_CTRL3__CYCLE_TIME__6MHz;
+ BF_CLR(LRADC_CTRL3, CYCLE_TIME);
+ BF_SETV(LRADC_CTRL3, CYCLE_TIME_V, 6MHZ);
// setup battery
battery_chan = 7;
imx233_lradc_reserve_channel(battery_chan);
/* setup them for the simplest use: no accumulation, no division*/
- imx233_lradc_setup_channel(battery_chan, false, false, 0, HW_LRADC_CHANNEL_BATTERY);
+ imx233_lradc_setup_channel(battery_chan, false, false, 0, LRADC_SRC_BATTERY);
/* setup delay channel for battery for automatic reading and scaling */
battery_delay_chan = 0;
imx233_lradc_reserve_delay(battery_delay_chan);
@@ -307,5 +306,5 @@ void imx233_lradc_init(void)
1 << battery_delay_chan, 0, 200);
imx233_lradc_kick_delay(battery_delay_chan);
/* enable automatic conversion, use Li-Ion type battery */
- imx233_lradc_setup_battery_conversion(true, HW_LRADC_CONVERSION__SCALE_FACTOR__LI_ION);
+ imx233_lradc_setup_battery_conversion(true, BV_LRADC_CONVERSION_SCALE_FACTOR__LI_ION);
}
diff --git a/firmware/target/arm/imx233/lradc-imx233.h b/firmware/target/arm/imx233/lradc-imx233.h
index f71843b3db..d1529f4266 100644
--- a/firmware/target/arm/imx233/lradc-imx233.h
+++ b/firmware/target/arm/imx233/lradc-imx233.h
@@ -28,101 +28,40 @@
#include "system.h"
#include "system-target.h"
-#define HW_LRADC_BASE 0x80050000
-
-#define HW_LRADC_CTRL0 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x0))
-#define HW_LRADC_CTRL0__XPLUS_ENABLE (1 << 16)
-#define HW_LRADC_CTRL0__YPLUS_ENABLE (1 << 17)
-#define HW_LRADC_CTRL0__XMINUS_ENABLE (1 << 18)
-#define HW_LRADC_CTRL0__YMINUS_ENABLE (1 << 19)
-#define HW_LRADC_CTRL0__TOUCH_DETECT_ENABLE (1 << 20)
-#define HW_LRADC_CTRL0__ONCHIP_GROUNDREF (1 << 21)
-#define HW_LRADC_CTRL0__SCHEDULE(x) (1 << (x))
-
-#define HW_LRADC_CTRL1 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x10))
-#define HW_LRADC_CTRL1__LRADCx_IRQ(x) (1 << (x))
-#define HW_LRADC_CTRL1__TOUCH_DETECT_IRQ (1 << 8)
-#define HW_LRADC_CTRL1__LRADCx_IRQ_EN(x) (1 << ((x) + 16))
-#define HW_LRADC_CTRL1__TOUCH_DETECT_IRQ_EN (1 << 24)
-
-#define HW_LRADC_CTRL2 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x20))
-#define HW_LRADC_CTRL2__TEMP_ISRC1_BP 4
-#define HW_LRADC_CTRL2__TEMP_ISRC1_BM 0xf0
-#define HW_LRADC_CTRL2__TEMP_ISRC0_BP 0
-#define HW_LRADC_CTRL2__TEMP_ISRC0_BM 0xf
-#define HW_LRADC_CTRL2__TEMP_ISRCx_BP(x) (4 * (x))
-#define HW_LRADC_CTRL2__TEMP_ISRCx_BM(x) (0xf << (4 * (x)))
-#define HW_LRADC_CTRL2__TEMP_ISRC__0uA 0
-#define HW_LRADC_CTRL2__TEMP_ISRC__20uA 1
-#define HW_LRADC_CTRL2__TEMP_ISRC__300uA 15
-#define HW_LRADC_CTRL2__TEMP_SENSOR_IENABLE0 (1 << 8)
-#define HW_LRADC_CTRL2__TEMP_SENSOR_IENABLE1 (1 << 9)
-#define HW_LRADC_CTRL2__TEMP_SENSOR_IENABLEx(x) (1 << (8 + (x)))
-#define HW_LRADC_CTRL2__TEMPSENSE_PWD (1 << 15)
-#define HW_LRADC_CTRL2__DIVIDE_BY_TWO(x) (1 << ((x) + 24))
-
-#define HW_LRADC_CTRL3 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x30))
-#define HW_LRADC_CTRL3__CYCLE_TIME_BM 0x300
-#define HW_LRADC_CTRL3__CYCLE_TIME_BP 8
-#define HW_LRADC_CTRL3__CYCLE_TIME__6MHz (0 << 8)
-#define HW_LRADC_CTRL3__CYCLE_TIME__4MHz (1 << 8)
-#define HW_LRADC_CTRL3__CYCLE_TIME__3MHz (2 << 8)
-#define HW_LRADC_CTRL3__CYCLE_TIME__2MHz (3 << 8)
-
-#define HW_LRADC_STATUS (*(volatile uint32_t *)(HW_LRADC_BASE + 0x40))
-#define HW_LRADC_STATUS__TOUCH_DETECT_RAW (1 << 0)
-
-#define HW_LRADC_CHx(x) (*(volatile uint32_t *)(HW_LRADC_BASE + 0x50 + (x) * 0x10))
-#define HW_LRADC_CHx__NUM_SAMPLES_BM (0x1f << 24)
-#define HW_LRADC_CHx__NUM_SAMPLES_BP 24
-#define HW_LRADC_CHx__ACCUMULATE 29
-#define HW_LRADC_CHx__VALUE_BM 0x3ffff
-#define HW_LRADC_CHx__VALUE_BP 0
-
-#define HW_LRADC_DELAYx(x) (*(volatile uint32_t *)(HW_LRADC_BASE + 0xD0 + (x) * 0x10))
-#define HW_LRADC_DELAYx__DELAY_BP 0
-#define HW_LRADC_DELAYx__DELAY_BM 0x7ff
-#define HW_LRADC_DELAYx__LOOP_COUNT_BP 11
-#define HW_LRADC_DELAYx__LOOP_COUNT_BM (0x1f << 11)
-#define HW_LRADC_DELAYx__TRIGGER_DELAYS_BP 16
-#define HW_LRADC_DELAYx__TRIGGER_DELAYS_BM (0xf << 16)
-#define HW_LRADC_DELAYx__KICK (1 << 20)
-#define HW_LRADC_DELAYx__TRIGGER_LRADCS_BP 24
-#define HW_LRADC_DELAYx__TRIGGER_LRADCS_BM (0xff << 24)
-
-#define HW_LRADC_CONVERSION (*(volatile uint32_t *)(HW_LRADC_BASE + 0x130))
-#define HW_LRADC_CONVERSION__SCALED_BATT_VOLTAGE_BP 0
-#define HW_LRADC_CONVERSION__SCALED_BATT_VOLTAGE_BM 0x3ff
-#define HW_LRADC_CONVERSION__SCALE_FACTOR_BM (3 << 16)
-#define HW_LRADC_CONVERSION__SCALE_FACTOR_BP 16
-#define HW_LRADC_CONVERSION__SCALE_FACTOR__LI_ION (2 << 16)
-#define HW_LRADC_CONVERSION__AUTOMATIC (1 << 20)
-
-#define HW_LRADC_CTRL4 (*(volatile uint32_t *)(HW_LRADC_BASE + 0x140))
-#define HW_LRADC_CTRL4__LRADCxSELECT_BM(x) (0xf << ((x) * 4))
-#define HW_LRADC_CTRL4__LRADCxSELECT_BP(x) ((x) * 4)
-
-#define HW_LRADC_VERSION (*(volatile uint32_t *)(HW_LRADC_BASE + 0x150))
-
-#define HW_LRADC_NUM_CHANNELS 8
-#define HW_LRADC_NUM_DELAYS 4
-
-#define HW_LRADC_CHANNEL(x) (x)
-#define HW_LRADC_CHANNEL_XPLUS HW_LRADC_CHANNEL(2)
-#define HW_LRADC_CHANNEL_YPLUS HW_LRADC_CHANNEL(3)
-#define HW_LRADC_CHANNEL_XMINUS HW_LRADC_CHANNEL(4)
-#define HW_LRADC_CHANNEL_YMINUS HW_LRADC_CHANNEL(5)
-#define HW_LRADC_CHANNEL_VDDIO HW_LRADC_CHANNEL(6)
-#define HW_LRADC_CHANNEL_BATTERY HW_LRADC_CHANNEL(7)
-#define HW_LRADC_CHANNEL_PMOS_THIN HW_LRADC_CHANNEL(8)
-#define HW_LRADC_CHANNEL_NMOS_THIN HW_LRADC_CHANNEL(9)
-#define HW_LRADC_CHANNEL_NMOS_THICK HW_LRADC_CHANNEL(10)
-#define HW_LRADC_CHANNEL_PMOS_THICK HW_LRADC_CHANNEL(11)
-#define HW_LRADC_CHANNEL_PMOS_THICK HW_LRADC_CHANNEL(11)
-#define HW_LRADC_CHANNEL_USB_DP HW_LRADC_CHANNEL(12)
-#define HW_LRADC_CHANNEL_USB_DN HW_LRADC_CHANNEL(13)
-#define HW_LRADC_CHANNEL_VBG HW_LRADC_CHANNEL(14)
-#define HW_LRADC_CHANNEL_5V HW_LRADC_CHANNEL(15)
+#include "regs/regs-lradc.h"
+
+/** additional defines */
+#define BP_LRADC_CTRL4_LRADCxSELECT(x) (4 * (x))
+#define BM_LRADC_CTRL4_LRADCxSELECT(x) (0xf << (4 * (x)))
+
+#define BP_LRADC_CTRL1_LRADCx_IRQ(x) (x)
+#define BM_LRADC_CTRL1_LRADCx_IRQ(x) (1 << (x))
+
+#define BP_LRADC_CTRL1_LRADCx_IRQ_EN(x) (16 + (x))
+#define BM_LRADC_CTRL1_LRADCx_IRQ_EN(x) (1 << (16 + (x)))
+
+#define LRADC_NUM_CHANNELS 8
+#define LRADC_NUM_DELAYS 4
+
+#define LRADC_SRC(x) (x)
+#define LRADC_SRC_XPLUS LRADC_SRC(2)
+#define LRADC_SRC_YPLUS LRADC_SRC(3)
+#define LRADC_SRC_XMINUS LRADC_SRC(4)
+#define LRADC_SRC_YMINUS LRADC_SRC(5)
+#define LRADC_SRC_VDDIO LRADC_SRC(6)
+#define LRADC_SRC_BATTERY LRADC_SRC(7)
+#define LRADC_SRC_PMOS_THIN LRADC_SRC(8)
+#define LRADC_SRC_NMOS_THIN LRADC_SRC(9)
+#define LRADC_SRC_NMOS_THICK LRADC_SRC(10)
+#define LRADC_SRC_PMOS_THICK LRADC_SRC(11)
+#define LRADC_SRC_PMOS_THICK LRADC_SRC(11)
+#define LRADC_SRC_USB_DP LRADC_SRC(12)
+#define LRADC_SRC_USB_DN LRADC_SRC(13)
+#define LRADC_SRC_VBG LRADC_SRC(14)
+#define LRADC_SRC_5V LRADC_SRC(15)
+
+/* frequency of the delay counter */
+#define LRADC_DELAY_FREQ 2000
typedef void (*lradc_irq_fn_t)(int chan);
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/adc-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/adc-fuzeplus.c
index cf420ae84f..5d04f6f6b0 100644
--- a/firmware/target/arm/imx233/sansa-fuzeplus/adc-fuzeplus.c
+++ b/firmware/target/arm/imx233/sansa-fuzeplus/adc-fuzeplus.c
@@ -28,7 +28,7 @@ int imx233_adc_mapping[] =
[ADC_VDDIO] = IMX233_ADC_VDDIO,
[ADC_5V] = IMX233_ADC_VDD5V,
[ADC_BATT_TEMP] = IMX233_ADC_BATT_TEMP,
- [ADC_CH2] = HW_LRADC_CHANNEL(2),
+ [ADC_CH2] = LRADC_SRC(2),
};
const char *imx233_adc_channel_name[] =
diff --git a/firmware/target/arm/imx233/touchscreen-imx233.c b/firmware/target/arm/imx233/touchscreen-imx233.c
index 475103c3d4..4f35110df7 100644
--- a/firmware/target/arm/imx233/touchscreen-imx233.c
+++ b/firmware/target/arm/imx233/touchscreen-imx233.c
@@ -82,13 +82,13 @@ static void enter_state(enum touch_state_t state)
imx233_lradc_enable_touch_detect_irq(true);
break;
case TOUCH_STATE_MEASURE_X:
- kick_measure(true, false, false, HW_LRADC_CHANNEL_YPLUS);
+ kick_measure(true, false, false, LRADC_SRC_YPLUS);
break;
case TOUCH_STATE_MEASURE_Y:
- kick_measure(false, true, false, HW_LRADC_CHANNEL_XPLUS);
+ kick_measure(false, true, false, LRADC_SRC_XPLUS);
break;
case TOUCH_STATE_VERIFY:
- kick_measure(false, false, true, HW_LRADC_CHANNEL_YPLUS);
+ kick_measure(false, false, true, LRADC_SRC_YPLUS);
break;
}
}