Skip to content

Commit 1ccd336

Browse files
committed
mod: extract init and ready methods
1 parent cb84623 commit 1ccd336

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/bridge.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff 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

241241
private:
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

0 commit comments

Comments
 (0)