/**
 * @file version.c
 *
 * @brief This file contains the software version
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "version.h"
#include "string.h"


/*---------------------------------------------------------------------------*/
/*   Index of table                                                          */
/*---------------------------------------------------------------------------*/

const uint8_t software_Version[2] =
{
  /* Software Version Major */
  (uint8_t) VER_u8DATA_SW_MAJOR,
  /* Software Version Minor */
  (uint8_t) VER_u8DATA_SW_MINOR
};



/*---------------------------------------------------------------------------*/
/* !Comment: Convert a BCD value to ASCII format                             */
/* !WARNING: The value to convert must be in LSB 4bits of u8ToConv           */
/*---------------------------------------------------------------------------*/
uint8_t u8ConvBcdToAscii(uint8_t u8ToConv)
{
	uint8_t LOC_u8Value;
	uint8_t LOC_u8ConvertedValue;

  /* We get the value to convert */
  LOC_u8Value = (uint8_t) (u8ToConv & (uint8_t) 0x0F);

  if (LOC_u8Value < (uint8_t)10 )
  {
    /* If the value to convert is a number [0;9] */
    LOC_u8ConvertedValue = (uint8_t)(LOC_u8Value + (uint8_t)0x30);
  }

  else
  {
    /* If the value to convert is a letter [A;F]*/
    LOC_u8ConvertedValue = (uint8_t)(LOC_u8Value + (uint8_t)0x37);
  }

  return (uint8_t)LOC_u8ConvertedValue;
}

/*---------------------------------------------------------------------------*/
/* !Description :                                                            */
/*      Get the version of the software                                      */
/*---------------------------------------------------------------------------*/
 void VER_vidGetVersionInfo(uint8_t au8VersionInfo[])
{
  /* !Pseudo : copy all data */
  memcpy(au8VersionInfo,software_Version,(uint8_t)2);
}


 /*---------------------------------------------------------------------------*/
 /* @Description :                                                            */
 /*      Get the SW Version in ASCII format                           */
 /* Return: 4 Bytes containing the VERSION in ASCII FORMAT                    */
 /*---------------------------------------------------------------------------*/
  void verGetSWVersionInAscii(uint8_t u8SWVersionAscii[])
 {
   u8SWVersionAscii[0] = u8ConvBcdToAscii((uint8_t)(software_Version[0] >> (uint8_t)4));
   u8SWVersionAscii[1] = u8ConvBcdToAscii(software_Version[0]);
   u8SWVersionAscii[2] = u8ConvBcdToAscii((uint8_t)(software_Version[1] >> (uint8_t)4));
   u8SWVersionAscii[3] = u8ConvBcdToAscii(software_Version[1]);
 }


uint16_t get_nvm_revision_no()
{
   return (NVM_REV_N0_MAJOR<<8 | NVM_REV_N0_MINOR);
}
