Skip to content

Commit c9906dd

Browse files
Mierunskicarlescufi
authored andcommitted
dts: nrf: Remove qdec dts.fixup defines and use aliases instead.
Changed driver to use defines from aliases instead of fixup. Signed-off-by: Mieszko Mierunski <[email protected]>
1 parent 066fe72 commit c9906dd

File tree

7 files changed

+24
-46
lines changed

7 files changed

+24
-46
lines changed

drivers/sensor/qdec_nrfx/qdec_nrfx.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ static int qdec_nrfx_channel_get(struct device *dev,
9191
data->acc = 0;
9292
irq_unlock(key);
9393

94-
static_assert(DT_QDEC_STEPS > 0, "only positive number valid");
95-
static_assert(DT_QDEC_STEPS <= 2148, "overflow possible");
96-
97-
val->val1 = (acc * FULL_ANGLE) / DT_QDEC_STEPS;
98-
val->val2 = (acc * FULL_ANGLE) - (val->val1 * DT_QDEC_STEPS);
94+
static_assert(DT_NORDIC_NRF_QDEC_QDEC_0_STEPS > 0,
95+
"only positive number valid");
96+
static_assert(DT_NORDIC_NRF_QDEC_QDEC_0_STEPS <= 2148,
97+
"overflow possible");
98+
99+
val->val1 = (acc * FULL_ANGLE) / DT_NORDIC_NRF_QDEC_QDEC_0_STEPS;
100+
val->val2 = (acc * FULL_ANGLE)
101+
- (val->val1 * DT_NORDIC_NRF_QDEC_QDEC_0_STEPS);
99102
if (val->val2 != 0) {
100103
val->val2 *= 1000000;
101-
val->val2 /= DT_QDEC_STEPS;
104+
val->val2 /= DT_NORDIC_NRF_QDEC_QDEC_0_STEPS;
102105
}
103106

104107
return 0;
@@ -161,11 +164,11 @@ static void qdec_nrfx_event_handler(nrfx_qdec_event_t event)
161164

162165
static void qdec_nrfx_gpio_ctrl(bool enable)
163166
{
164-
#if defined(DT_QDEC_ENABLE_PIN)
167+
#if defined(DT_NORDIC_NRF_QDEC_QDEC_0_ENABLE_PIN)
165168
uint32_t val = (enable)?(0):(1);
166169

167-
nrf_gpio_pin_write(DT_QDEC_ENABLE_PIN, val);
168-
nrf_gpio_cfg_output(DT_QDEC_ENABLE_PIN);
170+
nrf_gpio_pin_write(DT_NORDIC_NRF_QDEC_QDEC_0_ENABLE_PIN, val);
171+
nrf_gpio_cfg_output(DT_NORDIC_NRF_QDEC_QDEC_0_ENABLE_PIN);
169172
#endif
170173
}
171174

@@ -174,14 +177,14 @@ static int qdec_nrfx_init(struct device *dev)
174177
static const nrfx_qdec_config_t config = {
175178
.reportper = NRF_QDEC_REPORTPER_40,
176179
.sampleper = NRF_QDEC_SAMPLEPER_2048us,
177-
.psela = DT_QDEC_A_PIN,
178-
.pselb = DT_QDEC_B_PIN,
179-
#if defined(DT_QDEC_LED_PIN)
180-
.pselled = DT_QDEC_LED_PIN,
180+
.psela = DT_NORDIC_NRF_QDEC_QDEC_0_A_PIN,
181+
.pselb = DT_NORDIC_NRF_QDEC_QDEC_0_B_PIN,
182+
#if defined(DT_NORDIC_NRF_QDEC_QDEC_0_LED_PIN)
183+
.pselled = DT_NORDIC_NRF_QDEC_QDEC_0_LED_PIN,
181184
#else
182185
.pselled = 0xFFFFFFFF, /* disabled */
183186
#endif
184-
.ledpre = DT_QDEC_LED_PRE,
187+
.ledpre = DT_NORDIC_NRF_QDEC_QDEC_0_LED_PRE,
185188
.ledpol = NRF_QDEC_LEPOL_ACTIVE_HIGH,
186189
.interrupt_priority = NRFX_QDEC_CONFIG_IRQ_PRIORITY,
187190
.dbfen = 0, /* disabled */
@@ -192,7 +195,8 @@ static int qdec_nrfx_init(struct device *dev)
192195

193196
LOG_DBG("");
194197

195-
IRQ_CONNECT(DT_QDEC_IRQ, DT_QDEC_IRQ_PRI,
198+
IRQ_CONNECT(DT_NORDIC_NRF_QDEC_QDEC_0_IRQ,
199+
DT_NORDIC_NRF_QDEC_QDEC_0_IRQ_PRIORITY,
196200
nrfx_isr, nrfx_qdec_irq_handler, 0);
197201

198202
nerr = nrfx_qdec_init(&config, qdec_nrfx_event_handler);
@@ -302,6 +306,6 @@ static const struct sensor_driver_api qdec_nrfx_driver_api = {
302306
.trigger_set = qdec_nrfx_trigger_set,
303307
};
304308

305-
DEVICE_DEFINE(qdec_nrfx, DT_QDEC_NAME, qdec_nrfx_init,
309+
DEVICE_DEFINE(qdec_nrfx, DT_NORDIC_NRF_QDEC_QDEC_0_LABEL, qdec_nrfx_init,
306310
qdec_nrfx_pm_control, NULL, NULL, POST_KERNEL,
307311
CONFIG_SENSOR_INIT_PRIORITY, &qdec_nrfx_driver_api);

dts/arm/nordic/nrf51822.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
gpio-0 = &gpio0;
4747
gpiote-0 = &gpiote;
4848
wdt-0 = &wdt;
49+
qdec-0 = &qdec;
4950
};
5051

5152
soc {

dts/arm/nordic/nrf52810.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
gpio-0 = &gpio0;
4444
gpiote-0 = &gpiote;
4545
wdt-0 = &wdt;
46+
qdec-0 = &qdec;
4647
};
4748

4849
soc {

dts/arm/nordic/nrf52832.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
gpio-0 = &gpio0;
4848
gpiote-0 = &gpiote;
4949
wdt-0 = &wdt;
50+
qdec-0 = &qdec;
5051
};
5152

5253
soc {

dts/arm/nordic/nrf52840.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
usbd-0 = &usbd;
5454
cc310 = &cryptocell;
5555
arm-cryptocell-310 = &cryptocell310;
56+
qdec-0 = &qdec;
5657
};
5758

5859
soc {

soc/arm/nordic_nrf/nrf51/dts_fixup.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@
1313
#define DT_I2C_0_NAME DT_NORDIC_NRF_I2C_I2C_0_LABEL
1414
#define DT_I2C_1_NAME DT_NORDIC_NRF_I2C_I2C_1_LABEL
1515

16-
#define DT_QDEC_BASE_ADDR DT_NORDIC_NRF_QDEC_40012000_BASE_ADDRESS
17-
#define DT_QDEC_NAME DT_NORDIC_NRF_QDEC_40012000_LABEL
18-
#define DT_QDEC_IRQ_PRI DT_NORDIC_NRF_QDEC_40012000_IRQ_0_PRIORITY
19-
#define DT_QDEC_IRQ DT_NORDIC_NRF_QDEC_40012000_IRQ_0
20-
#define DT_QDEC_A_PIN DT_NORDIC_NRF_QDEC_40012000_A_PIN
21-
#define DT_QDEC_B_PIN DT_NORDIC_NRF_QDEC_40012000_B_PIN
22-
#if defined(DT_NORDIC_NRF_QDEC_40012000_LED_PIN)
23-
#define DT_QDEC_LED_PIN DT_NORDIC_NRF_QDEC_40012000_LED_PIN
24-
#endif
25-
#if defined(DT_NORDIC_NRF_QDEC_40012000_ENABLE_PIN)
26-
#define DT_QDEC_ENABLE_PIN DT_NORDIC_NRF_QDEC_40012000_ENABLE_PIN
27-
#endif
28-
#define DT_QDEC_LED_PRE DT_NORDIC_NRF_QDEC_40012000_LED_PRE
29-
#define DT_QDEC_STEPS DT_NORDIC_NRF_QDEC_40012000_STEPS
30-
3116
#define DT_SPI_0_NAME DT_NORDIC_NRF_SPI_SPI_0_LABEL
3217
#define DT_SPI_1_NAME DT_NORDIC_NRF_SPI_SPI_1_LABEL
3318

soc/arm/nordic_nrf/nrf52/dts_fixup.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@
1515
#define DT_I2C_0_NAME DT_NORDIC_NRF_I2C_I2C_0_LABEL
1616
#define DT_I2C_1_NAME DT_NORDIC_NRF_I2C_I2C_1_LABEL
1717

18-
#define DT_QDEC_BASE_ADDR DT_NORDIC_NRF_QDEC_40012000_BASE_ADDRESS
19-
#define DT_QDEC_NAME DT_NORDIC_NRF_QDEC_40012000_LABEL
20-
#define DT_QDEC_IRQ_PRI DT_NORDIC_NRF_QDEC_40012000_IRQ_0_PRIORITY
21-
#define DT_QDEC_IRQ DT_NORDIC_NRF_QDEC_40012000_IRQ_0
22-
#define DT_QDEC_A_PIN DT_NORDIC_NRF_QDEC_40012000_A_PIN
23-
#define DT_QDEC_B_PIN DT_NORDIC_NRF_QDEC_40012000_B_PIN
24-
#if defined(DT_NORDIC_NRF_QDEC_40012000_LED_PIN)
25-
#define DT_QDEC_LED_PIN DT_NORDIC_NRF_QDEC_40012000_LED_PIN
26-
#endif
27-
#if defined(DT_NORDIC_NRF_QDEC_40012000_ENABLE_PIN)
28-
#define DT_QDEC_ENABLE_PIN DT_NORDIC_NRF_QDEC_40012000_ENABLE_PIN
29-
#endif
30-
#define DT_QDEC_LED_PRE DT_NORDIC_NRF_QDEC_40012000_LED_PRE
31-
#define DT_QDEC_STEPS DT_NORDIC_NRF_QDEC_40012000_STEPS
32-
3318
#define DT_SPI_0_NAME DT_NORDIC_NRF_SPI_SPI_0_LABEL
3419
#define DT_SPI_1_NAME DT_NORDIC_NRF_SPI_SPI_1_LABEL
3520
#define DT_SPI_2_NAME DT_NORDIC_NRF_SPI_SPI_2_LABEL

0 commit comments

Comments
 (0)