1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017, 2019 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "slcd_engine.h"
10 #include <stdio.h>
11 #include <stdint.h>
12 
SLCD_Engine_Show_Num(tSLCD_Engine * slcd_engine,int32_t num,int32_t pos,int32_t on)13 int32_t SLCD_Engine_Show_Num(tSLCD_Engine *slcd_engine, int32_t num, int32_t pos, int32_t on)
14 {
15     int32_t slcd_pin = 0, pin_val = 0;
16     const uint16_t **ppSLCD_NumPos   = NULL;
17     const uint16_t *pSLCD_NumPosNVal = NULL;
18 
19     if ((pos < 0) || (pos >= (int32_t)NUM_POSEND))
20     {
21         return -1;
22     }
23     ppSLCD_NumPos = SLCD_NumPos[pos];
24     /* A number is comprised of several bytes' value */
25     for (pSLCD_NumPosNVal = ppSLCD_NumPos[num]; *pSLCD_NumPosNVal != 0U; pSLCD_NumPosNVal++)
26     {
27         slcd_pin = (int32_t)(uint16_t)(*pSLCD_NumPosNVal >> 8);
28         pin_val  = (int32_t)(uint16_t)(*pSLCD_NumPosNVal & 0xffU);
29         slcd_engine->slcd_set_pin_func(SLCD_Set_Num, slcd_pin, pin_val, on);
30     }
31 
32     return 0;
33 }
34 
SLCD_Engine_Show_Icon(tSLCD_Engine * slcd_engine,int32_t icon_pos,int32_t on)35 int32_t SLCD_Engine_Show_Icon(tSLCD_Engine *slcd_engine, int32_t icon_pos, int32_t on)
36 {
37     int32_t slcd_pin = 0;
38     int32_t pin_val  = 0;
39     uint16_t pos_val = 0U;
40 
41     if ((icon_pos < 0) || (icon_pos >= (int32_t)ICON_END))
42     {
43         return -1;
44     }
45     pos_val  = SLCD_Icon[icon_pos];
46     slcd_pin = (int32_t)(uint16_t)(pos_val >> 8);
47     pin_val  = (int32_t)(uint16_t)(pos_val & 0xffU);
48     slcd_engine->slcd_set_pin_func(SLCD_Set_Icon, slcd_pin, pin_val, on);
49 
50     return 0;
51 }
52 
SLCD_Engine_Init(tSLCD_Engine * slcd_engine,SLCD_SET_PIN_FUNC pslcd_hw_handler)53 void SLCD_Engine_Init(tSLCD_Engine *slcd_engine, SLCD_SET_PIN_FUNC pslcd_hw_handler)
54 {
55     slcd_engine->slcd_set_pin_func = pslcd_hw_handler;
56 }
57