475 #if defined(HAS_SERPORT_I2C)
484 #define I2C_BAUD_62K 255
488 #ifndef I2C_BAUD_100K
489 #define I2C_BAUD_100K 157
493 #ifndef I2C_BAUD_200K
494 #define I2C_BAUD_200K 77
498 #ifndef I2C_BAUD_300K
499 #define I2C_BAUD_300K 51
503 #ifndef I2C_BAUD_400K
504 #define I2C_BAUD_400K 37
508 #ifndef I2C_BAUD_506K
509 #define I2C_BAUD_506K 24
513 #ifndef I2C_BAUD_600K
514 #define I2C_BAUD_600K 24
518 #ifndef I2C_BAUD_708K
519 #define I2C_BAUD_708K 20
523 #ifndef I2C_BAUD_909K
524 #define I2C_BAUD_909K 15
528 #ifndef I2C_BAUD_970K
529 #define I2C_BAUD_970K 12
534 #define I2C_BAUD_1M 13
537 #ifndef I2C_ALWAYS_ADD_WHOLE_MESSAGE
538 #define I2C_ALWAYS_ADD_WHOLE_MESSAGE 0
540 #ifndef I2C2_ALWAYS_ADD_WHOLE_MESSAGE
541 #define I2C2_ALWAYS_ADD_WHOLE_MESSAGE 0
543 #ifndef I2C3_ALWAYS_ADD_WHOLE_MESSAGE
544 #define I2C3_ALWAYS_ADD_WHOLE_MESSAGE 0
548 #if !defined(I2C1_RXBUF_SIZE)
549 #define I2C1_RXBUF_SIZE 64
551 #if !defined(I2C1_TXBUF_SIZE)
552 #define I2C1_TXBUF_SIZE 256
554 #if !defined(I2C2_RXBUF_SIZE)
555 #define I2C2_RXBUF_SIZE 32
557 #if !defined(I2C2_TXBUF_SIZE)
558 #define I2C2_TXBUF_SIZE 128
560 #if !defined(I2C3_RXBUF_SIZE)
561 #define I2C3_RXBUF_SIZE 32
563 #if !defined(I2C3_TXBUF_SIZE)
564 #define I2C3_TXBUF_SIZE 128
571 #define I2C_TXION_STATUS_OK 0 //Currently OK, have not finished adding whole message to buffer
572 #define I2C_TXION_STATUS_ADDED_TO_BUF 1 //Successfully added whole message to the buffer (from start to stop)
573 #define I2C_TXION_STATUS_ERROR 4 //No space in buffer to add message
574 #define I2C_TXION_STATUS_ERR_NOSPACE 5 //No space in buffer to add message
575 #define I2C_TXION_STATUS_ERR_ADR_NOACK 6 //Slave did not ACK address we sent
576 #define I2C_TXION_STATUS_ERR_DAT_NOACK 7 //Slave did not ACK data we sent
577 #define I2C_TXION_STATUS_ERR_BUF_FRMT 8 //Buffer format error
578 #define I2C_TXION_STATUS_ERR_TIMEOUT 9 //Timeout
579 #define I2C_TXION_STATUS_NOT_AVAILABLE 0xFF //Status not available
582 #if (defined(HAS_SERPORT_I2C1) || defined(HAS_SERPORT_I2C2) || defined(HAS_SERPORT_I2C3))
583 #if !defined(HAS_A_SERPORT)
584 #define HAS_A_SERPORT
592 #if defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
593 #if defined(HAS_SERPORT_I2C1)
595 #if ((I2C1_TXBUF_SIZE & ~(I2C1_TXBUF_SIZE-1))!=I2C1_TXBUF_SIZE)
596 #error "I2C1 I2C1_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
600 #if ((I2C1_RXBUF_SIZE & ~(I2C1_RXBUF_SIZE-1))!=I2C1_RXBUF_SIZE)
601 #error "I2C1 I2C1_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
604 #if defined(HAS_SERPORT_I2C2)
606 #if ((I2C2_TXBUF_SIZE & ~(I2C2_TXBUF_SIZE-1))!=I2C2_TXBUF_SIZE)
607 #error "I2C2 I2C2_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
611 #if ((I2C2_RXBUF_SIZE & ~(I2C2_RXBUF_SIZE-1))!=I2C2_RXBUF_SIZE)
612 #error "I2C2 I2C2_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
615 #if defined(HAS_SERPORT_I2C3)
617 #if ((I2C3_TXBUF_SIZE & ~(I2C3_TXBUF_SIZE-1))!=I2C3_TXBUF_SIZE)
618 #error "I2C3 I2C3_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
622 #if ((I2C3_RXBUF_SIZE & ~(I2C3_RXBUF_SIZE-1))!=I2C3_RXBUF_SIZE)
623 #error "I2C3 I2C3_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
633 typedef struct __attribute__((aligned(2), packed))
638 unsigned int bFill : 16;
671 } SERPORT_I2C_CONFIG;
674 #define RD_DEST_TYPE_LISTENERS 0
675 #define RD_DEST_TYPE_POINTER 2
676 #define RD_DEST_TYPE_CIRBUF 3
678 typedef struct __attribute__((__packed__)) I2C_ISR_SMFLAGS_
684 unsigned int sAddress : 1;
686 unsigned int wrDstType : 2;
687 unsigned int isrTxionStatus: 4;
688 unsigned int fill12 : 4;
692 unsigned int fill0to5 : 6;
693 unsigned int bit0 : 1;
694 unsigned int bit1 : 1;
695 unsigned int fill8to15 : 8;
702 #define I2C_STATUS_BUF_SIZE 8
704 typedef struct I2C_INFO_
709 BYTE bufStat[I2C_STATUS_BUF_SIZE];
729 BYTE currTxionStatus;
747 void serI2CInit(
void);
754 void serI2CTask(I2C_INFO* objI2C);
770 BYTE serI2CRegisterListener(
CIRBUF* pBuf);
782 I2C_INFO* i2cGetInfoForBus(BYTE i2cBus);
816 BYTE i2cGetStatus(I2C_INFO* objI2C, BYTE adr);
850 BYTE i2cGetStatusWait(I2C_INFO* objI2C, BYTE adr);
862 BYTE i2cIsBusy(I2C_INFO* objI2C);
886 BYTE i2cWriteMessage(I2C_INFO* objI2C, BYTE adr, BYTE* msg, WORD size);
906 BYTE i2cBeginTransmission(I2C_INFO* objI2C, BYTE adr);
927 BYTE i2cEndTransmission(I2C_INFO* objI2C);
938 BYTE i2cWrite(I2C_INFO* objI2C, BYTE b);
951 BYTE i2cWriteArray(I2C_INFO* objI2C, BYTE* arr, BYTE size);
964 BYTE i2cWriteString(I2C_INFO* objI2C,
const char* str);
983 BYTE i2cWriteAsciiEscString(I2C_INFO* objI2C,
const char* str);
999 BYTE i2cRead(I2C_INFO* objI2C, BYTE size);
1013 BYTE i2cReadToArray(I2C_INFO* objI2C, BYTE* buf, BYTE size);
1055 BYTE i2cReadSlaveReg(I2C_INFO* objI2C, BYTE adr, BYTE reg, BYTE* buf, BYTE size);
1069 #define i2cGetByte(objI2C) cbufGetByte(objI2C->pCbufRx)
1087 #define i2cGetArray(objI2C, pDstArr, size) cbufGetArray(objI2C->pCbufRx, pDstArr, size)
1092 #if defined(HAS_SERPORT_I2C1)
1094 #if !defined(SERPORT_I2C1_CREATE_OWN_CIRBUFS)
1099 #define SERPORT_I2C1_MODE_ASCII 0
1102 #ifndef THIS_IS_NZ_SERI2C1_C
1103 extern I2C_INFO i2c1Info;
1105 #define I2C1_INFO &i2c1Info
1109 #if defined(SERPORT_I2C1_CREATE_OWN_CIRBUFS)
1111 #ifndef THIS_IS_NZ_SERI2C1_C
1112 extern CIRBUF cbufTxI2C1;
1113 extern CIRBUF cbufRxI2C1;
1116 #define CIRBUF_TX_I2C1 &cbufTxI2C1
1117 #define CIRBUF_RX_I2C1 &cbufRxI2C1
1124 void serI2C1Init(
void);
1160 BYTE i2c1GetStatus(BYTE adr);
1208 BYTE i2c1GetStatusWait(BYTE adr);
1227 BYTE i2c1IsBusy(
void);
1232 #define i2c1GetTxionCnt() (i2c1Info.isrCnt)
1237 #define i2c1GetTxionAddress() (i2c1Info.adr)
1268 BYTE i2c1WriteMessage(BYTE adr, BYTE* msg, WORD size);
1313 BYTE i2c1BeginTransmission(BYTE adr);
1358 BYTE i2c1EndTransmission(
void);
1368 BYTE i2c1Write(BYTE b);
1379 BYTE i2c1WriteArray(BYTE* arr, BYTE size);
1390 BYTE i2c1WriteString(
const char* str);
1407 BYTE i2c1WriteAsciiEscString(
const char* str);
1435 BYTE i2c1Read(BYTE size);
1461 BYTE i2c1ReadToArray(BYTE* buf, BYTE size);
1501 BYTE i2c1ReadSlaveReg(BYTE adr, BYTE reg, BYTE* buf, BYTE size);
1518 #define i2c1GetTxBufFree() cbufGetFree(CIRBUF_TX_I2C1)
1524 #define i2c1EmptyTxBuf() cbufEmpty(CIRBUF_TX_I2C1)
1532 #define i2c1IsTxBufEmpty() cbufIsEmpty(CIRBUF_TX_I2C1)
1540 #define i2c1IsTxBufFull() cbufIsFull(CIRBUF_TX_I2C1)
1550 #define i2c1GetRxBufCount() cbufGetCount(CIRBUF_RX_I2C1)
1559 #define i2c1HasData() cbufHasData(CIRBUF_RX_I2C1)
1568 #define i2c1IsRxBufEmpty() cbufIsEmpty(CIRBUF_RX_I2C1)
1580 #define i2c1GetByte() cbufGetByte(CIRBUF_RX_I2C1)
1593 #define i2c1GetArray(pDstArr, size) cbufGetArray(CIRBUF_RX_I2C1, pDstArr, size)
1595 #endif //#if defined(HAS_SERPORT_I2C1)
1597 #endif //#if defined(HAS_SERPORT_I2C)
1598 #endif //#ifndef NZ_SERI2C_H