static void sensors_callback_accelero(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id) { puts("Callback activated"); } void main(void) { // Initialize chip. bool bhy_init_success = bhy_driver_init(bhy_firmware_image); // Wait for the bhy chip to be in running mode. while(GPIO_read(Board_BHI160B_GPIO)) { } while(!GPIO_read(Board_BHI160B_GPIO)) { } 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; // Install callback. if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_accelerometer)) { puts("Failed to install sensor callback"); } // Enable virtual sensor. if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, 100, 0, VS_FLUSH_NONE, 0, 0)) { puts("Failed to enable sensor); } while (!GPIO_read(Board_BHI160B_GPIO) && !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_DEBUG) { bhy_print_debug_packet(&fifo_packet.data_debug, bhy_printf); } /* 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++); } } }