mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-20 09:43:23 +00:00
76e3fd3060
* Firmware, Bootloader: add f3 target. Refactor code to be portable across targets. * Firmware: remove bkpt * Makefile: debug agent. Debug: f3 platform throw openocd. * freertos-openocd helper * separate hal resources * return of input_dump app * using hew target resources abstration layer for backlight and blink * dirty hack for input driver, f3 has no charging pin * worked input interrupts * working display * F3: switch to 32mHz resonator * F3: configure SD_CS pin * NFC: port to F3. * fat uart app * sd card hal api * separate CC1101 spi config * faster spi gpio for sd card * Assets: disable LFS * Cube: disable css on LSE * Input: format code * Make: add bootloader source code to formatting rule * F3: enable rf by default, adjust clock settings, map all pins where they should be. * libs for coreglitch_demo_0 * nvic priority * bus clocks all to 64 * lf-rfid timer and pin * irda * ir rx setup * tim2 irq handler * Makefile: environment aware mkdir * Makefile, Irukagotchi: commit seq number. * split falling and rising ir rx events * Makefile: proper git branch detect on old git. Firmware: api fix. * fix irda * Makefile,Irukagotchi: date timestamp. * NFC: adjust SPI speed * Irukagotchi: format code * Make: add blackmagic debug in host mode * Makefile: detach blackmagic from terminal signals * Makefile,Irukagotchi: stamp target * add F3 bootloader/firmware to CI Co-authored-by: Aleksandr Kutuzov <aku@plooks.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com> Co-authored-by: aanper <mail@s3f.ru>
57 lines
No EOL
2.1 KiB
C
57 lines
No EOL
2.1 KiB
C
#include "api-hal-pwm.h"
|
|
|
|
void hal_pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {
|
|
tim->Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
tim->Init.Period = (uint32_t)((SystemCoreClock / (tim->Init.Prescaler + 1)) / freq);
|
|
tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
HAL_TIM_PWM_Init(tim);
|
|
|
|
TIM_OC_InitTypeDef sConfigOC;
|
|
|
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
|
sConfigOC.Pulse = (uint16_t)(tim->Init.Period * value);
|
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
|
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
HAL_TIM_PWM_ConfigChannel(tim, &sConfigOC, channel);
|
|
HAL_TIM_PWM_Start(tim, channel);
|
|
}
|
|
|
|
void hal_pwmn_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {
|
|
tim->Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
tim->Init.Period = (uint32_t)((SystemCoreClock / (tim->Init.Prescaler + 1)) / freq - 1);
|
|
tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
HAL_TIM_PWM_Init(tim);
|
|
|
|
TIM_OC_InitTypeDef sConfigOC;
|
|
|
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
|
sConfigOC.Pulse = (uint16_t)(tim->Init.Period * value);
|
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
|
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
HAL_TIM_PWM_ConfigChannel(tim, &sConfigOC, channel);
|
|
HAL_TIMEx_PWMN_Start(tim, channel);
|
|
}
|
|
|
|
void hal_pwm_stop(TIM_HandleTypeDef* tim, uint32_t channel) {
|
|
HAL_TIM_PWM_Stop(tim, channel);
|
|
}
|
|
|
|
void hal_pwmn_stop(TIM_HandleTypeDef* tim, uint32_t channel) {
|
|
HAL_TIMEx_PWMN_Stop(tim, channel);
|
|
}
|
|
|
|
void irda_pwm_set(float value, float freq){
|
|
hal_pwmn_set(value, freq, &IRDA_TIM, IRDA_CH);
|
|
}
|
|
|
|
void irda_pwm_stop(){
|
|
hal_pwmn_stop(&IRDA_TIM, IRDA_CH);
|
|
} |