#include "stm32f0xx.h"
#include "utils.h"

extern volatile uint16_t tick;

void delay_ms(uint16_t delay)
{
  uint32_t i;

  i = tick + delay;
  if(i > 65535)
    i -= 65536;

  while(tick != i)
    ;
}

void number2text(uint8_t *text, uint32_t number, uint8_t digits, uint8_t dp_digits)
{
  uint8_t i, size;

  size = (dp_digits > 0) + digits; // extra space for decimal point
  text += size;
  *text-- = '\0';

  for(i = 0; i < size; i++)
  {
    if(dp_digits != 0 && dp_digits == i)
      *text = ',';
    else
    {
      *text = '0' + (number % 10);
      number /= 10;
    }
    text--;
  }
}
