From 060e49888fca157f59819f83e4bd0a64e8a41d0f Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sat, 16 Sep 2023 15:59:21 +0200 Subject: [PATCH] Fix #45 support STM set I2C pins --- AS5600.cpp | 32 +++++++++++++++++++++++++++++--- AS5600.h | 7 ++++--- CHANGELOG.md | 6 ++++++ README.md | 12 ++++++++++++ library.json | 4 ++-- library.properties | 2 +- 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/AS5600.cpp b/AS5600.cpp index 03ddeb6..33b03bd 100644 --- a/AS5600.cpp +++ b/AS5600.cpp @@ -1,7 +1,7 @@ // // FILE: AS56000.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.4.0 +// VERSION: 0.4.1 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -79,6 +79,32 @@ bool AS5600::begin(int dataPin, int clockPin, uint8_t directionPin) #endif +#if defined (STM32) + +bool AS5600::begin(int dataPin, int clockPin, uint8_t directionPin) +{ + _directionPin = directionPin; + if (_directionPin != AS5600_SW_DIRECTION_PIN) + { + pinMode(_directionPin, OUTPUT); + } + setDirection(AS5600_CLOCK_WISE); + + if ((dataPin < 255) && (clockPin < 255)) + { + _wire->setSDA(dataPin); + _wire->setSCL(clockPin); + _wire->begin(); + } else { + _wire->begin(); + } + if (! isConnected()) return false; + return true; +} + +#endif + + bool AS5600::begin(uint8_t directionPin) { _directionPin = directionPin; @@ -331,7 +357,7 @@ uint16_t AS5600::rawAngle() int16_t value = readReg2(AS5600_RAW_ANGLE) & 0x0FFF; if (_offset > 0) value = (value + _offset) & 0x0FFF; - if ((_directionPin == AS5600_SW_DIRECTION_PIN) && + if ((_directionPin == AS5600_SW_DIRECTION_PIN) && (_direction == AS5600_COUNTERCLOCK_WISE)) { value = (4096 - value) & 0x0FFF; @@ -345,7 +371,7 @@ uint16_t AS5600::readAngle() uint16_t value = readReg2(AS5600_ANGLE) & 0x0FFF; if (_offset > 0) value = (value + _offset) & 0x0FFF; - if ((_directionPin == AS5600_SW_DIRECTION_PIN) && + if ((_directionPin == AS5600_SW_DIRECTION_PIN) && (_direction == AS5600_COUNTERCLOCK_WISE)) { value = (4096 - value) & 0x0FFF; diff --git a/AS5600.h b/AS5600.h index 08c88bb..6bd4904 100644 --- a/AS5600.h +++ b/AS5600.h @@ -2,7 +2,7 @@ // // FILE: AS5600.h // AUTHOR: Rob Tillaart -// VERSION: 0.4.0 +// VERSION: 0.4.1 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -12,7 +12,7 @@ #include "Wire.h" -#define AS5600_LIB_VERSION (F("0.4.0")) +#define AS5600_LIB_VERSION (F("0.4.1")) // default addresses const uint8_t AS5600_DEFAULT_ADDRESS = 0x36; @@ -89,10 +89,11 @@ class AS5600 public: AS5600(TwoWire *wire = &Wire); -#if defined (ESP8266) || defined(ESP32) +#if defined (ESP8266) || defined(ESP32) || (STM32) // AS5600_SW_DIRECTION_PIN is software controlled direction pin bool begin(int dataPin, int clockPin, uint8_t directionPin = AS5600_SW_DIRECTION_PIN); #endif + bool begin(uint8_t directionPin = AS5600_SW_DIRECTION_PIN); bool isConnected(); diff --git a/CHANGELOG.md b/CHANGELOG.md index c661202..9d21768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.4.1] - 2023-09-16 +- fix #45 support STM32 set I2C pins +- update readme badges +- minor edits + + ## [0.4.0] - 2023-06-27 - fix #39 support for Wire2 on ESP32 - update readme.md diff --git a/README.md b/README.md index fdc240e..0ada705 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,11 @@ [![Arduino CI](https://github.com/RobTillaart/AS5600/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino-lint](https://github.com/RobTillaart/AS5600/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AS5600/actions/workflows/arduino-lint.yml) [![JSON check](https://github.com/RobTillaart/AS5600/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AS5600/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AS5600.svg)](https://github.com/RobTillaart/AS5600/issues) + [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AS5600/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/AS5600.svg?maxAge=3600)](https://github.com/RobTillaart/AS5600/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AS5600.svg)](https://registry.platformio.org/libraries/robtillaart/AS5600) # AS5600 @@ -683,3 +686,12 @@ priority is relative. - see getAngularSpeed() +## Support + +If you appreciate my libraries, you can support the development and maintenance. +Improve the quality of the libraries by providing issues and Pull Requests, or +donate through PayPal or GitHub sponsors. + +Thank you, + + diff --git a/library.json b/library.json index bfc897e..7710922 100644 --- a/library.json +++ b/library.json @@ -15,9 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/AS5600.git" }, - "version": "0.4.0", + "version": "0.4.1", "license": "MIT", - "frameworks": "arduino", + "frameworks": "*", "platforms": "*", "headers": "AS5600.h" } diff --git a/library.properties b/library.properties index 0cd7a0b..4b88ad9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AS5600 -version=0.4.0 +version=0.4.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.