Skip to content

Commit 53918c7

Browse files
authored
Merge pull request #1 from JF002/develop
Develop
2 parents 16e5b05 + a2d2f93 commit 53918c7

File tree

10 files changed

+482
-70
lines changed

10 files changed

+482
-70
lines changed

libs/pinetime_boot/include/pinetime_boot/pinetime_boot.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,36 @@
2525
extern "C" { // Expose the types and functions below to C functions.
2626
#endif
2727

28+
// Colors
29+
#define BLACK 0
30+
#define WHITE 0xffff
31+
#define RED 0xF800
32+
#define BLUE 0x001F
33+
#define GREEN 0x07E0
34+
2835
/// Init the display and render the boot graphic. Called by sysinit() during startup, defined in pkg.yml.
2936
void pinetime_boot_init(void);
3037

3138
/// Write a converted graphic file to SPI Flash
3239
int pinetime_boot_write_image(void);
3340

34-
/// Display the image in SPI Flash to ST7789 display controller
41+
/// Display the boot logo to ST7789 display controller
3542
int pinetime_boot_display_image(void);
43+
44+
/// Display the boot logo to ST7789 display controller using 2 colors. The first x lines (x = colorLine)
45+
/// will be drawn in color1, the rest in color2.
46+
int pinetime_boot_display_image_colors(uint16_t color1, uint16_t color2, uint8_t colorLine);
47+
48+
/// Display the bootloader version to ST7789 display controller
3649
int pinetime_version_image(void);
50+
51+
/// Clear the display
3752
void pinetime_clear_screen(void);
3853

3954
/// Check whether the watch button is pressed
4055
void pinetime_boot_check_button(void);
4156

42-
int pinetime_boot_display_image_colors(uint16_t color1, uint16_t color2, uint8_t colorLine);
57+
4358

4459
#ifdef __cplusplus
4560
}

libs/pinetime_boot/include/pinetime_boot/pinetime_factory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __PINETIME_FACTORY_H__
22
#define __PINETIME_FACTORY_H__
33

4+
/// Copy the recovery firmware from the external SPI Flash memory to the secondary slot.
5+
/// It'll be installed in the primary slot by MCUBoot.
46
void restore_factory(void);
57

68

libs/pinetime_boot/src/display.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
// ST7789 Colour Settings
4848
#define INVERTED 1 // Display colours are inverted
49-
#define RGB 1 // Display colours are RGB
49+
#define RGB 1 // Display colours are RGB
5050

5151
// Flash Device for Image
5252
#define FLASH_DEVICE 1 // 0 for Internal Flash ROM, 1 for External SPI Flash
@@ -105,67 +105,70 @@ static int write_data(const uint8_t *data, uint16_t len);
105105
static int transmit_spi(const uint8_t *data, uint16_t len);
106106

107107
/// Buffer for reading flash and writing to display
108-
static uint8_t flash_buffer[240*2];
108+
static uint8_t flash_buffer[COL_COUNT * BYTES_PER_PIXEL];
109109

110-
int pinetime_display_image_colors(struct imgInfo* info, int posx, int posy, uint16_t color1, uint16_t color2, uint8_t colorLine) {
110+
/// Display the image described by info to the ST7789 display controller using 2 colors. The first x lines (x = colorLine)
111+
/// will be drawn in color1, the rest in color2.
112+
int pinetime_display_image_colors(struct imgInfo* info, int posX, int posY, uint16_t color1, uint16_t color2, uint8_t colorLine) {
111113
int rc;
112114
int y = 0;
113-
uint16_t bp = 0;
114-
uint16_t fg = 0xffff;
115-
const uint16_t bg = 0;
116-
uint16_t color = bg;
117-
uint16_t trueColor = color;
118-
for (int i=0; i<info->dataSize; i++) {
119-
uint8_t rl = info->data[i];
120-
while (rl) {
121-
flash_buffer[bp] = trueColor >> 8;
122-
flash_buffer[bp + 1] = trueColor & 0xff;
123-
bp += 2;
124-
rl -= 1;
125-
126-
if (bp >= (info->width*2)) {
127-
rc = set_window(posx, y+posy, posx+info->width-1, y+posy); assert(rc == 0);
115+
uint16_t bufferIndex = 0;
116+
uint8_t isBackground = 1;
117+
const uint16_t backgroundColor = BLACK;
118+
uint16_t trueColor = backgroundColor;
119+
120+
for (int i = 0; i < info->dataSize; i++) {
121+
uint8_t runLength = info->data[i];
122+
while (runLength) {
123+
flash_buffer[bufferIndex] = trueColor >> 8;
124+
flash_buffer[bufferIndex + 1] = trueColor & 0xff;
125+
bufferIndex += BYTES_PER_PIXEL;
126+
runLength -= 1;
127+
128+
if (bufferIndex >= (info->width * BYTES_PER_PIXEL)) {
129+
rc = set_window(posX, y + posY, posX + info->width - 1, y + posY); assert(rc == 0);
128130

129131
// Write Pixels (RAMWR): st7735_lcd::draw() → set_pixel()
130132
rc = write_command(RAMWR, NULL, 0); assert(rc == 0);
131-
rc = write_data(flash_buffer, info->width*2); assert(rc == 0);
132-
bp = 0;
133+
rc = write_data(flash_buffer, info->width * BYTES_PER_PIXEL); assert(rc == 0);
134+
bufferIndex = 0;
133135
y += 1;
134136
}
135137
}
136138

137-
if (color == bg) {
138-
color = fg;
139+
if (isBackground) {
140+
isBackground = 0;
139141
trueColor = (y < colorLine) ? color1 : color2;
140142
}
141143
else {
142-
color = bg;
143-
trueColor = color;
144+
isBackground = 1;
145+
trueColor = backgroundColor;
144146
}
145147
if(y >= info->height)
146148
break;
147149
}
148150
return 0;
149151
}
150152

153+
/// Clear the display
151154
void pinetime_clear_screen(void) {
152155
int rc = 0;
153-
for(int i = 0 ; i < 240*2; i++) {
156+
for(int i = 0 ; i < COL_COUNT * BYTES_PER_PIXEL; i++) {
154157
flash_buffer[i] = 0;
155158
}
156-
for(int i = 0; i < 240; i++) {
157-
rc = set_window(0, i, 239, i); assert(rc == 0);
159+
for(int i = 0; i < ROW_COUNT; i++) {
160+
rc = set_window(0, i, COL_COUNT-1, i); assert(rc == 0);
158161
rc = write_command(RAMWR, NULL, 0); assert(rc == 0);
159-
rc = write_data(flash_buffer, 240*2); assert(rc == 0);
162+
rc = write_data(flash_buffer, COL_COUNT * BYTES_PER_PIXEL); assert(rc == 0);
160163
}
161164
}
162165

163-
int pinetime_display_image(struct imgInfo* info, int posx, int posy) {
164-
return pinetime_display_image_colors(info, posx, posy, 0xffff, 0xffff, 0);
166+
/// Display the image described by info at position (posX, posY) using default color (black and white)
167+
int pinetime_display_image(struct imgInfo* info, int posX, int posY) {
168+
return pinetime_display_image_colors(info, posX, posY, WHITE, WHITE, 0);
165169
}
166170

167-
/// Display the image in SPI Flash to ST7789 display controller.
168-
/// Derived from https://github.com/lupyuen/pinetime-rust-mynewt/blob/main/logs/spi-non-blocking.log
171+
/// Display the boot logo to ST7789 display controller
169172
int pinetime_boot_display_image(void) {
170173
console_printf("Displaying boot logo...\n"); console_flush();
171174

@@ -175,14 +178,16 @@ int pinetime_boot_display_image(void) {
175178
return pinetime_display_image(&bootLogoInfo, 0, 0);
176179
}
177180

181+
/// Display the boot logo to ST7789 display controller using 2 colors. The first x lines (x = colorLine)
182+
/// will be drawn in color1, the rest in color2.
178183
int pinetime_boot_display_image_colors(uint16_t color1, uint16_t color2, uint8_t colorLine) {
179184
return pinetime_display_image_colors(&bootLogoInfo, 0, 0, color1, color2, colorLine);
180185
}
181186

182-
187+
/// Display the bootloader version to ST7789 display controller on the bottom of the display (centered)
183188
int pinetime_version_image(void) {
184189
console_printf("Displaying version image...\n"); console_flush();
185-
return pinetime_display_image(&versionInfo, 120 - (versionInfo.width/2), 240 - (versionInfo.height));
190+
return pinetime_display_image(&versionInfo, (COL_COUNT/2) - (versionInfo.width/2), ROW_COUNT - (versionInfo.height));
186191
}
187192

188193
/// Set the ST7789 display window to the coordinates (left, top), (right, bottom)
@@ -316,7 +321,7 @@ static int transmit_spi(const uint8_t *data, uint16_t len) {
316321
// Select the device
317322
hal_gpio_write(DISPLAY_CS, 0);
318323
// Send the data
319-
int rc = hal_spi_txrx(DISPLAY_SPI,
324+
int rc = hal_spi_txrx(DISPLAY_SPI,
320325
(void *) data, // TX Buffer
321326
NULL, // RX Buffer (don't receive)
322327
len); // Length

libs/pinetime_boot/src/graphic.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,41 @@ struct imgInfo bootLogoInfo = {
110110
bootLogoRle
111111
};
112112

113-
// /home/jf/nrf52/Pinetime/tools/rle_encode.py /home/jf/nrf52/pinetime-rust-mynewt/libs/pinetime_boot/src/version-1.2.3.png --c
113+
// /home/jf/nrf52/Pinetime/tools/rle_encode.py /home/jf/nrf52/pinetime-rust-mynewt/libs/pinetime_boot/src/version-0.0.1.png --c
114114
static const uint8_t versionRle[] = {
115-
0x59, 0x56, 0x2, 0x1, 0x3, 0xc, 0x3, 0xa, 0x1, 0x38, 0x2, 0x1,
116-
0x3, 0xc, 0x3, 0x9, 0x2, 0x14, 0x6, 0x13, 0x6, 0x5, 0x2, 0x2,
117-
0x3, 0xb, 0x2, 0xa, 0x2, 0x13, 0x9, 0xf, 0xa, 0x3, 0x2, 0x2,
118-
0x3, 0xa, 0x3, 0x9, 0x3, 0x12, 0x4, 0x3, 0x4, 0xd, 0x5, 0x2,
119-
0x5, 0x2, 0x2, 0x2, 0x3, 0xa, 0x3, 0x6, 0x6, 0x11, 0x3, 0x6,
120-
0x4, 0xc, 0x3, 0x6, 0x3, 0x2, 0x2, 0x3, 0x3, 0x9, 0x2, 0x6,
121-
0x7, 0x11, 0x3, 0x7, 0x3, 0xc, 0x2, 0x8, 0x2, 0x2, 0x2, 0x3,
122-
0x3, 0x8, 0x3, 0x6, 0x7, 0x11, 0x2, 0x9, 0x2, 0xb, 0x3, 0x8,
123-
0x3, 0x1, 0x2, 0x4, 0x2, 0x8, 0x3, 0xb, 0x2, 0x11, 0x2, 0x9,
124-
0x2, 0xb, 0x3, 0x8, 0x2, 0x2, 0x2, 0x4, 0x3, 0x7, 0x2, 0xc,
125-
0x2, 0x1b, 0x3, 0x15, 0x3, 0x2, 0x2, 0x4, 0x3, 0x6, 0x3, 0xc,
126-
0x2, 0x1b, 0x3, 0x14, 0x4, 0x2, 0x2, 0x5, 0x3, 0x5, 0x3, 0xc,
127-
0x2, 0x1a, 0x3, 0x12, 0x5, 0x4, 0x2, 0x5, 0x3, 0x5, 0x2, 0xd,
128-
0x2, 0x19, 0x4, 0x12, 0x6, 0x3, 0x2, 0x5, 0x3, 0x4, 0x3, 0xd,
129-
0x2, 0x17, 0x4, 0x18, 0x3, 0x2, 0x2, 0x6, 0x3, 0x3, 0x3, 0xd,
130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, 0x6, 0x2, 0x6, 0xa, 0x6,
138+
0x2, 0x9, 0x3, 0xd, 0x5, 0x8, 0x2, 0x9, 0x5, 0x8, 0x2, 0x6,
139+
0xa, 0x6, 0x2, 0x56, 0x2, 0x56, 0x59,
140140

141141
};
142142

143+
143144
struct imgInfo versionInfo = {
144145
88,
145146
26,
146-
299,
147+
295,
147148
versionRle
148149
};
149150

libs/pinetime_boot/src/pinetime_boot.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pinetime_boot/pinetime_boot.h"
3030
#include "pinetime_boot/pinetime_factory.h"
3131
#include "pinetime_boot/pinetime_delay.h"
32+
#include <hal/hal_watchdog.h>
3233

3334
#define PUSH_BUTTON_IN 13 // GPIO Pin P0.13: PUSH BUTTON_IN
3435
#define PUSH_BUTTON_OUT 15 // GPIO Pin P0.15/TRACEDATA2: PUSH BUTTON_OUT
@@ -71,19 +72,20 @@ void pinetime_boot_init(void) {
7172
}
7273
if(i % 64 == 0) {
7374
console_printf("step %d - %d\n", (i / (64)) + 1, (int)button_samples); console_flush();
75+
hal_watchdog_tickle();
7476
}
7577

7678
if(i % 8 == 0) {
77-
uint16_t color = 0xF800;
79+
uint16_t color = RED;
7880
if (button_samples < 3000 * 64 * 2) {
79-
color = 0x07E0;
81+
color = GREEN;
8082
} else if (button_samples < 3000 * 64 * 4) {
81-
color = 0x001F;
83+
color = BLUE;
8284
} else {
83-
color = 0xF800;
85+
color = RED;
8486
}
8587

86-
pinetime_boot_display_image_colors(0xffff, color, 240 - ((i / 8) * 6) + 1);
88+
pinetime_boot_display_image_colors(WHITE, color, 240 - ((i / 8) * 6) + 1);
8789
}
8890
}
8991
console_printf("Waited 5 seconds (%d)\n", (int)button_samples); console_flush();
@@ -109,6 +111,7 @@ void pinetime_boot_init(void) {
109111
}
110112
}
111113

114+
/// Configure and start the watchdog
112115
void setup_watchdog() {
113116
NRF_WDT->CONFIG &= ~(WDT_CONFIG_SLEEP_Msk << WDT_CONFIG_SLEEP_Pos);
114117
NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Run << WDT_CONFIG_SLEEP_Pos);

libs/pinetime_boot/src/pinetime_factory.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pinetime_boot/pinetime_factory.h"
22
#include <hal/hal_flash.h>
33
#include "os/mynewt.h"
4+
#include <hal/hal_watchdog.h>
45

56
// Flash Device for Image
67
#define FLASH_DEVICE 1 // 0 for Internal Flash ROM, 1 for External SPI Flash
@@ -18,9 +19,11 @@ void restore_factory(void) {
1819
int rc;
1920
for (uint32_t erased = 0; erased < FACTORY_SIZE; erased += 0x1000) {
2021
rc = hal_flash_erase_sector(FLASH_DEVICE, FACTORY_OFFSET_DESTINATION + erased);
22+
hal_watchdog_tickle();
2123
}
2224

2325
for(uint32_t offset = 0; offset < FACTORY_SIZE; offset += BATCH_SIZE) {
26+
hal_watchdog_tickle();
2427
rc = hal_flash_read(FLASH_DEVICE, FACTORY_OFFSET_SOURCE + offset, flash_buffer, BATCH_SIZE);
2528
assert(rc == 0);
2629
rc = hal_flash_write(FLASH_DEVICE, FACTORY_OFFSET_DESTINATION + offset, flash_buffer, BATCH_SIZE);
768 Bytes
Loading
2.66 KB
Binary file not shown.

targets/nrf52_boot/syscfg.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ syscfg.vals:
4949
OS_SYSVIEW_TRACE_CALLOUT: 0 # Disable trace of callouts
5050
OS_SYSVIEW_TRACE_EVENTQ: 0 # Disable trace of event queues
5151
OS_SYSVIEW_TRACE_MUTEX: 0 # Disable trace of mutex
52-
OS_SYSVIEW_TRACE_SEM: 0 # Disable trace of semaphores
52+
OS_SYSVIEW_TRACE_SEM: 0 # Disable trace of semaphores
53+
BOOTUTIL_FEED_WATCHDOG: 1 # Enable watchdog feeding while performing a swap upgrade
54+
SANITY_INTERVAL: 1000 # The interval (in milliseconds) at which the sanity checks should run, should be at least 200ms prior to watchdog
55+
WATCHDOG_INTERVAL: 2000 # The interval (in milliseconds) at which the watchdog should reset if not tickled, in ms
56+

0 commit comments

Comments
 (0)