PAN1080 Peripheral API
pan_i2c.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Panchip Technology Corp. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
15#ifndef __PAN_I2C_H__
16#define __PAN_I2C_H__
17
24#ifdef __cplusplus
25extern "C"
26{
27#endif
28
29
44typedef struct
45{
47 uint16_t I2C_Mode;
48 uint16_t I2C_DutyCycle;
49 uint16_t I2C_OwnAddress1;
52
53
54
55
56#define PAN_I2C_MODE_MASTER ((uint16_t)0x0021)
57#define PAN_I2C_MODE_SLAVE ((uint16_t)0x0000)
58#define IS_I2C_MODE(MODE) (((MODE) == PAN_I2C_MODE_MASTER) || \
59 ((MODE) == PAN_I2C_MODE_SLAVE))
62#define I2C_SPEED_STANDARD_MODE (uint16_t)(0x0002)
63#define I2C_SPEED_FAST_MODE (uint16_t)(0x0004)
64#define I2C_SPEED_HIGH_MODE (uint16_t)(0x0006)
67#define I2C_DutyCycle_16_9 ((uint16_t)0x4000)
68#define I2C_DutyCycle_2 ((uint16_t)0xBFFF)
69#define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DutyCycle_16_9) || \
70 ((CYCLE) == I2C_DutyCycle_2))
73#define I2C_AcknowledgedAddress_7bit ((uint16_t)0x4000)
74#define I2C_AcknowledgedAddress_10bit ((uint16_t)0xC000)
76#define I2C_CMD_WR ((uint8_t)0x00)
77#define I2C_CMD_RD ((uint8_t)0x01)
78#define I2C_CMD_STOP ((uint8_t)0x02)
79#define I2C_CMD_RESTART ((uint8_t)0x04)
84#define I2C_RX_TL_0 ((uint8_t)0x00)
85#define I2C_RX_TL_1 ((uint8_t)0x01)
86#define I2C_RX_TL_2 ((uint8_t)0x02)
87#define I2C_RX_TL_3 ((uint8_t)0x03)
88#define I2C_RX_TL_4 ((uint8_t)0x04)
89#define I2C_RX_TL_5 ((uint8_t)0x05)
90#define I2C_RX_TL_6 ((uint8_t)0x06)
91#define I2C_RX_TL_7 ((uint8_t)0x07)
92#define I2C_RX_TL_8 ((uint8_t)0x08)
98#define I2C_TX_TL_0 ((uint8_t)0x00)
99#define I2C_TX_TL_1 ((uint8_t)0x01)
100#define I2C_TX_TL_2 ((uint8_t)0x02)
101#define I2C_TX_TL_3 ((uint8_t)0x03)
102#define I2C_TX_TL_4 ((uint8_t)0x04)
103#define I2C_TX_TL_5 ((uint8_t)0x05)
104#define I2C_TX_TL_6 ((uint8_t)0x06)
105#define I2C_TX_TL_7 ((uint8_t)0x07)
106#define I2C_TX_TL_8 ((uint8_t)0x08)
112#define I2C_IT_RX_UNDER ((uint16_t)0x0001)
113#define I2C_IT_RX_OVER ((uint16_t)0x0002)
114#define I2C_IT_RX_FULL ((uint16_t)0x0004)
115#define I2C_IT_TX_OVER ((uint16_t)0x0008)
116#define I2C_IT_TX_EMPTY ((uint16_t)0x0010)
117#define I2C_IT_RD_REQ ((uint16_t)0x0020)
118#define I2C_IT_TX_ABORT ((uint16_t)0x0040)
119#define I2C_IT_RX_DONE ((uint16_t)0x0080)
120#define I2C_IT_ACTIVITY ((uint16_t)0x0100)
121#define I2C_IT_STOP_DET ((uint16_t)0x0200)
122#define I2C_IT_START_DET ((uint16_t)0x0400)
123#define I2C_IT_GEN_CALL ((uint16_t)0x0800)
124#define I2C_IT_MST_ON_HOLD ((uint16_t)0x2000)
125#define I2C_IT_ALL ((uint16_t)0x2FFF)
131#define I2C_FLAG_SLV_ACTIVITY ((uint32_t)0x00000040)
132#define I2C_FLAG_MST_ACTIVITY ((uint32_t)0x00000020)
133#define I2C_FLAG_RFF ((uint32_t)0x00000010)
134#define I2C_FLAG_RFNE ((uint32_t)0x00000008)
135#define I2C_FLAG_TFE ((uint32_t)0x00000004)
136#define I2C_FLAG_TFNF ((uint32_t)0x00000002)
137#define I2C_FLAG_ACTIVITY ((uint32_t)0x00000001)
140#define FLAG_MASK ((uint32_t)0x007F0FFF)
141#define ITEN_MASK ((uint16_t)0x2FFF)
142#define IT_FLAG_MASK ((uint16_t)0x2FFF)
154__STATIC_INLINE void I2C_SetMode(I2C_T* I2Cx, uint16_t Mode)
155{
156 (Mode == PAN_I2C_MODE_MASTER)?(I2Cx->CON |= (I2C_CON_IC_SLAVE_DISABLE | I2C_CON_MASTER_MODE)):(I2Cx->CON &= ~(I2C_CON_IC_SLAVE_DISABLE | I2C_CON_MASTER_MODE));
157}
171__STATIC_INLINE void I2C_SetTxTirggerLevel(I2C_T* I2Cx, uint8_t ThresholdValue)
172{
173 I2Cx->TX_TL = (I2Cx->TX_TL & ~I2C_TX_TL) | (ThresholdValue & 0xF);
174}
175
189__STATIC_INLINE void I2C_SetRxTirggerLevel(I2C_T* I2Cx, uint8_t ThresholdValue)
190{
191 I2Cx->RX_TL = (I2Cx->RX_TL & ~I2C_RX_TL) | (ThresholdValue & 0xF);
192}
200__STATIC_INLINE void I2C_Cmd(I2C_T* I2Cx, FunctionalState NewState)
201{
202 (NewState != DISABLE)?(I2Cx->IC_ENABLE |= I2C_ENABLE_ENABLE):(I2Cx->IC_ENABLE &= (uint32_t)~((uint32_t)I2C_ENABLE_ENABLE));
203}
211__STATIC_INLINE void I2C_GeneralCallCmd(I2C_T* I2Cx, FunctionalState NewState)
212{
213 (NewState != DISABLE)?(I2Cx->TAR = (I2Cx->TAR | I2C_TAR_SPECIAL) & (~I2C_TAR_GC_OR_START)):(I2Cx->TAR = I2Cx->TAR);
214}
215
223__STATIC_INLINE void I2C_SendDataCmd(I2C_T* I2Cx, uint8_t Data, uint8_t Cmd)
224{
225 I2Cx->DATACMD = ((Cmd << 8 ) | (Data & 0xFF));
226}
233__STATIC_INLINE void I2C_SendCmd(I2C_T* I2Cx, uint8_t Cmd)
234{
235 I2Cx->DATACMD |= (Cmd << 8);
236}
242__STATIC_INLINE uint8_t I2C_ReceiveData(I2C_T* I2Cx)
243{
244 return (uint8_t)I2Cx->DATACMD;
245}
251__STATIC_INLINE void I2C_AbortTransfer(I2C_T* I2Cx)
252{
253 I2Cx->IC_ENABLE |= I2C_ENABLE_ABORT;
254}
262__STATIC_INLINE void I2C_DMACmd(I2C_T* I2Cx, FunctionalState NewState)
263{
264 (NewState != DISABLE)?(I2Cx->DMA_CR |= (I2C_DMA_CR_RDMAE | I2C_DMA_CR_TDMAE)):(I2Cx->DMA_CR &= (uint32_t)~((uint32_t)(I2C_DMA_CR_RDMAE | I2C_DMA_CR_TDMAE)));
265}
272__STATIC_INLINE void I2C_DMATransferDataLevel(I2C_T* I2Cx, uint8_t Level)
273{
274 I2Cx->DMA_TDLR |= (Level & 0x07);
275}
282__STATIC_INLINE void I2C_DMAReceiveDataLevel(I2C_T* I2Cx, uint8_t Level)
283{
284 I2Cx->DMA_RDLR |= (Level & 0x07);
285}
306__STATIC_INLINE ITStatus I2C_GetITStatus(I2C_T* I2Cx, uint16_t I2C_IT)
307{
308 return ((I2Cx->INTR_STAT & (I2C_IT & IT_FLAG_MASK)) != (uint32_t)RESET)?(SET):(RESET);
309}
330__STATIC_INLINE ITStatus I2C_GetRawITStatus(I2C_T* I2Cx, uint16_t I2C_IT)
331{
332 return ((I2Cx->RAW_INTR_STAT & (I2C_IT & IT_FLAG_MASK)) != (uint32_t)RESET)?(SET):(RESET);
333}
355__STATIC_INLINE void I2C_ITConfig(I2C_T* I2Cx, uint16_t I2C_IT, FunctionalState NewState)
356{
357 (NewState != DISABLE)?(I2Cx->INTR_MASK |= I2C_IT):(I2Cx->INTR_MASK &= (uint16_t)~I2C_IT);
358}
359
365__STATIC_INLINE void I2C_DisableAllIT(I2C_T* I2Cx)
366{
367 I2Cx->INTR_MASK = 0x0;
368}
374__STATIC_INLINE void I2C_ClearAllITPendingBit(I2C_T* I2Cx)
375{
376 (void)(I2Cx->CLR_INTR);
377}
378
384__STATIC_INLINE bool I2C_AbortSrcCheck(I2C_T* I2Cx,uint32_t IC_MSK)
385{
386 return (I2Cx->TX_ABRT_SRC & IC_MSK)?(true):(false);
387}
388
389
396__STATIC_INLINE void I2C_SetSlaveAddr(I2C_T* I2Cx,uint32_t addr)
397{
398 I2Cx->SAR = (I2Cx->SAR & ~I2C_TAR_TAR) | addr;
399}
400
401
429bool I2C_Init(I2C_T* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
436void I2C_Set7bitAddress(I2C_T* I2Cx, uint8_t Address);
443void I2C_Set10bitAddress(I2C_T* I2Cx, uint16_t Address);
444
459FlagStatus I2C_GetFlagStatus(I2C_T* I2Cx, uint32_t I2C_FLAG);
479void I2C_ClearITPendingBit(I2C_T* I2Cx, uint16_t I2C_IT);
480
488void I2C_Write(I2C_T* I2Cx,uint8_t *WriteBuf,uint32_t Size);
489
497void I2C_Read(I2C_T* I2Cx,uint8_t *ReadBuf,uint32_t Size);
498
501#ifdef __cplusplus
502}
503#endif
504
505#endif /* __PAN_I2C_H__ */
void I2C_Set7bitAddress(I2C_T *I2Cx, uint8_t Address)
Configure the target address for any master transaction.
__STATIC_INLINE void I2C_SetRxTirggerLevel(I2C_T *I2Cx, uint8_t ThresholdValue)
Set I2C Rx fifo threshold value .
Definition: pan_i2c.h:191
FlagStatus I2C_GetFlagStatus(I2C_T *I2Cx, uint32_t I2C_FLAG)
Checks whether the specified I2C flag is set or not.
#define PAN_I2C_MODE_MASTER
Definition: pan_i2c.h:56
void I2C_Write(I2C_T *I2Cx, uint8_t *WriteBuf, uint32_t Size)
read data from the I2Cx peripheral.
__STATIC_INLINE void I2C_AbortTransfer(I2C_T *I2Cx)
Aborting I2C Transfers.
Definition: pan_i2c.h:253
__STATIC_INLINE bool I2C_AbortSrcCheck(I2C_T *I2Cx, uint32_t IC_MSK)
Get the source of tx_abort.
Definition: pan_i2c.h:386
__STATIC_INLINE void I2C_SetMode(I2C_T *I2Cx, uint16_t Mode)
Set I2C mode .
Definition: pan_i2c.h:156
__STATIC_INLINE uint8_t I2C_ReceiveData(I2C_T *I2Cx)
Returns the most recent received data by the I2Cx peripheral.
Definition: pan_i2c.h:244
void I2C_ClearITPendingBit(I2C_T *I2Cx, uint16_t I2C_IT)
Clears the I2Cx's interrupt pending bits.
#define IT_FLAG_MASK
Definition: pan_i2c.h:144
__STATIC_INLINE void I2C_DMAReceiveDataLevel(I2C_T *I2Cx, uint8_t Level)
DMA Receive Data Level Register.
Definition: pan_i2c.h:284
__STATIC_INLINE ITStatus I2C_GetRawITStatus(I2C_T *I2Cx, uint16_t I2C_IT)
Checks whether the specified I2C interrupt has occurred or not.
Definition: pan_i2c.h:332
__STATIC_INLINE void I2C_GeneralCallCmd(I2C_T *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C general call feature.
Definition: pan_i2c.h:213
__STATIC_INLINE void I2C_DisableAllIT(I2C_T *I2Cx)
Enables or disables all the specified I2C interrupts.
Definition: pan_i2c.h:367
__STATIC_INLINE void I2C_ClearAllITPendingBit(I2C_T *I2Cx)
Clears all the I2Cx's interrupt pending bits.
Definition: pan_i2c.h:376
__STATIC_INLINE void I2C_DMACmd(I2C_T *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C DMA requests.
Definition: pan_i2c.h:264
void I2C_Read(I2C_T *I2Cx, uint8_t *ReadBuf, uint32_t Size)
write data to the I2Cx peripheral.
__STATIC_INLINE void I2C_SendDataCmd(I2C_T *I2Cx, uint8_t Data, uint8_t Cmd)
Sends a data byte through the I2Cx peripheral.
Definition: pan_i2c.h:225
void I2C_Set10bitAddress(I2C_T *I2Cx, uint16_t Address)
Configure the target address for any master transaction.
__STATIC_INLINE void I2C_SetSlaveAddr(I2C_T *I2Cx, uint32_t addr)
Set slave address.
Definition: pan_i2c.h:398
__STATIC_INLINE void I2C_Cmd(I2C_T *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C peripheral.
Definition: pan_i2c.h:202
__STATIC_INLINE void I2C_SendCmd(I2C_T *I2Cx, uint8_t Cmd)
Sends a data byte through the I2Cx peripheral.
Definition: pan_i2c.h:235
bool I2C_Init(I2C_T *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
__STATIC_INLINE void I2C_SetTxTirggerLevel(I2C_T *I2Cx, uint8_t ThresholdValue)
Set I2C Tx fifo threshold value .
Definition: pan_i2c.h:173
__STATIC_INLINE void I2C_DMATransferDataLevel(I2C_T *I2Cx, uint8_t Level)
DMA Transmit Data Level Register.
Definition: pan_i2c.h:274
__STATIC_INLINE ITStatus I2C_GetITStatus(I2C_T *I2Cx, uint16_t I2C_IT)
Checks whether the specified I2C interrupt has occurred or not.
Definition: pan_i2c.h:308
__STATIC_INLINE void I2C_ITConfig(I2C_T *I2Cx, uint16_t I2C_IT, FunctionalState NewState)
Enables or disables the specified I2C interrupts.
Definition: pan_i2c.h:357
Structure with i2c init feature.
Definition: pan_i2c.h:45
uint16_t I2C_Mode
Definition: pan_i2c.h:47
uint16_t I2C_DutyCycle
Definition: pan_i2c.h:48
uint16_t I2C_OwnAddress1
Definition: pan_i2c.h:49
uint16_t I2C_AcknowledgedAddress
Definition: pan_i2c.h:50
uint32_t I2C_ClockSpeed
Definition: pan_i2c.h:46