53#ifndef _MULTICHANNELI2C_H
54#define _MULTICHANNELI2C_H
55#include <basictypes.h>
64#define I2C_MAX_BUF_SIZE (64)
66#define DEFAULT_I2C_MODULE (0)
70#define I2C_RX_TX_TIMEOUT (5)
71#define I2C_START_TIMEOUT (20)
73#define I2C_SLAVE_TX_TERM_CHAR (0)
82#define I2C_NEXT_WRITE_OK (1)
83#define I2C_NEXT_READ_OK (2)
84#define I2C_MASTER_OK (3)
85#define I2C_TIMEOUT (4)
86#define I2C_BUS_NOT_AVAIL (5)
87#define I2C_NOT_READY (6)
88#define I2C_LOST_ARB (7)
89#define I2C_LOST_ARB_ADD (8)
90#define I2C_NO_LINK_RX_ACK (9)
105#define I2C_SR i2cModule->i2sr
106#define I2C_CR i2cModule->i2cr
107#define I2C_DR i2cModule->i2dr
108#define I2C_FDR i2cModule->i2fdr
109#define I2C_ADR i2cModule->i2adr
124 void MultiChannel_I2CInit(
int moduleNum = DEFAULT_I2C_MODULE, uint8_t slave_Addr = 0x08, uint8_t freqdiv = 0x3C);
183 uint32_t I2CTXAvail();
192 uint8_t I2CGetByte();
207 uint8_t I2CFillSlaveTXBuf(puint8_t buf, uint32_t num,
bool restart =
true);
219 extern uint8_t (*I2C_SlaveTX_Callback)();
229 extern void (*I2C_SlaveTX_NAK_Callback)();
243 extern void (*I2C_SlaveRX_Callback)(uint8_t RX_Data);
245#define I2C_START_READ (1)
246#define I2C_START_WRITE (0)
264 uint8_t
MultiChannel_I2CRestart(
int moduleNum, uint8_t addr,
bool Read_Not_Write, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT);
295 uint8_t
MultiChannel_I2CStart(
int moduleNum, uint8_t addr,
bool Read_Not_Write, uint32_t ticks_to_wait = I2C_START_TIMEOUT);
353 struct I2C_Slave_Record
355 OS_SEM I2C_Slave_RX_Semaphore;
357 volatile uint8_t *pI2CRxbuf;
358 volatile uint8_t *pI2CTxbuf;
360 volatile uint32_t I2Crx_put;
361 volatile uint32_t I2Crx_get;
363 volatile uint32_t I2Ctx_put;
364 volatile uint32_t I2Ctx_get;
375#define I2C_SR_BUSY (((0x20 & I2C_SR) == 0x20))
376#define I2C_CR_SLAVE (((0x20 & I2C_CR) == 0x00))
377#define I2C_SR_ARB_LOST (((0x10 & I2C_SR) == 0x10))
378#define I2C_SR_ADRES_AS_SLAVE (((0x40 & I2C_SR) == 0x40))
379#define I2C_SR_SLAVE_TX (((0x04 & I2C_SR) == 0x04))
381#define I2C_CR_TX (((0x10 & I2C_CR) == 0x10))
382#define I2C_SR_RX_ACK (((0x01 & I2C_SR) == 0x00))
383#define I2C_CR_RX_ACK (((0x08 & I2C_CR) == 0x00))
385#define I2C_SET_NO_ACK ((I2C_CR |= 0x08))
386#define I2C_SET_ACK ((I2C_CR &= 0xF7))
387#define I2C_SET_TX ((I2C_CR |= 0x10))
388#define I2C_SET_RX ((I2C_CR &= 0xEF))
389#define I2C_SET_REPEAT_START ((I2C_CR |= 0x04))
390#define I2C_CLR_ARB_LOST ((I2C_SR &= 0xEF))
395 inline void I2CInit(uint8_t slave_Addr = 0x08, uint8_t freqdiv = 0x3C)
400 inline void Mulit_I2CInit(uint8_t slave_Addr = 0x08, uint8_t freqdiv = 0x3C)
405 inline uint8_t I2CSendBuf(uint8_t addr, puint8_t buf,
int num,
bool stop =
true)
410 inline uint8_t Multi_I2CSendBuf(uint8_t addr, puint8_t buf,
int num,
bool stop =
true)
415 inline uint8_t I2CReadBuf(uint8_t addr, puint8_t buf,
int num,
bool stop =
true)
420 inline uint8_t Multi_I2CReadBuf(uint8_t addr, puint8_t buf,
int num,
bool stop =
true)
425 inline uint8_t I2CRestart(uint8_t addr,
bool Read_Not_Write, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
430 inline uint8_t Multi_I2CRestart(uint8_t addr,
bool Read_Not_Write, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
435 inline uint8_t I2CStart(uint8_t addr,
bool Read_Not_Write, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
440 inline uint8_t Multi_I2CStart(uint8_t addr,
bool Read_Not_Write, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
445 inline uint8_t I2CStop(uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT) {
return MultiChannel_I2CStop(DEFAULT_I2C_MODULE, ticks_to_wait); }
447 inline uint8_t Multi_I2CStop(uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
452 inline uint8_t I2CSend(uint8_t val, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
457 inline uint8_t Multi_I2CSend(uint8_t val, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
462 inline uint8_t I2CRead(puint8_t val, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
467 inline uint8_t Multi_I2CRead(puint8_t val, uint32_t ticks_to_wait = I2C_RX_TX_TIMEOUT)
uint8_t MultiChannel_I2CRead(int moduleNum, puint8_t val, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
Read a single byte from the I2C bus.
void MultiChannel_I2CInit(int moduleNum=DEFAULT_I2C_MODULE, uint8_t slave_Addr=0x08, uint8_t freqdiv=0x3C)
Initialize the I2C peripheral module.
uint8_t MultiChannel_I2CStop(int moduleNum=DEFAULT_I2C_MODULE, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
Issue an I2C stop terminate communication with an I2C device and release the bus.
uint8_t MultiChannel_I2CSend(int moduleNum, uint8_t val, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
Send a single byte on the I2C bus.
uint8_t MultiChannel_I2CSendBuf(int moduleNum, uint8_t addr, puint8_t buf, int num, bool stop=true)
Send a buffer of bytes to an I2C device.
void I2CMultiChannelResetPeripheral(int moduleNum)
Reset the specified I2C peripheral module.
uint8_t MultiChannel_I2CReadBuf(int moduleNum, uint8_t addr, puint8_t buf, int num, bool stop=true)
Read a number of bytes from an I2C device and store in the specified buffer.
uint8_t MultiChannel_I2CStart(int moduleNum, uint8_t addr, bool Read_Not_Write, uint32_t ticks_to_wait=I2C_START_TIMEOUT)
Send an I2C start to an I2C device to begin communication.
uint8_t MultiChannel_I2CRestart(int moduleNum, uint8_t addr, bool Read_Not_Write, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
Restart communication with a I2C device.
Counting semaphore for task synchronization and resource management.
Definition nbrtos.h:550