Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.2.2 to add support to Seeeduino nRF52
Browse files Browse the repository at this point in the history
### Releases v1.2.2

1. Add support to Seeeduino nRF52840-based boards such as **Seeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE**, etc. using Seeeduino `nRF52` core
2. Add astyle using `allman` style. Restyle the library
3. Update all examples
4. Update `Packages' Patches` to add Seeeduino `nRF52` core
  • Loading branch information
khoih-prog committed Oct 26, 2022
1 parent f20e8b3 commit 2c86fbf
Show file tree
Hide file tree
Showing 6 changed files with 398 additions and 392 deletions.
83 changes: 42 additions & 41 deletions examples/ISR_16_PWMs_Array/ISR_16_PWMs_Array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define LED_ON LOW

#ifndef LED_BUILTIN
#define LED_BUILTIN 25
#define LED_BUILTIN 25
#endif

#ifndef LED_BLUE_PIN
Expand Down Expand Up @@ -63,7 +63,7 @@ NRF52_Slow_PWM ISR_PWM;

void TimerHandler()
{
ISR_PWM.run();
ISR_PWM.run();
}

//////////////////////////////////////////////////////
Expand Down Expand Up @@ -93,29 +93,29 @@ void TimerHandler()
// You can assign pins here. Be carefull to select good pin to use or crash, e.g pin 6-11
uint32_t PWM_Pin[] =
{
LED_BUILTIN, LED_BLUE_PIN, LED_GREEN_PIN, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4,
PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12
LED_BUILTIN, LED_BLUE_PIN, LED_GREEN_PIN, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4,
PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12
};

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period[] =
{
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
};

// You can assign any interval for any timer here, in Hz
float PWM_Freq[] =
{
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
};

// You can assign any interval for any timer here, in milliseconds
float PWM_DutyCycle[] =
{
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
};

typedef void (*irqCallback) ();
Expand Down Expand Up @@ -190,59 +190,60 @@ void doingSomething15()

irqCallback irqCallbackStartFunc[] =
{
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
doingSomething8, doingSomething9, doingSomething10, doingSomething11,
doingSomething12, doingSomething13, doingSomething14, doingSomething15
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
doingSomething8, doingSomething9, doingSomething10, doingSomething11,
doingSomething12, doingSomething13, doingSomething14, doingSomething15
};

////////////////////////////////////////////////

void setup()
{
Serial.begin(115200);
Serial.begin(115200);

while (!Serial && millis() < 5000);
while (!Serial && millis() < 5000);

delay(2000);
delay(2000);

Serial.print(F("\nStarting ISR_16_PWMs_Array on ")); Serial.println(BOARD_NAME);
Serial.println(NRF52_SLOW_PWM_VERSION);
Serial.print(F("\nStarting ISR_16_PWMs_Array on "));
Serial.println(BOARD_NAME);
Serial.println(NRF52_SLOW_PWM_VERSION);

// Interval in microsecs
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler))
{
startMicros = micros();
Serial.print(F("Starting ITimer OK, micros() = "));
Serial.println(startMicros);
}
else
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
// Interval in microsecs
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler))
{
startMicros = micros();
Serial.print(F("Starting ITimer OK, micros() = "));
Serial.println(startMicros);
}
else
Serial.println(F("Can't set ITimer. Select another freq. or timer"));

#if 1

// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
// You can use up to 16 timer for each ISR_PWM
for (uint16_t i = 0; i < NUMBER_ISR_PWMS; i++)
{
//void setPWM(uint32_t pin, float frequency, float dutycycle
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
// You can use up to 16 timer for each ISR_PWM
for (uint16_t i = 0; i < NUMBER_ISR_PWMS; i++)
{
//void setPWM(uint32_t pin, float frequency, float dutycycle
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)

#if USING_PWM_FREQUENCY

// You can use this with PWM_Freq in Hz
ISR_PWM.setPWM(PWM_Pin[i], PWM_Freq[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
// You can use this with PWM_Freq in Hz
ISR_PWM.setPWM(PWM_Pin[i], PWM_Freq[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);

#else
#if USING_MICROS_RESOLUTION
// Or using period in microsecs resolution
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
// Or using period in microsecs resolution
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
#else
// Or using period in millisecs resolution
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i] / 1000, PWM_DutyCycle[i], irqCallbackStartFunc[i]);
// Or using period in millisecs resolution
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i] / 1000, PWM_DutyCycle[i], irqCallbackStartFunc[i]);
#endif
#endif
}
}

#endif
}
Expand Down
Loading

0 comments on commit 2c86fbf

Please sign in to comment.