/**
 * \file    drv_oled.h
 * \brief
 *
 * \par     Copyright (c) 2017 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  James
 * \date    2017-11-15
 * \version
 *
 * \history
 *  Date        Note
 *  2017-11-15  Original Creation
 *
 */

#ifndef __DRV_OLED_H_
#define __DRV_OLED_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "types.h"

/** OLED I2C slave address */
#define OLED_ADDR               (0x78)
/** OLED write command definition */
#define OLED_CMD                (0x00)
/** OLED write data definition */
#define OLED_DATA               (0x40)

/** OLED write command interface */
#define OLED_WR_CMD(cmd)        drv_i2c_reg_set(DRV_I2C_ID_0,OLED_ADDR,OLED_CMD,cmd)

/** OLED write data interface */
#define OLED_WR_DATA(dat)       drv_i2c_reg_set(DRV_I2C_ID_0,OLED_ADDR,OLED_DATA,dat)


/** Misc definitions */
#define FONT_SIZE_8             (8)
#define FONT_SIZE_8_WIDTH       (6)
#define FONT_SIZE_16            (16)
#define FONT_SIZE_16_WIDTH      (8)
#define OLED_MAX_COL            (128)
//page
#define OLED_MAX_ROW            (4)
#define OLED_BRIGHTNESS         (0xFF)

#define DEFAULT_FONT_SIZE       (FONT_SIZE_16)
#define DEFAULT_FONT_WIDTH_SIZE (FONT_SIZE_16_WIDTH)


/** OLED control functions */
void OLED_init(void);
void OLED_display_on(void);
void OLED_display_off(void);
void OLED_clear(void);
void OLED_on(void);

/** \brief Set OLED start position
 *
 * \param x Start X pixel position (0~127)
 * \param y Start Y page position (0~3 for 128x32, 0~7 for 128x64)
 */
void OLED_set_pos(u8_t x, u8_t y);

/** \brief Draw a character
 *
 * \param font_size Font size
 * \param chr The charactor that will be drawn
 * \param x Start X pixel position (0~127)
 * \param y Start Y page position (0~3 for 128x32, 0~7 for 128x64)
 */
void OLED_draw_char(u8_t x, u8_t y, u8_t chr, u8_t font_size);

/** \brief Draw a number(digits)
 *
 * \param len The length of the number
 * \param digits The number that will be drawn (0~4294967295)
 * \param font_size Font size
 * \param x Start X pixel position (0~127)
 * \param y Start Y page position (0~3 for 128x32, 0~7 for 128x64)
 */
void OLED_draw_digits(u8_t x, u8_t y, u32_t digits, u8_t len, u8_t font_size);
void OLED_draw_digits_zero_prefix(u8_t x, u8_t y, u32_t digits, u8_t len, u8_t font_size);

/** \brief Draw a string
 *
 * \param font_size Font size
 * \param p The string pointer that will be drawn
 * \param x Start X pixel position (0~127)
 * \param y Start Y page position (0~3 for 128x32, 0~7 for 128x64)
 */
void OLED_draw_string(u8_t x, u8_t y, const u8_t *p, u8_t font_size);

/** \brief Draw hanzi
 *
 * \param hzk 16x16 Hanzi array
 * \param idx Index of the array of Hanzi
 * \param x Start X pixel position (0~127)
 * \param y Start Y page position (0~3 for 128x32, 0~7 for 128x64)
 */
void OLED_draw_chinese(u8_t x, u8_t y, u8_t idx, u8_t hzk[][16]);

/** \brief Draw BMP
 *
 * \param bmp BMP array
 * \param x0 Start X pixel position (0~127)
 * \param x1 End X pixel position (0~128)
 * \param y0 Start Y page position (0~3 for 128x32, 0~7 for 128x64)
 * \param y1 End Y page position (0~3 for 128x32, 0~7 for 128x64)
 */
void OLED_draw_bmp(u8_t x0, u8_t y0, u8_t x1, u8_t y1, const u8_t bmp[]);

#ifdef __cplusplus
}
#endif

#endif /* #ifndef __DRV_OLED_H_ */

