Skip to content

Commit

Permalink
with demos
Browse files Browse the repository at this point in the history
  • Loading branch information
Viha123 committed Jan 18, 2025
1 parent 916d6af commit 5c6c311
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions demos/platforms/stm32f103c8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <libhal-util/inert_drivers/inert_adc.hpp>
#include <libhal-util/steady_clock.hpp>
#include <libhal/output_pin.hpp>
#include <libhal/pwm.hpp>
#include <libhal/units.hpp>
#include <libhal-arm-mcu/stm32f1/timer1_pwm.hpp>

#include <resource_list.hpp>

Expand Down Expand Up @@ -104,6 +106,10 @@ void initialize_platform(resource_list& p_resources)
.copi = &copi,
.cipo = &cipo };

hal::stm32f1::timer1_pwm pwm(hal::stm32f1::timer1_pwm::pwm_pins::pa8);

p_resources.pwm = &pwm;

static hal::spi::settings bit_bang_spi_settings{
.clock_rate = 250.0_kHz,
.clock_polarity = false,
Expand Down
9 changes: 5 additions & 4 deletions src/stm32f1/timer1_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ void timer1_pwm::driver_duty_cycle(float p_duty_cycle)
{
auto const peripheral_id = get_peripheral_id(m_pin);
pwm_reg_t* reg = get_pwm_reg(peripheral_id);

std::uint16_t desired_ccr_value =
(static_cast<std::uint16_t>(reg->auto_reload_register) *
static_cast<std::uint16_t>(p_duty_cycle));

// std::uint16_t desired_ccr_value =
// (static_cast<std::uint16_t>(reg->auto_reload_register) *
// static_cast<std::uint16_t>(p_duty_cycle));
std::uint16_t desired_ccr_value = static_cast<std::uint16_t>(reg->auto_reload_register * p_duty_cycle);

*m_compare_register_addr = desired_ccr_value;
}
Expand Down

0 comments on commit 5c6c311

Please sign in to comment.