@@ -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