Skip to content

Commit

Permalink
Move timer specific stuff into core.
Browse files Browse the repository at this point in the history
I moved the code that disables the period buffer into a new member function.  I then checked for this in the set_period(p) call, which will either allow it to go to FSP code, or directly set the appropriate register with the new period.

arduino/ArduinoCore-renesas#131
  • Loading branch information
KurtE committed Sep 10, 2023
1 parent 02c5ee9 commit 04b9322
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/renesas/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ static FspTimer servo_timer;
static bool servo_timer_started = false;
void servo_timer_callback(timer_callback_args_t *args);

// GPT pointer.
static R_GPT0_Type *s_pgpt0 = nullptr;
static uint32_t servo_ticks_per_cycle = 0;
static uint32_t min_servo_cycle_low = 0;
static uint32_t active_servos_mask = 0;
Expand All @@ -83,14 +81,7 @@ static int servo_timer_config(uint32_t period_us)
// lets initially configure the servo to 50ms
servo_timer.begin(TIMER_MODE_PERIODIC, type, channel,
1000000.0f/period_us, 50.0f, servo_timer_callback, nullptr);

// First pass assume GPT timer
if (type == GPT_TIMER) {
s_pgpt0 = (R_GPT0_Type *)((uint32_t)R_GPT0 + ((uint32_t)R_GPT1 - (uint32_t)R_GPT0) * channel);
// turn off GTPR Buffer
s_pgpt0->GTBER_b.PR = 0;
s_pgpt0->GTBER_b.BD1 = 1;
}
servo_timer.use_period_buffer(false); // disable period buffering
servo_timer.setup_overflow_irq(10);
servo_timer.open();
servo_timer.stop();
Expand Down Expand Up @@ -128,12 +119,7 @@ static int servo_timer_stop()
}

inline static void updateClockPeriod(uint32_t period) {
if (s_pgpt0) {
s_pgpt0->GTPR = period;
} else {
// AGT...
servo_timer.set_period(period);
}
}


Expand Down

0 comments on commit 04b9322

Please sign in to comment.