Skip to content

Commit

Permalink
Jolt.js: ensure GPIO attached to outputs always default to input at s…
Browse files Browse the repository at this point in the history
…tartup
  • Loading branch information
gfwilliams committed Jun 20, 2024
1 parent f663093 commit da9f8e9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Bangle.js2: Allow configuring device privacy to use random BLE addresses
Fix STM32 Nucleo regression from ESPR_PACKED_SYMPTR
Fixed issue with static fields in classes if defined before the constructor (fix #2517)
Jolt.js: ensure GPIO attached to outputs always default to input at startup

2v22 : Graphics: Ensure floodFill sets modified area correctly
nRF52: Lower expected BLE XTAL accuracy to 50ppm (can improve BLE stability on some Bangle.js 2)
Expand Down
8 changes: 6 additions & 2 deletions boards/JOLTJS.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@
'pin_d0' : 'D17',
'pin_d1' : 'D15',
'pin_d2' : 'D13',
'pin_d3' : 'D14'
'pin_d3' : 'D14',
'pin_d0_analog' : 'D4',
'pin_d2_analog' : 'D5'
},
'DRIVER1' : {
'pin_nsleep' : 'D23',
Expand All @@ -127,7 +129,9 @@
'pin_d0' : 'D22',
'pin_d1' : 'D32',
'pin_d2' : 'D25',
'pin_d3' : 'D34'
'pin_d3' : 'D34',
'pin_d0_analog' : 'D30',
'pin_d2_analog' : 'D28'
}
};

Expand Down
41 changes: 31 additions & 10 deletions libs/joltjs/jswrap_jolt.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ bool _jswrap_jolt_selfTest(bool advertisePassOrFail) {
jswrap_jolt_setDriverMode_(1,true);
// test every pin on the motor driver one at a time
for (int i=0;i<8;i++) {
for (int p=0;p<8;p++)
for (int p=0;p<8;p++) {
jshPinSetState(JSH_PORTH_OFFSET+p, JSHPINSTATE_GPIO_OUT);
jshPinSetValue(JSH_PORTH_OFFSET+p, p == i);
}
nrf_delay_ms(5);
// we can only read H0/2/4/8
for (int p=0;p<8;p+=2) {
Expand Down Expand Up @@ -537,6 +539,9 @@ bool _jswrap_jolt_selfTest(bool advertisePassOrFail) {
jsiConsolePrintf("Error code %s\n",err);
}

// ensure we put motor driver back to sleep
jswrap_jolt_hwinit();

return ok;
}
bool jswrap_jolt_selfTest() {
Expand All @@ -560,22 +565,38 @@ void jswrap_jolt_hwinit() {
driverMode[0] = JDM_AUTO;
driverMode[1] = JDM_AUTO;
// set all outputs to 0 by default
jshPinOutput(DRIVER0_PIN_D0, 0);
jshPinOutput(DRIVER0_PIN_D1, 0);
jshPinOutput(DRIVER0_PIN_D2, 0);
jshPinOutput(DRIVER0_PIN_D3, 0);
jshPinOutput(DRIVER1_PIN_D0, 0);
jshPinOutput(DRIVER1_PIN_D1, 0);
jshPinOutput(DRIVER1_PIN_D2, 0);
jshPinOutput(DRIVER1_PIN_D3, 0);
Pin driverPins[] = {
DRIVER0_PIN_D0,
DRIVER0_PIN_D1,
DRIVER0_PIN_D2,
DRIVER0_PIN_D3,
DRIVER1_PIN_D0,
DRIVER1_PIN_D1,
DRIVER1_PIN_D2,
DRIVER1_PIN_D3
};
for (int i=0;i<8;i++) {
Pin pin = driverPins[i];
jshPinSetState(pin, JSHPINSTATE_GPIO_IN);
jshSetPinStateIsManual(pin, false);
}
Pin analogPins[] = {
DRIVER0_PIN_D0_ANALOG,
DRIVER0_PIN_D2_ANALOG,
DRIVER1_PIN_D0_ANALOG,
DRIVER1_PIN_D2_ANALOG
};
for (int i=0;i<4;i++) {
Pin pin = analogPins[i];
jshPinSetState(pin, JSHPINSTATE_ADC_IN);
}
}

/*JSON{
"type" : "init",
"generate" : "jswrap_jolt_init"
}*/
void jswrap_jolt_init() {

/* If the button is pressed during reset, perform a self test.
* With bootloader this means apply power while holding button for >3 secs */
bool firstStart = jsiStatus & JSIS_FIRST_BOOT; // is this the first time jswrapjolt_init was called?
Expand Down

0 comments on commit da9f8e9

Please sign in to comment.