Skip to content

Commit

Permalink
Fix #45 support STM32 set I2C pins (#46)
Browse files Browse the repository at this point in the history
- fix #45 support STM32 set I2C pins  ARDUINO_ARCH_STM32
- update readme badges
- minor edits
  • Loading branch information
RobTillaart authored Sep 20, 2023
1 parent 319985d commit 75cdb95
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
32 changes: 29 additions & 3 deletions AS5600.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -79,6 +79,32 @@ bool AS5600::begin(int dataPin, int clockPin, uint8_t directionPin)
#endif


#if defined (ARDUINO_ARCH_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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions AS5600.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -89,10 +89,11 @@ class AS5600
public:
AS5600(TwoWire *wire = &Wire);

#if defined (ESP8266) || defined(ESP32)
#if defined (ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_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();

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ARDUINO_ARCH_STM32
- update readme badges
- minor edits


## [0.4.0] - 2023-06-27
- fix #39 support for Wire2 on ESP32
- update readme.md
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,


1 change: 1 addition & 0 deletions examples/AS5600_demo_radians/AS5600_demo_radians.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void setup()

Wire.begin();

// as5600.begin(11, 12, 4); // test for STM32 or ESP32
as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
}
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AS5600
version=0.4.0
version=0.4.1
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.
Expand Down

0 comments on commit 75cdb95

Please sign in to comment.