Skip to content

Commit 04149e3

Browse files
committed
Aggregate IO expander code initialisation within expander_init() function.
1 parent 3eb0154 commit 04149e3

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

src/Braccio++.cpp

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,9 @@ bool BraccioClass::begin(voidFuncPtr custom_menu)
7272
return false;
7373
_bl.turnOn();
7474

75-
76-
if (!_expander.testConnection())
75+
if (!expander_init())
7776
return false;
7877

79-
for (int i = 0; i < 14; i++) {
80-
_expander.setPinDirection(i, 0);
81-
}
82-
83-
// Set SLEW to low
84-
_expander.setPinDirection(21, 0); // P25 = 8 * 2 + 5
85-
_expander.writePin(21, 0);
86-
87-
// Set TERM to HIGH (default)
88-
_expander.setPinDirection(19, 0); // P23 = 8 * 2 + 3
89-
_expander.writePin(19, 1);
90-
91-
_expander.setPinDirection(18, 0); // P22 = 8 * 2 + 2
92-
_expander.writePin(18, 0); // reset LCD
93-
_expander.writePin(18, 1); // LCD out of reset
94-
95-
/* Set all motor status LEDs to red. */
96-
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++) {
97-
setRed(id);
98-
}
99-
10078
pinMode(BTN_LEFT, INPUT_PULLUP);
10179
pinMode(BTN_RIGHT, INPUT_PULLUP);
10280
pinMode(BTN_UP, INPUT_PULLUP);
@@ -332,6 +310,37 @@ void BraccioClass::lvgl_defaultMenu()
332310
lv_obj_set_pos(label1, 0, 0);
333311
}
334312

313+
bool BraccioClass::expander_init()
314+
{
315+
if (!_expander.testConnection())
316+
return false;
317+
318+
/* Init IO expander outputs of RGB LEDs */
319+
for (int i = 0; i < 14; i++) {
320+
_expander.setPinDirection(i, 0);
321+
}
322+
323+
/* Set SLEW to low */
324+
_expander.setPinDirection(21, 0); // P25 = 8 * 2 + 5
325+
_expander.writePin(21, 0);
326+
327+
/* Set TERM to HIGH (default) */
328+
_expander.setPinDirection(19, 0); // P23 = 8 * 2 + 3
329+
_expander.writePin(19, 1);
330+
331+
/* Reset GLCD */
332+
_expander.setPinDirection(18, 0); // P22 = 8 * 2 + 2
333+
_expander.writePin(18, 0); // reset LCD
334+
_expander.writePin(18, 1); // LCD out of reset
335+
336+
/* Set all motor status LEDs to red. */
337+
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++) {
338+
setRed(id);
339+
}
340+
341+
return true;
342+
}
343+
335344
bool BraccioClass::isPingAllowed()
336345
{
337346
mbed::ScopedLock<rtos::Mutex> lock(_motors_connected_mtx);

src/Braccio++.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class BraccioClass
7777
SmartServoClass servos;
7878
PD_UFP_log_c PD_UFP;
7979
TCA6424A _expander;
80+
bool expander_init();
8081

8182
bool _is_ping_allowed;
8283
bool _is_motor_connected[SmartServoClass::NUM_MOTORS];

0 commit comments

Comments
 (0)