This commit is contained in:
João Victor 2025-01-12 16:52:41 +08:00 committed by GitHub
commit f94549a4d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 80 additions and 32 deletions

View file

@ -333,6 +333,10 @@ static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
stm32_tim_mode_t mode); stm32_tim_mode_t mode);
static int stm32_tim_setclock(struct stm32_tim_dev_s *dev, static int stm32_tim_setclock(struct stm32_tim_dev_s *dev,
uint32_t freq); uint32_t freq);
static uint32_t stm32_tim_getprescaler(struct stm32_tim_dev_s *dev);
static void stm32_tim_setprescaler(struct stm32_tim_dev_s *dev,
uint32_t prescaler);
static uint32_t stm32_tim_getperiod(struct stm32_tim_dev_s *dev);
static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev, static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
uint32_t period); uint32_t period);
static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev); static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev);
@ -364,6 +368,9 @@ static const struct stm32_tim_ops_s stm32_tim_ops =
.disable = stm32_tim_disable, .disable = stm32_tim_disable,
.setmode = stm32_tim_setmode, .setmode = stm32_tim_setmode,
.setclock = stm32_tim_setclock, .setclock = stm32_tim_setclock,
.setprescaler = stm32_tim_setprescaler,
.getprescaler = stm32_tim_getprescaler,
.getperiod = stm32_tim_getperiod,
.setperiod = stm32_tim_setperiod, .setperiod = stm32_tim_setperiod,
.getcounter = stm32_tim_getcounter, .getcounter = stm32_tim_getcounter,
.setcounter = stm32_tim_setcounter, .setcounter = stm32_tim_setcounter,
@ -899,6 +906,41 @@ static int stm32_tim_setclock(struct stm32_tim_dev_s *dev, uint32_t freq)
return prescaler; return prescaler;
} }
/****************************************************************************
* Name: stm32_tim_getprescaler
****************************************************************************/
static uint32_t stm32_tim_getprescaler(struct stm32_tim_dev_s *dev)
{
DEBUGASSERT(dev != NULL);
return stm32_tim_getwidth(dev) > 16 ?
stm32_getreg32(dev, STM32_GTIM_PSC_OFFSET) :
(uint32_t)stm32_getreg16(dev, STM32_GTIM_PSC_OFFSET);
}
/****************************************************************************
* Name: stm32_tim_setprescaler
****************************************************************************/
static void stm32_tim_setprescaler(struct stm32_tim_dev_s *dev,
uint32_t prescaler)
{
DEBUGASSERT(dev != NULL);
stm32_putreg32(dev, STM32_GTIM_PSC_OFFSET, prescaler);
}
/****************************************************************************
* Name: stm32_tim_getperiod
****************************************************************************/
static uint32_t stm32_tim_getperiod(struct stm32_tim_dev_s *dev)
{
DEBUGASSERT(dev != NULL);
return stm32_tim_getwidth(dev) > 16 ?
stm32_getreg32(dev, STM32_GTIM_ARR_OFFSET) :
(uint32_t)stm32_getreg16(dev, STM32_GTIM_ARR_OFFSET);
}
/**************************************************************************** /****************************************************************************
* Name: stm32_tim_setperiod * Name: stm32_tim_setperiod
****************************************************************************/ ****************************************************************************/

View file

@ -42,7 +42,10 @@
#define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode)) #define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode))
#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq)) #define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period)) #define STM32_TIM_GETPRESCALER(d) ((d)->ops->getprescaler(d))
#define STM32_TIM_SETPRESCALER(d,p) ((d)->ops->setprescaler(d,p))
#define STM32_TIM_GETPERIOD(d) ((d)->ops->getperiod(d))
#define STM32_TIM_SETPERIOD(d,p) ((d)->ops->setperiod(d,p))
#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d)) #define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c)) #define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c))
#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d)) #define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
@ -159,6 +162,9 @@ struct stm32_tim_ops_s
void (*disable)(struct stm32_tim_dev_s *dev); void (*disable)(struct stm32_tim_dev_s *dev);
int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode); int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode);
int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq); int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq);
uint32_t (*getprescaler)(struct stm32_tim_dev_s *dev);
void (*setprescaler)(struct stm32_tim_dev_s *dev, uint32_t prescaler);
uint32_t (*getperiod)(struct stm32_tim_dev_s *dev);
void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period); void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period);
uint32_t (*getcounter)(struct stm32_tim_dev_s *dev); uint32_t (*getcounter)(struct stm32_tim_dev_s *dev);
void (*setcounter)(struct stm32_tim_dev_s *dev, uint32_t count); void (*setcounter)(struct stm32_tim_dev_s *dev, uint32_t count);