🐛 fix wrong array indexing logic (#331)

* 🐛 fix wrong array indexing logic

* using TIMER_MAX instead of TIMER_GROUP_MAX

* 🐛 wrong TIMER11 index definition

* update CHANGELOG

* rearange indexing to - "[ [T00,T01], [T10, T11]]"
This commit is contained in:
Frederick Vollbrecht 2023-10-29 16:10:03 +01:00 committed by GitHub
parent 6ecb09b2f8
commit bdbba132f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.42.3] - 2023-10-29
* Fix Timer array index bug #331 - prevented the use of TIMER10 on devices that support only 2 Timers
* Fix wrong TIMER11 index definition that declared TIMER11 as TIMER10 #331
## [0.42.2] - 2023-10-28
* Support for latest ESP IDF 5.2 dev (master)

View File

@ -226,8 +226,7 @@ impl<'d> TimerDriver<'d> {
self.group(),
self.index(),
Some(Self::handle_isr),
(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index())
as *mut core::ffi::c_void,
(self.group() * timer_idx_t_TIMER_MAX + self.index()) as *mut core::ffi::c_void,
0,
)
})?;
@ -267,14 +266,12 @@ impl<'d> TimerDriver<'d> {
}
pub fn reset_wait(&mut self) {
let notif =
&PIN_NOTIF[(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index()) as usize];
let notif = &PIN_NOTIF[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize];
notif.reset();
}
pub async fn wait(&mut self) -> Result<(), EspError> {
let notif =
&PIN_NOTIF[(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index()) as usize];
let notif = &PIN_NOTIF[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize];
notif.wait().await;
@ -297,7 +294,7 @@ impl<'d> TimerDriver<'d> {
let callback: Box<dyn FnMut() + Send + 'd> = Box::new(callback);
ISR_HANDLERS[(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index()) as usize] =
ISR_HANDLERS[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize] =
Some(unsafe { core::mem::transmute(callback) });
Ok(())
@ -310,8 +307,7 @@ impl<'d> TimerDriver<'d> {
self.disable_interrupt()?;
unsafe {
ISR_HANDLERS[(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index()) as usize] =
None;
ISR_HANDLERS[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize] = None;
}
Ok(())
@ -355,11 +351,10 @@ impl<'d> Drop for TimerDriver<'d> {
#[cfg(feature = "alloc")]
unsafe {
ISR_HANDLERS[(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index()) as usize] =
None;
ISR_HANDLERS[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize] = None;
}
PIN_NOTIF[(self.group() * timer_group_t_TIMER_GROUP_MAX + self.index()) as usize].reset();
PIN_NOTIF[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize].reset();
esp!(unsafe { timer_deinit(self.group(), self.index()) }).unwrap();
}
@ -432,4 +427,4 @@ impl_timer!(TIMER01: timer_group_t_TIMER_GROUP_0, timer_idx_t_TIMER_1);
#[cfg(not(esp32c2))]
impl_timer!(TIMER10: timer_group_t_TIMER_GROUP_1, timer_idx_t_TIMER_0);
#[cfg(any(esp32, esp32s2, esp32s3))]
impl_timer!(TIMER11: timer_group_t_TIMER_GROUP_1, timer_idx_t_TIMER_0);
impl_timer!(TIMER11: timer_group_t_TIMER_GROUP_1, timer_idx_t_TIMER_1);