123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include "mlx90614.h"
- #include "smbus.h"
- #include "hi_time.h"
- void SMBus_Start(void)
- {
- SMBUS_SDA_H();
- hi_udelay(5);
- SMBUS_SCL_H();
- hi_udelay(5);
- SMBUS_SDA_L();
- hi_udelay(5);
- SMBUS_SCL_L();
- hi_udelay(5);
- }
- void SMBus_Stop(void)
- {
- SMBUS_SCL_L();
- hi_udelay(5);
- SMBUS_SDA_L();
- hi_udelay(5);
- SMBUS_SCL_H();
- hi_udelay(5);
- SMBUS_SDA_H();
- }
- void SMBus_SendBit(uint8_t bit_out)
- {
- if(bit_out==0)
- {
- SMBUS_SDA_L();
- }
- else
- {
- SMBUS_SDA_H();
- }
- hi_udelay(2);
- SMBUS_SCL_H();
- hi_udelay(6);
- SMBUS_SCL_L();
- hi_udelay(3);
- return;
- }
- static uint8_t SMBUS_SDA_READ(void)
- {
- IotGpioValue temp = {0};
- IoTGpioGetInputVal(WIFI_IOT_IO_NAME_GPIO_12,&temp);
- return temp;
- }
- uint8_t SMBus_ReceiveBit(void)
- {
- uint8_t Ack_bit;
- SMBUS_SDA_H();
- hi_udelay(2);
- SMBUS_SCL_H();
- hi_udelay(5);
- if (SMBUS_SDA_READ())
- {
- Ack_bit=1;
- }
- else
- {
- Ack_bit=0;
- }
- SMBUS_SCL_L();
- hi_udelay(3);
- return Ack_bit;
- }
- uint8_t SMBus_SendByte(uint8_t Tx_buffer)
- {
- uint8_t Bit_counter;
- uint8_t Ack_bit;
- uint8_t bit_out;
- for(Bit_counter=8; Bit_counter; Bit_counter--)
- {
- if (Tx_buffer&0x80)
- {
- bit_out=1;
- }
- else
- {
- bit_out=0;
- }
- SMBus_SendBit(bit_out);
- Tx_buffer<<=1;
- }
- Ack_bit=SMBus_ReceiveBit();
- return Ack_bit;
- }
- uint8_t SMBus_ReceiveByte(uint8_t ack_nack)
- {
- uint8_t RX_buffer;
- uint8_t Bit_Counter;
- for(Bit_Counter=8; Bit_Counter; Bit_Counter--)
- {
- if(SMBus_ReceiveBit())
- {
- RX_buffer <<= 1;
- RX_buffer |=0x01;
- }
- else
- {
- RX_buffer <<= 1;
- RX_buffer &=0xfe;
- }
- }
- SMBus_SendBit(ack_nack);
- return RX_buffer;
- }
|