Skip to content

Commit 943ea13

Browse files
Merge pull request #633 from pimoroni/feature/badger2040w
Badger2040w support
2 parents 05391d2 + 5a62a79 commit 943ea13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4631
-18
lines changed

.github/workflows/micropython-badger2040.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
types: [created]
88

99
env:
10-
MICROPYTHON_VERSION: 67fac4ebc53db6337008ba06df7932faec80f57c
10+
MICROPYTHON_VERSION: 35524a6fda1e44692ad599a39c802c168c897de9
1111
BOARD_TYPE: PIMORONI_BADGER2040
1212
# MicroPython version will be contained in github.event.release.tag_name for releases
1313
RELEASE_FILE: pimoroni-badger2040-${{github.event.release.tag_name || github.sha}}-micropython
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: MicroPython for Badger2040W
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types: [created]
8+
9+
env:
10+
MICROPYTHON_VERSION: 67fac4ebc53db6337008ba06df7932faec80f57c
11+
BOARD_TYPE: PIMORONI_BADGER2040W
12+
# MicroPython version will be contained in github.event.release.tag_name for releases
13+
RELEASE_FILE: pimoroni-badger2040w-${{github.event.release.tag_name || github.sha}}-micropython
14+
15+
jobs:
16+
deps:
17+
runs-on: ubuntu-20.04
18+
name: Dependencies
19+
steps:
20+
- name: Workspace Cache
21+
id: cache
22+
uses: actions/cache@v3
23+
with:
24+
path: ${{runner.workspace}}
25+
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}
26+
restore-keys: |
27+
workspace-micropython-${{env.MICROPYTHON_VERSION}}
28+
29+
# Check out MicroPython
30+
- name: Checkout MicroPython
31+
if: steps.cache.outputs.cache-hit != 'true'
32+
uses: actions/checkout@v3
33+
with:
34+
repository: micropython/micropython
35+
ref: ${{env.MICROPYTHON_VERSION}}
36+
submodules: false # MicroPython submodules are hideously broken
37+
path: micropython
38+
39+
- name: Fetch base MicroPython submodules
40+
if: steps.cache.outputs.cache-hit != 'true'
41+
shell: bash
42+
working-directory: micropython
43+
run: git submodule update --init
44+
45+
- name: Fetch Pico SDK submodules
46+
if: steps.cache.outputs.cache-hit != 'true'
47+
shell: bash
48+
working-directory: micropython/lib/pico-sdk
49+
run: git submodule update --init
50+
51+
- name: Build mpy-cross
52+
if: steps.cache.outputs.cache-hit != 'true'
53+
shell: bash
54+
working-directory: micropython/mpy-cross
55+
run: make
56+
57+
build:
58+
needs: deps
59+
name: Build Badger 2040W
60+
runs-on: ubuntu-20.04
61+
62+
steps:
63+
- name: Compiler Cache
64+
uses: actions/cache@v3
65+
with:
66+
path: /home/runner/.ccache
67+
key: ccache-micropython-badger2040w-${{github.ref}}-${{github.sha}}
68+
restore-keys: |
69+
ccache-micropython-badger2040w-${{github.ref}}
70+
ccache-micropython-badger2040w-
71+
72+
- name: Workspace Cache
73+
uses: actions/cache@v3
74+
with:
75+
path: ${{runner.workspace}}
76+
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}
77+
restore-keys: |
78+
workspace-micropython-${{env.MICROPYTHON_VERSION}}
79+
80+
- uses: actions/checkout@v3
81+
with:
82+
submodules: true
83+
path: pimoroni-pico-${{ github.sha }}
84+
85+
# Check out dir2u2f
86+
- uses: actions/checkout@v3
87+
with:
88+
repository: gadgetoid/dir2uf2
89+
ref: v0.0.1
90+
path: dir2uf2
91+
92+
- name: "HACK: MicroPython Board Fixups"
93+
shell: bash
94+
working-directory: micropython/ports/rp2
95+
run: |
96+
../../../pimoroni-pico-${GITHUB_SHA}/micropython/_board/board-fixup.sh badger2040w ${{env.BOARD_TYPE}} ../../../pimoroni-pico-${GITHUB_SHA}/micropython/_board
97+
98+
# Linux deps
99+
- name: Install Compiler & CCache
100+
if: runner.os == 'Linux'
101+
run: |
102+
sudo apt update && sudo apt install ccache gcc-arm-none-eabi
103+
python3 -m pip install pillow
104+
105+
# Build firmware
106+
- name: Configure MicroPython
107+
shell: bash
108+
working-directory: micropython/ports/rp2
109+
run: |
110+
cmake -S . -B build-${{env.BOARD_TYPE}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython-badger2040w.cmake -DMICROPY_BOARD=${{env.BOARD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
111+
112+
- name: Build MicroPython
113+
shell: bash
114+
working-directory: micropython/ports/rp2
115+
run: |
116+
ccache --zero-stats || true
117+
cmake --build build-${{env.BOARD_TYPE}} -j 2
118+
ccache --show-stats || true
119+
120+
- name: Rename .uf2 for artifact
121+
shell: bash
122+
working-directory: micropython/ports/rp2/build-${{env.BOARD_TYPE}}
123+
run: |
124+
cp firmware.uf2 ${{env.RELEASE_FILE}}.uf2
125+
126+
- name: Append Filesystem
127+
shell: bash
128+
run: |
129+
python3 -m pip install littlefs-python
130+
./dir2uf2/dir2uf2 --append-to micropython/ports/rp2/build-${{env.BOARD_TYPE}}/${{env.RELEASE_FILE}}.uf2 --manifest pimoroni-pico-${{ github.sha }}/micropython/examples/badger2040w/uf2-manifest.txt --filename with-examples.uf2 pimoroni-pico-${{ github.sha }}/micropython/examples/badger2040w/
131+
132+
- name: Store .uf2 as artifact
133+
uses: actions/upload-artifact@v3
134+
with:
135+
name: ${{env.RELEASE_FILE}}.uf2
136+
path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/${{env.RELEASE_FILE}}.uf2
137+
138+
- name: Store .uf2 + examples as artifact
139+
uses: actions/upload-artifact@v3
140+
with:
141+
name: ${{env.RELEASE_FILE}}-with-examples.uf2
142+
path: ${{env.RELEASE_FILE}}-with-examples.uf2
143+
144+
- name: Upload .uf2
145+
if: github.event_name == 'release'
146+
uses: actions/upload-release-asset@v1
147+
env:
148+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
149+
with:
150+
asset_path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/${{env.RELEASE_FILE}}.uf2
151+
upload_url: ${{github.event.release.upload_url}}
152+
asset_name: ${{env.RELEASE_FILE}}.uf2
153+
asset_content_type: application/octet-stream

drivers/icp10125/icp10125.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ namespace pimoroni {
3939
}
4040

4141
void ICP10125::reset() {
42-
uint16_t command = __bswap16(SOFT_RESET);
42+
uint16_t command = __builtin_bswap16(SOFT_RESET);
4343
i2c->write_blocking(address, (uint8_t *)&command, 2, false);
4444
sleep_ms(10); // Soft reset time is 170us but you can never be too sure...
4545
}
4646

4747
ICP10125::reading ICP10125::measure(meas_command cmd) {
48-
uint16_t command = __bswap16(cmd);
48+
uint16_t command = __builtin_bswap16(cmd);
4949
reading result = {0.0f, 0.0f, OK};
5050
uint16_result results[3];
5151

@@ -74,17 +74,17 @@ namespace pimoroni {
7474
if(results[1].crc8 != crc8((uint8_t *)&results[1].data, 2)) {result.status = CRC_FAIL; return result;};
7575
if(results[2].crc8 != crc8((uint8_t *)&results[2].data, 2)) {result.status = CRC_FAIL; return result;};
7676

77-
int temperature = __bswap16(results[0].data);
77+
int temperature = __builtin_bswap16(results[0].data);
7878
// Due to all the byte swapping nonsense I'm not sure if I've discarded the LLSB or LMSB here...
79-
int pressure = ((int32_t)__bswap16(results[1].data) << 8) | (__bswap16(results[2].data >> 8)); // LLSB is discarded
79+
int pressure = ((int32_t)__builtin_bswap16(results[1].data) << 8) | (__builtin_bswap16(results[2].data >> 8)); // LLSB is discarded
8080

8181
process_data(pressure, temperature, &result.pressure, &result.temperature);
8282
return result;
8383
}
8484

8585
int ICP10125::chip_id() {
8686
uint16_result result;
87-
uint16_t command = __bswap16(READ_ID);
87+
uint16_t command = __builtin_bswap16(READ_ID);
8888

8989
i2c->write_blocking(address, (uint8_t *)&command, 2, true);
9090
i2c->read_blocking(address, (uint8_t *)&result, 3, false);
@@ -93,12 +93,12 @@ namespace pimoroni {
9393
return -1;
9494
}
9595

96-
return __bswap16(result.data) & 0x3f;
96+
return __builtin_bswap16(result.data) & 0x3f;
9797
}
9898

9999
bool ICP10125::read_otp() {
100100
uint16_result result[4];
101-
uint16_t command = __bswap16(READ_OTP);
101+
uint16_t command = __builtin_bswap16(READ_OTP);
102102
uint8_t move_address_ptr[] = {
103103
MOVE_ADDRESS_PTR >> 8, MOVE_ADDRESS_PTR & 0xff,
104104
0x00,
@@ -114,7 +114,7 @@ namespace pimoroni {
114114
if(result[x].crc8 != crc8((uint8_t *)&result[x].data, 2)) {
115115
return false;
116116
}
117-
sensor_constants[x] = (float)__bswap16(result[x].data);
117+
sensor_constants[x] = (float)__builtin_bswap16(result[x].data);
118118
}
119119

120120
return true;

drivers/vl53l1x/vl53l1x.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ namespace pimoroni {
205205
i2c->read_blocking(address, (uint8_t *)&value, 2, false);
206206

207207
// TODO do we need to bswap this return value?
208-
return __bswap16(value);
208+
return __builtin_bswap16(value);
209209
}
210210

211211
// Read a 32-bit register

libraries/pico_graphics/pico_graphics.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,15 @@ namespace pimoroni {
164164
}
165165

166166
if (hershey_font) {
167-
hershey::text(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
168-
line(Point(x1, y1), Point(x2, y2));
169-
}, t, p.x, p.y, s, a);
167+
if(thickness == 1) {
168+
hershey::text(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
169+
line(Point(x1, y1), Point(x2, y2));
170+
}, t, p.x, p.y, s, a);
171+
} else {
172+
hershey::text(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
173+
thick_line(Point(x1, y1), Point(x2, y2), thickness);
174+
}, t, p.x, p.y, s, a);
175+
}
170176
return;
171177
}
172178
}
@@ -292,6 +298,42 @@ namespace pimoroni {
292298
}
293299
}
294300

301+
void PicoGraphics::thick_line(Point p1, Point p2, uint thickness) {
302+
// general purpose line
303+
// lines are either "shallow" or "steep" based on whether the x delta
304+
// is greater than the y delta
305+
int32_t dx = p2.x - p1.x;
306+
int32_t dy = p2.y - p1.y;
307+
bool shallow = std::abs(dx) > std::abs(dy);
308+
if(shallow) {
309+
// shallow version
310+
int32_t s = std::abs(dx); // number of steps
311+
int32_t sx = dx < 0 ? -1 : 1; // x step value
312+
int32_t sy = (dy << 16) / s; // y step value in fixed 16:16
313+
int32_t x = p1.x;
314+
int32_t y = p1.y << 16;
315+
while(s--) {
316+
int32_t ht = thickness / 2;
317+
rectangle({x - ht, (y >> 16) - ht, ht * 2, ht * 2});
318+
y += sy;
319+
x += sx;
320+
}
321+
}else{
322+
// steep version
323+
int32_t s = std::abs(dy); // number of steps
324+
int32_t sy = dy < 0 ? -1 : 1; // y step value
325+
int32_t sx = (dx << 16) / s; // x step value in fixed 16:16
326+
int32_t y = p1.y;
327+
int32_t x = p1.x << 16;
328+
while(s--) {
329+
int32_t ht = thickness / 2;
330+
rectangle({(x >> 16) - ht, y - ht, ht * 2, ht * 2});
331+
y += sy;
332+
x += sx;
333+
}
334+
}
335+
}
336+
295337
void PicoGraphics::line(Point p1, Point p2) {
296338
// fast horizontal line
297339
if(p1.y == p2.y) {

libraries/pico_graphics/pico_graphics.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ namespace pimoroni {
175175
PenType pen_type;
176176
Rect bounds;
177177
Rect clip;
178+
uint thickness = 1;
178179

179180

180181

@@ -228,6 +229,7 @@ namespace pimoroni {
228229
virtual void set_pen(uint8_t r, uint8_t g, uint8_t b) = 0;
229230
virtual void set_pixel(const Point &p) = 0;
230231
virtual void set_pixel_span(const Point &p, uint l) = 0;
232+
virtual void set_thickness(uint t) = 0;
231233

232234
virtual int create_pen(uint8_t r, uint8_t g, uint8_t b);
233235
virtual int create_pen_hsv(float h, float s, float v);
@@ -264,6 +266,7 @@ namespace pimoroni {
264266
void triangle(Point p1, Point p2, Point p3);
265267
void line(Point p1, Point p2);
266268
void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b);
269+
void thick_line(Point p1, Point p2, uint thickness);
267270

268271
protected:
269272
void frame_convert_rgb565(conversion_callback_func callback, next_pixel_func get_next_pixel);
@@ -276,6 +279,7 @@ namespace pimoroni {
276279
PicoGraphics_Pen1Bit(uint16_t width, uint16_t height, void *frame_buffer);
277280
void set_pen(uint c) override;
278281
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
282+
void set_thickness(uint t) override;
279283

280284
void set_pixel(const Point &p) override;
281285
void set_pixel_span(const Point &p, uint l) override;
@@ -292,6 +296,7 @@ namespace pimoroni {
292296
PicoGraphics_Pen1BitY(uint16_t width, uint16_t height, void *frame_buffer);
293297
void set_pen(uint c) override;
294298
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
299+
void set_thickness(uint t) override;
295300

296301
void set_pixel(const Point &p) override;
297302
void set_pixel_span(const Point &p, uint l) override;
@@ -334,6 +339,7 @@ namespace pimoroni {
334339

335340
void set_pen(uint c) override;
336341
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
342+
void set_thickness(uint t) override {};
337343

338344
void set_pixel(const Point &p) override;
339345
void set_pixel_span(const Point &p, uint l) override;
@@ -360,6 +366,7 @@ namespace pimoroni {
360366
PicoGraphics_PenP4(uint16_t width, uint16_t height, void *frame_buffer);
361367
void set_pen(uint c) override;
362368
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
369+
void set_thickness(uint t) override {};
363370
int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override;
364371
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
365372
int reset_pen(uint8_t i) override;
@@ -389,6 +396,7 @@ namespace pimoroni {
389396
PicoGraphics_PenP8(uint16_t width, uint16_t height, void *frame_buffer);
390397
void set_pen(uint c) override;
391398
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
399+
void set_thickness(uint t) override {};
392400
int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override;
393401
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
394402
int reset_pen(uint8_t i) override;
@@ -410,6 +418,7 @@ namespace pimoroni {
410418
PicoGraphics_PenRGB332(uint16_t width, uint16_t height, void *frame_buffer);
411419
void set_pen(uint c) override;
412420
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
421+
void set_thickness(uint t) override {};
413422
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
414423
void set_pixel(const Point &p) override;
415424
void set_pixel_span(const Point &p, uint l) override;
@@ -431,6 +440,7 @@ namespace pimoroni {
431440
PicoGraphics_PenRGB565(uint16_t width, uint16_t height, void *frame_buffer);
432441
void set_pen(uint c) override;
433442
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
443+
void set_thickness(uint t) override {};
434444
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
435445
int create_pen_hsv(float h, float s, float v) override;
436446
void set_pixel(const Point &p) override;
@@ -447,6 +457,7 @@ namespace pimoroni {
447457
PicoGraphics_PenRGB888(uint16_t width, uint16_t height, void *frame_buffer);
448458
void set_pen(uint c) override;
449459
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
460+
void set_thickness(uint t) override {};
450461
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
451462
int create_pen_hsv(float h, float s, float v) override;
452463
void set_pixel(const Point &p) override;

libraries/pico_graphics/pico_graphics_pen_1bit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace pimoroni {
1818
color = std::max(r, std::max(g, b)) >> 4;
1919
}
2020

21+
void PicoGraphics_Pen1Bit::set_thickness(uint t) {
22+
thickness = t;
23+
}
24+
2125
void PicoGraphics_Pen1Bit::set_pixel(const Point &p) {
2226
// pointer to byte in framebuffer that contains this pixel
2327
uint8_t *buf = (uint8_t *)frame_buffer;

0 commit comments

Comments
 (0)