File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ class BridgeClass {
115115 k_tid_t upd_tid{};
116116 k_thread_stack_t *upd_stack_area{};
117117 struct k_thread upd_thread_data{};
118+ const struct gpio_dt_spec mpu_boot_pin = GPIO_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), control_gpios, CTRL_GPIOG_13_ID);
118119
119120 bool started = false ;
120121
@@ -135,19 +136,18 @@ class BridgeClass {
135136 return out;
136137 }
137138
139+ bool ready () {
140+ return gpio_pin_get_dt (&mpu_boot_pin) == 1 ;
141+ }
142+
138143 // Initialize the bridge
139144 bool begin (unsigned long baud=DEFAULT_SERIAL_BAUD) {
140- k_mutex_init (&read_mutex);
141- k_mutex_init (&write_mutex);
142- k_mutex_init (&bridge_mutex);
143145
144- if ( is_started ()) return true ;
146+ init () ;
145147
146- const struct gpio_dt_spec mpu_boot_pin = GPIO_DT_SPEC_GET_BY_IDX ( DT_PATH (zephyr_user), control_gpios, CTRL_GPIOG_13_ID) ;
148+ if ( is_started ()) return true ;
147149
148- gpio_pin_configure_dt (&mpu_boot_pin, GPIO_INPUT | GPIO_PULL_DOWN);
149- k_sleep (K_MSEC (200 ));
150- while (gpio_pin_get_dt (&mpu_boot_pin) == 0 ) {
150+ while (!ready ()) {
151151 k_sleep (K_MSEC (10 ));
152152 }
153153
@@ -240,6 +240,16 @@ class BridgeClass {
240240
241241private:
242242
243+ void init () {
244+
245+ k_mutex_init (&read_mutex);
246+ k_mutex_init (&write_mutex);
247+ k_mutex_init (&bridge_mutex);
248+
249+ gpio_pin_configure_dt (&mpu_boot_pin, GPIO_INPUT | GPIO_PULL_DOWN);
250+ k_sleep (K_MSEC (200 ));
251+ }
252+
243253 void update_safe () {
244254
245255 // Lock read mutex
You can’t perform that action at this time.
0 commit comments