Skip to content

Commit e03407e

Browse files
authored
Merge pull request #4 from fpistm/Example
Add an example and CI
2 parents 45ca013 + d1e1d3a commit e03407e

9 files changed

Lines changed: 215 additions & 41 deletions

File tree

.github/workflows/astyle.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Astyle Check
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Astyle check
14+
id: Astyle
15+
uses: stm32duino/actions/astyle-check@master
16+
# Use the output from the `Astyle` step
17+
- name: Astyle Errors
18+
if: failure()
19+
run: |
20+
cat ${{ steps.Astyle.outputs.astyle-result }}
21+
exit 1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Compile Examples
2+
on:
3+
- push
4+
- pull_request
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
fqbn:
13+
- STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG
14+
# - STMicroelectronics:stm32:Disco:pnum=B_U585I_IOT02A
15+
# - STMicroelectronics:stm32:Disco:pnum=STM32WB5MM_DK
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: arduino/compile-sketches@v1
20+
with:
21+
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
fqbn: ${{ matrix.fqbn }}
23+
platforms: |
24+
- source-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/package_stmicroelectronics_index.json
25+
name: STMicroelectronics:stm32

.github/workflows/spell-check.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Spell Check
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Spell check
14+
uses: arduino/actions/libraries/spell-check@master
15+
with:
16+
ignore-words-list: ./extras/codespell-ignore-words-list.txt
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
@file ISM330DHCX_DataLogTerminal.ino
3+
@author Frederic Pillon <frederic.pillon@st.com>
4+
@brief Example to use the ISM330DHCX 3D accelerometer and 3D gyroscope
5+
*******************************************************************************
6+
Copyright (c) 2021, STMicroelectronics
7+
All rights reserved.
8+
9+
This software component is licensed by ST under BSD 3-Clause license,
10+
the "License"; You may not use this file except in compliance with the
11+
License. You may obtain a copy of the License at:
12+
opensource.org/licenses/BSD-3-Clause
13+
14+
*******************************************************************************
15+
*/
16+
17+
18+
// Includes
19+
#include <ISM330DHCXSensor.h>
20+
21+
#define SerialPort Serial
22+
23+
#if defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_B_U585I_IOT02A)
24+
#define USE_I2C_INTERFACE
25+
#else
26+
// Uncomment one communication interface to use:
27+
// X-NUCLEO-IKS02A1 uses I2C interface (set by default)
28+
// #define USE_SPI_INTERFACE
29+
#define USE_I2C_INTERFACE
30+
#endif
31+
32+
#if !defined(USE_SPI_INTERFACE) && !defined(USE_I2C_INTERFACE) || \
33+
defined(USE_SPI_INTERFACE) && defined(USE_I2C_INTERFACE)
34+
#error "Uncomment one communication interface to use!"
35+
#endif
36+
37+
#ifdef USE_SPI_INTERFACE
38+
// Uncomment to set SPI pins to use else default instance will be used
39+
// #define ISM330DHCX_SPI_MOSI PB10
40+
// #define ISM330DHCX_SPI_MISO PB11
41+
// #define ISM330DHCX_SPI_SCLK PB11
42+
// Define Software Chip Select pin to use (default: SS)
43+
#define ISM330DHCX_SPI_SSEL SS
44+
45+
#if defined(ISM330DHCX_SPI_MOSI) && defined(ISM330DHCX_SPI_MISO) && \
46+
defined(ISM330DHCX_SPI_SCLK) && defined(ISM330DHCX_SPI_SSEL)
47+
SPIClass dev_interface(ISM330DHCX_SPI_MOSI, ISM330DHCX_SPI_MISO, ISM330DHCX_SPI_SCLK);
48+
#else
49+
#define dev_interface SPI
50+
#endif
51+
52+
ISM330DHCXSensor AccGyr(&dev_interface, ISM330DHCX_SPI_SSEL);
53+
#else // USE_I2C_INTERFACE
54+
#if defined(ARDUINO_STM32WB5MM_DK)
55+
#define ISM330DHCX_I2C_SCL PB13
56+
#define ISM330DHCX_I2C_SDA PB11
57+
#elif defined(ARDUINO_B_U585I_IOT02A)
58+
#define ISM330DHCX_I2C_SCL PH4
59+
#define ISM330DHCX_I2C_SDA PH5
60+
#else
61+
// Uncomment to set I2C pins to use else default instance will be used
62+
// #define ISM330DHCX_I2C_SCL PYn
63+
// #define ISM330DHCX_I2C_SDA PYn
64+
#endif
65+
#if defined(ISM330DHCX_I2C_SCL) && defined(ISM330DHCX_I2C_SDA)
66+
TwoWire dev_interface(ISM330DHCX_I2C_SDA, ISM330DHCX_I2C_SCL);
67+
#else
68+
// X-NUCLEO-IKS02A1 uses default instance
69+
#define dev_interface Wire
70+
#endif
71+
72+
ISM330DHCXSensor AccGyr(&dev_interface);
73+
#endif
74+
75+
void setup() {
76+
// Led
77+
pinMode(LED_BUILTIN, OUTPUT);
78+
// Initialize serial for output
79+
SerialPort.begin(9600);
80+
81+
// Initialize bus interface
82+
dev_interface.begin();
83+
84+
// Initlialize component
85+
AccGyr.begin();
86+
AccGyr.ACC_Enable();
87+
AccGyr.GYRO_Enable();
88+
}
89+
90+
void loop() {
91+
// Led blinking
92+
digitalWrite(LED_BUILTIN, HIGH);
93+
delay(250);
94+
digitalWrite(LED_BUILTIN, LOW);
95+
delay(250);
96+
97+
// Read accelerometer and gyroscope
98+
int32_t accelerometer[3];
99+
int32_t gyroscope[3];
100+
AccGyr.ACC_GetAxes(accelerometer);
101+
AccGyr.GYRO_GetAxes(gyroscope);
102+
103+
// Print compatible with Serial plotter
104+
Serial.print("Acc[mg]:");
105+
Serial.print(accelerometer[0]);
106+
Serial.print(", ");
107+
Serial.print(accelerometer[1]);
108+
Serial.print(", ");
109+
Serial.print(accelerometer[2]);
110+
Serial.print(", Gyro[mdps]:");
111+
Serial.print(gyroscope[0]);
112+
Serial.print(", ");
113+
Serial.print(gyroscope[1]);
114+
Serial.print(", ");
115+
Serial.println(gyroscope[2]);
116+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ois

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino ISM330DHCX
2-
version=2.0.0
2+
version=2.0.1
33
author=SRA
44
maintainer=stm32duino
55
sentence=High-Performance 3D digital accelerometer and 3D digital gyroscope.

src/ISM330DHCXSensor.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ISM330DHCXSensor::ISM330DHCXSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed
2828
reg_ctx.read_reg = ISM330DHCX_io_read;
2929
reg_ctx.handle = (void *) this;
3030
dev_i2c = NULL;
31-
address = 0U;
31+
address = 0U;
3232
acc_is_enabled = 0U;
3333
gyro_is_enabled = 0U;
3434
}
@@ -92,15 +92,13 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::Init()
9292
*/
9393
ISM330DHCXStatusTypeDef ISM330DHCXSensor::begin()
9494
{
95-
if(dev_spi)
96-
{
95+
if (dev_spi) {
9796
// Configure CS pin
9897
pinMode(cs_pin, OUTPUT);
99-
digitalWrite(cs_pin, HIGH);
98+
digitalWrite(cs_pin, HIGH);
10099
}
101100

102-
if (Init() != ISM330DHCX_OK)
103-
{
101+
if (Init() != ISM330DHCX_OK) {
104102
return ISM330DHCX_ERROR;
105103
}
106104

@@ -114,21 +112,18 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::begin()
114112
ISM330DHCXStatusTypeDef ISM330DHCXSensor::end()
115113
{
116114
/* Disable both acc and gyro */
117-
if (ACC_Disable() != ISM330DHCX_OK)
118-
{
115+
if (ACC_Disable() != ISM330DHCX_OK) {
119116
return ISM330DHCX_ERROR;
120117
}
121118

122-
if (GYRO_Disable() != ISM330DHCX_OK)
123-
{
119+
if (GYRO_Disable() != ISM330DHCX_OK) {
124120
return ISM330DHCX_ERROR;
125121
}
126122

127123
/* Reset CS configuration */
128-
if(dev_spi)
129-
{
124+
if (dev_spi) {
130125
// Configure CS pin
131-
pinMode(cs_pin, INPUT);
126+
pinMode(cs_pin, INPUT);
132127
}
133128

134129
return ISM330DHCX_OK;
@@ -763,7 +758,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::WriteReg(uint8_t reg, uint8_t data)
763758

764759
/*
765760
* @brief Get the ISM330DHCX Status of the Event
766-
* @param Status pointer to a structur Event_Status_t
761+
* @param Status pointer to a structure Event_Status_t
767762
* @retval 0 in case of success, an error code otherwise
768763
*/
769764
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetEventStatus(ISM330DHCX_Event_Status_t *Status)
@@ -907,7 +902,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_Get_DRDY_Status(uint8_t *Status)
907902
/**
908903
* @brief Set HP filter for ISM330DHCX accelerometer
909904
* @param CutOff value to set frequency
910-
* @retval 0 in case of succes, an error code otherwise
905+
* @retval 0 in case of success, an error code otherwise
911906
*/
912907
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_Enable_HP_Filter(ism330dhcx_hp_slope_xl_en_t CutOff)
913908
{
@@ -991,7 +986,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_Get_DRDY_Status(uint8_t *Status)
991986
/**
992987
* @brief Set HP filter for ISM330DHCX gyroscope
993988
* @param CutOff value to set frequency
994-
* @retval 0 in case of succes, an error code otherwise
989+
* @retval 0 in case of success, an error code otherwise
995990
*/
996991
ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_Enable_HP_Filter(ism330dhcx_hpm_g_t CutOff)
997992
{

src/ism330dhcx_reg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ int32_t ism330dhcx_steps_reset(ism330dhcx_ctx_t *ctx)
14951495

14961496
/**
14971497
* @defgroup ISM330DHCX_common
1498-
* @brief This section groups common usefull functions.
1498+
* @brief This section groups common useful functions.
14991499
* @{
15001500
*
15011501
*/
@@ -1670,7 +1670,7 @@ int32_t ism330dhcx_ln_pg_write_byte(ism330dhcx_ctx_t *ctx, uint16_t add,
16701670
* @param ctx Read / write interface definitions.(ptr)
16711671
* @param buf Page line address.(ptr)
16721672
* @param val Value to write.
1673-
* @param len buffer lengh.
1673+
* @param len buffer length.
16741674
* @retval Interface status (MANDATORY: return 0 -> no Error).
16751675
*
16761676
*/
@@ -3817,7 +3817,7 @@ int32_t ism330dhcx_i2c_interface_get(ism330dhcx_ctx_t *ctx,
38173817
/**
38183818
* @defgroup ISM330DHCX_interrupt_pins
38193819
* @brief This section groups all the functions that manage
3820-
* interrup pins
3820+
* interrupt pins
38213821
* @{
38223822
*
38233823
*/

src/ism330dhcx_reg.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ extern "C" {
5757
*/
5858

5959
typedef union {
60-
int16_t i16bit[3];
61-
uint8_t u8bit[6];
60+
int16_t i16bit[3];
61+
uint8_t u8bit[6];
6262
} axis3bit16_t;
6363

6464
typedef union {
65-
int16_t i16bit;
66-
uint8_t u8bit[2];
65+
int16_t i16bit;
66+
uint8_t u8bit[2];
6767
} axis1bit16_t;
6868

6969
typedef union {
70-
int32_t i32bit[3];
71-
uint8_t u8bit[12];
70+
int32_t i32bit[3];
71+
uint8_t u8bit[12];
7272
} axis3bit32_t;
7373

7474
typedef union {
75-
int32_t i32bit;
76-
uint8_t u8bit[4];
75+
int32_t i32bit;
76+
uint8_t u8bit[4];
7777
} axis1bit32_t;
7878

7979
/**
@@ -82,14 +82,14 @@ typedef union {
8282
*/
8383

8484
typedef struct {
85-
uint8_t bit0 : 1;
86-
uint8_t bit1 : 1;
87-
uint8_t bit2 : 1;
88-
uint8_t bit3 : 1;
89-
uint8_t bit4 : 1;
90-
uint8_t bit5 : 1;
91-
uint8_t bit6 : 1;
92-
uint8_t bit7 : 1;
85+
uint8_t bit0 : 1;
86+
uint8_t bit1 : 1;
87+
uint8_t bit2 : 1;
88+
uint8_t bit3 : 1;
89+
uint8_t bit4 : 1;
90+
uint8_t bit5 : 1;
91+
uint8_t bit6 : 1;
92+
uint8_t bit7 : 1;
9393
} bitwise_t;
9494

9595
#define PROPERTY_DISABLE (0U)
@@ -140,11 +140,11 @@ typedef int32_t (*ism330dhcx_write_ptr)(void *, uint8_t, uint8_t *, uint16_t);
140140
typedef int32_t (*ism330dhcx_read_ptr)(void *, uint8_t, uint8_t *, uint16_t);
141141

142142
typedef struct {
143-
/** Component mandatory fields **/
144-
ism330dhcx_write_ptr write_reg;
145-
ism330dhcx_read_ptr read_reg;
146-
/** Customizable optional pointer **/
147-
void *handle;
143+
/** Component mandatory fields **/
144+
ism330dhcx_write_ptr write_reg;
145+
ism330dhcx_read_ptr read_reg;
146+
/** Customizable optional pointer **/
147+
void *handle;
148148
} ism330dhcx_ctx_t;
149149

150150
/**

0 commit comments

Comments
 (0)