Skip to content

Commit 8a41004

Browse files
Merge pull request #5 from monolithicpower/dev
remove SPI setDataMode function and replace it by SPISettings. This will improve the compatibility of the code across different platforms. For instance setDataMode is not supported on mbed based platforms like the Raspberry Pi Pico
2 parents 33838a9 + f74adba commit 8a41004

File tree

6 files changed

+123
-4
lines changed

6 files changed

+123
-4
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Compile Examples
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/compile-examples.yml"
7+
- "examples/**"
8+
- "src/**"
9+
push:
10+
paths:
11+
- ".github/workflows/compile-examples.yml"
12+
- "examples/**"
13+
- "src/**"
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
env:
20+
SKETCHES_REPORTS_PATH: sketches-reports
21+
22+
strategy:
23+
fail-fast: false
24+
25+
matrix:
26+
board:
27+
- fqbn: arduino:avr:uno
28+
platforms: |
29+
- name: arduino:avr
30+
- fqbn: arduino:samd:mkr1000
31+
platforms: |
32+
- name: arduino:samd
33+
- fqbn: arduino:samd:mkrzero
34+
platforms: |
35+
- name: arduino:samd
36+
- fqbn: arduino:samd:mkrwifi1010
37+
platforms: |
38+
- name: arduino:samd
39+
- fqbn: arduino:samd:mkrfox1200
40+
platforms: |
41+
- name: arduino:samd
42+
- fqbn: arduino:samd:mkrwan1300
43+
platforms: |
44+
- name: arduino:samd
45+
- fqbn: arduino:samd:mkrwan1310
46+
platforms: |
47+
- name: arduino:samd
48+
- fqbn: arduino:samd:mkrgsm1400
49+
platforms: |
50+
- name: arduino:samd
51+
- fqbn: arduino:samd:mkrnb1500
52+
platforms: |
53+
- name: arduino:samd
54+
- fqbn: arduino:samd:mkrvidor4000
55+
platforms: |
56+
- name: arduino:samd
57+
- fqbn: arduino:mbed_rp2040:pico
58+
platforms: |
59+
- name: arduino:mbed_rp2040
60+
- fqbn: arduino:mbed_portenta:envie_m7
61+
platforms: |
62+
- name: arduino:mbed_portenta
63+
- fqbn: arduino:mbed_portenta:envie_m4
64+
platforms: |
65+
- name: arduino:mbed_portenta
66+
- fqbn: arduino:mbed_nano:nano33ble
67+
platforms: |
68+
- name: arduino:mbed_nano
69+
- fqbn: arduino:mbed_nano:nanorp2040connect
70+
platforms: |
71+
- name: arduino:mbed_nano
72+
- fqbn: arduino:mbed_edge:edge_control
73+
platforms: |
74+
- name: arduino:mbed_edge
75+
- fqbn: esp32:esp32:esp32
76+
platforms: |
77+
- name: esp32:esp32
78+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
79+
- fqbn: rp2040:rp2040:rpipico
80+
platforms: |
81+
- name: rp2040:rp2040
82+
source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
83+
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v3
87+
88+
- name: Install ESP32 platform dependencies
89+
if: startsWith(matrix.board.fqbn, 'esp32:esp32')
90+
run: pip3 install pyserial
91+
92+
- name: Compile examples
93+
uses: arduino/compile-sketches@v1
94+
with:
95+
fqbn: ${{ matrix.board.fqbn }}
96+
platforms: ${{ matrix.board.platforms }}
97+
enable-deltas-report: true
98+
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
99+
github-token: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Save memory usage change report as artifact
102+
if: github.event_name == 'pull_request'
103+
uses: actions/upload-artifact@v3
104+
with:
105+
name: ${{ env.SKETCHES_REPORTS_PATH }}
106+
path: ${{ env.SKETCHES_REPORTS_PATH }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# IDE related files
2+
.vscode/
3+
.idea/
4+
5+
# Build related folders
6+
build/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# MagAlpha library
2+
[![Compile Examples](https://github.com/monolithicpower/MagAlpha-Arduino-Library/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/monolithicpower/MagAlpha-Arduino-Library/actions/workflows/compile-examples.yml)
3+
24
Arduino library for the MPS MagAlpha magnetic angle sensor.
35

46
## About

examples/edit-magalpha-config/edit-magalpha-config.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void loop() {
2525
uint16_t angleRaw16;
2626
uint8_t angleRaw8;
2727

28-
Serial.println("Read Angle using differents methods:");
28+
Serial.println("Read Angle using different methods:");
2929

3030
//Read the angle in degree (Read 16-bit raw angle value and then convert it to the 0-360 degree range)
3131
angle = magAlpha.readAngle();
@@ -49,7 +49,7 @@ void loop() {
4949

5050
//Read the angle (16-bit raw angle value) and check the parity bit to detect possible communication error
5151
bool error;
52-
angleRaw16 = magAlpha.readAngleRaw16(&error);
52+
angleRaw16 = magAlpha.readAngleRaw(&error);
5353
Serial.print(" magAlpha.readAngleRaw16(&error) = ");
5454
Serial.print(angleRaw16, DEC);
5555
if (error == true){

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=MagAlpha Angle Sensor Library
2-
version=1.0.1
2+
version=1.0.2
33
author=Mathieu Kaelin, Monolithic Power Systems <sensors@monolithicpower.com>
44
maintainer=Mathieu Kaelin <sensors@monolithicpower.com>
55
sentence=Arduino library for the MPS MagAlpha magnetic angle sensor.

src/MagAlpha.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void MagAlpha::begin(int32_t spiSclkFrequency, uint8_t spiMode, uint8_t spiChip
3636
}
3737

3838
void MagAlpha::end(){
39+
SPI.endTransaction();
3940
SPI.end();
4041
}
4142

@@ -132,12 +133,14 @@ uint8_t MagAlpha::writeRegister(uint8_t address, uint8_t value){
132133

133134
void MagAlpha::setSpiClockFrequency(uint32_t speedMaximum){
134135
_speedMaximum = speedMaximum;
136+
SPI.endTransaction();
135137
SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, _spiMode));
136138
}
137139

138140
void MagAlpha::setSpiDataMode(uint8_t spiMode){
139141
_spiMode = spiMode;
140-
SPI.setDataMode(_spiMode);
142+
SPI.endTransaction();
143+
SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, _spiMode));
141144
}
142145

143146
void MagAlpha::setSpiChipSelectPin(uint8_t spiChipSelectPin){
@@ -167,6 +170,7 @@ void MagAlphaSSI::begin(int32_t ssiSsckFrequency){
167170
}
168171

169172
void MagAlphaSSI::end(){
173+
SPI.endTransaction();
170174
SPI.end();
171175
}
172176

@@ -234,6 +238,7 @@ uint16_t MagAlphaSSI::readAngleRaw(bool* error){
234238

235239
void MagAlphaSSI::setSsiClockFrequency(uint32_t speedMaximum){
236240
_speedMaximum = speedMaximum;
241+
SPI.endTransaction();
237242
SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, SSI_MODE));
238243
}
239244

0 commit comments

Comments
 (0)