Files
kunlun/dtest/dtest3/kl3_i2c_test/kl3_i2c_test.c
2024-09-28 14:24:04 +08:00

821 lines
37 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/****************************************************************************
*
* Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
*
* This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics 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.
*
* ****************************************************************************/
/* os shim includes */
#include "os_types.h"
#include "os_task.h"
#include "os_utils.h"
/* common includes */
#include "iot_io.h"
#include "iot_bitops.h"
/* debug includes*/
#include "dbg_io.h"
#include "apb_glb_reg.h"
#include "hw_reg_api.h"
#include "gpio_mtx_reg.h"
#include "pin_rf.h"
#include "gpio_reg.h"
#include "i2c_reg.h"
#include "i2c_hw.h"
#include "iot_i2c_api.h"
#include "iot_gpio_api.h"
#include "iot_irq.h"
#include "cpu.h"
#define OLED_X_WIDTH 132
#define OLED_Y_WIDTH 64
#define I2C_OLED_ADD 0x3C
#define I2C_AT24C02_ADDR 0X50
int g_port = IOT_I2C_PORT_0;
const unsigned char pic1[]={
0xFF,0x01,0x01,0xF9,0xF9,0x09,0x89,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0x49,
0x49,0x49,0x49,0x49,0x49,0x49,0x09,0x09,0x89,0x89,0xC9,0xC1,0x61,0x31,0x31,0x49,
0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,0xC9,
0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,0x99,0x19,0xF9,0xF1,0x01,0xFF,0xFF,
0xFF,0x00,0x00,0xFF,0x01,0x00,0xFF,0xFF,0x00,0xC0,0xFE,0x06,0x06,0xE6,0x46,0x66,
0x32,0x10,0x98,0xCC,0xCC,0x66,0x66,0x33,0x31,0x99,0x8C,0xCC,0xC6,0x66,0x33,0x32,
0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
0x36,0x76,0xD6,0x06,0x06,0xFE,0xC0,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0x01,0xFF,
0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0x00,0xFF,0x00,0x00,
0xFF,0xF3,0x01,0xF8,0xFC,0x06,0x26,0xB3,0x33,0x99,0x99,0xCC,0xCC,0x66,0x66,0x23,
0xD9,0xD9,0xD9,0xD9,0xD9,0xC9,0xC9,0xC9,0xC9,0x09,0xE9,0xC9,0x09,0x39,0xF1,0xC7,
0x0E,0x38,0xE1,0xC7,0x0C,0x38,0xE1,0xC0,0x0F,0x3F,0x00,0x01,0xFF,0x00,0x00,0xFF,
0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0x07,0x00,0xFF,0xFF,0x00,0x00,0xFF,0x00,0x00,
0xFF,0xFF,0x00,0x3F,0xFF,0x00,0x00,0xFF,0x80,0x01,0xFD,0xE4,0x0C,0x64,0xE6,0x26,
0x64,0x24,0xE6,0x06,0x06,0xFE,0xF0,0x00,0x0F,0xFC,0xE0,0x03,0x0F,0x7C,0xF0,0xC3,
0x0F,0x3C,0xF0,0xC3,0x0F,0x3C,0x70,0xC3,0x07,0x1C,0x78,0xE0,0x87,0x00,0x00,0xFF,
0xFF,0x00,0x00,0xE1,0x06,0x0E,0x38,0xF0,0xC3,0x0E,0x1C,0x70,0xC3,0x8F,0x1C,0x70,
0xE1,0x87,0x1E,0x38,0xE1,0x87,0x0E,0x38,0x70,0x03,0x0F,0x3C,0xB0,0xB3,0xB7,0xB2,
0x66,0x67,0x67,0x20,0x21,0x3F,0x80,0x80,0xFF,0xFF,0x00,0x1F,0xFF,0x00,0x00,0xFF,
0x00,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,
0xFF,0x00,0x00,0xFF,0x00,0x00,0xFC,0xF8,0x01,0x87,0x1E,0x38,0xE1,0xC7,0x0E,0x38,
0xF1,0xC3,0x8E,0x9C,0xD0,0xDB,0xD9,0xD8,0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,0xD9,
0xCC,0x66,0x66,0x63,0x33,0x33,0x99,0x99,0xCC,0xCD,0x64,0x20,0x3F,0x00,0x80,0xFF,
0x00,0x00,0xFF,0xFF,0x00,0x7F,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,
0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x01,0x7F,0x60,0x60,0x61,0x67,0x64,
0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,
0x0C,0xCC,0xC6,0x66,0x33,0x33,0x99,0x99,0xCC,0xCC,0x66,0x62,0x33,0x19,0x19,0x4C,
0x6C,0x66,0x63,0x67,0x60,0x60,0x3F,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,
0xFF,0x80,0x80,0x9F,0x90,0x90,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
0x93,0x9C,0x8C,0x86,0x86,0x93,0x93,0x91,0x90,0x90,0x92,0x93,0x93,0x93,0x93,0x93,
0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x9B,0x9B,0x9B,0x98,0x98,0x9F,0x80,0x80,0xFF//"C:\Users\fortest\Desktop\blackwhite.bmp",0
};
const unsigned char pic2[]=
{
0xFF,0xF1,0x01,0x01,0x03,0x03,0x03,0x03,0x07,0x87,0x87,0xC7,0xC7,0xEF,0xEF,0xEF,
0xEF,0xEF,0xEF,0xEF,0xC7,0xC7,0x87,0x87,0x03,0x03,0x03,0x03,0x01,0x01,0x81,0xF1,
0xFD,0x81,0x01,0x01,0x03,0x03,0x03,0x03,0x87,0x87,0xC7,0xC7,0xE7,0xEF,0xEF,0xEF,
0xEF,0xEF,0xEF,0xC7,0xC7,0xC7,0x87,0x03,0x03,0x03,0x03,0x01,0x01,0x01,0xE1,0xFF,
0xFF,0xFF,0xFF,0xF0,0x00,0xE0,0xFC,0xFE,0x7F,0x0F,0x07,0x03,0x03,0xC1,0xE1,0xE0,
0xE0,0xE0,0xE1,0xC1,0x03,0x03,0x07,0x1F,0xFF,0xFE,0xF8,0xE0,0x00,0x78,0x3F,0x1F,
0x1F,0x3F,0x78,0x00,0xE0,0xF8,0xFE,0xFF,0x1F,0x07,0x03,0x03,0xC1,0xE1,0xE0,0xE0,
0xE0,0xE1,0xC1,0x01,0x03,0x07,0x0F,0x7F,0xFE,0xFC,0xF0,0x00,0xE0,0xFE,0xFF,0xFF,
0xFF,0xFF,0xFF,0x0F,0x00,0x0F,0x3F,0xFF,0xFC,0xE0,0xC0,0x80,0x80,0x07,0x0F,0x0F,
0x0F,0x0F,0x0F,0x07,0x80,0xC0,0xE0,0xF0,0xFF,0x7F,0x3F,0x07,0x00,0x1C,0xF8,0xF0,
0xF0,0xF8,0x1C,0x00,0x0F,0x3F,0x7F,0xFF,0xF0,0xE0,0xC0,0x80,0x03,0x07,0x0F,0x0F,
0x0F,0x0F,0x07,0x80,0x80,0xC0,0xF0,0xFC,0xFF,0x3F,0x0F,0x00,0x1F,0xFF,0xFF,0xFF,
0xFF,0x0F,0x00,0x00,0x80,0x80,0x80,0x80,0xC1,0xC3,0xC3,0xC7,0xE7,0x6F,0x2F,0x0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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x07,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x86,0x00,0x02,0xE1,
0xF0,0xF8,0xF8,0xFC,0xFC,0xFC,0xF8,0xF8,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF8,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xF8,0xF0,0x40,0x02,0x00,0x66,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,
0xFF,0xFF,0xF1,0xC0,0x80,0x81,0x83,0x87,0x87,0x87,0x83,0x03,0x01,0x01,0x00,0x00,
0x40,0xF8,0x00,0x7C,0x60,0x00,0x00,0x01,0x01,0x03,0x03,0x03,0x03,0x03,0x03,0x01,
0x00,0x80,0xF0,0xFC,0xFF,0xFF,0x7F,0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x83,0x01,0x00,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E,0xFE,0xDE,0xE7,0xE0,0xF0,0xF0,0xF8,0xFC,0xFC,0xBF,
0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFE,0xC0,0xF0,0xF8,0xFE,0xFF,0xFF,0xFF,0xFE,0xFC,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF//"C:\Users\fortest\Desktop\center.bmp",0
};
const unsigned char pic5[]=
{
0x00,0x00,0x00,0x80,0xC0,0x61,0x27,0x1C,0x10,0x03,0x06,0x0C,0x18,0x0C,0x04,0x06,
0xE2,0xA1,0x11,0x19,0x0F,0x82,0xF0,0x3C,0x0E,0xC2,0xE3,0x9E,0x80,0x80,0xFE,0x7F,
0x01,0x00,0x60,0x7B,0x3E,0x31,0x97,0x9C,0xC0,0x80,0x80,0x80,0x80,0x86,0x83,0x86,
0x46,0x3C,0xD8,0x60,0x10,0x09,0x09,0x06,0x86,0x4D,0x38,0x00,0x03,0xF4,0x14,0x0A,
0x09,0x08,0x18,0xF0,0x00,0x00,0x87,0xF8,0x00,0x00,0x30,0x3F,0x20,0x20,0x20,0x20,
0x20,0x20,0x60,0xC0,0xC1,0x01,0x01,0x01,0x01,0x01,0xF0,0x1F,0x03,0x00,0x80,0xF0,
0x3F,0x00,0x00,0x80,0xC0,0x60,0x30,0x18,0x08,0x07,0x07,0x80,0xC0,0xC1,0x81,0x83,
0x03,0x01,0x00,0x18,0x3C,0x24,0x66,0x43,0x41,0x40,0x78,0x7F,0x07,0x00,0x30,0x3C,
0x00,0x1E,0x33,0x61,0x60,0x20,0x30,0x18,0x0C,0x83,0xC3,0x43,0x66,0x66,0x64,0xCC,
0x88,0x18,0x59,0xF9,0x81,0x81,0x81,0xF0,0x38,0x08,0x89,0x8D,0x4C,0x64,0x24,0x34,
0x16,0x92,0x8A,0xCB,0x09,0x0D,0x04,0x04,0x24,0x64,0xE5,0xA5,0x25,0x25,0x25,0x24,
0x24,0xE7,0x01,0x00,0x00,0x00,0x44,0xEF,0x29,0x48,0xD0,0x90,0x20,0x21,0x23,0x1C,
0x90,0x80,0x40,0x43,0x42,0x99,0xBD,0x26,0x22,0x62,0x46,0x44,0x44,0x64,0x2C,0x34,
0x14,0x14,0x16,0x13,0x11,0x30,0x20,0x60,0xC0,0x00,0x01,0x03,0x02,0x03,0x01,0x00,
0x00,0x00,0x00,0x1F,0x30,0x20,0x20,0x30,0x10,0x18,0x06,0x83,0xC0,0xE0,0x61,0x61,
0x23,0x63,0x66,0xE6,0xC6,0x04,0x0C,0xFC,0xCC,0x80,0xC0,0xC0,0xFC,0x3E,0x06,0x82,
0x03,0x03,0xCE,0x7C,0x00,0x00,0x00,0xFC,0xCF,0x01,0x00,0x00,0x00,0x00,0x00,0xE0,
0xFF,0x40,0x60,0x20,0xB1,0xD9,0xC9,0x84,0x06,0x13,0x39,0x2C,0xE4,0x06,0x83,0x81,
0x81,0x80,0x80,0x87,0x9C,0x70,0xC0,0x80,0x00,0x00,0x00,0x01,0x03,0x0E,0xF8,0x00,
0x1F,0x71,0xC0,0x80,0x00,0x00,0x80,0x61,0x0C,0x70,0x0C,0x03,0x00,0x00,0xFC,0x0C,
0x18,0x33,0x26,0x4C,0x98,0x10,0x20,0x7D,0xE3,0xC0,0xC0,0x44,0x3C,0x0C,0x08,0x08,
0x18,0x18,0x10,0x10,0x98,0x98,0x88,0x8C,0x07,0x00,0x80,0xF0,0x1C,0x0E,0x06,0x03,
0x03,0x03,0x03,0x06,0xFE,0xF8,0x00,0x00,0x00,0xF8,0xFF,0x03,0x01,0x00,0x00,0x00,
0x00,0x00,0x80,0xF0,0x9F,0x80,0xC0,0x40,0x61,0x31,0x99,0x18,0x0C,0x06,0x33,0x39,
0xCE,0x6F,0x25,0x24,0x24,0xE4,0xE4,0x06,0x03,0x3A,0xE8,0x88,0x08,0x04,0x04,0x08,
0x90,0xE2,0x03,0x05,0xC4,0x88,0x88,0x11,0x11,0x21,0x21,0x3D,0x06,0x03,0x01,0x01,
0x80,0xC0,0xC0,0x60,0x39,0x0F,0x80,0x81,0xC3,0x62,0x62,0x62,0x22,0x23,0x61,0xC0,
0x80,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x07,0x18,0x30,0x30,0x30,0x18,0x07,0x00,
0x00,0x00,0x00,0x80,0x9F,0x90,0x98,0x0E,0x06,0x0C,0x19,0x33,0x22,0x46,0xC4,0x8C,
0x98,0x18,0x0C,0x03,0x30,0x38,0x2C,0x27,0x20,0x30,0xBF,0x03,0x00,0x00,0x00,0x00,
0x30,0x38,0x3C,0x37,0x33,0x10,0x10,0x90,0x18,0x19,0x0F,0xCC,0xC0,0x60,0x20,0x20,
0x30,0x30,0x61,0x41,0x81,0x09,0x1C,0x16,0x32,0x21,0x61,0x43,0x43,0xC6,0x86,0x84,
0x6E,0xC3,0x00,0x00,0x00,0x3F,0xE0,0x80,0x00,0x00,0x00,0x03,0x0E,0x78,0xC0,0x0F,
0x1F,0x20,0x20,0x30,0x1F,0x00,0x7D,0xC3,0x80,0x00,0x00,0x80,0xC0,0x7C,0x0C,0x08,
0x19,0x13,0xF2,0x26,0x06,0x03,0x01,0x01,0xE0,0xF0,0x30,0x10,0x98,0x88,0x8C,0x06,
0x03,0x00,0x00,0x1C,0x66,0xC2,0x82,0x06,0x04,0x08,0x30,0x60,0x20,0x30,0x90,0x90,
0x98,0x48,0x4F,0xC1,0x80,0x00,0x31,0x6E,0x40,0x40,0x40,0x80,0x80,0x80,0x00,0x0F,
0x3F,0x60,0xC0,0xC0,0x60,0x7F,0x03,0x01,0x01,0x01,0x01,0x07,0x1C,0x30,0x40,0xC0,
0xC0,0x7F,0x3F,0x01,0x01,0x01,0x61,0xFF,0x03,0x00,0x00,0x01,0x03,0x0E,0x78,0xE0,
0x00,0x00,0xE0,0xFC,0x0F,0x03,0x00,0x00,0xFE,0x0C,0x8C,0xF8,0x30,0x00,0x00,0x01,
0x03,0x81,0xC0,0x60,0x30,0x30,0x11,0x13,0x26,0xE6,0x8C,0x04,0x04,0x07,0xF3,0x18,
0x08,0x08,0x18,0x30,0xE0,0x80,0x00,0x80,0xC1,0x61,0x61,0x41,0xC0,0x00,0x00,0x00,
0x00,0x00,0x0F,0x18,0x30,0x20,0x60,0x30,0x3D,0x1F,0x00,0x7F,0xC1,0x01,0x01,0x01,
0x03,0x04,0x38,0xE0,0xC0,0x38,0x0F,0x03,0xE0,0x30,0x18,0x18,0x23,0x63,0x42,0x82,
0x84,0x8C,0x78,0x00,0x1F,0x30,0x20,0xE0,0xE2,0xBE,0x86,0xFC,0xE0,0x01,0x71,0xF3,
0x22,0x26,0x4C,0xC8,0x90,0x30,0x10,0x18,0x0C,0x04,0x86,0x86,0x82,0x82,0x83,0xC2,
0x62,0x7E,0x1C,0x00,0x00,0x00,0x00,0x0F,0x38,0xE0,0xC0,0x80,0x80,0x00,0x80,0x81,
0xFF,0x30,0x00,0x03,0x06,0x04,0x04,0x06,0x03,0x00,0x0F,0x1C,0x30,0x30,0x20,0x60,
0xC3,0x81,0x00,0x30,0x30,0x70,0x58,0x4C,0xC6,0x87,0x81,0x80,0x80,0x80,0x83,0x8E,
0xB8,0xE0,0x80,0x00,0x00,0x3F,0x30,0xB3,0x9F,0x90,0xC0,0x80,0x98,0x3F,0x20,0xC0,
0x00,0x00,0x80,0xC0,0xCF,0x99,0xB1,0x61,0xC3,0x82,0x04,0x08,0x30,0x61,0xC2,0xE6,
0x3C,0x0C,0x00,0x00,0xE0,0x70,0x20,0x61,0x43,0x43,0xC3,0xC3,0xC2,0xC6,0xC4,0x7C,
0x30,0x00,0x00,0x06,0x0B,0x11,0x11,0x10,0x10,0x10,0x10,0x10,0x88,0x58,0x40,0x01,
0x79,0x89,0x09,0x12,0x1C,0x01,0x02,0x04,0x08,0x31,0x63,0xC7,0x0D,0x19,0x70,0xC0,
0x80,0xE0,0x70,0x18,0x18,0x0C,0x0C,0x04,0x04,0x0C,0x99,0xF1,0x01,0x01,0x01,0x01,
0xFC,0x8E,0x02,0x03,0x03,0x06,0x0E,0x1C,0xF0,0x80,0x00,0x80,0xE0,0x30,0x30,0x30,
0x20,0x41,0x83,0x06,0x0C,0x18,0x30,0x60,0x5C,0xBC,0x2C,0x4C,0x8D,0x8D,0x0D,0x8D,
0x85,0xC4,0x44,0x4C,0x58,0x50,0xA0,0x21,0x43,0x64,0xBC,0xB0,0x80,0x01,0x01,0xC0,
0xC0,0x40,0x47,0x9D,0xB0,0x60,0x81,0x03,0x06,0x0D,0x33,0x66,0x3C,0x18,0x01,0x81,
0xC0,0x60,0x2C,0x2F,0xE8,0x08,0x08,0x08,0xE8,0xA8,0x48,0xC0,0x08,0x0C,0xE6,0x22,
0x21,0x31,0x11,0x1A,0x0E,0x00,0x00,0x00,0x38,0x46,0x83,0x81,0x00,0x00,0x80,0xE0,
0x38,0x19,0x31,0x21,0x43,0xC2,0x86,0x84,0x98,0xF0,0x00,0x00,0xE3,0x3E,0x00,0xC0,
0xC0,0x80,0x00,0x10,0x30,0x38,0x58,0x4C,0xC6,0x87,0x83,0x81,0x80,0x00,0x00,0x00,
0x01,0x07,0x3C,0xE0,0x80,0x00,0x00,0x00,0x3F,0x21,0x20,0x33,0x3F,0x90,0x80,0x00//"C:\Users\fortest\Desktop\23987259200809112241263643115724376_003_640.bmp",0
};
const unsigned char pic6[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,
0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x7F,0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,0x0F,0x07,0x07,0x07,0x03,0x03,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,0xE0,0xE0,0xF0,0xF0,
0xF8,0xF8,0xF8,0xFC,0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0x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0xFF,0x7F,0x7F,0x3F,0x3F,0x1F,0x1F,
0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0xFC,
0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,
0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//C:\Users\fortest\Desktop\t015385bc585c6df988.bmp0
};
void delay_sometime(void)
{
uint32_t loop;
loop = 0;
while (loop++ < 1000000) {
__asm volatile ("nop\n");
}
}
int i2c_oled_write_command(char cmd)
{
uint8_t data[2] ;
int ret=0;
data[0] = 0x00;
data[1] = cmd;
ret = iot_i2c_write(g_port, I2C_OLED_ADD, (char *)data, 2 );
return ret;
}
int i2c_oled_write_data(char data)
{
uint8_t dat[2] ;
int ret=0;
dat[0] = 0x40;
dat[1] = data;
ret = iot_i2c_write(g_port, I2C_OLED_ADD, (char *)dat, 2 );
return ret;
}
void OLED_Set_Pos(unsigned int x, unsigned char y)
{
i2c_oled_write_command(0xb0+y);
i2c_oled_write_command(((x&0xf0)>>4)|0x10);
i2c_oled_write_command((x&0x0f)|0x01);
}
unsigned char g_buf[100*1024];
void i2c_oled_draw2(unsigned int x_st, char y_st, unsigned int x_end, char y_end,
const unsigned char pic[])
{
unsigned char x, y=0;
unsigned int j=0;
int len = 0;
int ret = 0;
if (y_end%8==0) {
y=y_end/8;
} else {
y=y_end/8+1;
}
for (y=y_st; y<=y_end; y++) {
g_buf[len ++] = 0xb0+y;
g_buf[len ++] = ((x&0xf0)>>4)|0x10 ;
g_buf[len ++] = (x&0x0f)|0x01;
//OLED_Set_Pos(x_st,y);
for (x=x_st; x<x_end; x++) {
g_buf[len ++] = 0x40;
g_buf[len ++] = pic[j++];
//i2c_oled_write_data(pic[j++]);
}
ret = iot_i2c_write(g_port, I2C_OLED_ADD, (char *)g_buf, len );
iot_printf("len = %d, ret = %d\r\n", len, ret);
}
}
void i2c_oled_draw(unsigned int x_st, char y_st, unsigned int x_end, char y_end,
const unsigned char pic[])
{
unsigned char x, y=0;
unsigned int j=0;
if (y_end%8==0) {
y=y_end/8;
} else {
y=y_end/8+1;
}
for (y=y_st; y<=y_end; y++) {
OLED_Set_Pos(x_st,y);
for (x=x_st; x<x_end; x++) {
i2c_oled_write_data(pic[j++]);
}
}
}
void OLED_clear_screen(void)
{
unsigned char y=0;
unsigned int x=0;
for (y=0;y<8;y++) {
i2c_oled_write_command(0xb0+y);
i2c_oled_write_command(0x01);
i2c_oled_write_command(0x10);
for (x=0;x<OLED_X_WIDTH;x++) {
i2c_oled_write_data(0x00);
}
}
}
unsigned char i2c_oled_read(void)
{
char buf[2];
if (iot_i2c_read(g_port, I2C_OLED_ADD, buf, 1)) {
iot_printf("read failed.\n");
}
return buf[0];
}
void i2c_oled_init(void)
{
delay_sometime();
i2c_oled_write_command(0xae);//--turn off oled panel
i2c_oled_write_command(0x00);//---set low column address
i2c_oled_write_command(0x10);//---set high column address
i2c_oled_write_command(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
i2c_oled_write_command(0x81);//--set contrast control register
i2c_oled_write_command(0xCF); // Set SEG Output Current Brightness
i2c_oled_write_command(0xa1);//--Set SEG/Column Mapping 0xa0???? 0xa1??
i2c_oled_write_command(0xc8);//Set COM/Row Scan Direction 0xc0???? 0xc8??
i2c_oled_write_command(0xa6);//--set normal display
i2c_oled_write_command(0xa8);//--set multiplex ratio(1 to 64)
i2c_oled_write_command(0x3f);//--1/64 duty
i2c_oled_write_command(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
i2c_oled_write_command(0x00);//-not offset
i2c_oled_write_command(0xd5);//--set display clock divide ratio/oscillator frequency
i2c_oled_write_command(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
i2c_oled_write_command(0xd9);//--set pre-charge period
i2c_oled_write_command(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
i2c_oled_write_command(0xda);//--set com pins hardware configuration
i2c_oled_write_command(0x12);
i2c_oled_write_command(0xdb);//--set vcomh
i2c_oled_write_command(0x40);//Set VCOM Deselect Level
i2c_oled_write_command(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
i2c_oled_write_command(0x02);//
i2c_oled_write_command(0x8d);//--set Charge Pump enable/disable
i2c_oled_write_command(0x14);//--set(0x10) disable
i2c_oled_write_command(0xa4);// Disable Entire Display On (0xa4/0xa5)
i2c_oled_write_command(0xa6);// Disable Inverse Display On (0xa6/a7)
OLED_Set_Pos(0,0);
i2c_oled_write_command(0xaf);//--turn on oled panel
OLED_clear_screen();
}
void register_print_by_addr(uint32_t addr, int num)
{
volatile uint32_t *p_addr = (volatile uint32_t *)addr;
iot_printf("base:%08x\r\n", addr);
for (int i = 0; i < num; i++) {
iot_printf("%02x:%08x,", (uint32_t)p_addr & 0xff, *p_addr);
p_addr ++;
}
iot_printf("\r\n");
}
#include "gp_timer.h"
#include "gpio_hw.h"
#include "gpio_mtx.h"
extern iot_gpio_op_t hw_gpio_api_table;
extern void IRAM_ATTR iot_delay_us_cpu_cycle(uint32_t us);
uint32_t i2c_base[]={I2C_M0_REG_BASEADDR, I2C_M1_REG_BASEADDR,
I2C_M2_REG_BASEADDR, I2C_M3_REG_BASEADDR};
void at24c02_test_loop(void)
{
int ret ;
char send_buf[9];
static uint8_t read_buf[255];
int inc = 0;
int addr = 0;
int pin = 8;
hw_gpio_api_table.gpio_init();
gpio_pin_select(pin, 0);
hw_gpio_api_table.set_gpio_mode(pin, GPIO_OUTPUT);
hw_gpio_api_table.set_value(pin, 0);
delay_sometime();
while(1) {
for(addr = 0; addr < 0xff; addr += 8) {
send_buf[0] = addr;
send_buf[1] = (inc ++) % 0xff;
send_buf[2] = (inc ++) % 0xff;
send_buf[3] = (inc ++) % 0xff;
send_buf[4] = (inc ++) % 0xff;
send_buf[5] = (inc ++) % 0xff;
send_buf[6] = (inc ++) % 0xff;
send_buf[7] = (inc ++) % 0xff;
send_buf[8] = (inc ++) % 0xff;
ret = iot_i2c_write(g_port,I2C_AT24C02_ADDR,(char *)send_buf, sizeof(send_buf));
if ( ret ) {
iot_printf("write failed ret = %d, times = %d.\n", ret, addr/8);
}
hw_gpio_api_table.set_value(pin, 1);
iot_delay_us_cpu_cycle(5000/2);
hw_gpio_api_table.set_value(pin, 0);
}
inc ++;
send_buf[0] = 0;
iot_i2c_write(g_port, I2C_AT24C02_ADDR,(char *)send_buf, 1); //告诉24C02从哪个地址开始读
if (iot_i2c_read(g_port, I2C_AT24C02_ADDR, (char *)read_buf, sizeof(read_buf) - 1)) {
iot_printf("read failed.\n");
} else {
for (int i = 0; i < sizeof(read_buf) - 1; i++) {
iot_printf("read[%d]=%02x\r\n", i, read_buf[i] & 0xff);
}
}
}
// write test
send_buf[0] = 0; // byte addr 从24c02的哪个地址开始写
send_buf[1] = 0x22; //写入的测试数据
send_buf[2] = 0x33; //写入的测试数据
send_buf[3] = 0x44; //写入的测试数据
send_buf[4] = 0x55; //写入的测试数据
send_buf[5] = 0x66; //写入的测试数据
ret = iot_i2c_write(g_port,I2C_AT24C02_ADDR,(char *)send_buf, sizeof(send_buf));
if ( ret ) {
iot_printf("write failed ret = %d.\n", ret);
}
//read test
send_buf[0] = 0; // byte addr
delay_sometime();//延时一小会儿等24c02写入数据
iot_i2c_write(g_port, I2C_AT24C02_ADDR,(char *)send_buf, 1); //告诉24C02从哪个地址开始读
if (iot_i2c_read(g_port, I2C_AT24C02_ADDR, send_buf, sizeof(send_buf) - 1)) {
iot_printf("read failed.\n");
} else {
for (int i = 0; i < sizeof(send_buf) - 1; i++) {
iot_printf("read[%d]=%02x\r\n", i, send_buf[i] & 0xff);
}
}
while(0) {
register_print_by_addr(i2c_base[g_port], 0x3c / 4);
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
delay_sometime();
ret = iot_i2c_write(g_port,I2C_AT24C02_ADDR,(char *)send_buf, sizeof(send_buf) );
if ( ret ) {
iot_printf("write failed ret = %d.\n", ret);
}
}
}
void oled_test(void)
{
i2c_oled_draw(32,0,96,7,pic1);
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
i2c_oled_draw(32,0,96,7,pic2);
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
OLED_clear_screen();
i2c_oled_draw(37,0,91,7,pic3);
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
i2c_oled_draw(32,0,96,7,pic4);
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
i2c_oled_draw(0,0,127,7,pic5);
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
i2c_oled_draw(0,0,127,7,pic6);
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
OLED_clear_screen();
delay_sometime();delay_sometime();delay_sometime();delay_sometime();
register_print_by_addr(i2c_base[g_port], 0x3c / 4);
delay_sometime();
delay_sometime();
delay_sometime();
}
void i2c_cb(uint32_t port, uint32_t mask)
{
iot_printf("port=%d, mask=%02x\r\n", port, mask);
}
extern void SHT2x_test_loop(void);
#define MASTER_REQ_READ 0x12
#define MASTER_REQ_WRITE 0x34
void stm32_slave_test(void)
{
uint8_t addr = 0x66;
int ret ;
uint8_t inc = 0;
static uint8_t send_buf[254];
static uint8_t read_buf[254];
uint8_t bTransferRequest = 0;
uint8_t hTxNumData = 0;
uint8_t hRxNumData = 0;
int pin = 8;
hw_gpio_api_table.gpio_init();
gpio_pin_select(pin, 0);
hw_gpio_api_table.set_gpio_mode(pin, GPIO_OUTPUT);
// rst slave
hw_gpio_api_table.set_value(pin, 0);
delay_sometime();
hw_gpio_api_table.set_value(pin, 1);
delay_sometime();
uint32_t loops = 0;
while(1)
{
++loops;
for(int bytes = 1; bytes < 254; bytes ++) {
for(int band = 50; band <= 400; band += 50) {
iot_printf("loops=%d, bytes=%d, band=%d\n", loops, bytes, band);
i2c_set_baudrate(g_port, band);
for(int times = 0; times < 100; times++) {
// write test
bTransferRequest = MASTER_REQ_WRITE;
ret = iot_i2c_write(g_port, addr ,(char *)&bTransferRequest, 1);
if ( ret ) {
iot_printf("write req failed ret = %d.\n", ret);
}
hTxNumData = bytes;
//delay_sometime();
ret = iot_i2c_write(g_port, addr ,(char *)&hTxNumData, 1);
if ( ret ) {
iot_printf("write num failed ret = %d.\n", ret);
}
//delay_sometime();
ret = iot_i2c_write(g_port,addr ,(char *)send_buf, hTxNumData );
if ( ret ) {
iot_printf("write data failed ret = %d.\n", ret);
}
// read test
bTransferRequest = MASTER_REQ_READ;
ret = iot_i2c_write(g_port, addr ,(char *)&bTransferRequest, 1);
if ( ret ) {
iot_printf("write req failed ret = %d.\n", ret);
}
hRxNumData = hTxNumData;
//delay_sometime();
ret = iot_i2c_write(g_port, addr ,(char *)&hRxNumData, 1);
if ( ret ) {
iot_printf("write num failed ret = %d.\n", ret);
}
if (iot_i2c_read(g_port, addr, (char *)read_buf, hRxNumData)) {
iot_printf("read failed.\n");
} else {
for (int i = 0; i < hRxNumData; i ++) {
if(read_buf[i] != send_buf[i]) {
iot_printf("err at %d read:%02x send:%02x\r\n", i, read_buf[i] , send_buf[i]);
}
}
}
inc ++;
for(int i = 0; i < sizeof(send_buf)/sizeof(send_buf[0]); i++) {
send_buf[i] = (i + inc) % 0xff;
}
}
}
}
}
}
int i2c_main(void)
{
uint8_t ret = 0;
g_port = IOT_I2C_PORT_0;
iot_i2c_module_cfg_t i2c_cfg;
dbg_uart_init();
uint32_t cpu_id = cpu_get_mhartid();
iot_interrupt_init(cpu_id);
iot_printf("start\r\n");
i2c_cfg.baud = 2000;
i2c_cfg.gpio.scl = 58; //23
i2c_cfg.gpio.sda = 59; //24
i2c_cfg.nack_wait_num = 2;
i2c_cfg.open_cnt = 0;
i2c_cfg.port = g_port;
ret = iot_i2c_module_init(&i2c_cfg);
if (0 != ret) {
iot_printf("ret=%d\r\n", ret);
}
at24c02_test_loop();
stm32_slave_test();
SHT2x_test_loop();
// 是否测试中断 测试中断时将I2C_AT24C02_ADDR 定义成非0x50的值如 0X51
// 由于不是24c02的地址master收不到ack超时后会触发nack中断和done中断
// 上面的i2c_nack_cb 和 i2c_done_cb 会被调用,超时次数由 i2c_set_nack_wait_num
// 设置
#if 0
i2c_interrupt_init(g_port, I2C_NACK_TIMEOUT | I2C_TRANS_DOWN, i2c_cb);
while(1)
{
at24c02_test();
}
#else
i2c_oled_init();
while(1)
{
oled_test();
at24c02_test_loop();
}
#endif
return 0;
}
#ifdef __GNUC__
int main(void)
{
i2c_main();
return 0;
}
#endif // __GCC__