Skip to content

Commit 7d2b29d

Browse files
masz-nordicnordic-krch
authored andcommitted
tmp: GPIOTE output
Signed-off-by: Marcin Szymczyk <[email protected]>
1 parent ff2ac0b commit 7d2b29d

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

samples/subsys/usb/uac2_implicit_feedback/boards/nrf54h20dk_nrf54h20_cpuapp.overlay

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,25 @@ i2s_rxtx: &tdm130 {
4747
/* TDM130 PPI needs routing to TIMER131 through main APB */
4848
&dppic130 {
4949
compatible = "nordic,nrf-dppic-global";
50-
owned-channels = <0>;
51-
sink-channels = <0>;
52-
source-channels = <0>;
53-
nonsecure-channels = <0>;
50+
owned-channels = <0 2>;
51+
sink-channels = <0 2>;
52+
source-channels = <0 2>;
53+
nonsecure-channels = <0 2>;
5454
status = "okay";
5555
};
5656

5757
/* TIMER131 PPI channel 1 is used for SOF */
5858
&dppic133 {
5959
compatible = "nordic,nrf-dppic-global";
60-
owned-channels = <0 1>;
60+
owned-channels = <0 1 2>;
6161
sink-channels = <0 1>;
62+
source-channels = <2>;
63+
status = "okay";
64+
};
65+
66+
&gpiote130 {
6267
status = "okay";
68+
owned-channels = <0 2>;
6369
};
6470

6571
&timer131 {

samples/subsys/usb/uac2_implicit_feedback/src/feedback_nrf.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,48 @@ static inline void feedback_target_init(void)
4747
*(volatile uint32_t *)0x5F9A3C80 = 0x00000082;
4848
}
4949

50+
#include <nrfx_gpiote.h>
51+
#include <nrfx_timer.h>
52+
#include <helpers/nrfx_gppi.h>
53+
54+
static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(130);
55+
56+
#define GPIOTE_PPI_SOF_PIN (9 * 32)
57+
#define GPIOTE_PPI_MAXCNT_PIN (9 * 32) + 1
58+
59+
static uint32_t gpiote_setup(uint32_t pin)
60+
{
61+
uint8_t gpiote_ch;
62+
nrfx_err_t err;
63+
64+
err = nrfx_gpiote_channel_alloc(&gpiote, &gpiote_ch);
65+
if (err != NRFX_SUCCESS) {
66+
LOG_ERR("failed to allocate gpiote");
67+
return 0;
68+
}
69+
70+
nrfx_gpiote_task_config_t task_config = {
71+
.task_ch = gpiote_ch,
72+
.polarity = NRF_GPIOTE_POLARITY_TOGGLE,
73+
.init_val = NRF_GPIOTE_INITIAL_VALUE_LOW
74+
};
75+
nrfx_gpiote_output_config_t out_config = {
76+
.drive = NRF_GPIO_PIN_S0S1,
77+
.input_connect = NRF_GPIO_PIN_INPUT_DISCONNECT,
78+
.pull = NRF_GPIO_PIN_NOPULL
79+
};
80+
81+
err = nrfx_gpiote_output_configure(&gpiote, pin, &out_config, &task_config);
82+
if (err != NRFX_SUCCESS) {
83+
LOG_ERR("failed to configure pin");
84+
return 0;
85+
}
86+
87+
nrfx_gpiote_out_task_enable(&gpiote, pin);
88+
89+
return nrfx_gpiote_out_task_address_get(&gpiote, pin);
90+
}
91+
5092
#else
5193
#error "Unsupported target"
5294
#endif
@@ -106,8 +148,14 @@ struct feedback_ctx *feedback_init(void)
106148
return &fb_ctx;
107149
}
108150

151+
/* GPIOTE needs to hop through bridge, so we have to set it up first.
152+
* The "forks" are not hopping through, and the GPIOTE would fail if
153+
* setup was called with USB SOF to TIMER CAPTURE.
154+
*/
109155
nrfx_gppi_channel_endpoints_setup(usbd_sof_gppi_channel,
110156
USB_SOF_EVENT_ADDRESS,
157+
gpiote_setup(GPIOTE_PPI_SOF_PIN));
158+
nrfx_gppi_fork_endpoint_setup(usbd_sof_gppi_channel,
111159
nrfx_timer_capture_task_address_get(&feedback_timer_instance,
112160
FEEDBACK_TIMER_USBD_SOF_CAPTURE));
113161
nrfx_gppi_fork_endpoint_setup(usbd_sof_gppi_channel,
@@ -127,6 +175,8 @@ struct feedback_ctx *feedback_init(void)
127175
I2S_FRAMESTART_EVENT_ADDRESS,
128176
nrfx_timer_capture_task_address_get(&feedback_timer_instance,
129177
FEEDBACK_TIMER_I2S_FRAMESTART_CAPTURE));
178+
nrfx_gppi_fork_endpoint_setup(i2s_framestart_gppi_channel,
179+
gpiote_setup(GPIOTE_PPI_MAXCNT_PIN));
130180

131181
nrfx_gppi_channels_enable(BIT(i2s_framestart_gppi_channel));
132182

0 commit comments

Comments
 (0)