Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/Arduino-Lint-Check.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: Arduino Lint Check
on:
push:
branches: [ master ]
branches: [main, master]
pull_request:
branches: [ master ]
branches: [main, master]
workflow_dispatch:
jobs:
lint:
name: Lint Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v2
with:
library-manager: update
compliance: strict
project-type: all
project-type: all
5 changes: 2 additions & 3 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ jobs:
matrix:
path:
- check: './' # path to include
exclude: './lib' # path to exclude
exclude: './include' # path to exclude
exclude: '(^|[\\/])(lib|include)([\\/]|$)' # paths to exclude
# - check: 'src'
# exclude: '(Fonts)' # Exclude file paths containing "Fonts"
# - check: 'examples'
# exclude: ''
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/clang-format-action@v4.9.0
with:
Expand Down
31 changes: 22 additions & 9 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
name: Build test with platformio
name: Build test with PlatformIO

on: [push, pull_request]
on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
name: Build (${{ matrix.environment }})
runs-on: ubuntu-latest

timeout-minutes: 30
strategy:
fail-fast: false
matrix:
environment:
- esp32-s3-devkitc-1
- esp32-s3-devkitc-1-arduino3311

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
key: ${{ runner.os }}-pio-${{ matrix.environment }}-${{ hashFiles('platformio.ini') }}
restore-keys: |
${{ runner.os }}-pio-${{ matrix.environment }}-
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
run: pip install platformio==6.1.19

- name: Build PlatformIO Project
run: pio run
run: pio run -e ${{ matrix.environment }}
53 changes: 53 additions & 0 deletions include/arduino_esp32_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <stdint.h>
#include <esp_arduino_version.h>
#include <esp_idf_version.h>

#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
#define STAMPFLY_ARDUINO_ESP32_V3 1
#define STAMPFLY_ARDUINO_ESP32_BRANCH_NAME "3.x compatibility branch"
#else
#define STAMPFLY_ARDUINO_ESP32_V3 0
#define STAMPFLY_ARDUINO_ESP32_BRANCH_NAME "legacy compatibility branch"
#endif

#define STAMPFLY_STRINGIFY_IMPL(value) #value
#define STAMPFLY_STRINGIFY(value) STAMPFLY_STRINGIFY_IMPL(value)
#define STAMPFLY_ARDUINO_ESP32_VERSION_STRING \
STAMPFLY_STRINGIFY(ESP_ARDUINO_VERSION_MAJOR) "." \
STAMPFLY_STRINGIFY(ESP_ARDUINO_VERSION_MINOR) "." \
STAMPFLY_STRINGIFY(ESP_ARDUINO_VERSION_PATCH)

#if STAMPFLY_ARDUINO_ESP32_V3
#include <esp_rom_sys.h>

static inline void stampfly_delay_us(uint32_t us)
{
esp_rom_delay_us(us);
}
#else
#include <rom/ets_sys.h>

static inline void stampfly_delay_us(uint32_t us)
{
ets_delay_us(us);
}
#endif
#ifdef __cplusplus
#if STAMPFLY_ARDUINO_ESP32_V3

#if !defined(ARDUINO_USB_MODE) || !ARDUINO_USB_MODE
#error "StampFly HWCDC compatibility requires ARDUINO_USB_MODE=1"
#endif

#if !defined(ARDUINO_USB_CDC_ON_BOOT) || !ARDUINO_USB_CDC_ON_BOOT
#error "StampFly HWCDC compatibility requires ARDUINO_USB_CDC_ON_BOOT=1"
#endif

#include <HWCDC.h>

#define USBSerial HWCDCSerial

#endif
#endif
27 changes: 27 additions & 0 deletions include/arduino_esp32_i2c_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <stddef.h>
#include <stdint.h>

#include "arduino_esp32_compat.h"

#ifdef __cplusplus
extern "C" {
#endif

#if STAMPFLY_ARDUINO_ESP32_V3

int stampfly_i2c_write(uint8_t i2c_num, uint16_t address, const uint8_t *data, size_t length);
int stampfly_i2c_read(uint8_t i2c_num, uint16_t address, uint8_t *data, size_t length);
int stampfly_i2c_write_read(uint8_t i2c_num,
uint16_t address,
const uint8_t *write_data,
size_t write_length,
uint8_t *read_data,
size_t read_length);

#endif

#ifdef __cplusplus
}
#endif
29 changes: 26 additions & 3 deletions lib/bmi270/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string.h>

#include "common.h"
#include "../../include/arduino_esp32_i2c_compat.h"
//#include "bmi2_defs.h"

//#include "driver/i2c.h"
Expand Down Expand Up @@ -39,18 +40,22 @@ static struct coines_intf_config intf_conf;
struct bmi2_dev Bmi270;
struct bmi2_dev *pBmi270=&Bmi270;

i2c_cmd_handle_t i2chandle;
#if !STAMPFLY_ARDUINO_ESP32_V3
static i2c_cmd_handle_t i2chandle;
#endif

// SPIデバイスハンドラーを使って通信する
spi_device_handle_t spidev;



#if !STAMPFLY_ARDUINO_ESP32_V3
i2c_port_t i2c_port=1;
#endif

uint8_t Bmi270_address = 0x69;

uint8_t _I2CBuffer[256];
static uint8_t _I2CBuffer[256];

struct bmi2_sens_config config;

Expand All @@ -65,6 +70,7 @@ void bmi270_dev_init(void)
Bmi270.gyro_en = 1;
}

#if !STAMPFLY_ARDUINO_ESP32_V3
void getI2cBus(void)
{
i2chandle = i2c_cmd_link_create();
Expand Down Expand Up @@ -98,6 +104,7 @@ int _i2cRead(uint8_t slave_address, uint8_t *pdata, uint32_t count) {
status = i2c_master_read_byte(i2chandle, pdata+count-1, I2C_MASTER_NACK);
return status;
}
#endif

/******************************************************************************/
/*! User interface functions */
Expand All @@ -111,6 +118,13 @@ BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_
int32_t status_int;

_I2CBuffer[0] = reg_addr;
#if STAMPFLY_ARDUINO_ESP32_V3
status_int = stampfly_i2c_write_read(1, Bmi270_address, _I2CBuffer, 1, reg_data, len);
if (status_int != 0) {
Status = 0x66;
}
return Status;
#else
getI2cBus();
status_int = _i2cWrite(Bmi270_address, _I2CBuffer, 1);
if (status_int != 0) {
Expand All @@ -124,6 +138,7 @@ BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_
done:
putI2cBus();
return Status;
#endif
}

/*!
Expand All @@ -138,13 +153,21 @@ BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data,
}
_I2CBuffer[0] = reg_addr;
memcpy(&_I2CBuffer[1], reg_data, len);
#if STAMPFLY_ARDUINO_ESP32_V3
status_int = stampfly_i2c_write(1, Bmi270_address, _I2CBuffer, len + 1);
if (status_int != 0) {
Status = 0x55;
}
return Status;
#else
getI2cBus();
status_int = _i2cWrite(Bmi270_address, _I2CBuffer, len + 1);
if (status_int != 0) {
Status = 0x55;
}
putI2cBus();
return Status;
#endif
}

//SPIバスの設定
Expand Down Expand Up @@ -256,7 +279,7 @@ BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data,
void bmi2_delay_us(uint32_t period, void *intf_ptr)
{
//coines_delay_usec(period);
ets_delay_us(period);
stampfly_delay_us(period);
}

/*!
Expand Down
3 changes: 3 additions & 0 deletions lib/bmi270/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ extern "C" {
#include <math.h>
#include "bmi2.h"
#include "bmi2_defs.h"
#include "../../include/arduino_esp32_i2c_compat.h"
#if !STAMPFLY_ARDUINO_ESP32_V3
#include "driver/i2c.h"
#endif
#include <driver/spi_master.h>
#include "driver/gpio.h"
#include "sdkconfig.h"
Expand Down
Loading
Loading