Prusa MINI Firmware overview
hwio.h File Reference
#include <inttypes.h>

Go to the source code of this file.

Macros

#define HWIO_CLS_DI   0x01
 
#define HWIO_CLS_DO   0x02
 
#define HWIO_CLS_ADC   0x03
 
#define HWIO_CLS_DAC   0x04
 
#define HWIO_CLS_PWM   0x05
 
#define HWIO_CLS_FAN   0x10
 
#define HWIO_CLS_HEATER   0x11
 

Functions

int hwio_di_get_cnt (void)
 
int hwio_di_get_val (int i_di)
 
int hwio_do_get_cnt (void)
 
void hwio_do_set_val (int i_do, int val)
 
int hwio_adc_get_cnt (void)
 
int hwio_adc_get_max (int i_adc)
 
int hwio_adc_get_val (int i_adc)
 
int hwio_dac_get_cnt (void)
 
int hwio_dac_get_max (int i_dac)
 
void hwio_dac_set_val (int i_dac, int val)
 
int hwio_pwm_get_cnt (void)
 
int hwio_pwm_get_max (int i_pwm)
 
void hwio_pwm_set_val (int i_pwm, int val)
 
int hwio_pwm_get_val (int i_pwm)
 
void hwio_pwm_set_period_us (int i_pwm, int T_us)
 
int hwio_pwm_get_period_us (int i_pwm)
 
void hwio_pwm_set_prescaler (int i_pwm, int prescaler)
 
int hwio_pwm_get_prescaler (int i_pwm)
 
void hwio_pwm_set_prescaler_exp2 (int i_pwm, int exp)
 
int hwio_pwm_get_prescaler_log2 (int i_pwm)
 
int hwio_fan_get_cnt (void)
 
void hwio_fan_set_pwm (int i_fan, int val)
 
int hwio_heater_get_cnt (void)
 
void hwio_heater_set_pwm (int i_heater, int val)
 
void hwio_jogwheel_enable (void)
 
void hwio_jogwheel_disable (void)
 
float hwio_beeper_get_vol (void)
 
void hwio_beeper_set_vol (float vol)
 
void hwio_beeper_set_pwm (uint32_t per, uint32_t pul)
 
void hwio_beeper_tone (float frq, uint32_t del)
 
void hwio_beeper_tone2 (float frq, uint32_t del, float vol)
 
void hwio_beeper_notone (void)
 
void hwio_update_1ms (void)
 

Macro Definition Documentation

◆ HWIO_CLS_DI

#define HWIO_CLS_DI   0x01

◆ HWIO_CLS_DO

#define HWIO_CLS_DO   0x02

◆ HWIO_CLS_ADC

#define HWIO_CLS_ADC   0x03

◆ HWIO_CLS_DAC

#define HWIO_CLS_DAC   0x04

◆ HWIO_CLS_PWM

#define HWIO_CLS_PWM   0x05

◆ HWIO_CLS_FAN

#define HWIO_CLS_FAN   0x10

◆ HWIO_CLS_HEATER

#define HWIO_CLS_HEATER   0x11

Function Documentation

◆ hwio_di_get_cnt()

int hwio_di_get_cnt ( void  )
195 { return _DI_CNT; }

◆ hwio_di_get_val()

int hwio_di_get_val ( int  i_di)
198 {
199  if ((i_di >= 0) && (i_di < _DI_CNT))
200  return gpio_get(_di_pin32[i_di]);
201  /* {
202  uint32_t pin32 = ;
203  GPIO_TypeDef* gpio = (GPIO_TypeDef*)_gpio[pin32 >> 4];
204  uint16_t msk = (1 << (pin32 & 0x0f));
205  return HAL_GPIO_ReadPin(gpio, msk)?1:0;
206  }*/
207  //else //TODO: check
208  return 0;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_do_get_cnt()

int hwio_do_get_cnt ( void  )
215 { return _DO_CNT; }

◆ hwio_do_set_val()

void hwio_do_set_val ( int  i_do,
int  val 
)
225 {
226  if ((i_do >= 0) && (i_do < _DO_CNT))
227  gpio_set(_do_pin32[i_do], val);
228  /* {
229  uint32_t pin32 = _do_pin32[i_do];
230  GPIO_TypeDef* gpio = (GPIO_TypeDef*)_gpio[pin32 >> 4];
231  uint16_t msk = (1 << (pin32 & 0x0f));
232  HAL_GPIO_WritePin(gpio, msk, val?GPIO_PIN_SET:GPIO_PIN_RESET);
233  }*/
234  //else //TODO: check
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_adc_get_cnt()

int hwio_adc_get_cnt ( void  )
241 { return _ADC_CNT; }

◆ hwio_adc_get_max()

int hwio_adc_get_max ( int  i_adc)
244 { return _adc_max[i_adc]; }

◆ hwio_adc_get_val()

int hwio_adc_get_val ( int  i_adc)
247 {
248  if ((i_adc >= 0) && (i_adc < _ADC_CNT))
249  return _adc_val[i_adc];
250  //else //TODO: check
251  return 0;
Here is the caller graph for this function:

◆ hwio_dac_get_cnt()

int hwio_dac_get_cnt ( void  )
258 { return _DAC_CNT; }

◆ hwio_dac_get_max()

int hwio_dac_get_max ( int  i_dac)
261 { return _dac_max[i_dac]; }

◆ hwio_dac_set_val()

void hwio_dac_set_val ( int  i_dac,
int  val 
)
264 {

◆ hwio_pwm_get_cnt()

int hwio_pwm_get_cnt ( void  )
275 { return _PWM_CNT; }

◆ hwio_pwm_get_max()

int hwio_pwm_get_max ( int  i_pwm)
278 {
279  if (!is_pwm_id_valid(i_pwm))
280  return -1;
281  return _pwm_max[i_pwm];
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_pwm_set_val()

void hwio_pwm_set_val ( int  i_pwm,
int  val 
)
378 {
379  if (!is_pwm_id_valid(i_pwm))
380  return;
381 
382  uint32_t chan = _pwm_get_chan(i_pwm);
383  TIM_HandleTypeDef *htim = _pwm_get_htim(i_pwm);
384  uint32_t cmp = __HAL_TIM_GET_COMPARE(htim, chan);
385 
386  if ((_pwm_analogWrite_val[i_pwm] ^ val) || (cmp != val)) {
387  _hwio_pwm_set_val(i_pwm, val);
388 
389  //actualize _pwm_analogWrite_val
390  int pwm_max = hwio_pwm_get_max(i_pwm);
391  int pwm_analogWrite_max = _pwm_analogWrite_max[i_pwm];
392 
393  uint32_t pulse = (val * pwm_analogWrite_max) / pwm_max;
394  _pwm_analogWrite_val[i_pwm] = pulse; //arduino compatible
395  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_pwm_get_val()

int hwio_pwm_get_val ( int  i_pwm)

◆ hwio_pwm_set_period_us()

void hwio_pwm_set_period_us ( int  i_pwm,
int  T_us 
)
287 {
288  if (!is_pwm_id_valid(i_pwm))
289  return;
290  int *ptr_period_us = _pwm_period_us[i_pwm];
291 
292  if (T_us == *ptr_period_us)
293  return;
294 
295  int prescaler = T_us * (int32_t)TIM_BASE_CLK_MHZ / (_pwm_max[i_pwm] + 1) - 1;
296  hwio_pwm_set_prescaler(i_pwm, prescaler);
297  //actualize seconds
298  *ptr_period_us = T_us;
Here is the call graph for this function:

◆ hwio_pwm_get_period_us()

int hwio_pwm_get_period_us ( int  i_pwm)
301  {
302  if (!is_pwm_id_valid(i_pwm))
303  return -1;
304  return *_pwm_period_us[i_pwm];
Here is the call graph for this function:

◆ hwio_pwm_set_prescaler()

void hwio_pwm_set_prescaler ( int  i_pwm,
int  prescaler 
)
307  {
308  if (hwio_pwm_get_prescaler(i_pwm) == prescaler)
309  return;
310 
311  TIM_HandleTypeDef *htim = _pwm_get_htim(i_pwm);
312 
313  //uint32_t chan = _pwm_get_chan(i_pwm);
314  //uint32_t cmp = __HAL_TIM_GET_COMPARE(htim,chan);
315 
316  htim->Init.Prescaler = prescaler;
317  //__pwm_set_val(htim, chan, cmp);
318 
319  __HAL_TIM_SET_PRESCALER(htim, prescaler);
320 
321  //calculate micro seconds
322  int T_us = GEN_PERIOD_US(prescaler, htim->Init.Period);
323  //actualize micro
324  int *ptr_period_us = _pwm_period_us[i_pwm];
325  *ptr_period_us = T_us;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_pwm_get_prescaler()

int hwio_pwm_get_prescaler ( int  i_pwm)
328  {
329  if (!is_pwm_id_valid(i_pwm))
330  return -1;
331  TIM_HandleTypeDef *htim = _pwm_get_htim(i_pwm);
332  return htim->Init.Prescaler;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_pwm_set_prescaler_exp2()

void hwio_pwm_set_prescaler_exp2 ( int  i_pwm,
int  exp 
)
344  {
345  uint32_t prescaler = (1 << (exp)) - 1;
346  hwio_pwm_set_prescaler(i_pwm, prescaler);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_pwm_get_prescaler_log2()

int hwio_pwm_get_prescaler_log2 ( int  i_pwm)
350  {
351  if (!is_pwm_id_valid(i_pwm))
352  return -1;
353  uint32_t prescaler = hwio_pwm_get_prescaler(i_pwm) + 1;
354  int index = 0;
355 
356  while (prescaler != 0) {
357  ++index;
358  prescaler = prescaler >> 1;
359  }
360 
361  return index - 1;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_fan_get_cnt()

int hwio_fan_get_cnt ( void  )
446 { return _FAN_CNT; }
Here is the caller graph for this function:

◆ hwio_fan_set_pwm()

void hwio_fan_set_pwm ( int  i_fan,
int  val 
)
448  {
449  i_fan += _FAN_ID_MIN;
450  if ((i_fan >= _FAN_ID_MIN) && (i_fan <= _FAN_ID_MAX))
451  _hwio_pwm_analogWrite_set_val(i_fan, val);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_heater_get_cnt()

int hwio_heater_get_cnt ( void  )
458 { return _HEATER_CNT; }
Here is the caller graph for this function:

◆ hwio_heater_set_pwm()

void hwio_heater_set_pwm ( int  i_heater,
int  val 
)
460  {
461  i_heater += _HEATER_ID_MIN;
462  if ((i_heater >= _HEATER_ID_MIN) && (i_heater <= _HEATER_ID_MAX))
463  _hwio_pwm_analogWrite_set_val(i_heater, val);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_jogwheel_enable()

void hwio_jogwheel_enable ( void  )
469  {
Here is the caller graph for this function:

◆ hwio_jogwheel_disable()

void hwio_jogwheel_disable ( void  )
473  {
Here is the caller graph for this function:

◆ hwio_beeper_get_vol()

float hwio_beeper_get_vol ( void  )
480  {
481  return hwio_beeper_vol;

◆ hwio_beeper_set_vol()

void hwio_beeper_set_vol ( float  vol)
484  {
485  if (vol < 0)
486  vol *= -1;
487  if (vol > 1)
488  vol = 1;
489  hwio_beeper_vol = vol;
Here is the caller graph for this function:

◆ hwio_beeper_set_pwm()

void hwio_beeper_set_pwm ( uint32_t  per,
uint32_t  pul 
)
492  {
493  TIM_OC_InitTypeDef sConfigOC = { 0 };
494  if (per) {
495  htim2.Init.Prescaler = 0;
497  htim2.Init.Period = per;
500  sConfigOC.OCMode = TIM_OCMODE_PWM1;
501  if (pul) {
502  sConfigOC.Pulse = pul;
503  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
504  } else {
505  sConfigOC.Pulse = per;
506  sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
507  }
508  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
511  } else
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_beeper_tone()

void hwio_beeper_tone ( float  frq,
uint32_t  del 
)
515  {
516  uint32_t per;
517  uint32_t pul;
518  if (frq && del && hwio_beeper_vol) {
519  if (frq < 0)
520  frq *= -1;
521  if (frq > 100000)
522  frq = 100000;
523  per = (uint32_t)(84000000.0F / frq);
524  pul = (uint32_t)(per * hwio_beeper_vol / 2);
525  hwio_beeper_set_pwm(per, pul);
526  hwio_beeper_del = del;
527  } else
528  hwio_beeper_set_pwm(0, 0);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_beeper_tone2()

void hwio_beeper_tone2 ( float  frq,
uint32_t  del,
float  vol 
)
531  {
532  hwio_beeper_set_vol(vol);
533  hwio_beeper_tone(frq, del);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwio_beeper_notone()

void hwio_beeper_notone ( void  )
536  {
537  hwio_beeper_set_pwm(0, 0);
Here is the call graph for this function:

◆ hwio_update_1ms()

void hwio_update_1ms ( void  )
540  {
541  if ((hwio_beeper_del) && ((--hwio_beeper_del) == 0))
542  hwio_beeper_set_pwm(0, 0);
Here is the call graph for this function:
Here is the caller graph for this function:
is_pwm_id_valid
int is_pwm_id_valid(int i_pwm)
Definition: hwio_a3ides_2209_02.c:269
TIM_Base_InitTypeDef::Period
uint32_t Period
Definition: stm32f4xx_hal_tim.h:71
_adc_val
int _adc_val[]
Definition: hwio_a3ides_2209_02.c:85
HAL_TIM_Base_Init
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
_pwm_max
const int _pwm_max[]
Definition: hwio_a3ides_2209_02.c:135
TIM_OCFAST_DISABLE
#define TIM_OCFAST_DISABLE
Definition: stm32f4xx_hal_tim.h:377
HAL_TIM_PWM_ConfigChannel
HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
hwio_beeper_tone
void hwio_beeper_tone(float frq, uint32_t del)
Definition: hwio_a3ides_2209_02.c:514
_PWM_CNT
#define _PWM_CNT
Definition: hwio_a3ides_2209_02.c:136
_hwio_pwm_analogWrite_set_val
void _hwio_pwm_analogWrite_set_val(int i_pwm, int val)
Definition: hwio_a3ides_2209_02.c:429
TIM_Base_InitTypeDef::ClockDivision
uint32_t ClockDivision
Definition: stm32f4xx_hal_tim.h:75
_HEATER_ID_MAX
#define _HEATER_ID_MAX
Definition: hwio_a3ides_2209_02.c:98
_do_pin32
const uint32_t _do_pin32[]
Definition: hwio_a3ides_2209_02.c:57
hwio_jogwheel_enabled
int hwio_jogwheel_enabled
Definition: hwio_a3ides_2209_02.c:176
TIM_OC_InitTypeDef::OCPolarity
uint32_t OCPolarity
Definition: stm32f4xx_hal_tim.h:100
_DI_CNT
#define _DI_CNT
Definition: hwio_a3ides_2209_02.c:54
_adc_max
const int _adc_max[]
Definition: hwio_a3ides_2209_02.c:82
htim2
TIM_HandleTypeDef htim2
Definition: main.c:86
_HEATER_ID_MIN
#define _HEATER_ID_MIN
Definition: hwio_a3ides_2209_02.c:97
TIM_OC_InitTypeDef::OCFastMode
uint32_t OCFastMode
Definition: stm32f4xx_hal_tim.h:107
hwio_beeper_set_pwm
void hwio_beeper_set_pwm(uint32_t per, uint32_t pul)
Definition: hwio_a3ides_2209_02.c:491
TIM_Base_InitTypeDef::CounterMode
uint32_t CounterMode
Definition: stm32f4xx_hal_tim.h:68
_ADC_CNT
#define _ADC_CNT
Definition: hwio_a3ides_2209_02.c:83
TIM_OCMODE_PWM1
#define TIM_OCMODE_PWM1
Definition: stm32f4xx_hal_tim.h:365
hwio_beeper_vol
float hwio_beeper_vol
Definition: hwio_a3ides_2209_02.c:178
TIM_OC_InitTypeDef
TIM Output Compare Configuration Structure definition.
Definition: stm32f4xx_hal_tim.h:92
F
#define F(str)
Definition: UHS_macros.h:164
_DO_CNT
#define _DO_CNT
Definition: hwio_a3ides_2209_02.c:71
gpio_get
static int gpio_get(uint8_t pin8)
Definition: gpio.h:94
TIM_CLOCKDIVISION_DIV1
#define TIM_CLOCKDIVISION_DIV1
Definition: stm32f4xx_hal_tim.h:351
HAL_TIM_PWM_Start
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
_FAN_CNT
#define _FAN_CNT
Definition: hwio_a3ides_2209_02.c:95
hwio_pwm_set_prescaler
void hwio_pwm_set_prescaler(int i_pwm, int prescaler)
Definition: hwio_a3ides_2209_02.c:306
_hwio_pwm_set_val
void _hwio_pwm_set_val(int i_pwm, int val)
Definition: hwio_a3ides_2209_02.c:397
_HEATER_CNT
#define _HEATER_CNT
Definition: hwio_a3ides_2209_02.c:99
_FAN_ID_MIN
#define _FAN_ID_MIN
Definition: hwio_a3ides_2209_02.c:93
TIM_COUNTERMODE_DOWN
#define TIM_COUNTERMODE_DOWN
Definition: stm32f4xx_hal_tim.h:340
TIM_CHANNEL_1
#define TIM_CHANNEL_1
Definition: stm32f4xx_hal_tim.h:422
_dac_max
const int _dac_max[]
Definition: hwio_a3ides_2209_02.c:90
TIM_Base_InitTypeDef::Prescaler
uint32_t Prescaler
Definition: stm32f4xx_hal_tim.h:65
_pwm_get_chan
uint32_t _pwm_get_chan(int i_pwm)
Definition: hwio_a3ides_2209_02.c:363
TIM_OC_InitTypeDef::Pulse
uint32_t Pulse
Definition: stm32f4xx_hal_tim.h:97
TIM_OC_InitTypeDef::OCMode
uint32_t OCMode
Definition: stm32f4xx_hal_tim.h:94
_pwm_analogWrite_val
int _pwm_analogWrite_val[_PWM_CNT]
Definition: hwio_a3ides_2209_02.c:151
_FAN_ID_MAX
#define _FAN_ID_MAX
Definition: hwio_a3ides_2209_02.c:94
hwio_pwm_get_max
int hwio_pwm_get_max(int i_pwm)
Definition: hwio_a3ides_2209_02.c:276
TIM_OCPOLARITY_HIGH
#define TIM_OCPOLARITY_HIGH
Definition: stm32f4xx_hal_tim.h:386
HAL_TIM_PWM_Stop
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
hwio_beeper_del
uint32_t hwio_beeper_del
Definition: hwio_a3ides_2209_02.c:179
gpio_set
static void gpio_set(uint8_t pin8, int state)
Definition: gpio.h:98
TIM_OCPOLARITY_LOW
#define TIM_OCPOLARITY_LOW
Definition: stm32f4xx_hal_tim.h:387
TIM_HandleTypeDef
TIM Time Base Handle Structure definition.
Definition: stm32f4xx_hal_tim.h:287
_DAC_CNT
#define _DAC_CNT
Definition: hwio_a3ides_2209_02.c:91
TIM_HandleTypeDef::Init
TIM_Base_InitTypeDef Init
Definition: stm32f4xx_hal_tim.h:290
__HAL_TIM_GET_COMPARE
#define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__)
Gets the TIM Capture Compare Register value on runtime.
Definition: stm32f4xx_hal_tim.h:1132
hwio_pwm_get_prescaler
int hwio_pwm_get_prescaler(int i_pwm)
Definition: hwio_a3ides_2209_02.c:327
_di_pin32
const uint32_t _di_pin32[]
Definition: hwio_a3ides_2209_02.c:44
GEN_PERIOD_US
#define GEN_PERIOD_US(prescaler, period)
Definition: timer_defaults.h:16
__HAL_TIM_SET_PRESCALER
#define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__)
Set the TIM Prescaler on runtime.
Definition: stm32f4xx_hal_tim.h:1077
TIM_BASE_CLK_MHZ
#define TIM_BASE_CLK_MHZ
Definition: timer_defaults.h:6
_pwm_get_htim
TIM_HandleTypeDef * _pwm_get_htim(int i_pwm)
Definition: hwio_a3ides_2209_02.c:369
_pwm_analogWrite_max
const int _pwm_analogWrite_max[_PWM_CNT]
Definition: hwio_a3ides_2209_02.c:149
_pwm_period_us
int *const _pwm_period_us[]
Definition: hwio_a3ides_2209_02.c:127
hwio_beeper_set_vol
void hwio_beeper_set_vol(float vol)
Definition: hwio_a3ides_2209_02.c:483