Skip to content

Commit

Permalink
Bangle.js2: Bootloader now shows 'Hold button to turn on' to avoid us…
Browse files Browse the repository at this point in the history
…ers assuming it is dead when it's not
  • Loading branch information
gfwilliams committed Oct 15, 2024
1 parent c05f231 commit bac3a13
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
Bangle.js2: Pass the modified touch event on through both E.showScroller and E.showMenu (to enable more complex interaction with menus).
Bangle.js: Add Bangle.setOptions({manualWatchdog:true}) to enable users to supply their own JS watchdog
Bangle.js2: DFU update from flash now retries if CRC doesn't match

Bangle.js2: Bootloader now shows 'Hold button to turn on' to avoid users assuming it is dead when it's not

2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'
Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off)
Fix for unexpected power draw on newest batch of Bangle.js devices
Expand Down
19 changes: 16 additions & 3 deletions targets/nrf5x_dfu/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#define NRF_GPIO_PIN_CNF(PIN,value) NRF_P0->PIN_CNF[PIN]=value;
#endif

#ifdef BANGLEJS_F18
#define I2C_SDA 15
#define I2C_SCL 14
#endif

// Using a macro means we hard-code values from pinInfo, and can ditch the pinInfo array
#define jshPinSetValue(PIN,value) \
nrf_gpio_pin_write((uint32_t)pinInfo[PIN].pin, value ^ ((pinInfo[PIN].port&JSH_PIN_NEGATED)!=0))
Expand Down Expand Up @@ -93,6 +98,10 @@ static void print_fw_version(void) {
}

static void hardware_init(void) {
#ifdef I2C_SDA
nrf_gpio_cfg_input(I2C_SDA, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(I2C_SCL, NRF_GPIO_PIN_PULLUP);
#endif
#if defined(PIXLJS)
// LED1 is backlight - don't use it, but ensure it's off
jshPinOutput(LED1_PININDEX, 0);
Expand All @@ -102,7 +111,7 @@ static void hardware_init(void) {
NRF_GPIO_PIN_CNF(BTN1_PININDEX,0x0000000c); // BTN1 input (with pullup)
NRF_GPIO_PIN_CNF(BTN2_PININDEX,0x0000000c); // BTN2 input (with pullup)
jshPinOutput(LCD_BL, !LCD_BL_ON); // backlight off
// NRF_P1->OUT=0x00000001; // Backlight output high (for off)
// NRF_P1->OUT=0x00000001; // Backlight output high (for off)
#ifdef BAT_PIN_CHARGING
NRF_GPIO_PIN_CNF(BAT_PIN_CHARGING,0x0000000c); // Charge input (with pullup)
#endif
Expand Down Expand Up @@ -131,6 +140,10 @@ static void hardware_init(void) {
#ifdef VIBRATE_PIN
jshPinOutput(VIBRATE_PIN,0); // vibrate off
#endif


#ifdef GPS_PIN_EN
jshPinOutput(GPS_PIN_EN, 0); // GPS off
#endif
#ifdef HEARTRATE_PIN_EN
jshPinOutput(HEARTRATE_PIN_EN, 0); // HRM off
#endif
}
13 changes: 4 additions & 9 deletions targets/nrf5x_dfu/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,6 @@ void lcd_send_data(uint8_t cmd) {
}

void lcd_init() {
nrf_gpio_cfg_input(I2C_SDA, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(I2C_SCL, NRF_GPIO_PIN_PULLUP);

jshPinOutput(LCD_PIN_CS,1);
jshPinOutput(LCD_PIN_DC,1);
jshPinOutput(LCD_PIN_SCK,1);
Expand Down Expand Up @@ -735,16 +732,12 @@ void lcd_flip() {
}

void lcd_init() {
#ifdef GPS_PIN_EN
jshPinOutput(GPS_PIN_EN, 0); // GPS off
#endif
// jshPinOutput(LCD_BL, LCD_BL_ON); // Don't turn the backlight on yet, otherwise it could show garbage - do it at the end of lcd_flip() instead
#ifdef LCD_EN
jshPinOutput(LCD_EN,1); // enable on
#endif
// LCD Init 1
jshPinOutput(LCD_SPI_CS,1);

jshPinOutput(LCD_SPI_DC,1);
jshPinOutput(LCD_SPI_SCK,1);
jshPinOutput(LCD_SPI_MOSI,1);
Expand Down Expand Up @@ -817,7 +810,8 @@ void lcd_init() {
jshPinOutput(LCD_SPI_MOSI,1);
jshPinOutput(LCD_DISP,1);
jshPinOutput(LCD_EXTCOMIN,1);
jshPinOutput(LCD_BL, LCD_BL_ON); // backlight on
// don't turn backlight on - let's save power
//jshPinOutput(LCD_BL, LCD_BL_ON); // backlight on
jshDelayMicroseconds(10000);
// force LCD to clear itself
lcd_clear();
Expand Down Expand Up @@ -868,7 +862,6 @@ void lcd_print(char *ch) {
} else lcdx += 4;
ch++;
}
lcd_flip();
}
void lcd_print_hex(unsigned int v) {
char buf[11] = "0x";
Expand All @@ -882,6 +875,7 @@ void lcd_print_hex(unsigned int v) {
void lcd_println(char *ch) {
lcd_print(ch);
lcd_print("\r\n");
lcd_flip();
}
void lcd_clear() {
memset(lcd_data,0,sizeof(lcd_data));
Expand All @@ -901,4 +895,5 @@ void lcd_kill() {}
void lcd_clear() {}; // clear screen
void lcd_print(char *ch) {}
void lcd_println(char *ch) {}
void lcd_flip() {}
#endif
9 changes: 4 additions & 5 deletions targets/nrf5x_dfu/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#define LCD_DATA_WIDTH 120 // pixel doubled
#define LCD_DATA_HEIGHT 120 // pixel doubled
//#define LCD_STORE_MODIFIED // removed just to try and scrape a few extra bytes!
#define I2C_SDA 15
#define I2C_SCL 14
#define LCD_START_Y 16
#endif
#ifdef LCD_CONTROLLER_LPM013M126
Expand Down Expand Up @@ -69,8 +67,9 @@
void lcd_init();
void lcd_kill();
void lcd_clear();
void lcd_print(char *ch);
void lcd_print_hex(unsigned int v); // just for debugging - print a number
void lcd_println(char *ch);
void lcd_print(char *ch); // prints text, doesn't flip
void lcd_print_hex(unsigned int v); // just for debugging - print a number, doesn't flip
void lcd_println(char *ch); // prints a line and flips screen
void lcd_flip();


14 changes: 12 additions & 2 deletions targets/nrf5x_dfu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void turn_off() {
lcd_kill();
#if defined(SPIFLASH_SLEEP_CMD) && defined(ESPR_BOOTLOADER_SPIFLASH)
flashPowerDown(); // Put the SPI Flash into deep power-down
#endif
#endif
#if defined(VIBRATE_PIN) && !defined(DICKENS)
jshPinOutput(VIBRATE_PIN,1); // vibrate whilst waiting for button release
#endif
Expand Down Expand Up @@ -161,20 +161,25 @@ bool dfu_enter_check(void) {
#else
lcd_print("RELEASE BTN1 FOR DFU\r\nBTN1 TO BOOT\r\n\r\n< >\r");
#endif
lcd_flip();
#ifdef BTN1_PININDEX
int count = 20;
#ifdef BANGLEJS_F18
while (get_btn1_state() && --count) {
// the screen update takes long enough that
// we don't need a delay
lcd_print("=");
lcd_flip();
}
#else
count *= 128;
while (get_btn1_state() && count) {
nrf_delay_us(999);
set_led_state((count&3)==0, false);
if ((count&127)==0) lcd_print("=");
if ((count&127)==0) {
lcd_print("=");
lcd_flip();
}
count--;
}
#endif
Expand Down Expand Up @@ -345,6 +350,11 @@ int main(void)

hardware_init();

#ifdef BANGLEJS_Q3
lcd_init();
lcd_println("\n HOLD BUTTON\r\n TO TURN ON");
#endif

// Did we just power on? If not (we watchdog/softreset) RESETREAS will be nonzero

/* NRF_POWER->RESETREAS reset reason flags:
Expand Down

0 comments on commit bac3a13

Please sign in to comment.