/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 CW.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/

#include "cw32l012.h"
#include "system_cw32l012.h"
#include "interrupts_cw32l012.h"
#include "base_types.h"

#include "cw32l012_lpi2c.h"
#include "cw32l012_gpio.h"
#include "cw32l012_sysctrl.h"
#include "cw32l012_flash.h"
#include "cw32l012_ram.h"
#include "cw32l012_dma.h"


/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */


/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
typedef struct {
  uint8_t *pu8RegAddr;                 // Register address
  uint16_t slaveAddr;                  // Slave address
  I2C_SlaveRegAddrTypeDef regAddrType; // Register address type
} I2C_SlaveRegTypeDef;

typedef struct {
  uint16_t *pu16DataIndexDMA;          // Data index for DMA
  uint8_t *pu8Data;
  uint16_t u16Len;
} I2C_MasterDataTypeDef;


/* USER CODE END ET */


/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */


/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
//#define ADDR_SLAVE_10B_EN            // Set 10-bit slave address, default is 7-bit address

#define LEN_DATA_RAM                   (16UL)        // Data length in RAM
#define LEN_DATA_ADDRESS               (2UL)         // Data address length
#ifdef  ADDR_SLAVE_10B_EN
#define LEN_SLAVE_ADDRESS              (2UL)
#else
#define LEN_SLAVE_ADDRESS              (1UL)
#endif
/* USER CODE END EM */


/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */
void SYSCTRL_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void LPI2C_MasterInit(void);

void I2C_ExceptionHandling(void);
//...
uint8_t LPI2C_MasterTransferDataRestartCmd(I2C_SlaveRegTypeDef *I2C_SlaveData, I2C_MasterDataTypeDef *I2C_MasterData);
uint8_t LPI2C_MasterReceiveIT(I2C_SlaveRegTypeDef *I2C_SlaveData, I2C_MasterDataTypeDef *I2C_MasterData);
uint8_t LPI2C_MasterTransferIT(I2C_SlaveRegTypeDef *I2C_SlaveData, I2C_MasterDataTypeDef *I2C_MasterData);
uint8_t LPI2C_MasterTransferDataPreProcess(I2C_SlaveRegTypeDef *I2C_SlaveData, I2C_MasterDataTypeDef *I2C_MasterData);

void LPI2C_MasterStopIT(void);
void DMA_DataPacketReset(void);
//...
void DMA_Configuration(void);
void DMACH12_Callback(void);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */



#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT CW *****END OF FILE****/
