293 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			293 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 *
 | 
						|
 * Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 *
 | 
						|
 * This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics Ltd and MAY NOT
 | 
						|
 * be copied by any method or incorporated into another program without
 | 
						|
 * the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
 * thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
 * is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
 * liability for its use in any way and conveys no license or title under
 | 
						|
 * any patent or copyright and makes no representation or warranty that this
 | 
						|
 * Information is free from patent or copyright infringement.
 | 
						|
 *
 | 
						|
 * ****************************************************************************/
 | 
						|
 | 
						|
#ifndef _INCLUDE_LCD_HT16K23_H_
 | 
						|
#define _INCLUDE_LCD_HT16K23_H_
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
    extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
/* Maximum of the display ram length. */
 | 
						|
#define HT16K23_MAX_DISPLAY_RAM_LEN      15
 | 
						|
 | 
						|
/* bitmap of the lcd keypad.*/
 | 
						|
typedef enum {
 | 
						|
    HT16K23_K0_BIT = 1,          /* K0_BIT 00000001*/
 | 
						|
    HT16K23_K1_BIT = 2,          /* K1_BIT 00000010*/
 | 
						|
    HT16K23_K2_BIT = 4,          /* K2_BIT 00000100*/
 | 
						|
    HT16K23_K3_BIT = 8,          /* K3_BIT 00001000*/
 | 
						|
}keypad_bit_map;
 | 
						|
 | 
						|
/* the lcd work status.*/
 | 
						|
enum {
 | 
						|
    HT16K23_STAT_STANDBY = 0,         /* standby mode*/
 | 
						|
    HT16K23_STAT_NORMAL = 1,          /* normal mode*/
 | 
						|
};
 | 
						|
 | 
						|
typedef union _display_bitmap {
 | 
						|
    uint8_t display_data[HT16K23_MAX_DISPLAY_RAM_LEN];
 | 
						|
    struct {
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_relay_2       继电器2
 | 
						|
                    com6:1,         //symbol_relay_1       继电器1
 | 
						|
                    com5:1,         //symbol_switch_6      开关6
 | 
						|
                    com4:1,         //symbol_switch_5      开关5
 | 
						|
                    com3:1,         //symbol_switch_4      开关4
 | 
						|
                    com2:1,         //symbol_switch_3      开关3
 | 
						|
                    com1:1,         //symbol_switch_2      开关2
 | 
						|
                    com0:1;         //symbol_switch_1      开关1
 | 
						|
        } seg_0;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_float  平---尖峰平谷
 | 
						|
                    com6:1,         //symbol_demand 需量
 | 
						|
                    com5:1,         //symbol_zero   零序
 | 
						|
                    com4:1,         //symbol_Hz     单位Hz
 | 
						|
                    com3:1,         //symbol_%      %
 | 
						|
                    com2:1,         //symbol_h      单位h
 | 
						|
                    com1:1,         //symbol_var    单位var
 | 
						|
                    com0:1;         //symbol_k      单位k   --- kvarh
 | 
						|
        } seg_1;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_tip    尖---尖峰平谷
 | 
						|
                    com6:1,         //symbol_peak   峰---尖峰平谷
 | 
						|
                    com5:1,         //symbol_h      单位h
 | 
						|
                    com4:1,         //symbol_A      单位A
 | 
						|
                    com3:1,         //symbol_V      单位V
 | 
						|
                    com2:1,         //symbol_V      单位V ---W
 | 
						|
                    com1:1,         //symbol_k      单位k ---kVVAh
 | 
						|
                    com0:1;         //none
 | 
						|
        } seg_2;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_total  总
 | 
						|
                    com6:1,         //symbol_harmonic  谐波
 | 
						|
                    com5:1,         //symbol_cosφ   功率因数
 | 
						|
                    com4:1,         //symbol_S
 | 
						|
                    com3:1,         //symbol_E
 | 
						|
                    com2:1,         //symbol_Q
 | 
						|
                    com1:1,         //symbol_P      PQES
 | 
						|
                    com0:1;         //symbol_P8_2   第二个冒号上面的点,point_8
 | 
						|
        } seg_3;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_month  月
 | 
						|
                    com6:1,         //symbol_combination  组合
 | 
						|
                    com5:1,         //symbol_positive  正
 | 
						|
                    com4:1,         //symbol_reverse   反
 | 
						|
                    com3:1,         //symbol_direction 向---正|反向
 | 
						|
                    com2:1,         //symbol_U      电压符号
 | 
						|
                    com1:1,         //symbol_I      电流符号
 | 
						|
                    com0:1;         //symbol_last   上---上1X月
 | 
						|
        } seg_4;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_digit1_7bit---上1X月:个位
 | 
						|
                    com6:1,
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;         //symbol_decade_1  上1x月:十位
 | 
						|
        } seg_5;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_vally     谷---尖峰平谷
 | 
						|
                    com6:1,         //symbol_digit9_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_6;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_P9    小数点:decimal point
 | 
						|
                    com6:1,         //symbol_digit8_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_7;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,     //symbol_P7_2  小数点|第二个冒号下面的点,point_7
 | 
						|
                    com6:1,         //symbol_digit7_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_8;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_P6    小数点:decimal point
 | 
						|
                    com6:1,         //symbol_digit6_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_9;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,      //symbol_P4_1 小数点|第一个冒号下面的点,point_4
 | 
						|
                    com6:1,         //symbol_digit5_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_10;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_P3    小数点:decimal point
 | 
						|
                    com6:1,         //symbol_digit4_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_11;
 | 
						|
            struct {
 | 
						|
            uint8_t com7:1,         //symbol_P2    小数点:decimal point
 | 
						|
                    com6:1,         //symbol_digit3_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_12;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_P1    小数点:decimal point
 | 
						|
                    com6:1,         //symbol_digit2_7bit
 | 
						|
                    com5:1,
 | 
						|
                    com4:1,
 | 
						|
                    com3:1,
 | 
						|
                    com2:1,
 | 
						|
                    com1:1,
 | 
						|
                    com0:1;
 | 
						|
        } seg_13;
 | 
						|
        struct {
 | 
						|
            uint8_t com7:1,         //symbol_c
 | 
						|
                    com6:1,         //symbol_b    bc
 | 
						|
                    com5:1,         //symbol_a
 | 
						|
                    com4:1,         //symbol_b    ab
 | 
						|
                    com3:1,         //symbol_c
 | 
						|
                    com2:1,         //symbol_a    va
 | 
						|
                    com1:1,         //none
 | 
						|
                    com0:1;         //symbol_P5_1 第一个冒号上面的点,point_5
 | 
						|
        } seg_14;
 | 
						|
    }display_ram_bitmap;
 | 
						|
/* COM value of digit 0 ~ 9
 | 
						|
#define NUM_0    (1<<0)|(1<<1)|(1<<2)|(1<<4)|(1<<5)|(1<<6)    //1110111  0x77
 | 
						|
#define NUM_1    (1<<1)|(1<<4)                                //0010010  0x12
 | 
						|
#define NUM_2    (1<<0)|(1<<1)|(1<<6)|(1<<5)|(1<<3)           //1101011  0x6b
 | 
						|
#define NUM_3    (1<<0)|(1<<1)|(1<<3)|(1<<4)|(1<<6)           //1011011  0x5b
 | 
						|
#define NUM_4    (1<<1)|(1<<4)|(1<<3)|(1<<2)                  //0011110  0x1e
 | 
						|
#define NUM_5    (1<<0)|(1<<2)|(1<<3)|(1<<4)|(1<<6)           //1011101  0x5d
 | 
						|
#define NUM_6    (1<<0)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<5)    //1111101  0x7d
 | 
						|
#define NUM_7    (1<<0)|(1<<1)|(1<<4)                         //0010011  0x13
 | 
						|
#define NUM_8    (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6) //1111111 0x7f
 | 
						|
#define NUM_9    (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)    //1011111  0x5f
 | 
						|
*/
 | 
						|
}display_bitmap;
 | 
						|
 | 
						|
/* The upper app callback function
 | 
						|
 * used to get the pressed key, reference HT16K23_K0_XXX.
 | 
						|
 */
 | 
						|
typedef uint8_t(* iot_lcd_key_handle_cb)(uint8_t which_key);
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_lcd_key_handle_register() - register lcd key handle callback func.
 | 
						|
@param: keycb      the lcd key handle callback func.
 | 
						|
return:            ERR_OK:success.
 | 
						|
*                  ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_key_handle_register(iot_lcd_key_handle_cb keycb);
 | 
						|
 | 
						|
/*
 | 
						|
@brief lcd_init() - lcd i2c init, open lcd, clear screen.
 | 
						|
return:         ERR_OK:success.
 | 
						|
*               ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_init();
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_lcd_int_init() - init interrupt
 | 
						|
return:         ERR_OK:success.
 | 
						|
*               ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_int_init();
 | 
						|
 | 
						|
/*
 | 
						|
@brief lcd_stand_by_set() - set system mode to standby
 | 
						|
return:            ERR_OK:success.
 | 
						|
*                  ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_set_standby();
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_lcd_set_weakup() - set system mode to normal working.
 | 
						|
return:            ERR_OK:success.
 | 
						|
*                  ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_set_weakup();
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_lcd_get_status() - get lcd work status, normal or standy.
 | 
						|
return:            reference HT16K23_STAT_XXX.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_get_status();
 | 
						|
 | 
						|
/*
 | 
						|
@brief lcd_clear_screen() - clear lcd screen
 | 
						|
return:            ERR_OK:success.
 | 
						|
*                  ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_clear_screen();
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_lcd_get_display_data() - query display status.
 | 
						|
@param: display_buf    the buffer that save display ram data.
 | 
						|
return:         ERR_OK:success.
 | 
						|
*               ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_get_display_data(display_bitmap *display_buf);
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_lcd_set_display_data() - set display data.
 | 
						|
@param: display_data    data that set to the display memory.
 | 
						|
@param: data_len        the length of the display data.
 | 
						|
return:         ERR_OK:success.
 | 
						|
*               ERR_FAIL:failed.
 | 
						|
*/
 | 
						|
uint8_t iot_lcd_set_display_data(display_bitmap *display_data);
 | 
						|
 | 
						|
/*
 | 
						|
@brief iot_poll_read_key_data() - poll read ram key data
 | 
						|
                     If enable interrupt,when interrupt triggered will call it.
 | 
						|
                                  otherwise upper-app polling call is required
 | 
						|
* @return        which key was pressed.
 | 
						|
*                ERR_FAIL: something error.
 | 
						|
*/
 | 
						|
uint8_t iot_poll_read_key_data();
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif //IOT_LED_H
 |