This commit is contained in:
moyuhai
2026-06-09 16:39:17 +08:00
commit 41a602f89c
3057 changed files with 771495 additions and 0 deletions
@@ -0,0 +1,94 @@
/*!
* \file i2c_eeprom.c
*
* \brief Target i2c eeprom implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "i2c_eeprom.h"
#include "xc6xxx_hal_i2c.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
* @brief i2c_eeprom_test_demo
* @details
* @param void
* @retval void
*/
void i2c_eeprom_demo(void) {
uint8_t txbuff[512] = {"XC66xx I2C TEST \n"};
uint8_t rxbuff[sizeof(txbuff)] = {0};
I2C_InitTypeDef I2C_InitStruct = {0};
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Mux = GPIO_Mux0;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Int = NOT_INT;
GPIO_InitStruct.Pin = GPIO_3;
GPIO_InitStruct.Dir = GPIO_DIR_OUTPUT;
GPIO_InitStruct.FunSel = I2C_SCL;
GPIO_Init(&GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_2;
GPIO_InitStruct.Dir = GPIO_DIR_INPUT;
GPIO_InitStruct.FunSel = I2C_SDA;
GPIO_Init(&GPIO_InitStruct);
I2C_InitStruct.I2C_ClockSpeed = I2C_ClockSpeed_1M;
I2C_InitStruct.I2C_Mode = I2C_Mode_MASTER;
I2C_InitStruct.I2C_OwnAddress1 = 0x50;
I2C_Init(XC_I2C, &I2C_InitStruct);
for (int i = 0; i < sizeof(txbuff) / 2; i++) {
txbuff[i] = i;
}
for (int i = sizeof(txbuff) / 2; i < sizeof(txbuff); i++) {
txbuff[i] = sizeof(txbuff) - i - 1;
}
DEBUG("Start Write 24Cxx....\r\n");
AT24CXX_Write(0, (uint8_t *)txbuff, sizeof(txbuff));
DEBUG("24Cxx Write Sucess!\r\n");
DEBUG("Start Read 24Cxx....\r\n");
AT24CXX_Read(0, rxbuff, sizeof(rxbuff));
DEBUG("The Data Readed Is: \r\n");
for (int i = 0; i < sizeof(rxbuff); i++) {
DEBUG("[%d-%d] ", i, rxbuff[i]);
}
}
@@ -0,0 +1,62 @@
/*!
* \file i2c_eeprom.h
*
* \brief The head file of i2c_eeprom.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __I2C_EEPROM_H__
#define __I2C_EEPROM_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void i2c_eeprom_demo(void);
#ifdef __cplusplus
}
#endif
#endif /* __I2C_EEPROM_H__ */
@@ -0,0 +1,86 @@
/*!
* \file i2c_master.c
*
* \brief Target i2c master implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "i2c_master.h"
#include "xc6xxx_hal_i2c.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
* @brief i2c_master_demo
* @details
* @param void
* @retval void
*/
void i2c_master_demo(void) {
DEBUG("i2c_master_test \n");
uint8_t txbuff[32];
uint8_t rxbuff[32];
I2C_InitTypeDef I2C_InitStruct = {0};
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Mux = GPIO_Mux0;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Int = NOT_INT;
GPIO_InitStruct.Pin = GPIO_5;
GPIO_InitStruct.Dir = GPIO_DIR_OUTPUT;
GPIO_InitStruct.FunSel = I2C_SCL;
GPIO_Init(&GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_4;
GPIO_InitStruct.Dir = GPIO_DIR_INPUT;
GPIO_InitStruct.FunSel = I2C_SDA;
GPIO_Init(&GPIO_InitStruct);
I2C_InitStruct.I2C_ClockSpeed = I2C_ClockSpeed_400K;
I2C_InitStruct.I2C_Mode = I2C_Mode_MASTER;
I2C_InitStruct.I2C_OwnAddress1 = 0xA0 >> 1;
I2C_Init(XC_I2C, &I2C_InitStruct);
for (int i = 0; i < 32; i++) {
txbuff[i] = i;
}
I2C_Master_Write(XC_I2C, (uint8_t *)txbuff, sizeof(txbuff));
I2C_Master_Read(XC_I2C, (uint8_t *)rxbuff, sizeof(rxbuff));
DEBUG("reve:");
for (int i = 0; i < sizeof(rxbuff); i++) {
DEBUG("%d-", rxbuff[i]);
}
DEBUG("\n");
}
@@ -0,0 +1,61 @@
/*!
* \file i2C_master.h
*
* \brief The head file of i2C_master.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __I2C_MASTER_TEST_H__
#define __I2C_MASTER_TEST_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void i2c_master_demo(void);
#ifdef __cplusplus
}
#endif
#endif /* __XC60xx_I2C_MASTER_TEST_H_ */
@@ -0,0 +1,90 @@
/*!
* \file i2c_slave.c
*
* \brief Target i2c slave implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "i2c_slave.h"
#include "xc6xxx_hal_i2c.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
* @brief i2c_slave_demo
* @details
* @param void
* @retval void
*/
void i2c_slave_demo(void) {
DEBUG("i2c_slave_test \n");
I2C_InitTypeDef I2C_InitStruct = {0};
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Mux = GPIO_Mux0;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Int = NOT_INT;
GPIO_InitStruct.Pin = GPIO_5;
GPIO_InitStruct.Dir = GPIO_DIR_OUTPUT;
GPIO_InitStruct.FunSel = I2C_SCL;
GPIO_Init(&GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_4;
GPIO_InitStruct.Dir = GPIO_DIR_INPUT;
GPIO_InitStruct.FunSel = I2C_SDA;
GPIO_Init(&GPIO_InitStruct);
I2C_InitStruct.I2C_ClockSpeed = I2C_ClockSpeed_400K;
I2C_InitStruct.I2C_Mode = I2C_Mode_SLAVE;
I2C_InitStruct.I2C_OwnAddress1 = 0xA0 >> 1;
I2C_Init(XC_I2C, &I2C_InitStruct);
I2C_Enable_IT(XC_I2C, I2C_INTR_STAT_RX_DONE_GENERATED |
I2C_INTR_STAT_STOP_DET_GENERATED |
I2C_INTR_STAT_RD_REQ_GENERATED |
I2C_INTR_STAT_RX_FULL_GENERATED);
I2C_FIFO_IT_RXTL_Set(XC_I2C, I2C_RX_TL_FIFO_1);
I2C_FIFO_IT_TXTL_Set(XC_I2C, I2C_TX_TL_FIFO_0);
NVIC_EnableIRQ(I2C_IRQn);
while (1) {
if (i2c_slave_rx_flag == 1) {
for (int i = 0; i < 32; i++) {
DEBUG("test_buff[%d]=%d\n", i, i2c_slave_rx_buff[i]);
}
i2c_slave_rx_flag = 0;
}
}
}
@@ -0,0 +1,62 @@
/*!
* \file i2C_slave.h
*
* \brief The head file of i2C_slave.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __I2C_SLAVE_TEST_H__
#define __I2C_SLAVE_TEST_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void i2c_slave_demo(void);
#ifdef __cplusplus
}
#endif
#endif /* __I2C_SLAVE_TEST_H__ */
@@ -0,0 +1,73 @@
/*!
* \file i2c_software.c
*
* \brief Target i2c software implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "i2c_software.h"
#include "xc6xxx_sw_i2c.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
* @brief i2c_software_demo
* @details
* @param void
* @retval void
*/
void i2c_software_demo(void) {
uint8_t txbuff[512] = {"XINCHIP AT24C08 IIC TEST 20190507 . . . . . . . ."};
uint8_t rxbuff[sizeof(txbuff)];
I2C_SoftWareInit();
for (int i = 0; i < sizeof(txbuff) / 2; i++) {
txbuff[i] = i;
}
for (int i = sizeof(txbuff) / 2; i < sizeof(txbuff); i++) {
txbuff[i] = sizeof(txbuff) - i - 1;
}
DEBUG("AT24CXX_Write\n");
for (int i = 0; i < sizeof(txbuff); i++) {
DEBUG("[%d-%d] ", i, txbuff[i]);
}
AT24CXX_WriteLenByte(0, (uint8_t *)txbuff, sizeof(txbuff));
DEBUG("AT24CXX_Read\n");
AT24CXX_ReadLenByte(0, rxbuff, sizeof(txbuff));
for (int i = 0; i < sizeof(rxbuff); i++) {
DEBUG("[%d-%d] ", i, rxbuff[i]);
}
}
@@ -0,0 +1,62 @@
/*!
* \file i2c_software.h
*
* \brief The header of i2c_software.c
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __I2C_SOFTWARE_H__
#define __I2C_SOFTWARE_H__
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
TypeDef
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Exported Functions
-------------------------------------------------------------------------------------*/
void i2c_software_demo(void);
#ifdef __cplusplus
}
#endif
#endif /* __XC60xx_I2C_SOFTWARE_H_ */