/******************************************************************************
 * @file     ymodem.h
 * @brief    Common function header file.
 * @version  V4.0.1
 * @date     30-July-2026
 *
 * @note
 * Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd.. All rights reserved.
 *
 * @attention
 * THIS SOFTWARE JUST PROVIDES CUSTOMERS WITH CODING INFORMATION REGARDING
 * THEIR PRODUCTS, WHICH AIMS AT SAVING TIME FOR THEM. SPINTROL SHALL NOT BE
 * LIABLE FOR THE USE OF THE SOFTWARE. SPINTROL DOES NOT GUARANTEE THE
 * CORRECTNESS OF THIS SOFTWARE AND RESERVES THE RIGHT TO MODIFY THE SOFTWARE
 * WITHOUT NOTIFICATION.
 *
 ******************************************************************************/

#ifndef COMMON_H
#define COMMON_H

#ifdef __cplusplus
extern "C" {
#endif

#if defined(SPC1158)
#include "spc1158.h"
#elif defined(SPD1148)
#include "spd1148.h"
#elif defined(SPD1178)
#include "spd1178.h"
#elif defined(SPD1188)
#include "spd1188.h"
#elif defined(SPD1163)
#include "spd1163.h"
#else
#include "spc1168.h"
#endif



/**
 *  @brief  Function pointer definition
 */
typedef  void (*pFunction)(void);




/**
 *  @brief  RS485 interface definition - update its value according to the hardware board
 */
#define RS485_INTERFACE_ENABLED   (1)           /* 0 - UART, 1 - RS485              */
#define RS485_CONTROL_PIN         (GPIO_32)     /* GPIO pin for RS485 Tx/Rx control */


#define APPLICATION_ADDR          (0x10004000)
#define PAGE_SIZE                 (FLASH_SECTOR_SIZE)
#define FLASH_IMAGE_SIZE          (uint32_t)(FLASH_CHIP_SIZE - (APPLICATION_ADDR - FLASH_START_ADDR))


#define IS_AF(c)                  ((c >= 'A') && (c <= 'F'))
#define IS_af(c)                  ((c >= 'a') && (c <= 'f'))
#define IS_09(c)                  ((c >= '0') && (c <= '9'))
#define ISVALIDHEX(c)             IS_AF(c) || IS_af(c) || IS_09(c)
#define ISVALIDDEC(c)             IS_09(c)
#define CONVERTDEC(c)             (c - '0')

#define CONVERTHEX_alpha(c)       (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10))
#define CONVERTHEX(c)             (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c))




/**
 *  @brief  Public Function Declaration
 */
void Int2Str(uint8_t *str, uint32_t intnum);
uint32_t Str2Int(uint8_t *inputstr, uint32_t *intnum);

uint8_t GetKey(void);

void SerialDownload(void);
void SerialUpload(void);


#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* COMMON_H */


/******************* Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd. ***** END OF FILE ****/
