18extern TIM_HandleTypeDef
TIM_FFB;
21#ifndef OVERRIDE_FFBRATES
32 Thread(
"FFBMAIN", 256, 30),
37 reportHID = std::make_unique<HID_GamepadReport<int32_t>>();
39 reportHID = std::make_unique<HID_GamepadReport<int16_t>>();
79 uint8_t rateidx = conf1 & 0x3;
103 bool estopState = HAL_GPIO_ReadPin(E_STOP_GPIO_Port, E_STOP_Pin) == GPIO_PIN_RESET;
111 HAL_TIM_Base_Start_IT(&
TIM_FFB);
130 if(
control.request_update_disabled) {
132 control.update_disabled =
true;
133 control.request_update_disabled =
false;
164 return this->
ffb->getRate();
168 return this->
ffb->getFfbActive();
194 for(
auto val : *
axes){
198 val = val >> (32-HIDAXISRES_32B_BITS);
201 reportHID->setHidReportAxis(count++, val);
206 for(int32_t val : *
axes){
210 val = val << (HIDAXISRES_32B_BITS-16);
211 reportHID->setHidReportAxis(count++, val);
245 uint32_t usbrate_base = TUD_OPT_HIGH_SPEED ? 8000 : 1000;
269 ffb->updateSamplerate(newRate);
279 uint32_t usbrate_base = TUD_OPT_HIGH_SPEED ? 8000 : 1000;
283 for(uint8_t i = 0 ; i <
ffbrates.dividers.size();i++){
284 uint32_t updatefreq =
ffbrates.basefreq/((uint32_t)
ffbrates.dividers[i].basediv);
286 while((updatefreq/
hidrate) > usbrate_base){
289 uint32_t hidfreq = updatefreq/
hidrate;
290 s +=
"FFB "+std::to_string(updatefreq) +
"Hz\nUSB " + std::to_string(hidfreq) +
"Hz:"+std::to_string(i);
321 if(
control.emergency && HAL_GPIO_ReadPin(E_STOP_GPIO_Port, E_STOP_Pin) != GPIO_PIN_RESET){
333 if(GPIO_Pin == BUTTON_A_Pin){
335 if(HAL_GPIO_ReadPin(BUTTON_A_GPIO_Port, BUTTON_A_Pin)){
336 this->
control.resetEncoder =
true;
340 if(GPIO_Pin == E_STOP_Pin){
342 bool estopPinState = HAL_GPIO_ReadPin(E_STOP_GPIO_Port, E_STOP_Pin) == GPIO_PIN_RESET;
343 if(HAL_GetTick()-
lastEstop > 1000 && estopPinState != this->
control.emergency){
TIM_HandleTypeDef TIM_FFB
osThreadId_t defaultTaskHandle
std::shared_ptr< EffectsControlItf > ffb
void setReportRate(uint8_t rateidx)
std::string usb_report_rates_names()
void exti(uint16_t GPIO_Pin)
volatile Control_t control
static const FFB_update_rates ffbrates
volatile uint32_t lastEstop
uint8_t usb_report_rate_idx
std::unique_ptr< AxesManager > axes_manager
const bool allowEstopReset
void setFFBEffectsCalc(std::shared_ptr< EffectsControlItf > ffb, std::shared_ptr< EffectsCalculator > effects_calc)
void timerElapsed(TIM_HandleTypeDef *htim)
FFBHIDMain(uint8_t axisCount, bool hidAxis32b=false)
const uint8_t analogAxisCount
std::shared_ptr< EffectsCalculator > effects_calc
std::unique_ptr< HID_GamepadReport_base > reportHID
void errorCallback(const Error &error, bool cleared)
void emergencyStop(bool reset)
std::unique_ptr< HID_CommandInterface > hidCommands
uint8_t reportSendCounter
void restoreFlashDelayed()
uint32_t WaitForNotification(TickType_t Timeout=portMAX_DELAY)
void Delay(const TickType_t Delay)
Thread(const std::string Name, uint16_t StackDepth, UBaseType_t Priority)
bool Flash_Write(uint16_t adr, uint16_t dat)
bool Flash_Read(uint16_t adr, uint16_t *buf, bool checkempty=true)
bool tud_hid_n_ready(uint8_t instance)
static TU_ATTR_ALWAYS_INLINE bool tud_hid_report(uint8_t report_id, void const *report, uint16_t len)
tusb_speed_t tud_speed_get(void)