Skip to content

Commit 0d18847

Browse files
author
Juri
committedJul 14, 2019
Merge remote-tracking branch 'Calliope-DAL/merge-upstream' into pxtgc
2 parents 6e9b1d5 + c7331c1 commit 0d18847

28 files changed

+2206
-81
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
build
2-
.yotta.json
32
yotta_modules
43
yotta_targets
54
*.swp
65
*~
76
Makefile
7+
.idea
8+
*.iml

‎.yotta.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"build": {
3+
"target": "calliope-mini-classic-gcc,*",
4+
"targetSetExplicitly": true
5+
}
6+
}

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
> This is a fork of the original microbit-dal adapted for the [Calliope](http://calliope.cc) board.
2+
> The master branch tracks the __latest changes__ (board rev. 1.0+), for code covering the 2016 board (rev 0.3 and lower)
3+
> see the [calliope-mini-2016 branch](../../tree/calliope-mini-2016).
4+
15
# microbit-dal
26

37
The core set of drivers, mechanisms and types that make up the micro:bit runtime.

‎inc/bluetooth/MicroBitIOPinService.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DEALINGS IN THE SOFTWARE.
3030
#include "ble/BLE.h"
3131
#include "MicroBitIO.h"
3232

33-
#define MICROBIT_IO_PIN_SERVICE_PINCOUNT 19
33+
#define MICROBIT_IO_PIN_SERVICE_PINCOUNT 20
3434
#define MICROBIT_IO_PIN_SERVICE_DATA_SIZE 10
3535
#define MICROBIT_PWM_PIN_SERVICE_DATA_SIZE 2
3636

‎inc/core/MicroBitComponent.h

+23-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2121
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2222
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2323
DEALINGS IN THE SOFTWARE.
24+
25+
==================
26+
Modifications Copyright (c) 2016 Calliope GbR
27+
Modifications are provided by DELTA Systems (Georg Sommer) - Thomas Kern
28+
und Björn Eberhardt GbR by arrangement with Calliope GbR.
2429
*/
2530

2631
#ifndef MICROBIT_COMPONENT_H
@@ -37,27 +42,34 @@ DEALINGS IN THE SOFTWARE.
3742
#define MICROBIT_ID_DISPLAY 6
3843

3944
//EDGE connector events
45+
#ifdef TARGET_NRF51_CALLIOPE
46+
#define MICROBIT_IO_PINS 21
47+
#else
4048
#define MICROBIT_IO_PINS 20
49+
#endif
4150

42-
#define MICROBIT_ID_IO_P0 7 //P0 is the left most pad (ANALOG/DIGITAL)
43-
#define MICROBIT_ID_IO_P1 8 //P1 is the middle pad (ANALOG/DIGITAL)
44-
#define MICROBIT_ID_IO_P2 9 //P2 is the right most pad (ANALOG/DIGITAL)
51+
#define MICROBIT_ID_IO_P0 7 //P0 is the left most pad (ANALOG/DIGITAL) (CM: P1)
52+
#define MICROBIT_ID_IO_P1 8 //P1 is the middle pad (ANALOG/DIGITAL) (CM: P2)
53+
#define MICROBIT_ID_IO_P2 9 //P2 is the right most pad (ANALOG/DIGITAL) (CM: analog/tx)
4554
#define MICROBIT_ID_IO_P3 10 //COL1 (ANALOG/DIGITAL)
4655
#define MICROBIT_ID_IO_P4 11 //BTN_A
4756
#define MICROBIT_ID_IO_P5 12 //COL2 (ANALOG/DIGITAL)
4857
#define MICROBIT_ID_IO_P6 13 //ROW2
4958
#define MICROBIT_ID_IO_P7 14 //ROW1
50-
#define MICROBIT_ID_IO_P8 15 //PIN 18
59+
#define MICROBIT_ID_IO_P8 15 //PIN 18 (CM: analog/tx)
5160
#define MICROBIT_ID_IO_P9 16 //ROW3
5261
#define MICROBIT_ID_IO_P10 17 //COL3 (ANALOG/DIGITAL)
5362
#define MICROBIT_ID_IO_P11 18 //BTN_B
54-
#define MICROBIT_ID_IO_P12 19 //PIN 20
63+
#define MICROBIT_ID_IO_P12 19 //PIN 20 (CM: P0)
5564
#define MICROBIT_ID_IO_P13 20 //SCK
5665
#define MICROBIT_ID_IO_P14 21 //MISO
5766
#define MICROBIT_ID_IO_P15 22 //MOSI
58-
#define MICROBIT_ID_IO_P16 23 //PIN 16
67+
#define MICROBIT_ID_IO_P16 23 //PIN 16 (CM: P3)
5968
#define MICROBIT_ID_IO_P19 24 //SCL
6069
#define MICROBIT_ID_IO_P20 25 //SDA
70+
#ifdef TARGET_NRF51_CALLIOPE
71+
#define MICROBIT_ID_IO_P21 50 // CM: analog microphone
72+
#endif
6173

6274
#define MICROBIT_ID_BUTTON_AB 26 // Button A+B multibutton
6375
#define MICROBIT_ID_GESTURE 27 // Gesture events
@@ -86,17 +98,17 @@ DEALINGS IN THE SOFTWARE.
8698
*
8799
* All components should inherit from this class.
88100
*
89-
* If a component requires regular updates, then that component can be added to the
101+
* If a component requires regular updates, then that component can be added to the
90102
* to the systemTick and/or idleTick queues. This provides a simple, extensible mechanism
91103
* for code that requires periodic/occasional background processing but does not warrant
92-
* the complexity of maintaining its own thread.
104+
* the complexity of maintaining its own thread.
93105
*
94-
* Two levels of support are available.
106+
* Two levels of support are available.
95107
*
96108
* systemTick() provides a periodic callback during the
97109
* micro:bit's system timer interrupt. This provides a guaranteed periodic callback, but in interrupt context
98110
* and is suitable for code with lightweight processing requirements, but strict time constraints.
99-
*
111+
*
100112
* idleTick() provides a periodic callback whenever the scheduler is idle. This provides occasional, callbacks
101113
* in the main thread context, but with no guarantees of frequency. This is suitable for non-urgent background tasks.
102114
*
@@ -133,7 +145,7 @@ class MicroBitComponent
133145

134146
/**
135147
* The idle thread will call this member function once the component has been added to the array
136-
* of idle components using fiber_add_idle_component.
148+
* of idle components using fiber_add_idle_component.
137149
*/
138150
virtual void idleTick()
139151
{

‎inc/drivers/BMX055Accelerometer.h

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2019 ubirch GmbH.
5+
Adapted from LSM303Accelerometer.h by (c) Lancaster University.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the "Software"),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
#ifndef BMX055_ACCELEROMETER_H
27+
#define BMX055_ACCELEROMETER_H
28+
29+
#include "MicroBitConfig.h"
30+
#include "MicroBitComponent.h"
31+
#include "CoordinateSystem.h"
32+
#include "MicroBitAccelerometer.h"
33+
#include "MicroBitI2C.h"
34+
#include "MicroBitUtil.h"
35+
36+
#define BMX055_A_DEFAULT_ADDR 0x30 //!< address of the BMX055 accelerometer
37+
38+
#define BMX055_A_WHOAMI 0x00 // should return 0xFA
39+
//#define BMX055_A_Reserved 0x01
40+
#define BMX055_A_D_X_LSB 0x02
41+
#define BMX055_A_D_X_MSB 0x03
42+
#define BMX055_A_D_Y_LSB 0x04
43+
#define BMX055_A_D_Y_MSB 0x05
44+
#define BMX055_A_D_Z_LSB 0x06
45+
#define BMX055_A_D_Z_MSB 0x07
46+
#define BMX055_A_D_TEMP 0x08
47+
#define BMX055_A_INT_STATUS_0 0x09
48+
#define BMX055_A_INT_STATUS_1 0x0A
49+
#define BMX055_A_INT_STATUS_2 0x0B
50+
#define BMX055_A_INT_STATUS_3 0x0C
51+
//#define BMX055_A_Reserved 0x0D
52+
#define BMX055_A_FIFO_STATUS 0x0E
53+
#define BMX055_A_PMU_RANGE 0x0F
54+
#define BMX055_A_PMU_BW 0x10
55+
#define BMX055_A_PMU_LPW 0x11
56+
#define BMX055_A_PMU_LOW_POWER 0x12
57+
#define BMX055_A_D_HBW 0x13
58+
#define BMX055_A_BGW_SOFTRESET 0x14
59+
//#define BMX055_A_Reserved 0x15
60+
#define BMX055_A_INT_EN_0 0x16
61+
#define BMX055_A_INT_EN_1 0x17
62+
#define BMX055_A_INT_EN_2 0x18
63+
#define BMX055_A_INT_MAP_0 0x19
64+
#define BMX055_A_INT_MAP_1 0x1A
65+
#define BMX055_A_INT_MAP_2 0x1B
66+
//#define BMX055_A_Reserved 0x1C
67+
//#define BMX055_A_Reserved 0x1D
68+
#define BMX055_A_INT_SRC 0x1E
69+
//#define BMX055_A_Reserved 0x1F
70+
#define BMX055_A_INT_OUT_CTRL 0x20
71+
#define BMX055_A_INT_RST_LATCH 0x21
72+
#define BMX055_A_INT_0 0x22
73+
#define BMX055_A_INT_1 0x23
74+
#define BMX055_A_INT_2 0x24
75+
#define BMX055_A_INT_3 0x25
76+
#define BMX055_A_INT_4 0x26
77+
#define BMX055_A_INT_5 0x27
78+
#define BMX055_A_INT_6 0x28
79+
#define BMX055_A_INT_7 0x29
80+
#define BMX055_A_INT_8 0x2A
81+
#define BMX055_A_INT_9 0x2B
82+
#define BMX055_A_INT_A 0x2C
83+
#define BMX055_A_INT_B 0x2D
84+
#define BMX055_A_INT_C 0x2E
85+
#define BMX055_A_INT_D 0x2F
86+
#define BMX055_A_FIFO_CONFIG_0 0x30
87+
//#define BMX055_A_Reserved 0x31
88+
#define BMX055_A_PMU_SELF_TEST 0x32
89+
#define BMX055_A_TRIM_NVM_CTRL 0x33
90+
#define BMX055_A_BGW_SPI3_WDT 0x34
91+
//#define BMX055_A_Reserved 0x35
92+
#define BMX055_A_OFC_CTRL 0x36
93+
#define BMX055_A_OFC_SETTING 0x37
94+
#define BMX055_A_OFC_OFFSET_X 0x38
95+
#define BMX055_A_OFC_OFFSET_Y 0x39
96+
#define BMX055_A_OFC_OFFSET_Z 0x3A
97+
#define BMX055_A_TRIM_GPO 0x3B
98+
#define BMX055_A_TRIM_GP1 0x3C
99+
//#define BMX055_A_Reserved 0x3D
100+
#define BMX055_A_FIFO_CONFIG_1 0x3E
101+
#define BMX055_A_FIFO_DATA 0x3F
102+
103+
#define BMX055_A_WHOAMI_VAL 0xFA
104+
105+
/**
106+
* Class definition for BMX055Accelerometer.
107+
*
108+
* This class defines the interface for the BMX055 accelerometer.
109+
*/
110+
class BMX055Accelerometer : public MicroBitAccelerometer
111+
{
112+
MicroBitI2C& i2c; // The I2C interface to use.
113+
MicroBitPin int1; // Data ready interrupt.
114+
uint16_t address; // I2C address of this accelerometer.
115+
116+
public:
117+
118+
/**
119+
* Constructor.
120+
* Create a software abstraction of an accelerometer.
121+
*
122+
* @param coordinateSpace The orientation of the sensor. Defaults to: SIMPLE_CARTESIAN
123+
* @param id The unique EventModel id of this component. Defaults to: MICROBIT_ID_ACCELEROMETER
124+
*
125+
*/
126+
BMX055Accelerometer(MicroBitI2C& _i2c, MicroBitPin _int1, CoordinateSpace &coordinateSpace, uint16_t address = BMX055_A_DEFAULT_ADDR, uint16_t id = MICROBIT_ID_ACCELEROMETER);
127+
128+
/**
129+
* Configures the accelerometer for G range and sample rate defined
130+
* in this object. The nearest values are chosen to those defined
131+
* that are supported by the hardware. The instance variables are then
132+
* updated to reflect reality.
133+
*
134+
* @return MICROBIT_OK on success, MICROBIT_I2C_ERROR if the accelerometer could not be configured.
135+
*
136+
* @note This method should be overidden by the hardware driver to implement the requested
137+
* changes in hardware.
138+
*/
139+
virtual int configure();
140+
141+
/**
142+
* Poll to see if new data is available from the hardware. If so, update it.
143+
* n.b. it is not necessary to explicitly call this funciton to update data
144+
* (it normally happens in the background when the scheduler is idle), but a check is performed
145+
* if the user explicitly requests up to date data.
146+
*
147+
* @return MICROBIT_OK on success, MICROBIT_I2C_ERROR if the update fails.
148+
*
149+
* @note This method should be overidden by the hardware driver to implement the requested
150+
* changes in hardware.
151+
*/
152+
virtual int requestUpdate();
153+
154+
/**
155+
* A periodic callback invoked by the fiber scheduler idle thread.
156+
*
157+
* Internally calls updateSample().
158+
*/
159+
virtual void idleTick();
160+
161+
/**
162+
* Attempts to read the 8 bit WHO_AM_I value from the accelerometer
163+
*
164+
* @return true if the WHO_AM_I value is succesfully read. false otherwise.
165+
*/
166+
static int isDetected(MicroBitI2C &i2c, uint16_t address = BMX055_A_DEFAULT_ADDR);
167+
168+
/**
169+
* Destructor.
170+
*/
171+
~BMX055Accelerometer();
172+
173+
};
174+
175+
#endif
176+

0 commit comments

Comments
 (0)
Please sign in to comment.