Skip to content

Commit

Permalink
Merge pull request #299 from runger1101001/dev
Browse files Browse the repository at this point in the history
Fixing errors with new Arduino framework versions
  • Loading branch information
runger1101001 authored Sep 2, 2023
2 parents 451be63 + a5ecace commit 04a8a88
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/communication/StepDirListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../common/foc_utils.h"


#if !defined(TARGET_RP2040) && !defined(_SAMD21_) && !defined(_SAMD51_) && !defined(_SAME51_) && !defined(ARDUINO_UNOR4_WIFI) && !defined(ARDUINO_UNOR4_MINIMA)
#if !defined(TARGET_RP2040) && !defined(_SAMD21_) && !defined(_SAMD51_) && !defined(_SAME51_) && !defined(ARDUINO_UNOR4_WIFI) && !defined(ARDUINO_UNOR4_MINIMA) && !defined(NRF52_SERIES) && !defined(ARDUINO_ARCH_MEGAAVR)
#define PinStatus int
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/current_sense/hardware_specific/esp32/esp32_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../../../drivers/hardware_api.h"
#include "../../../drivers/hardware_specific/esp32/esp32_driver_mcpwm.h"

#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) && defined(SOC_MCPWM_SUPPORTED)
#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) && defined(SOC_MCPWM_SUPPORTED) && !defined(SIMPLEFOC_ESP32_USELEDC)

#include "esp32_adc_driver.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
//#include "esp_intr.h" // deprecated
#include "esp_intr_alloc.h"
#include "soc/rtc_io_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/hardware_specific/atmega/atmega2560_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#if defined(__AVR_ATmega2560__) || defined(AVR_ATmega1280)


#pragma message("")
#pragma message("SimpleFOC: compiling for Arduino/ATmega2560 or Arduino/ATmega1280")
#pragma message("")


#define _PWM_FREQUENCY 32000
#define _PWM_FREQUENCY_MAX 32000
#define _PWM_FREQUENCY_MIN 4000
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/atmega/atmega328_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__)

#pragma message("")
#pragma message("SimpleFOC: compiling for Arduino/ATmega328 ATmega168 ATmega328PB")
#pragma message("")

#define _PWM_FREQUENCY 32000
#define _PWM_FREQUENCY_MAX 32000
#define _PWM_FREQUENCY_MIN 4000
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/atmega/atmega32u4_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#if defined(__AVR_ATmega32U4__)

#pragma message("")
#pragma message("SimpleFOC: compiling for Arduino/ATmega32U4")
#pragma message("")

// set pwm frequency to 32KHz
void _pinHighFrequency(const int pin){
// High PWM frequency
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/hardware_specific/due_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#if defined(__arm__) && defined(__SAM3X8E__)


#pragma message("")
#pragma message("SimpleFOC: compiling for Arduino/Due")
#pragma message("")


#define _PWM_FREQUENCY 25000 // 25khz
#define _PWM_FREQUENCY_MAX 50000 // 50khz

Expand Down
7 changes: 7 additions & 0 deletions src/drivers/hardware_specific/esp32/esp32_driver_mcpwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) && defined(SOC_MCPWM_SUPPORTED) && !defined(SIMPLEFOC_ESP32_USELEDC)



#pragma message("")
#pragma message("SimpleFOC: compiling for ESP32 MCPWM driver")
#pragma message("")


#include "driver/mcpwm.h"
#include "soc/mcpwm_reg.h"
#include "soc/mcpwm_struct.h"
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/esp32/esp32_ledc_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) && ( !defined(SOC_MCPWM_SUPPORTED) || defined(SIMPLEFOC_ESP32_USELEDC) )

#pragma message("")
#pragma message("SimpleFOC: compiling for ESP32 LEDC driver")
#pragma message("")

#include "driver/ledc.h"

#define _PWM_FREQUENCY 25000 // 25khz
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/hardware_specific/esp8266_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP8266)


#pragma message("")
#pragma message("SimpleFOC: compiling for ESP8266")
#pragma message("")


#define _PWM_FREQUENCY 25000 // 25khz
#define _PWM_FREQUENCY_MAX 50000 // 50khz

Expand Down
3 changes: 2 additions & 1 deletion src/drivers/hardware_specific/generic_mcu.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

#include "../hardware_api.h"

// if the mcu doen't have defiend analogWrite
#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32)
#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) && !defined(analogWrite)
__attribute__((weak)) void analogWrite(uint8_t pin, int value){ };
#endif

Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/nrf52_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#if defined(NRF52_SERIES)

#pragma message("")
#pragma message("SimpleFOC: compiling for NRF52")
#pragma message("")


#define PWM_CLK (16000000)
#define PWM_FREQ (40000)
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/hardware_specific/portenta_h7_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

#if defined(TARGET_PORTENTA_H7)


#pragma message("")
#pragma message("SimpleFOC: compiling for Arduino/Portenta_H7")
#pragma message("")


#include "pwmout_api.h"
#include "pinDefinitions.h"
#include "platform/mbed_critical.h"
Expand Down
7 changes: 7 additions & 0 deletions src/drivers/hardware_specific/renesas/renesas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

#if defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA)


#pragma message("")
#pragma message("SimpleFOC: compiling for Arduino/Renesas (UNO R4)")
#pragma message("")



#include "communication/SimpleFOCDebug.h"
#include "FspTimer.h"

Expand Down
6 changes: 6 additions & 0 deletions src/drivers/hardware_specific/rp2040/rp2040_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
*/
#if defined(TARGET_RP2040)


#pragma message("")
#pragma message("SimpleFOC: compiling for RP2040")
#pragma message("")


#define SIMPLEFOC_DEBUG_RP2040

#include "../../hardware_api.h"
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/samd/samd21_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifdef _SAMD21_


#pragma message("")
#pragma message("SimpleFOC: compiling for SAMD21")
#pragma message("")


#ifndef TCC3_CH0
#define TCC3_CH0 NOT_ON_TIMER
Expand Down
5 changes: 5 additions & 0 deletions src/drivers/hardware_specific/samd/samd51_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#if defined(_SAMD51_)||defined(_SAME51_)


#pragma message("")
#pragma message("SimpleFOC: compiling for SAMD51/SAME51")
#pragma message("")



// expected frequency on DPLL, since we don't configure it ourselves. Typically this is the CPU frequency.
// for custom boards or overclockers you can override it using this define.
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/stm32/stm32_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#if defined(_STM32_DEF_)

#pragma message("")
#pragma message("SimpleFOC: compiling for STM32")
#pragma message("")


//#define SIMPLEFOC_STM32_DEBUG

Expand Down
4 changes: 4 additions & 0 deletions src/drivers/hardware_specific/teensy/teensy3_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#if defined(__arm__) && defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))


#pragma message("")
#pragma message("SimpleFOC: compiling for Teensy 3.x")
#pragma message("")

// pin definition from https://github.com/PaulStoffregen/cores/blob/286511f3ec849a6c9e0ec8b73ad6a2fada52e44c/teensy3/pins_teensy.c
#if defined(__MK20DX128__)
#define FTM0_CH0_PIN 22
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/hardware_specific/teensy/teensy4_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
// - Teensy 4.1
#if defined(__arm__) && defined(CORE_TEENSY) && ( defined(__IMXRT1062__) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY_MICROMOD) )


#pragma message("")
#pragma message("SimpleFOC: compiling for Teensy 4.x")
#pragma message("")


// half_cycle of the PWM variable
int half_cycle = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/MagneticSensorPWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ float MagneticSensorPWM::getSensorAngle(){
int MagneticSensorPWM::getRawCount(){
if (!is_interrupt_based){ // if it's not interrupt based read the value in a blocking way
pulse_timestamp = _micros(); // ideally this should be done right at the rising edge of the pulse
pulse_length_us = pulseIn(pinPWM, HIGH);
pulse_length_us = pulseIn(pinPWM, HIGH, 1200); // 1200us timeout, should this be configurable?
}
return pulse_length_us;
}
Expand Down

0 comments on commit 04a8a88

Please sign in to comment.