Skip to content

Commit 78a1c12

Browse files
committed
working
1 parent 8b08ddc commit 78a1c12

14 files changed

+6874
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.elf
2+
*.hex
3+
*.img
4+
*.log
5+
*.o
6+
*.ppu
7+
release/

bcmfw.pas

+5,754
Large diffs are not rendered by default.

build.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
set -e
3+
4+
LPR=$1
5+
if [[ $LPR == "" ]]
6+
then
7+
LPR=microbitdemo
8+
fi
9+
10+
CONF=$2
11+
if [[ $CONF == "" ]]
12+
then
13+
CONF=RPI3
14+
fi
15+
case $CONF in
16+
RPI)
17+
PROC=RPIB
18+
ARCH=ARMV6
19+
KERNEL=kernel.img
20+
;;
21+
RPI2)
22+
PROC=RPI2B
23+
ARCH=ARMV7a
24+
KERNEL=kernel7.img
25+
;;
26+
RPI3)
27+
PROC=RPI3B
28+
ARCH=ARMV7a
29+
KERNEL=kernel7.img
30+
;;
31+
esac
32+
33+
echo build.sh $LPR $CONF
34+
35+
ULTIBO=$HOME/ultibo/core
36+
ULTIBOBIN=$ULTIBO/fpc/bin
37+
REPO=prototype-microbit-as-ultibo-peripheral
38+
export PATH=$ULTIBOBIN:$PATH
39+
for f in *.lpr *.pas
40+
do
41+
ptop -l 1000 -i 1 -c ptop.cfg $f $f.formatted
42+
mv $f.formatted $f
43+
done
44+
45+
rm -rf lib/ *.o
46+
fpc -dBUILD_$CONF -B -O2 -Tultibo -Parm -Cp$ARCH -Wp$PROC -Fi$ULTIBO/source/rtl/ultibo/extras -Fi$ULTIBO/source/rtl/ultibo/core @$ULTIBOBIN/$CONF.CFG $LPR.lpr >& errors.log
47+
48+
mv $KERNEL $LPR-kernel-$CONF.img

create-release.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e # exit script on any error
3+
4+
VERSION=v$(date +%Y.%m.%d.%H%M)
5+
REPO=prototype-microbit-as-ultibo-peripheral
6+
ZIPFILE=$REPO-$VERSION.zip
7+
PATH=$HOME/hub-linux-arm-2.3.0-pre10/bin:$PATH
8+
9+
mkdir -p release
10+
rm -rf release/*
11+
12+
rm -f *kernel*.img
13+
LPR=microbitdemo
14+
for CONF in RPI RPI2 RPI3
15+
do
16+
./build.sh $LPR $CONF
17+
done
18+
set -x
19+
cp -a *.img release/
20+
cp -a *.hex release/
21+
cp -a $LPR-config.txt $LPR-cmdline.txt release/
22+
cp -a release/$LPR-config.txt release/config.txt
23+
echo "$REPO $VERSION" >> release/release-message.md
24+
echo >> release/release-message.md
25+
cat release-message.md >> release/release-message.md
26+
cp -a firmware/boot/bootcode.bin firmware/boot/start.elf firmware/boot/fixup.dat release/
27+
cd release
28+
zip $ZIPFILE *
29+
ls -lt $ZIPFILE
30+
cd ..
31+
32+
hub release create -d -p -F release/release-message.md -a release/$ZIPFILE $VERSION

firmware/boot/bootcode.bin

50.8 KB
Binary file not shown.

firmware/boot/fixup.dat

6.42 KB
Binary file not shown.

firmware/boot/start.elf

2.69 MB
Binary file not shown.

main.cpp

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include "MicroBit.h"
2+
MicroBit uBit;
3+
const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10};
4+
uint8_t advertising = 0;
5+
uint8_t tx_power_level = 6;
6+
uint8_t AdvData [] = {0xff, 0xff,
7+
0x55, 0x97,
8+
'0', '0',
9+
'.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'};
10+
uint8_t buttonsState = 0;
11+
uint8_t eventCounter = 0;
12+
13+
char digit(uint8_t n)
14+
{
15+
return '0' + n;
16+
}
17+
18+
void startAdvertising() {
19+
int connectable = 0;
20+
int interval = 160;
21+
uBit.bleManager.setTransmitPower(tx_power_level);
22+
uBit.bleManager.ble->setAdvertisingType(connectable ? GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED : GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
23+
uBit.bleManager.ble->setAdvertisingInterval(interval);
24+
uBit.bleManager.ble->clearAdvertisingPayload();
25+
uBit.bleManager.ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
26+
uBit.bleManager.ble->accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
27+
uBit.bleManager.ble->startAdvertising();
28+
uBit.display.printAsync("ULTIBO", 200);
29+
advertising = 1;
30+
}
31+
32+
void updatePayload ()
33+
{
34+
uBit.bleManager.ble->clearAdvertisingPayload();
35+
uBit.bleManager.ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
36+
AdvData [4] = digit (eventCounter / 10);
37+
AdvData [5] = digit (eventCounter % 10);
38+
for (int i = 19; i >= 1; i--)
39+
{
40+
AdvData [i + 6] = AdvData [i + 6 - 1];
41+
}
42+
AdvData [6] = buttonsState + '0';
43+
uBit.bleManager.ble->accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
44+
}
45+
46+
void stopAdvertising() {
47+
uBit.bleManager.stopAdvertising();
48+
uBit.display.scroll("OFF");
49+
advertising = 0;
50+
}
51+
52+
char text[] = "?";
53+
54+
void onButton(MicroBitEvent e)
55+
{
56+
uint8_t mask;
57+
uint8_t prev = buttonsState;
58+
if (e.source == MICROBIT_ID_BUTTON_A)
59+
mask = 0x01;
60+
61+
if (e.source == MICROBIT_ID_BUTTON_B)
62+
mask = 0x02;
63+
64+
if (e.source == MICROBIT_ID_BUTTON_AB)
65+
mask = 0x04;
66+
67+
if (e.source == MICROBIT_ID_IO_P0)
68+
mask = 0x08;
69+
70+
if (e.source == MICROBIT_ID_IO_P1)
71+
mask = 0x10;
72+
73+
if (e.source == MICROBIT_ID_IO_P2)
74+
mask = 0x20;
75+
76+
if (e.value == MICROBIT_BUTTON_EVT_DOWN)
77+
buttonsState |= mask;
78+
79+
if (e.value == MICROBIT_BUTTON_EVT_UP)
80+
buttonsState &= ~mask;
81+
82+
if (buttonsState != prev)
83+
{
84+
eventCounter = (eventCounter + 1) % 100;
85+
switch (buttonsState)
86+
{
87+
case 0: text [0] = ' ';
88+
break;
89+
case 1: text [0] = 'A';
90+
break;
91+
case 2: text [0] = 'B';
92+
break;
93+
case 3: text [0] = '2';
94+
break;
95+
default: text [0] = '?';
96+
}
97+
uBit.display.printAsync (text);
98+
updatePayload ();
99+
}
100+
101+
// if (e.value == MICROBIT_BUTTON_EVT_CLICK)
102+
// uBit.serial.printf("CLICK");
103+
//
104+
// if (e.value == MICROBIT_BUTTON_EVT_LONG_CLICK)
105+
// uBit.serial.printf("LONG_CLICK");
106+
//
107+
// if (e.value == MICROBIT_BUTTON_EVT_HOLD)
108+
// uBit.serial.printf("HOLD");
109+
//
110+
// if (e.value == MICROBIT_BUTTON_EVT_DOUBLE_CLICK)
111+
// uBit.serial.printf("DOUBLE_CLICK");
112+
//
113+
// uBit.serial.printf("\r\n");
114+
}
115+
116+
int main()
117+
{
118+
uBit.init();
119+
uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_EVT_ANY, onButton);
120+
uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_EVT_ANY, onButton);
121+
startAdvertising();
122+
release_fiber();
123+
}

microbitdemo-cmdline.txt

Whitespace-only changes.

microbitdemo-config.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[pi0]
2+
kernel=microbitdemo-kernel-RPI.img
3+
4+
[pi0w]
5+
kernel=microbitdemo-kernel-RPI.img
6+
7+
[pi1]
8+
kernel=microbitdemo-kernel-RPI.img
9+
10+
[pi2]
11+
kernel=microbitdemo-kernel-RPI2.img
12+
13+
[pi3]
14+
kernel=microbitdemo-kernel-RPI3.img
15+
16+
[pi3+]
17+
kernel=microbitdemo-kernel-RPI3.img
18+
19+
[all]
20+
cmdline=microbitdemo-cmdline.txt

0 commit comments

Comments
 (0)