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       <20>̵<EFBFBD><CCB5><EFBFBD>2
 | |||
|  |                     com6:1,         //symbol_relay_1       <20>̵<EFBFBD><CCB5><EFBFBD>1
 | |||
|  |                     com5:1,         //symbol_switch_6      <20><><EFBFBD><EFBFBD>6
 | |||
|  |                     com4:1,         //symbol_switch_5      <20><><EFBFBD><EFBFBD>5
 | |||
|  |                     com3:1,         //symbol_switch_4      <20><><EFBFBD><EFBFBD>4
 | |||
|  |                     com2:1,         //symbol_switch_3      <20><><EFBFBD><EFBFBD>3
 | |||
|  |                     com1:1,         //symbol_switch_2      <20><><EFBFBD><EFBFBD>2
 | |||
|  |                     com0:1;         //symbol_switch_1      <20><><EFBFBD><EFBFBD>1
 | |||
|  |         } seg_0; | |||
|  |         struct { | |||
|  |             uint8_t com7:1,         //symbol_float  ƽ---<2D><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
 | |||
|  |                     com6:1,         //symbol_demand <20><><EFBFBD><EFBFBD>
 | |||
|  |                     com5:1,         //symbol_zero   <20><><EFBFBD><EFBFBD>
 | |||
|  |                     com4:1,         //symbol_Hz     <20><>λHz
 | |||
|  |                     com3:1,         //symbol_%      %
 | |||
|  |                     com2:1,         //symbol_h      <20><>λh
 | |||
|  |                     com1:1,         //symbol_var    <20><>λvar
 | |||
|  |                     com0:1;         //symbol_k      <20><>λk   --- kvarh
 | |||
|  |         } seg_1; | |||
|  |         struct { | |||
|  |             uint8_t com7:1,         //symbol_tip    <20><>---<2D><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
 | |||
|  |                     com6:1,         //symbol_peak   <20><>---<2D><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
 | |||
|  |                     com5:1,         //symbol_h      <20><>λh
 | |||
|  |                     com4:1,         //symbol_A      <20><>λA
 | |||
|  |                     com3:1,         //symbol_V      <20><>λV
 | |||
|  |                     com2:1,         //symbol_V      <20><>λV ---W
 | |||
|  |                     com1:1,         //symbol_k      <20><>λk ---kVVAh
 | |||
|  |                     com0:1;         //none
 | |||
|  |         } seg_2; | |||
|  |         struct { | |||
|  |             uint8_t com7:1,         //symbol_total  <20><>
 | |||
|  |                     com6:1,         //symbol_harmonic  г<><D0B3>
 | |||
|  |                     com5:1,         //symbol_cos<6F><73>   <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  |                     com4:1,         //symbol_S
 | |||
|  |                     com3:1,         //symbol_E
 | |||
|  |                     com2:1,         //symbol_Q
 | |||
|  |                     com1:1,         //symbol_P      PQES
 | |||
|  |                     com0:1;         //symbol_P8_2   <20>ڶ<EFBFBD><DAB6><EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>,point_8
 | |||
|  |         } seg_3; | |||
|  |         struct { | |||
|  |             uint8_t com7:1,         //symbol_month  <20><>
 | |||
|  |                     com6:1,         //symbol_combination  <20><><EFBFBD><EFBFBD>
 | |||
|  |                     com5:1,         //symbol_positive  <20><>
 | |||
|  |                     com4:1,         //symbol_reverse   <20><>
 | |||
|  |                     com3:1,         //symbol_direction <20><>---<2D><>|<7C><><EFBFBD><EFBFBD>
 | |||
|  |                     com2:1,         //symbol_U      <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
 | |||
|  |                     com1:1,         //symbol_I      <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  |                     com0:1;         //symbol_last   <20><>---<2D><>1X<31><58>
 | |||
|  |         } seg_4; | |||
|  |         struct { | |||
|  |             uint8_t com7:1,         //symbol_digit1_7bit---<2D><>1X<31><58>:<3A><>λ
 | |||
|  |                     com6:1, | |||
|  |                     com5:1, | |||
|  |                     com4:1, | |||
|  |                     com3:1, | |||
|  |                     com2:1, | |||
|  |                     com1:1, | |||
|  |                     com0:1;         //symbol_decade_1  <20><>1x<31><78>:ʮλ
 | |||
|  |         } seg_5; | |||
|  |         struct { | |||
|  |             uint8_t com7:1,         //symbol_vally     <20><>---<2D><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
 | |||
|  |                     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    С<><D0A1><EFBFBD><EFBFBD>: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  С<><D0A1><EFBFBD><EFBFBD>|<7C>ڶ<EFBFBD><DAB6><EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>,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    С<><D0A1><EFBFBD><EFBFBD>: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 С<><D0A1><EFBFBD><EFBFBD>|<7C><>һ<EFBFBD><D2BB>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>,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    С<><D0A1><EFBFBD><EFBFBD>: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    С<><D0A1><EFBFBD><EFBFBD>: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    С<><D0A1><EFBFBD><EFBFBD>: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 <20><>һ<EFBFBD><D2BB>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>,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
 |