23 #include "si114x_sys_out.h"
24 #include "si114xhrm.h"
27 #include "usb_debug.h"
33 static bool usbDebugEnable;
35 static uint16_t irqSequence = 0;
37 #define IRQ_QUEUE_SIZE 270
39 static u8 IrqQueue[IRQ_QUEUE_SIZE];
41 static u16 irqQueueGetIndex = 0;
43 static u16 irqQueuePutIndex = 0;
46 static s16 Si114x_i2c_smbus_write_byte_data(HANDLE
si114x_handle,
u8 address,
u8 data,
bool block);
47 static s16 Si114x_i2c_smbus_read_byte_data(HANDLE
si114x_handle,
u8 address,
u8 *data,
bool block);
48 static s16 Si114x_i2c_smbus_write_i2c_block_data(HANDLE
si114x_handle,
u8 address,
u8 length,
u8 const* values,
bool block);
49 static s16 Si114x_i2c_smbus_read_i2c_block_data(HANDLE
si114x_handle,
u8 address,
u8 length,
u8* values,
bool block);
55 int si114xSetupDebug(HANDLE
si114x_handle,
void *si114x_debug)
57 int *enable_usb_debug = (
int *)si114x_debug;
59 if(*enable_usb_debug == 1)
60 usbDebugEnable =
true;
61 else if(*enable_usb_debug == 0)
62 usbDebugEnable =
false;
64 return SI114xHRM_SUCCESS;
70 int si114xOutputDebugMessage(HANDLE si114x_handle,
char *message)
74 uint8_t *Message_Buffer[1] = {message_buffer};
76 message_buffer[0] = 0x10;
77 for(i=0; i<strlen(message); i++)
78 message_buffer[i+1] = (uint8_t)message[i];
79 message_buffer[strlen(message)+1] = 0x10;
80 message_buffer[strlen(message)+2] = 0x0D;
82 USBD_Write(CDC_EP_DATA_IN, (
void*) Message_Buffer[0], strlen(message)+3, NULL);
84 return SI114xHRM_SUCCESS;
92 return Si114x_i2c_smbus_write_byte_data(si114x_handle, address, data,
true);
101 Si114x_i2c_smbus_read_byte_data(si114x_handle, address, &data,
true);
109 uint8_t address, uint8_t length, uint8_t *values)
111 return Si114x_i2c_smbus_write_i2c_block_data(si114x_handle,
122 uint8_t address, uint8_t length, uint8_t *values)
124 return Si114x_i2c_smbus_read_i2c_block_data(si114x_handle,
125 address, length, values,
true);
131 void DisableSi114xInterrupt ()
140 void EnableSi114xInterrupt ()
150 s16 Si114xProcessIrq(HANDLE si114x_handle,
u16 timestamp)
156 Si114x_i2c_smbus_read_i2c_block_data(si114x_handle, 0x21, 13, data_buffer,
false);
157 Si114x_i2c_smbus_write_byte_data(si114x_handle, 0x21, data_buffer[0],
false);
162 sample.
irqstat = data_buffer[0];
163 sample.
vis = (((
u16)(data_buffer[2]) << 8) & 0xff00) | data_buffer[1];
164 sample.
ir = (((
u16)(data_buffer[4]) << 8) & 0xff00) | data_buffer[3];
165 sample.
ps1 = (((
u16)(data_buffer[6]) << 8) & 0xff00) | data_buffer[5];
166 sample.
ps2 = (((
u16)(data_buffer[8]) << 8) & 0xff00) | data_buffer[7];
167 sample.
ps3 = (((
u16)(data_buffer[10]) << 8) & 0xff00) | data_buffer[9];
168 sample.
aux = (((
u16)(data_buffer[12]) << 8) & 0xff00) | data_buffer[11];;
170 error = Si114xIrqQueue_Put(&sample);
178 s16 Si114xIrqQueueNumentries(HANDLE si114x_handle)
180 (void) si114x_handle;
181 u16 runnerIndex = irqQueueGetIndex;
183 while (runnerIndex != irqQueuePutIndex)
187 if(runnerIndex == IRQ_QUEUE_SIZE)
199 (void) si114x_handle;
202 int8_t *data = (int8_t *)samples;
203 DisableSi114xInterrupt ();
204 if (irqQueueGetIndex == irqQueuePutIndex)
210 data[i] = IrqQueue[irqQueueGetIndex];
212 if(irqQueueGetIndex == IRQ_QUEUE_SIZE)
213 irqQueueGetIndex = 0;
218 EnableSi114xInterrupt();
220 if (usbDebugEnable == 1)
221 USBDebug_ProcessUSBOutput(data);
222 #endif // si114xHRM_USB_DEBUG
232 u8 *data = (
u8 *)samples;
235 IrqQueue[irqQueuePutIndex] = data[i];
237 if(irqQueuePutIndex == IRQ_QUEUE_SIZE)
238 irqQueuePutIndex = 0;
240 if (irqQueueGetIndex == irqQueuePutIndex)
251 s16 Si114xIrqQueue_Clear(HANDLE si114x_handle)
253 (void) si114x_handle;
254 irqQueueGetIndex = 0;
255 irqQueuePutIndex = 0;
262 s16 Si114xInit(
void *port,
int options, HANDLE *si114x_handle)
269 *si114x_handle = (HANDLE)&_handle;
277 if ((_handle.
i2cAddress == (0x60 << 1)) && (data != 0x46) && (data != 0x47))
279 if ((_handle.
i2cAddress == (0x5A << 1)) && (data != 0x43))
282 Si114xIrqQueue_Clear(*si114x_handle);
290 s16 Si114xClose(HANDLE si114x_handle)
292 (void) si114x_handle;
300 s16 Si114xSysReset(HANDLE si114x_handle)
302 (void) si114x_handle;
328 static s16 Si114x_i2c_smbus_write_byte_data(HANDLE si114x_handle,
u8 address,
u8 data,
bool block)
333 uint8_t i2c_write_data[2];
334 uint8_t i2c_read_data[1];
337 DisableSi114xInterrupt();
341 i2c_write_data[0] = address;
342 i2c_write_data[1] = data;
343 seq.
buf[0].
data = i2c_write_data;
345 seq.
buf[1].
data = i2c_read_data;
353 EnableSi114xInterrupt();
364 static s16 Si114x_i2c_smbus_read_byte_data(HANDLE si114x_handle,
u8 address,
u8 *data,
bool block)
369 uint8_t i2c_write_data[1];
373 DisableSi114xInterrupt ();
377 i2c_write_data[0] = address;
378 seq.
buf[0].
data = i2c_write_data;
389 EnableSi114xInterrupt();
401 static s16 Si114x_i2c_smbus_write_i2c_block_data(HANDLE si114x_handle,
u8 address,
u8 length,
u8 const* data,
bool block)
405 uint8_t i2c_write_data[10];
406 uint8_t i2c_read_data[1];
411 DisableSi114xInterrupt ();
415 i2c_write_data[0] = address;
416 for (i=0; i<length;i++)
418 i2c_write_data[i+1] = data[i];
420 seq.
buf[0].
data = i2c_write_data;
421 seq.
buf[0].
len = 1+length;
422 seq.
buf[1].
data = i2c_read_data;
430 EnableSi114xInterrupt ();
442 static s16 Si114x_i2c_smbus_read_i2c_block_data(HANDLE si114x_handle,
u8 address,
u8 length,
u8* data,
bool block)
446 uint8_t i2c_write_data[1];
452 DisableSi114xInterrupt ();
454 i2c_write_data[0] = address;
455 seq.
buf[0].
data = i2c_write_data;
467 EnableSi114xInterrupt ();
476 int si114xFindEvb(
char *port_description,
char *last_port,
int num_ports_found)
478 (void) port_description;
480 (void) num_ports_found;
void delay_10ms(void)
10ms delay required by Si114x reset sequence.
Si114x Sample Data Structure.
I2C_TransferReturn_TypeDef I2CSPM_Transfer(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
Perform I2C transfer.
Si114x function prototypes, structure and bit definitions.
int16_t Si114xBlockWrite(HANDLE si114x_handle, uint8_t address, uint8_t length, uint8_t *values)
block write to si114x
#define I2C_FLAG_WRITE
Indicate plain write sequence: S+ADDR(W)+DATA0+P.
RTCDRV timer API definition.
I2C_TransferReturn_TypeDef
int16_t Si114xWriteToRegister(HANDLE si114x_handle, uint8_t address, uint8_t data)
Write to Si114x register.
__STATIC_INLINE void GPIO_IntDisable(uint32_t flags)
Disable one or more GPIO interrupts.
__STATIC_INLINE void GPIO_IntEnable(uint32_t flags)
Enable one or more GPIO interrupts.
void delay_1ms(void)
1ms delay required by Si114x polling sequence.
General Purpose IO (GPIO) peripheral API.
I2C simple poll-based master mode driver for the DK/STK.
Ecode_t RTCDRV_Delay(uint32_t ms)
Millisecond delay function.
#define SL_ATTRIBUTE_ALIGN(X)
GCC style macro for aligning a variable.
Implementation specific functions for HRM code.
__STATIC_INLINE void GPIO_IntSet(uint32_t flags)
Set one or more pending GPIO interrupts from SW.
USB protocol stack library API for EFM32/EZR32.
struct I2C_TransferSeq_TypeDef::@0 buf[2]
int16_t Si114xReadFromRegister(HANDLE si114x_handle, uint8_t address)
Read from Si114x register.
Master mode transfer message structure used to define a complete I2C transfer sequence (from start to...
int16_t Si114xBlockRead(HANDLE si114x_handle, uint8_t address, uint8_t length, uint8_t *values)
Block read from Si114x.
int USBD_Write(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a write (IN) transfer on an endpoint.
static void * si114x_handle
Si114x PGM toolkit functions uses a void* to pass hardware parameters through to the lower level i2c ...
#define I2C_FLAG_WRITE_READ
Indicate combined write/read sequence: S+ADDR(W)+DATA0+Sr+ADDR(R)+DATA1+P.
Inter-intergrated circuit (I2C) peripheral API.
__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
uint16_t addr
Address to use after (repeated) start.
GPIO_Port_TypeDef irqPort