Thanks BSTRobin I tried the following, but with no success. No rtt prints. static void sensors_callback_acc(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
uint16_t i = 0;
switch(sensor_id)
{
case VS_ID_ACCELEROMETER:
case VS_ID_ACCELEROMETER_WAKEUP:
PDEBUG("acc,%d,%d,%d\r\n", sensor_data->data_vector.x, sensor_data->data_vector.y, sensor_data->data_vector.z);
break;
default:
PDEBUG("unknown id = %d\n", sensor_id);
break;
}
}
void demo_sensor(void)
{
int8_t ret;
/* BHY Variable*/
uint8_t *fifoptr = NULL;
uint8_t bytes_left_in_fifo = 0;
uint16_t bytes_remaining = 0;
uint16_t bytes_read = 0;
bhy_data_generic_t fifo_packet;
bhy_data_type_t packet_type;
BHY_RETURN_FUNCTION_TYPE result;
/* To get the customized version number in firmware, it is necessary to read Parameter Page 2, index 125 */
/* to get this information. This feature is only supported for customized firmware. To get this customized */
/* firmware, you need to contact your local FAE of Bosch Sensortec. */
//struct cus_version_t bhy_cus_version;
// BHY_RETURN_FUNCTION_TYPE com_rslt = BHY_COMM_RES;
// uint8_t data[1] = {1};
// com_rslt = bhy_write_reg(BHY_I2C_REG_RESET_REQUEST_ADDR, data, sizeof(data));
// while (!bhi160b_get_int_status());
// osDelay(100);
/* init the bhy chip */
if(bhy_driver_init(bhy1_fw))
{
PDEBUG("Fail to init bhy\n");
}
/* wait for the bhy trigger the interrupt pin go down and up again */
while(bhi160b_get_int_status());
while(!bhi160b_get_int_status());
/* install the callback function for parse fifo data */
if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_acc)) {
PDEBUG("Fail to install sensor callback\r\n");
}
if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, 100, 0, VS_FLUSH_NONE, 0, 0)) {
PDEBUG("Fail to enable sensor id=%d\n", VS_TYPE_ACCELEROMETER);
}
while(1)
{
osDelay(1);
/* wait until the interrupt fires */
/* unless we already know there are bytes remaining in the fifo */
while (!bhi160b_get_int_status() && !bytes_remaining);
bhy_read_fifo(fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
bytes_read += bytes_left_in_fifo;
fifoptr = fifo;
packet_type = BHY_DATA_TYPE_PADDING;
do
{
/* this function will call callbacks that are registered */
result = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type);
/* prints all the debug packets */
if (packet_type == BHY_DATA_TYPE_PADDING)
{
/* padding data only added at the end of each FIFO dump, discard it. */
PDEBUG(">Padding\n");
}
else if (packet_type == BHY_DATA_TYPE_DEBUG)
{
PDEBUG(">DebugString :");
bhy_print_debug_packet(&fifo_packet.data_debug, bhy_printf);
PDEBUG("\n");
}
/* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
/* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
/* packet */
} while ((result == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? MAX_PACKET_LENGTH : 0)));
bytes_left_in_fifo = 0;
if (bytes_remaining)
{
/* shifts the remaining bytes to the beginning of the buffer */
while (bytes_left_in_fifo < bytes_read)
{
fifo[bytes_left_in_fifo++] = *(fifoptr++);
}
}
}
}
... View more