/*
 * This file is part of the MicroPython project, http://micropython.org/
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2021 Kentaro Sekimoto
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef RGBLM_H_
#define RGBLM_H_

// The following definitions come from https://github.com/Seeed-Studio/Seeed_RGB_LED_Matrix

#define I2C_CMD_CONTINUE_DATA 0x81

#define GROVE_TWO_RGB_LED_MATRIX_DEF_I2C_ADDR 0x65    // The device i2c address in default
#define GROVE_TWO_RGB_LED_MATRIX_VID          0x2886  // Vender ID of the device
#define GROVE_TWO_RGB_LED_MATRIX_PID          0x8005  // Product ID of the device

#define I2C_CMD_GET_DEV_ID           0x00  // This command gets device ID information
#define I2C_CMD_DISP_BAR             0x01  // This command displays LED bar
#define I2C_CMD_DISP_EMOJI           0x02  // This command displays emoji
#define I2C_CMD_DISP_NUM             0x03  // This command displays number
#define I2C_CMD_DISP_STR             0x04  // This command displays string
#define I2C_CMD_DISP_CUSTOM          0x05  // This command displays user-defined pictures
#define I2C_CMD_DISP_OFF             0x06  // This command cleans the display
#define I2C_CMD_DISP_ASCII           0x07  // not use
#define I2C_CMD_DISP_FLASH           0x08  // This command displays pictures which are stored in flash
#define I2C_CMD_DISP_COLOR_BAR       0x09  // This command displays colorful led bar
#define I2C_CMD_DISP_COLOR_WAVE      0x0a  // This command displays built-in wave animation
#define I2C_CMD_DISP_COLOR_CLOCKWISE 0x0b  // This command displays built-in clockwise animation
#define I2C_CMD_DISP_COLOR_ANIMATION 0x0c  // This command displays other built-in animation
#define I2C_CMD_DISP_COLOR_BLOCK     0x0d  // This command displays an user-defined color
#define I2C_CMD_STORE_FLASH          0xa0  // This command stores frames in flash
#define I2C_CMD_DELETE_FLASH         0xa1  // This command deletes all the frames in flash

#define I2C_CMD_LED_ON         0xb0  // This command turns on the indicator LED flash mode
#define I2C_CMD_LED_OFF        0xb1  // This command turns off the indicator LED flash mode
#define I2C_CMD_AUTO_SLEEP_ON  0xb2  // This command enable device auto sleep mode
#define I2C_CMD_AUTO_SLEEP_OFF 0xb3  // This command disable device auto sleep mode (default mode)

#define I2C_CMD_DISP_ROTATE 0xb4  // This command setting the display orientation
#define I2C_CMD_DISP_OFFSET 0xb5  // This command setting the display offset

#define I2C_CMD_SET_ADDR       0xc0  // This command sets device i2c address
#define I2C_CMD_RST_ADDR       0xc1  // This command resets device i2c address
#define I2C_CMD_TEST_TX_RX_ON  0xe0  // This command enable TX RX pin test mode
#define I2C_CMD_TEST_TX_RX_OFF 0xe1  // This command disable TX RX pin test mode
#define I2C_CMD_TEST_GET_VER   0xe2  // This command use to get software version
#define I2C_CMD_GET_DEVICE_UID 0xf1  // This command use to get chip id

enum orientation_type_t
{
    DISPLAY_ROTATE_0 = 0,
    DISPLAY_ROTATE_90 = 1,
    DISPLAY_ROTATE_180 = 2,
    DISPLAY_ROTATE_270 = 3,
};

enum COLORS
{
    red = 0x00,
    orange = 0x12,
    yellow = 0x18,
    green = 0x52,
    cyan = 0x7f,
    blue = 0xaa,
    purple = 0xc3,
    pink = 0xdc,
    white = 0xfe,
    black = 0xff,
};

uint16_t rgblm_getDeviceVID(void);
uint16_t rgblm_getDevicePID(void);
void rgblm_changeDeviceBaseAddress(uint8_t newAddress);
void rgblm_defaultDeviceAddress(void);
void rgblm_turnOnLedFlash(void);
void rgblm_turnOffLedFlash(void);
void rgblm_enableAutoSleep(void);
void rgblm_wakeDevice(void);
void rgblm_disableAutoSleep(void);
void rgblm_setDisplayOrientation(int orientation);
void rgblm_setDisplayOffset(int offset_x, int offset_y);
void rgblm_displayBar(uint8_t bar, uint16_t duration_time, bool forever_flag, uint8_t color);
void rgblm_displayEmoji(uint8_t emoji, uint16_t duration_time, bool forever_flag);
void rgblm_displayNumber(int16_t number, uint16_t duration_time, bool forever_flag, uint8_t color);
void rgblm_displayString(char *str, uint16_t duration_time, bool forever_flag, uint8_t color);
void rgblm_displayFrames(uint8_t *buffer, uint16_t duration_time, bool forever_flag, uint8_t frames_number);
void rgblm_displayFrames_64(uint64_t *buffer, uint16_t duration_time, bool forever_flag, uint8_t frames_number);
void rgblm_stopDisplay(void);
void rgblm_storeFrames(void);
void rgblm_deleteFrames(void);
void rgblm_displayFramesFromFlash(uint16_t duration_time, bool forever_flag, uint8_t from, uint8_t to);
void rgblm_displayColorBlock(uint32_t rgb, uint16_t duration_time, bool forever_flag);
void rgblm_displayColorBar(uint8_t bar, uint16_t duration_time, bool forever_flag);
void rgblm_displayColorWave(uint8_t color, uint16_t duration_time, bool forever_flag);
void rgblm_displayClockwise(bool is_cw, bool is_big, uint16_t duration_time, bool forever_flag);
void rgblm_displayColorAnimation(uint8_t index, uint16_t duration_time, bool forever_flag);
void rgblm_enableTestMode(void);
void rgblm_disableTestMode(void);
uint32_t rgblm_getTestVersion(void);
void rgblm_resetDevice(void);
void rgblm_getDeviceId(void);
void rgblm_init(void);

#endif /* RGBLM_H_ */
