diff --git a/arduino_libraries/.DS_Store b/arduino_libraries/.DS_Store new file mode 100644 index 0000000..b0af650 Binary files /dev/null and b/arduino_libraries/.DS_Store differ diff --git a/arduino_libraries/BNO055-master/BNO055.c b/arduino_libraries/BNO055-master/BNO055.c new file mode 100644 index 0000000..8b79992 --- /dev/null +++ b/arduino_libraries/BNO055-master/BNO055.c @@ -0,0 +1,16137 @@ +/* + *************************************************************************** + * + * bno055.c - part of sample SW for using BNO055 with Arduino + * + * Usage: BNO055 Sensor Driver Source File + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + + +/****************************************************************************/ +/*! file + brief */ +#include "BNO055.h" + +/* user defined code to be added here ... */ +static struct bno055_t *p_bno055; +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/***************************************************************************** + * Description: *//**\brief + * This function initialises the structure pointer + * and assigns the I2C address. + * + * + * + * + * + * \param bno055_t *bno055 structure pointer. + * + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_init(struct bno055_t *bno055) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + unsigned char a_SWID_u8r[2] = {0, 0}; + + p_bno055 = bno055; + p_bno055->dev_addr = BNO055_I2C_ADDR; + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CHIP_ID__REG, &a_data_u8r, 1); + p_bno055->chip_id = a_data_u8r; + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_REV_ID__REG, &a_data_u8r, 1); + p_bno055->accel_revision_id = a_data_u8r; + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_REV_ID__REG, &a_data_u8r, 1); + p_bno055->mag_revision_id = a_data_u8r; + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_REV_ID__REG, &a_data_u8r, 1); + p_bno055->gyro_revision_id = a_data_u8r; + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_BL_Rev_ID__REG, &a_data_u8r, 1); + p_bno055->bootloader_revision_id = a_data_u8r; + + comres = p_bno055->BNO055_BUS_READ_FUNC(p_bno055->dev_addr, + BNO055_SW_REV_ID_LSB__REG, a_SWID_u8r, 2); + a_SWID_u8r[0] = BNO055_GET_BITSLICE(a_SWID_u8r[0], + BNO055_SW_REV_ID_LSB); + p_bno055->sw_revision_id = (BNO055_U16) + ((((BNO055_U16)((signed char)a_SWID_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_SWID_u8r[0])); + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_Page_ID__REG, &a_data_u8r, 1); + p_bno055->page_id = a_data_u8r; + + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API gives data to the given register and + * the data is written in the corresponding register address + * + * + * + * + * \param unsigned char addr, unsigned char data, unsigned char len + * addr -> Address of the register + * data -> Data to be written to the register + * len -> Length of the Data + * + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_register(unsigned char addr, +unsigned char *data, unsigned char len) { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, addr, data, len); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads the data from + * the given register address + * + * + * + * + * \param unsigned char addr, unsigned char *data, unsigned char len + * addr -> Address of the register + * data -> address of the variable, read value will be kept + * len -> Length of the data + * + * + * + * + * \return results of communication routine + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_register(unsigned char addr, +unsigned char *data, unsigned char len) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, addr, data, len); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads chip id + * from location 00h + * + * + * + * + * \param unsigned char *chip_id : Pointer holding the chip id + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_chip_id(unsigned char *chip_id) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CHIP_ID__REG, &a_data_u8r, 1); + *chip_id = a_data_u8r; + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads software revision id + * from location 04h and 05h + * + * + * + * + * \param BNO055_U16 *sw_id : Pointer holding the SW revision id + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sw_revision_id(BNO055_U16 *sw_id) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SW_REV_ID_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SW_REV_ID_LSB); + *sw_id = (BNO055_U16) + ((((BNO055_U16)((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads page id + * from location 07h + * + * + * + * + * \param unsigned char *page_id : Pointer holding the page id + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_page_id(unsigned char *pg_id) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_Page_ID__REG, &a_data_u8r, 1); + *pg_id = a_data_u8r; + p_bno055->page_id = a_data_u8r; + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API writes the page id register 07h + * + * + * + * + * + * \param unsigned char page_id + * PAGE_ZERO -> 0X00 + * PAGE_ONE -> 0X01 + * + * \return Communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_page_id(unsigned char page_id) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char pg_id = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_Page_ID__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_Page_ID, page_id); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_Page_ID__REG, &v_data_u8r, 1); + bno055_read_page_id(&pg_id); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads accel revision id + * from location 01h + * + * + * + * + * \param unsigned char *acc_rev_id : Pointer holding the accel revision id + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_revision_id( +unsigned char *acc_rev_id) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_REV_ID__REG, &a_data_u8r, 1); + *acc_rev_id = a_data_u8r; + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads mag revision id + * from location 02h + * + * + * + * + * \param unsigned char *mag_rev_id : Pointer holding the mag revision id + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_revision_id( +unsigned char *mag_rev_id) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_REV_ID__REG, &a_data_u8r, 1); + *mag_rev_id = a_data_u8r; + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads gyro revision id + * from location 03h + * + * + * + * + * \param unsigned char *gyr_rev_id : Pointer holding the gyro revision id + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_revision_id( +unsigned char *gyr_rev_id) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_REV_ID__REG, &a_data_u8r, 1); + *gyr_rev_id = a_data_u8r; + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads boot loader revision id + * from location 06h + * + * + * + * + * \param unsigned char *bl_rev_id : Pointer holding + * the boot loader revision id + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_bootloader_revision_id( +unsigned char *bl_rev_id) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_BL_Rev_ID__REG, &a_data_u8r, 1); + *bl_rev_id = a_data_u8r; + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads acceleration data X values + * from location 08h and 0dh + * + * + * + * + * \param BNO055_S16 *acc_x : Pointer holding the X-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_x(BNO055_S16 *acc_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_DATA_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_DATA_X_MSB_VALUEX); + *acc_x = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads acceleration data Y values + * from location 08h and 0dh + * + * + * + * + * \param BNO055_S16 *acc_y : Pointer holding the Y-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_y(BNO055_S16 *acc_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_DATA_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_DATA_Y_LSB_VALUEY); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_DATA_Y_MSB_VALUEY); + *acc_y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads acceleration data Z values + * from location 08h and 0dh + * + * + * + * + * \param BNO055_S16 *acc_z : Pointer holding the Z-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_z(BNO055_S16 *acc_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_DATA_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_DATA_Z_LSB_VALUEZ); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_DATA_Z_MSB_VALUEZ); + *acc_z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data X,Y,Z of accelerometer + * from location 08h to 0Dh + * + * + * + * + * \param + * bno055_accel *acc : Pointer holding the bno055_accel + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_xyz(struct bno055_accel *acc) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[7] = {0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_DATA_X_LSB_VALUEX__REG, a_data_u8r, 7); + /* Data X*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_DATA_X_MSB_VALUEX); + acc->x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data Y*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_ACC_DATA_Y_LSB_VALUEY); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_ACC_DATA_Y_MSB_VALUEY); + acc->y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Z*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_ACC_DATA_Z_LSB_VALUEZ); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_ACC_DATA_Z_MSB_VALUEZ); + acc->z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + } else { + return ERROR1; + } + } + return comres; +} + /***************************************************************************** + * Description: *//**\brief This API reads magnetometer data X values + * from location 0Eh and 0Fh + * + * + * + * + * \param BNO055_S16 *mag_x : Pointer holding the X-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_x(BNO055_S16 *mag_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_DATA_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_DATA_X_MSB_VALUEX); + *mag_x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads magnetometer data Y values + * from location 10h and 11h + * + * + * + * + * \param BNO055_S16 *mag_y : Pointer holding the Y-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_y(BNO055_S16 *mag_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_DATA_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_DATA_Y_LSB_VALUEY); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_DATA_Y_MSB_VALUEY); + *mag_y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads magnetometer data Z values + * from location 12h and 13h + * + * + * + * + * \param BNO055_S16 *mag_z : Pointer holding the Z-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_z(BNO055_S16 *mag_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_DATA_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_DATA_Z_LSB_VALUEZ); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_DATA_Z_MSB_VALUEZ); + *mag_z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data X,Y,Z of magnetometer + * from location 0Eh to 13h + * + * + * + * + * \param + * bno055_mag *mag : Pointer holding the bno055_mag + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_xyz(struct bno055_mag *mag) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[7] = {0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_DATA_X_LSB_VALUEX__REG, a_data_u8r, 7); + /* Data X*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_DATA_X_MSB_VALUEX); + mag->x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data Y*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_MAG_DATA_Y_LSB_VALUEY); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_MAG_DATA_Y_MSB_VALUEY); + mag->y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Z*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_MAG_DATA_Z_LSB_VALUEZ); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_MAG_DATA_Z_MSB_VALUEZ); + mag->z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + } else { + return ERROR1; + } + } + return comres; +} + /***************************************************************************** + * Description: *//**\brief This API reads gyroscope data X values + * from location 14h and 15h + * + * + * + * + * \param BNO055_S16 *gyr_x : Pointer holding the X-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_x(BNO055_S16 *gyr_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_DATA_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_DATA_X_MSB_VALUEX); + *gyr_x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads gyroscope data Y values + * from location 16h and 17h + * + * + * + * + * \param BNO055_S16 *gyr_y : Pointer holding the Y-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_y(BNO055_S16 *gyr_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_DATA_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_DATA_Y_LSB_VALUEY); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_DATA_Y_MSB_VALUEY); + *gyr_y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads gyroscope data Z values + * from location 18h and 19h + * + * + * + * + * \param short *gyr_z : Pointer holding the Z-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_z(BNO055_S16 *gyr_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_DATA_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_DATA_Z_LSB_VALUEZ); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_DATA_Z_MSB_VALUEZ); + *gyr_z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data X,Y,Z of gyroscope + * from location 14h to 19h + * + * + * + * + * \param + * bno055_gyro *gyr : Pointer holding the bno055_gyro + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_xyz(struct bno055_gyro *gyr) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[7] = {0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_DATA_X_LSB_VALUEX__REG, a_data_u8r, 7); + /* Data X*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_DATA_X_MSB_VALUEX); + gyr->x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data Y*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_GYR_DATA_Y_LSB_VALUEY); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_GYR_DATA_Y_MSB_VALUEY); + gyr->y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Z*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_GYR_DATA_Z_LSB_VALUEZ); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_GYR_DATA_Z_MSB_VALUEZ); + gyr->z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads Euler data H values + * from location 1Ah and 1Bh + * + * + * + * + * \param BNO055_S16 *eul_h : Pointer holding the H-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_h(BNO055_S16 *eul_h) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_EUL_HEADING_LSB_VALUEH__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE + (a_data_u8r[0], + BNO055_EUL_HEADING_LSB_VALUEH); + a_data_u8r[1] = BNO055_GET_BITSLICE + (a_data_u8r[1], + BNO055_EUL_HEADING_MSB_VALUEH); + *eul_h = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads Euler data R values + * from location 1Ch and 1Dh + * + * + * + * + * \param BNO055_S16 *eul_r : Pointer holding the R-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_r(BNO055_S16 *eul_r) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_EUL_ROLL_LSB_VALUER__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_EUL_ROLL_LSB_VALUER); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_EUL_ROLL_MSB_VALUER); + *eul_r = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Euler data P values + * from location 1Eh and 1Fh + * + * + * + * + * \param BNO055_S16 *eul_p : Pointer holding the P-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_p(BNO055_S16 *eul_p) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_EUL_PITCH_LSB_VALUEP__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_EUL_PITCH_LSB_VALUEP); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_EUL_PITCH_MSB_VALUEP); + *eul_p = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data H,R,P of Euler + * from location 1Ah to 1Fh + * + * + * + * + * \param + * bno055_euler *eul : Pointer holding the bno055_euler + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_hrp(struct bno055_euler *eul) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[7] = {0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_EUL_HEADING_LSB_VALUEH__REG, a_data_u8r, 7); + /* Data H*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_EUL_HEADING_LSB_VALUEH); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_EUL_HEADING_MSB_VALUEH); + eul->h = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data R*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_EUL_ROLL_LSB_VALUER); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_EUL_ROLL_MSB_VALUER); + eul->r = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data P*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_EUL_PITCH_LSB_VALUEP); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_EUL_PITCH_MSB_VALUEP); + eul->p = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + } else { + return ERROR1; + } + } + return comres; +} + /***************************************************************************** + * Description: *//**\brief This API reads quaternion data W values + * from location 20h and 21h + * + * + * + * + * \param BNO055_S16 *quan_w : Pointer holding the W-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_w(BNO055_S16 *quan_w) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_QUA_DATA_W_LSB_VALUEW__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_QUA_DATA_W_LSB_VALUEW); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_QUA_DATA_W_MSB_VALUEW); + *quan_w = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} + /***************************************************************************** + * Description: *//**\brief This API reads quaternion data X values + * from location 22h and 23h + * + * + * + * + * \param BNO055_S16 *quan_x : Pointer holding the X-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_x(BNO055_S16 *quan_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_QUA_DATA_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_QUA_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_QUA_DATA_X_MSB_VALUEX); + *quan_x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads quaternion data Y values + * from location 24h and 25h + * + * + * + * + * \param BNO055_S16 *quan_y : Pointer holding the Y-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_y(BNO055_S16 *quan_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_QUA_DATA_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE + (a_data_u8r[0], + BNO055_QUA_DATA_Y_LSB_VALUEY); + a_data_u8r[1] = BNO055_GET_BITSLICE + (a_data_u8r[1], + BNO055_QUA_DATA_Y_MSB_VALUEY); + *quan_y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads quaternion data Z values + * from location 26h and 27h + * + * + * + * + * \param BNO055_S16 *quan_z : Pointer holding the Z-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_z(BNO055_S16 *quan_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_QUA_DATA_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_QUA_DATA_Z_LSB_VALUEZ); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_QUA_DATA_Z_MSB_VALUEZ); + *quan_z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data W,X,Y,Z of quaternion + * from location 20h to 27h + * + * + * + * + * \param + * bno055_quaternion *qur : Pointer holding the bno055_quaternion + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_wxyz( +struct bno055_quaternion *qur) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_QUA_DATA_W_LSB_VALUEW__REG, a_data_u8r, 7); + /* Data W*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_QUA_DATA_W_LSB_VALUEW); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_QUA_DATA_W_MSB_VALUEW); + qur->w = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data X*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_QUA_DATA_X_LSB_VALUEX); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_QUA_DATA_X_MSB_VALUEX); + qur->x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Y*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_QUA_DATA_Y_LSB_VALUEY); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_QUA_DATA_Y_MSB_VALUEY); + qur->y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + /* Data Z*/ + a_data_u8r[6] = BNO055_GET_BITSLICE(a_data_u8r[6], + BNO055_QUA_DATA_Z_LSB_VALUEZ); + a_data_u8r[7] = BNO055_GET_BITSLICE(a_data_u8r[7], + BNO055_QUA_DATA_Z_MSB_VALUEZ); + qur->z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[7])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[6])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads linear acceleration data X values + * from location 28h and 29h + * + * + * + * + * \param BNO055_S16 *lia_x : Pointer holding the X-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_x(BNO055_S16 *lia_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_LIA_DATA_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_LIA_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_LIA_DATA_X_MSB_VALUEX); + *lia_x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads linear acceleration data Y values + * from location 2Ah and 2Bh + * + * + * + * + * \param BNO055_S16 *lia_y : Pointer holding the Y-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_y(BNO055_S16 *lia_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_LIA_DATA_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_LIA_DATA_Y_LSB_VALUEY); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_LIA_DATA_Y_MSB_VALUEY); + *lia_y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads linear acceleration data Z values + * from location 2Ch and 2Dh + * + * + * + * + * \param BNO055_S16 *lia_z : Pointer holding the Z-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_z(BNO055_S16 *lia_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_LIA_DATA_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_LIA_DATA_Z_LSB_VALUEZ); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_LIA_DATA_Z_MSB_VALUEZ); + *lia_z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data X,Y,Z of linear acceleration + * from location 28h to 2Dh + * + * + * + * + * \param + * bno055_linear_accel *lia : Pointer holding the bno055_linear_accel + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_xyz( +struct bno055_linear_accel *lia) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[7] = {0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_LIA_DATA_X_LSB_VALUEX__REG, a_data_u8r, 7); + /* Data X*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_LIA_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_LIA_DATA_X_MSB_VALUEX); + lia->x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data Y*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_LIA_DATA_Y_LSB_VALUEY); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_LIA_DATA_Y_MSB_VALUEY); + lia->y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Z*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_LIA_DATA_Z_LSB_VALUEZ); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_LIA_DATA_Z_MSB_VALUEZ); + lia->z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads gravity data X values + * from location 2Eh and 2Fh + * + * + * + * + * \param BNO055_S16 *grv_x : Pointer holding the X-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_x(BNO055_S16 *grv_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GRV_DATA_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GRV_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GRV_DATA_X_MSB_VALUEX); + *grv_x = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API reads gravity data Y values + * from location 30h and 31h + * + * + * + * + * \param BNO055_S16 *grv_y : Pointer holding the Y-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_y(BNO055_S16 *grv_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GRV_DATA_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GRV_DATA_Y_LSB_VALUEY); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GRV_DATA_Y_MSB_VALUEY); + *grv_y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads gravity data Z values + * from location 32h and 33h + * + * + * + * + * \param BNO055_S16 *grv_z : Pointer holding the Z-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_z(BNO055_S16 *grv_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GRV_DATA_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GRV_DATA_Z_LSB_VALUEZ); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GRV_DATA_Z_MSB_VALUEZ); + *grv_z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[1])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/**************************************************************************** + * Description: *//**\brief Reads data X,Y,Z of gravity + * from location 2Eh to 33h + * + * + * + * + * \param + * bno055_linear_accel *grvt : Pointer holding the bno055_linear_accel + * + * + * \return + * result of communication routines + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_xyz( +struct bno055_gravity *grvt) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[7] = {0, 0, 0, 0, 0, 0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GRV_DATA_X_LSB_VALUEX__REG, a_data_u8r, 7); + /* Data X*/ + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GRV_DATA_X_LSB_VALUEX); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GRV_DATA_X_MSB_VALUEX); + grvt->x = (BNO055_S16)(((BNO055_S16) + ((signed char)a_data_u8r[1]) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data Y*/ + a_data_u8r[2] = BNO055_GET_BITSLICE(a_data_u8r[2], + BNO055_GRV_DATA_Y_LSB_VALUEY); + a_data_u8r[3] = BNO055_GET_BITSLICE(a_data_u8r[3], + BNO055_GRV_DATA_Y_MSB_VALUEY); + grvt->y = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[3])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Z*/ + a_data_u8r[4] = BNO055_GET_BITSLICE(a_data_u8r[4], + BNO055_GRV_DATA_Z_LSB_VALUEZ); + a_data_u8r[5] = BNO055_GET_BITSLICE(a_data_u8r[5], + BNO055_GRV_DATA_Z_MSB_VALUEZ); + grvt->z = (BNO055_S16)((((BNO055_S16) + ((signed char)a_data_u8r[5])) << + BNO055_SHIFT_8_POSITION) | (a_data_u8r[4])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads temperature data + * from location 34h + * + * + * + * + * \param BNO055_S16 *temp : Pointer holding the temperature-DATA + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_temperature_data(BNO055_S16 *temp) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TEMP__REG, &a_data_u8r, 1); + *temp = a_data_u8r; + } else { + return ERROR1; + + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads mag calibration status register byte from 35h + * + * + * + * + * \param + * unsigned char *mag_calib : Pointer holding the mag_calib status register + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_magcalib_status( +unsigned char *mag_calib) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_CALIB_STAT__REG, &v_data_u8r, 1); + *mag_calib = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_MAG_CALIB_STAT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel calibration status register byte from 35h + * + * + * + * + * \param + * unsigned char *acc_calib : Pointer holding + * the accel_calib status register + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accelcalib_status( +unsigned char *acc_calib) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_CALIB_STAT__REG, &v_data_u8r, 1); + *acc_calib = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ACC_CALIB_STAT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro calibration status register byte from 35h + * + * + * + * + * \param + * unsigned char *gyr_calib : Pointer holding + * the gyro_calib status register + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyrocalib_status( +unsigned char *gyr_calib) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_CALIB_STAT__REG, &v_data_u8r, 1); + *gyr_calib = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_CALIB_STAT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/************************************************************************** + * Description: *//**\brief Reads system calibration status + * register byte from 35h + * + * + * + * \param + * unsigned char *sys_calib : Pointer holding the sys_calib + * status register + * + * \return + * Result of bus communication function + * + **************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_syscalib_status( +unsigned char *sys_calib) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SYS_CALIB_STAT__REG, &v_data_u8r, 1); + *sys_calib = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_SYS_CALIB_STAT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads ST result of + * accelerometer register byte from 36h + * + * + * + * + * \param + * unsigned char *st_acc : Pointer holding the + * ST result of accelerometer + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_st_accel( +unsigned char *st_acc) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ST_ACC__REG, &v_data_u8r, 1); + *st_acc = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ST_ACC); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads ST result of + * magnetometer register byte from 36h + * + * + * + * + * \param + * unsigned char *st_mag : Pointer holding the + * ST result of magnetometer + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_st_mag( +unsigned char *st_mag) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ST_MAG__REG, &v_data_u8r, 1); + *st_mag = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ST_MAG); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads ST result of + * gyroscope register byte from 36h + * + * + * + * + * \param + * unsigned char *st_gyr : Pointer holding the + * ST result of gyroscope + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_st_gyro( +unsigned char *st_gyr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ST_GYR__REG, &v_data_u8r, 1); + *st_gyr = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ST_GYR); + } else { + + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /**************************************************************************** + * Description: *//**\brief Reads ST result of + * MCU register byte from 36h + * + * + * + * + * \param + * unsigned char *st_mcu : Pointer holding the + * ST result of MCU + * + * + * \return + * Result of bus communication function + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_st_mcu( +unsigned char *st_mcu) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ST_MCU__REG, &v_data_u8r, 1); + *st_mcu = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ST_MCU); + } else { + return ERROR1; + + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads gyro any motion interrupt status + * from 36h + * + * + * + * + * \param + * unsigned char *gyr_anymotion : Pointer holding the + * gyro any motion interrupt status + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_interrupt_status_gyro_anymotion( +unsigned char *gyr_anymotion) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_INT_STAT_GYRO_AM__REG, &v_data_u8r, 1); + *gyr_anymotion = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_INT_STAT_GYRO_AM); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads gyro high rate interrupt status + * from 36h + * + * + * + * + * \param + * unsigned char *gyr_highrate : Pointer holding the + * high rate interrupt status + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_interrupt_status_gyro_highrate( +unsigned char *gyr_highrate) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_INT_STAT_GYRO_HIGH_RATE__REG, &v_data_u8r, 1); + *gyr_highrate = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_INT_STAT_GYRO_HIGH_RATE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads accel high g interrupt status + * from 36h + * + * + * + * + * \param + * unsigned char *acc_highg : Pointer holding the + * accel high g interrupt status + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_interrupt_status_accel_highg( +unsigned char *acc_highg) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_INT_STAT_ACC_HIGH_G__REG, &v_data_u8r, 1); + *acc_highg = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_INT_STAT_ACC_HIGH_G); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads accel any motion interrupt status + * from 36h + * + * + * + * + * \param + * unsigned char *acc_anymotion : Pointer holding the + * accel any motion interrupt status + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_interrupt_status_accel_anymotion( +unsigned char *acc_anymotion) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_INT_STAT_ACC_AM__REG, &v_data_u8r, 1); + *acc_anymotion = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_INT_STAT_ACC_AM); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads accel no motion interrupt status + * from 36h + * + * + * + * + * \param + * unsigned char *acc_nomotion : Pointer holding the + * accel no motion interrupt status + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_interrupt_status_accel_nomotion( +unsigned char *acc_nomotion) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_INT_STAT_ACC_NM__REG, &v_data_u8r, 1); + *acc_nomotion = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_INT_STAT_ACC_NM); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads system status code + * from 39h + * + * + * + * + * \param + * unsigned char *sys_status : Pointer holding the + * system status code + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_system_status_code( +unsigned char *sys_status) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SYSTEM_STATUS_CODE__REG, &v_data_u8r, 1); + *sys_status = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_SYSTEM_STATUS_CODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + + /***************************************************************************** + * Description: *//**\brief Reads system error code + * from 3Ah + * + * + * + * + * \param + * unsigned char *sys_error : Pointer holding the + * system error code + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_system_error_code( +unsigned char *sys_error) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SYSTEM_ERROR_CODE__REG, &v_data_u8r, 1); + *sys_error = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_SYSTEM_ERROR_CODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel unit + * register byte from 3Bh + * + * + * + * + * \param + * unsigned char *acc_unit : Pointer holding the + * accel unit + * 0 m/s2 + * 1 mG + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_unit( +unsigned char *acc_unit) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_UNIT__REG, &v_data_u8r, 1); + *acc_unit = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ACC_UNIT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel unit register 3Bh + * (0th bit) + * + * + * + * + * \param unsigned char acc_unit + * + * Accel unit + * 0 m/s2 + * 1 mG + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_unit( +unsigned char acc_unit) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_UNIT__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_UNIT, acc_unit); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_UNIT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro unit + * register byte from 3Bh + * + * + * + * + * \param + * unsigned char *gyr_unit : Pointer holding the + * gyro unit + * 0 Dps + * 1 Rps + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_unit( +unsigned char *gyr_unit) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_UNIT__REG, &v_data_u8r, 1); + *gyr_unit = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_UNIT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro unit register 3Bh + * (1st bit) + * + * + * + * + * \param unsigned char gyr_unit + * + * Gyro unit + * 0 Dps + * 1 Rps + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_unit(unsigned char gyr_unit) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_UNIT__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_UNIT, gyr_unit); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_UNIT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/***************************************************************************** + * Description: *//**\brief Reads Euler unit + * register byte from 3Bh + * + * + * + * + * \param + * unsigned char *eul_unit : Pointer holding the + * Euler unit + * 0 Degrees + * 1 Radians + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_euler_unit( +unsigned char *eul_unit) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_EUL_UNIT__REG, &v_data_u8r, 1); + *eul_unit = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_EUL_UNIT); + } else { + return ERROR1; + + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Euler unit register 3Bh + * (2nd bit) + * + * + * + * + * \param unsigned char eul_unit + * + * Euler unit + * 0 Degrees + * 1 Radians + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_euler_unit(unsigned char eul_unit) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_EUL_UNIT__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_EUL_UNIT, eul_unit); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_EUL_UNIT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads Tilt unit + * register byte from 3Bh + * + * + * + * + * \param + * unsigned char *tilt_unit : Pointer holding the + * Tilt unit + * 0 Degrees + * 1 Radians + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_tilt_unit( +unsigned char *tilt_unit) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TILT_UNIT__REG, &v_data_u8r, 1); + *tilt_unit = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_TILT_UNIT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Tilt unit register 3Bh + * (2nd bit) + * + * + * + * + * \param unsigned char tilt_unit + * + * Tilt unit + * 0 Degrees + * 1 Radians + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_tilt_unit(unsigned char tilt_unit) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TILT_UNIT__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_TILT_UNIT, tilt_unit); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_TILT_UNIT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads temperature unit + * register byte from 3Bh + * + * + * + * + * \param + * unsigned char *temp_unit : Pointer holding the + * temperature unit + * 0 Deg Centigrade + * 1 Deg Fahrenheit + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_temperature_unit( +unsigned char *temp_unit) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TEMP_UNIT__REG, &v_data_u8r, 1); + *temp_unit = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_TEMP_UNIT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the temperature unit register 3Bh + * (2nd bit) + * + * + * + * + * \param unsigned char temp_unit + * + * Temperature unit + * 0 Deg Centigrade + * 1 Deg Fahrenheit + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_temperature_unit( +unsigned char temp_unit) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TEMP_UNIT__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_TEMP_UNIT, temp_unit); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_TEMP_UNIT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description:*//**\brief Reads data out put format of android and windows OS + * register byte from 3Bh + * + * + * + * + * \param + * unsigned char *dof : Pointer holding the + * data out put format of android and windows OS + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_data_output_format( +unsigned char *dof) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_OUTPUT_FORMAT__REG, &v_data_u8r, 1); + *dof = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_DATA_OUTPUT_FORMAT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data out put format of + * android and windows OS 3Bh + * (7th bit) + * + * + * + * + * \param unsigned char dof + * + * Data output format + * 0 Windows + * 1 Android + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_data_output_format(unsigned char dof) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_OUTPUT_FORMAT__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_OUTPUT_FORMAT, dof); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_OUTPUT_FORMAT__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of accel + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *acc_datasel : Pointer holding the + * data select of accel + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_data_select( +unsigned char *acc_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_ACC__REG, &v_data_u8r, 1); + *acc_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_ACC); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of accel + * from 3Ch + * (0th bit) + * + * + * + * + * \param unsigned char acc_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_data_select( +unsigned char acc_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_ACC__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_ACC, acc_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_ACC__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of Mag + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *mag_datasel : Pointer holding the + * data select of Mag + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_data_select( +unsigned char *mag_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_MAG__REG, &v_data_u8r, 1); + *mag_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_MAG); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of Mag + * from 3Ch + * (1st bit) + * + * + * + * + * \param unsigned char mag_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_data_select( +unsigned char mag_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_MAG__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_MAG, mag_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_MAG__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of Gyro + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *gyro_datasel : Pointer holding the + * data select of Gyro + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_data_select( +unsigned char *gyro_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_GYR__REG, &v_data_u8r, 1); + *gyro_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_GYR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of Gyro + * from 3Ch + * (2nd bit) + * + * + * + * + * \param unsigned char gyro_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_data_select( +unsigned char gyro_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_GYR__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_GYR, gyro_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_GYR__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of Euler + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *eul_datasel : Pointer holding the + * data select of Euler + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_euler_data_select( +unsigned char *eul_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_EUL__REG, &v_data_u8r, 1); + *eul_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_EUL); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of Euler + * from 3Ch + * (3rd bit) + * + * + * + * + * \param unsigned char eul_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_euler_data_select( +unsigned char eul_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_EUL__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_EUL, eul_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_EUL__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of Quaternion + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *qur_datasel : Pointer holding the + * data select of Quaternion + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_quaternion_data_select( +unsigned char *qur_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_QUA__REG, &v_data_u8r, 1); + *qur_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_QUA); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of Quaternion + * from 3Ch + * (4th bit) + * + * + * + * + * \param unsigned char qur_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_quaternion_data_select( +unsigned char qur_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_QUA__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_QUA, qur_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_QUA__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of Linear acceleration + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *lia_datasel : Pointer holding the + * data select of Linear acceleration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_linear_accel_data_select( +unsigned char *lia_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_LINEAR_ACC__REG, &v_data_u8r, 1); + *lia_datasel = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_LINEAR_ACC); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of + * Linear acceleration from 3Ch + * (5th bit) + * + * + * + * + * \param unsigned char lia_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_linear_accel_data_select( +unsigned char lia_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_LINEAR_ACC__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_LINEAR_ACC, lia_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_LINEAR_ACC__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of Gravity + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *grv_datasel : Pointer holding the + * data select of Gravity + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gravity_data_select( +unsigned char *grv_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_GRV__REG, &v_data_u8r, 1); + *grv_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_GRV); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of + * Gravity from 3Ch + * (6th bit) + * + * + * + * + * \param unsigned char grv_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gravity_data_select( +unsigned char grv_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_GRV__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_GRV, grv_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_GRV__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data select of temperature + * register byte from 3Ch + * + * + * + * + * \param + * unsigned char *temp_datasel : Pointer holding the + * data select of temperature + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_temperature_data_select( +unsigned char *temp_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_TEMP__REG, &v_data_u8r, 1); + *temp_datasel = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_DATA_SEL_TEMP); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data select of + * temperature from 3Ch + * (7th bit) + * + * + * + * + * \param unsigned char temp_datasel + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_temperature_data_select( +unsigned char temp_datasel) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_TEMP__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_DATA_SEL_TEMP, temp_datasel); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_DATA_SEL_TEMP__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads data output rate + * register byte from 3Dh + * + * + * \param + * unsigned char *data_out_rate : Pointer holding the + * data output rate + * + * + * + * data_out_rate + * FASTEST_MODE_1 - 0x00 + * FASTEST_MODE_2 - 0x01 + * GAME_MODE - 0x02 + * UI_MODE - 0x03 + * NORMALA_MODE - 0x04 + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_data_output_rate( +unsigned char *data_out_rate) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_OUTPUT_DATA_RATE__REG, &v_data_u8r, 1); + *data_out_rate = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_OUTPUT_DATA_RATE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the data out put rate in + * 3Dh register + * + * + * \param unsigned char data_out_rate + * + * + * data_out_rate + * FASTEST_MODE_1 - 0x00 + * FASTEST_MODE_2 - 0x01 + * GAME_MODE - 0x02 + * UI_MODE - 0x03 + * NORMALA_MODE - 0x04 + * + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_data_output_rate( +unsigned char data_out_rate) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_OUTPUT_DATA_RATE__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_OUTPUT_DATA_RATE, data_out_rate); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_OUTPUT_DATA_RATE__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads operation mode + * register byte from 3Dh(0 to 3 bit) + * + * + * + * + * \param + * unsigned char *op_mode : Pointer holding the + * operation mode + *Operation mode: + *SLEEP MODE + *0x00 - OPERATION_MODE_CONFIG + *SENSOR MODE + *0x01 - OPERATION_MODE_ACCONLY + *0x02 - OPERATION_MODE_MAGONLY + *0x03 - OPERATION_MODE_GYRONLY + *0x04 - OPERATION_MODE_ACCMAG + *0x05 - OPERATION_MODE_ACCGYRO + *0x06 - OPERATION_MODE_MAGGYRO + *0x07 - OPERATION_MODE_AMG + *FUSION MODE + *0x08 - OPERATION_MODE_IMUPLUS + *0x09 - OPERATION_MODE_COMPASS + *0x0A - OPERATION_MODE_M4G + *0x0B - OPERATION_MODE_NDOF_FMC_OFF + *0x0C - OPERATION_MODE_NDOF + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_operation_mode( +unsigned char *op_mode) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_OPERATION_MODE__REG, &v_data_u8r, 1); + *op_mode = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_OPERATION_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the operation mode + * in 3Bh(0th bit to 3rd bit) + * + * + * + * + * + * \param unsigned char opr_mode + * + *Operation mode: + *SLEEP MODE + *0x00 - OPERATION_MODE_CONFIG + *SENSOR MODE + *0x01 - OPERATION_MODE_ACCONLY + *0x02 - OPERATION_MODE_MAGONLY + *0x03 - OPERATION_MODE_GYRONLY + *0x04 - OPERATION_MODE_ACCMAG + *0x05 - OPERATION_MODE_ACCGYRO + *0x06 - OPERATION_MODE_MAGGYRO + *0x07 - OPERATION_MODE_AMG + *FUSION MODE + *0x08 - OPERATION_MODE_IMUPLUS + *0x09 - OPERATION_MODE_COMPASS + *0x0A - OPERATION_MODE_M4G + *0x0B - OPERATION_MODE_NDOF_FMC_OFF + *0x0C - OPERATION_MODE_NDOF + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_operation_mode(unsigned char opr_mode) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode == OPERATION_MODE_CONFIG) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_OPERATION_MODE__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_OPERATION_MODE, opr_mode); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_OPERATION_MODE__REG, &v_data_u8r, 1); + } else { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_OPERATION_MODE__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_OPERATION_MODE, OPERATION_MODE_CONFIG); + bno055_write_register( + BNO055_OPERATION_MODE__REG, + &v_data_u8r, 1); + if (opr_mode != + OPERATION_MODE_CONFIG) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_OPERATION_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_OPERATION_MODE, opr_mode); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_OPERATION_MODE__REG, + &v_data_u8r, 1); + } + } + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads Power mode + * register byte from 3Eh + * + * + * + * + * \param + * unsigned char *pwm : Pointer holding the + * power mode + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_powermode( +unsigned char *pwm) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_POWER_MODE__REG, &v_data_u8r, 1); + *pwm = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_POWER_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the power mode register 3Eh + * (0 to 1 bits) + * + * + * + * + * \param unsigned char power mode + * + * power mode[0....7] + * 0x00 - Normal mode + * 0x01 - Low Power mode + * 0x02 - Suspend mode + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_powermode(unsigned char powermode) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_POWER_MODE__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_POWER_MODE, powermode); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_POWER_MODE__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads reset interrupt + * register byte from 3Fh + * + * + * + * + * \param + * unsigned char *rst_int : Pointer holding the + * reset interrupt + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_reset_int( +unsigned char *rst_int) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_RST_INT__REG, &v_data_u8r, 1); + *rst_int = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_RST_INT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the reset interrupt register 3Fh + * (6th bit) + * + * + * + * + * \param unsigned char rst_int + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_reset_int(unsigned char rst_int) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_RST_INT__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_RST_INT, rst_int); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_RST_INT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads reset system + * register byte from 3Fh + * + * + * + * + * \param + * unsigned char *rst_sys : Pointer holding the + * reset system + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_reset_sys( +unsigned char *rst_sys) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_RST_SYS__REG, &v_data_u8r, 1); + *rst_sys = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_RST_SYS); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief This API sets the reset system register 3Fh + * (5th bit) + * + * + * + * + * \param unsigned char rst_sys + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_reset_sys(unsigned char rst_sys) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_RST_SYS__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_RST_SYS, rst_sys); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_RST_SYS__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads self test + * register byte from 3Fh + * + * + * + * + * \param + * unsigned char *self_test : Pointer holding the + * Self test + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_selftest( +unsigned char *self_test) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SELF_TEST__REG, &v_data_u8r, 1); + *self_test = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_SELF_TEST); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Self Test register 3Fh + * (0 bit) + * + * + * + * + * \param unsigned char self_test + * + * self_test[0bit] + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_selftest(unsigned char self_test) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SELF_TEST__REG, &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_SELF_TEST, self_test); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SELF_TEST__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads temperature source + * register byte from 40h + * + * + * + * + * \param + * unsigned char *temp_sour : Pointer holding the + * temperature source + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_temp_source( +unsigned char *temp_sour) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TEMP_SOURCE__REG, &v_data_u8r, 1); + *temp_sour = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_TEMP_SOURCE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the temperature source register 40h + * (0 & 1st bit) + * + * + * + * + * \param unsigned char temp_sour + * + * temp_sour[0 to 1 bit] + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_temp_source(unsigned char temp_sour) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_TEMP_SOURCE__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_TEMP_SOURCE, temp_sour); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_TEMP_SOURCE__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads Remapped X axis value + * register byte from 41h + * + * + * + * + * \param + * unsigned char *remap_axis : Pointer holding the + * Remapped axis value + *remap_axis - 0X21 + *REMAP_X_Y -> This case the axis remapped as Z=Z;X=Y;Y=X + * + *remap_axis - 0X18 + *REMAP_Y_Z -> This case the axis remapped as X=X;Y=Z;Z=Y + * + *remap_axis - 0X06 + *REMAP_Z_X -> This case the axis remapped as Y=Y;X=Z;Z=X + * + *remap_axis - 0X12 + *REMAP_X_Y_Z_TYPE0 -> This case the axis remapped as X=Z;Y=X;Z=Y + * + *remap_axis - 0X09 + *REMAP_X_Y_Z_TYPE1 -> This case the axis remapped as X=Y;Y=Z;Z=X + * + *remap_axis - 0X24 + *DEFAULT_AXIS -> This case is the default axis settings X=X;Y=Y;Z=Z + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_axis_remap_value( +unsigned char *remap_axis) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_AXIS_VALUE__REG, &v_data_u8r, 1); + *remap_axis = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_REMAP_AXIS_VALUE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Remapped X,Y and Z axis value + * in the 41h + * (0 to 5th bit) + * + * + * + * + * \param unsigned char remap_axis + * + *remap_axis - 0X21 + *REMAP_X_Y -> This case the axis remapped as Z=Z;X=Y;Y=X + * + *remap_axis - 0X18 + *REMAP_Y_Z -> This case the axis remapped as X=X;Y=Z;Z=Y + * + *remap_axis - 0X06 + *REMAP_Z_X -> This case the axis remapped as Y=Y;X=Z;Z=X + * + *remap_axis - 0X12 + *REMAP_X_Y_Z_TYPE0 -> This case the axis remapped as X=Z;Y=X;Z=Y + * + *remap_axis - 0X09 + *REMAP_X_Y_Z_TYPE1 -> This case the axis remapped as X=Y;Y=Z;Z=X + * + *remap_axis - 0X24 + *DEFAULT_AXIS -> This case is the default axis settings X=X;Y=Y;Z=Z + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_axis_remap_value( +unsigned char remap_axis) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + switch (remap_axis) { + case REMAP_X_Y: + case REMAP_Y_Z: + case REMAP_Z_X: + case REMAP_X_Y_Z_TYPE0: + case REMAP_X_Y_Z_TYPE1: + case DEFAULT_AXIS: + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_AXIS_VALUE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_REMAP_AXIS_VALUE, + remap_axis); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_AXIS_VALUE__REG, + &v_data_u8r, 1); + break; + default: + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_AXIS_VALUE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_REMAP_AXIS_VALUE, + DEFAULT_AXIS); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_AXIS_VALUE__REG, + &v_data_u8r, 1); + break; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads Remapped X axis Sign + * register byte from 42h + * + * + * + * + * \param + * unsigned char *remap_sign_x : Pointer holding the + * Remapped X axis Sign + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_x_remap_sign( +unsigned char *remap_sign_x) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_X_SIGN__REG, &v_data_u8r, 1); + *remap_sign_x = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_REMAP_X_SIGN); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Remapped X axis sign 42h + * (2nd bit) + * + * + * + * + * \param unsigned char remap_sign_x + * + * remap_sign_x[2nd bit] + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_x_remap_sign( +unsigned char remap_sign_x) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_X_SIGN__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_REMAP_X_SIGN, remap_sign_x); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_X_SIGN__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads Remapped Y axis Sign + * register byte from 41h + * + * + * + * + * \param + * unsigned char *remap_sign_y : Pointer holding the + * Remapped Y axis Sign + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_y_remap_sign( +unsigned char *remap_sign_y) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_Y_SIGN__REG, &v_data_u8r, 1); + *remap_sign_y = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_REMAP_Y_SIGN); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Remapped Y axis Sign 42h + * (1st) + * + * + * + * + * \param unsigned char remap_sign_y + * + * remap_sign_y[1st bit] + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_y_remap_sign( +unsigned char remap_sign_y) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_Y_SIGN__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_REMAP_Y_SIGN, remap_sign_y); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_Y_SIGN__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + /***************************************************************************** + * Description: *//**\brief Reads Remapped Z axis Sign + * register byte from 42h + * + * + * + * + * \param + * unsigned char *remap_sign_z : Pointer holding the + * Remapped Z axis Sign + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_z_remap_sign( +unsigned char *remap_sign_z) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_Z_SIGN__REG, &v_data_u8r, 1); + *remap_sign_z = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_REMAP_Z_SIGN); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the Remapped Z axis Sign 42h + * (0th bit) + * + * + * + * + * \param unsigned char remap_sign_z + * + * remap_sign_z[4 to 5 bit] + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_z_remap_sign( +unsigned char remap_sign_z) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_Z_SIGN__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_REMAP_Z_SIGN, + remap_sign_z); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_REMAP_Z_SIGN__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 0 + * from location 43hh and 44h + * + * + * + * + * \param BNO055_S16 *sic_matrix_zero : Pointer holding the + * soft iron calibration matrix 0 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_zero( +BNO055_S16 *sic_matrix_zero) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_0_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_0_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_0_MSB); + *sic_matrix_zero = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 0 + * from location 43hh and 44h + * + * + * + * + * \param unsigned char + * + * sic_matrix_zero -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_zero( +BNO055_S16 sic_matrix_zero) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_0_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_zero & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_0_LSB, v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_0_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_0_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_zero >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_0_MSB, + v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_0_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 1 + * from location 45hh and 46h + * + * + * + * + * \param BNO055_S16 *sic_matrix_one : Pointer holding the + * soft iron calibration matrix 1 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_one( +BNO055_S16 *sic_matrix_one) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_1_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_1_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_1_MSB); + *sic_matrix_one = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 1 + * from location 45hh and 46h + * + * + * + * + * \param unsigned char + * + * sic_matrix_one -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_one( +BNO055_S16 sic_matrix_one) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_1_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_one & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_1_LSB, + v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_1_LSB__REG, + &v_data2_u8r, 1); + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_1_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_one >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_1_MSB, + v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_1_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 2 + * from location 47hh and 48h + * + * + * + * + * \param BNO055_S16 *sic_matrix_two : Pointer holding the + * soft iron calibration matrix 2 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_two( +BNO055_S16 *sic_matrix_two) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_2_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_2_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_2_MSB); + *sic_matrix_two = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 2 + * from location 47h and 48h + * + * + * + * + * \param unsigned char + * + * sic_matrix_two -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_two( +BNO055_S16 sic_matrix_two) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_2_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_two & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_2_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_2_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_2_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_two >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_2_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_2_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 3 + * from location 49h and 4Ah + * + * + * + * + * \param BNO055_S16 *sic_matrix_three : Pointer holding the + * soft iron calibration matrix 3 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_three( +BNO055_S16 *sic_matrix_three) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_3_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_3_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_3_MSB); + *sic_matrix_three = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 3 + * from location 49h and 4Ah + * + * + * + * + * \param unsigned char + * + * sic_matrix_three -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_three( +BNO055_S16 sic_matrix_three) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_3_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_three & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_3_LSB, v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_3_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_3_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_three >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_3_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_3_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 4 + * from location 4Bh and 4Ch + * + * + * + * + * \param BNO055_S16 *sic_matrix_four : Pointer holding the + * soft iron calibration matrix 4 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_four( +BNO055_S16 *sic_matrix_four) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_4_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_4_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_4_MSB); + *sic_matrix_four = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 4 + * from location 4Bh and 4Ch + * + * + * + * + * \param unsigned char + * + * sic_matrix_four -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_four( +BNO055_S16 sic_matrix_four) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_4_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_four & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_4_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_4_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_4_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_four >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_4_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_4_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 5 + * from location 4Dh and 4Eh + * + * + * + * + * \param BNO055_S16 *sic_matrix_five : Pointer holding the + * soft iron calibration matrix 5 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_five( +BNO055_S16 *sic_matrix_five) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_5_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_5_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_5_MSB); + *sic_matrix_five = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 5 + * from location 4Dh and 4Eh + * + * + * + * + * \param unsigned char + * + * sic_matrix_five -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_five( +BNO055_S16 sic_matrix_five) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_5_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_five & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_5_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_5_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_5_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_five >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_5_MSB, v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_5_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 6 + * from location 4Fh and 50h + * + * + * + * + * \param BNO055_S16 *sic_matrix_six : Pointer holding the + * soft iron calibration matrix 6 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_six( +BNO055_S16 *sic_matrix_six) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_6_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_6_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_6_MSB); + *sic_matrix_six = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 6 + * from location 4Fh and 50h + * + * + * + * + * \param unsigned char + * + * sic_matrix_six -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_six( +BNO055_S16 sic_matrix_six) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_6_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_six & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_6_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_6_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_6_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_six >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_6_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_6_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 7 + * from location 51h and 52h + * + * + * + * + * \param BNO055_S16 *sic_matrix_seven : Pointer holding the + * soft iron calibration matrix 7 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_seven( +BNO055_S16 *sic_matrix_seven) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_7_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_7_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_7_MSB); + *sic_matrix_seven = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 7 + * from location 51h and 52h + * + * + * + * + * \param unsigned char + * + * sic_matrix_seven -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_seven( +BNO055_S16 sic_matrix_seven) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_7_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_seven & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_7_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_7_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_7_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_seven >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_7_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_7_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads soft iron calibration matrix 8 + * from location 53h and 54h + * + * + * + * + * \param BNO055_S16 *sic_matrix_eight : Pointer holding the + * soft iron calibration matrix 8 + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix_eight( +BNO055_S16 *sic_matrix_eight) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_8_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_SIC_MATRIX_8_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_SIC_MATRIX_8_MSB); + *sic_matrix_eight = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write soft iron calibration matrix 8 + * from location 53h and 54h + * + * + * + * + * \param unsigned char + * + * sic_matrix_eight -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix_eight( +BNO055_S16 sic_matrix_eight) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_8_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_eight & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_8_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_8_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_8_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (sic_matrix_eight >> + BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_SIC_MATRIX_8_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_SIC_MATRIX_8_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Accel offset of X axis + * from location 55h and 56h + * + * + * + * + * \param BNO055_S16 *acc_off_x : Pointer holding the + * Accel offset of X axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_offset_x_axis( +BNO055_S16 *acc_off_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_X_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_OFFSET_X_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_OFFSET_X_MSB); + *acc_off_x = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Accel offset of X axis + * from location 55h and 56h + * + * + * + * + * \param unsigned char + * + * acc_off_x -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_accel_offset_x_axis( +BNO055_S16 acc_off_x) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_X_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (acc_off_x & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_ACC_OFFSET_X_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_X_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_X_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (acc_off_x >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_ACC_OFFSET_X_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_X_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Accel offset of Y axis + * from location 57h and 58h + * + * + * + * + * \param BNO055_S16 *acc_off_y : Pointer holding the + * Accel offset of Y axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_offset_y_axis( +BNO055_S16 *acc_off_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Y_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_OFFSET_Y_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_OFFSET_Y_MSB); + *acc_off_y = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Accel offset of Y axis + * from location 57h and 58h + * + * + * + * + * \param unsigned char + * + * acc_off_y -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_accel_offset_y_axis( +BNO055_S16 acc_off_y) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Y_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (acc_off_y & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_ACC_OFFSET_Y_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Y_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Y_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (acc_off_y >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_ACC_OFFSET_Y_MSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Y_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Accel offset of Z axis + * from location 59h and 5ah + * + * + * + * + * \param BNO055_S16 *acc_off_z : Pointer holding the + * Accel offset of Z axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_offset_z_axis( +BNO055_S16 *acc_off_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Z_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_ACC_OFFSET_Z_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_ACC_OFFSET_Z_MSB); + *acc_off_z = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Accel offset of Z axis + * from location 59h and 5Ah + * + * + * + * + * \param unsigned char + * + * acc_off_z -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_accel_offset_z_axis( +BNO055_S16 acc_off_z) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Z_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (acc_off_z & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_ACC_OFFSET_Z_LSB, + v_data1_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Z_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Z_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (acc_off_z >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_ACC_OFFSET_Z_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_OFFSET_Z_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Mag offset of X axis + * from location 5Bh and 5Ch + * + * + * + * + * \param BNO055_S16 *mag_off_x : Pointer holding the + * Mag offset of X axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_offset_x_axis( +BNO055_S16 *mag_off_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_X_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_OFFSET_X_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_OFFSET_X_MSB); + *mag_off_x = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Mag offset of X axis + * from location 5Bh and 5Ch + * + * + * + * + * \param unsigned char + * + * mag_off_x -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_mag_offset_x_axis( +BNO055_S16 mag_off_x) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_X_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (mag_off_x & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_MAG_OFFSET_X_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_X_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_X_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (mag_off_x >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_MAG_OFFSET_X_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_X_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/***************************************************************************** + * Description: *//**\brief This API reads Mag offset of Y axis + * from location 5Dh and 5Eh + * + * + * + * + * \param BNO055_S16 *mag_off_y : Pointer holding the + * Mag offset of Y axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_offset_y_axis( +BNO055_S16 *mag_off_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Y_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_OFFSET_Y_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_OFFSET_Y_MSB); + *mag_off_y = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Mag offset of Y axis + * from location 5Dh and 5Eh + * + * + * + * + * \param unsigned char + * + * mag_off_y -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_mag_offset_y_axis( +BNO055_S16 mag_off_y) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Y_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (mag_off_y & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_MAG_OFFSET_Y_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Y_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Y_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (mag_off_y >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_MAG_OFFSET_Y_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Y_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Mag offset of Z axis + * from location 5Fh and 60h + * + * + * + * + * \param BNO055_S16 *mag_off_z : Pointer holding the + * Mag offset of Z axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_offset_z_axis( +BNO055_S16 *mag_off_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Z_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_MAG_OFFSET_Z_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_MAG_OFFSET_Z_MSB); + *mag_off_z = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Mag offset of Z axis + * from location 5Fh and 60h + * + * + * + * + * \param unsigned char + * + * mag_off_z -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_mag_offset_z_axis( +BNO055_S16 mag_off_z) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Z_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (mag_off_z & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_MAG_OFFSET_Z_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Z_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Z_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (mag_off_z >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_MAG_OFFSET_Z_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_OFFSET_Z_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Gyro offset of X axis + * from location 61h and 62h + * + * + * + * + * \param BNO055_S16 *gyr_off_x : Pointer holding the + * Gyro offset of Z axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_offset_x_axis( +BNO055_S16 *gyr_off_x) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_X_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_OFFSET_X_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_OFFSET_X_MSB); + *gyr_off_x = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Gyro offset of X axis + * from location 61h and 62h + * + * + * + * + * \param unsigned char + * + * gyr_off_x -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_gyro_offset_x_axis( +BNO055_S16 gyr_off_x) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_X_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (gyr_off_x & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_GYR_OFFSET_X_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_X_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_X_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (gyr_off_x >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_GYR_OFFSET_X_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_X_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Gyro offset of Y axis + * from location 63h and 64h + * + * + * + * + * \param BNO055_S16 *gyr_off_y : Pointer holding the + * Gyro offset of Y axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_offset_y_axis( +BNO055_S16 *gyr_off_y) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Y_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_OFFSET_Y_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_OFFSET_Y_MSB); + *gyr_off_y = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Gyro offset of Y axis + * from location 63h and 64h + * + * + * + * + * \param unsigned char + * + * gyr_off_y -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_gyro_offset_y_axis( +BNO055_S16 gyr_off_y) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Y_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (gyr_off_y & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_GYR_OFFSET_Y_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Y_LSB__REG, + &v_data2_u8r, 1); + + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Y_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (gyr_off_y >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_GYR_OFFSET_Y_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Y_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API reads Gyro offset of Z axis + * from location 65h and 66h + * + * + * + * + * \param BNO055_S16 *gyr_off_z : Pointer holding the + * Gyro offset of Z axis + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_offset_z_axis( +BNO055_S16 *gyr_off_z) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char a_data_u8r[2] = {0, 0}; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ZERO); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Z_LSB__REG, a_data_u8r, 2); + a_data_u8r[0] = BNO055_GET_BITSLICE(a_data_u8r[0], + BNO055_GYR_OFFSET_Z_LSB); + a_data_u8r[1] = BNO055_GET_BITSLICE(a_data_u8r[1], + BNO055_GYR_OFFSET_Z_MSB); + *gyr_off_z = (BNO055_S16)((((BNO055_S16) + (signed char)(a_data_u8r[1])) << + (BNO055_SHIFT_8_POSITION)) | (a_data_u8r[0])); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API write Gyro offset of Z axis + * from location 65h and 66h + * + * + * + * + * \param unsigned char + * + * gyr_off_z -> Any valid value + * + * + * + * \return result of communication routines + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_write_gyro_offset_z_axis( +BNO055_S16 gyr_off_z) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data1_u8r = BNO055_Zero_U8X; +unsigned char v_data2_u8r = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Z_LSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (gyr_off_z & 0x00FF)); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_GYR_OFFSET_Z_LSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Z_LSB__REG, + &v_data2_u8r, 1); + + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Z_MSB__REG, + &v_data2_u8r, 1); + v_data1_u8r = ((signed char) + (gyr_off_z >> BNO055_SHIFT_8_POSITION) + & 0x00FF); + v_data2_u8r = + BNO055_SET_BITSLICE(v_data2_u8r, + BNO055_GYR_OFFSET_Z_MSB, v_data1_u8r); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_OFFSET_Z_MSB__REG, + &v_data2_u8r, 1); + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** +* PAGE 1 +***************************************************************************/ +/*************************************************************************** + * Description: *//**\brief Reads Accel range + * register byte from page1 08h + * + * + * \param + * unsigned char *accel_range : Pointer holding the + * Accel range + * + * + * + *accel_range + *ACCEL_RANGE_2G - 0x00 + *ACCEL_RANGE_4G - 0x01 + *ACCEL_RANGE_8G - 0x02 + *ACCEL_RANGE_16G- 0x03 + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_range( +unsigned char *accel_range) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_RANGE__REG, &v_data_u8r, 1); + *accel_range = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_ACC_RANGE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel range in + * page1 08h register + * + * + * \param unsigned char accel_range + * + * + *accel_range + *ACCEL_RANGE_2G - 0x00 + *ACCEL_RANGE_4G - 0x01 + *ACCEL_RANGE_8G - 0x02 + *ACCEL_RANGE_16G- 0x03 + * + * + * + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_range( +unsigned char accel_range) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (accel_range < BNO055_Five_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_RANGE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_ACC_RANGE, + accel_range); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_RANGE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } +} +if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); +return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the bandwidth of the accel + * + * + * + * + * \param unsigned char * accel_bw : Pointer holding the bandwidth + * accel_bw -> + + * 0x00 -> 7.81HZ + * 0x01 -> 15.63HZ + * 0x02 -> 31.25HZ + * 0X03 -> 62.50HZ + * 0X04 -> 125HZ + * 0X05 -> 250HZ + * 0X06 -> 500HZ + * 0X07 -> 1000HZ + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_bandwidth( +unsigned char *accel_bw) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_BW__REG, &v_data_u8r, 1); + *accel_bw = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_ACC_BW); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set Bandwidth of the accel + * + * + * + * + * \param unsigned char accel_bandwidth: The value of Bandwidth + * accel_bandwidth -> + * 0x00 -> 7.81HZ + * 0x01 -> 15.63HZ + * 0x02 -> 31.25HZ + * 0X03 -> 62.50HZ + * 0X04 -> 125HZ + * 0X05 -> 250HZ + * 0X06 -> 500HZ + * 0X07 -> 1000HZ + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_bandwidth( +unsigned char accel_bw) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (accel_bw < BNO055_Eight_U8X) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_BW__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, BNO055_CONFIG_ACC_BW, + accel_bw); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_BW__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endi +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the power mode of the accel + * + * + * + * + * \param unsigned char * accel_pw : Pointer holding + * the power mode of the accel + * accel_pw -> + * 0x00 -> Normal + * 0x01 -> Suspend + * 0x02 -> Lowpower1 + * 0X03 -> standby + * 0X04 -> Lowpower2 + * 0X05 -> Deep suspend + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_powermode( +unsigned char *accel_pw) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_PWR_MODE__REG, &v_data_u8r, 1); + *accel_pw = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_ACC_PWR_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set power mode of the accel + * + * + * + * + * \param unsigned char accel_bandwidth: The value of power mode of the accel + * accel_pm -> +* 0x00 -> Normal + * 0x01 -> Suspend + * 0x02 -> Lowpower1 + * 0X03 -> standby + * 0X04 -> Lowpower2 + * 0X05 -> Deep suspend + * + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_powermode( +unsigned char accel_pm) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (accel_pm < BNO055_Seven_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_PWR_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_ACC_PWR_MODE, + accel_pm); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_ACC_PWR_MODE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the data output rate of the mag + * + * + * + * + * \param unsigned char * mag_data_outrate : Pointer holding + * the data output rate of mag + * -> mag_data_outrate + * 0x00 -> MAG_DATA_OUTRATE_2Hz + * 0x01 -> MAG_DATA_OUTRATE_6Hz + * 0x02 -> MAG_DATA_OUTRATE_8Hz + * 0X03 -> MAG_DATA_OUTRATE_10Hz + * 0X04 -> MAG_DATA_OUTRATE_15Hz + * 0X05 -> MAG_DATA_OUTRATE_20Hz + * 0X06 -> MAG_DATA_OUTRATE_25Hz + * 0X07 -> MAG_DATA_OUTRATE_30Hz + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_data_outputrate( +unsigned char *mag_data_outrate) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__REG, + &v_data_u8r, 1); + *mag_data_outrate = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_MAG_DATA_OUTPUT_RATE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set the data output rate of + * mag in the register 09h + * + * + * + * + * \param unsigned char mag_data_outrate: The value of data output rate of mag + * mag_data_outrate -> + * 0x00 -> MAG_DATA_OUTRATE_2Hz + * 0x01 -> MAG_DATA_OUTRATE_6Hz + * 0x02 -> MAG_DATA_OUTRATE_8Hz + * 0X03 -> MAG_DATA_OUTRATE_10Hz + * 0X04 -> MAG_DATA_OUTRATE_15Hz + * 0X05 -> MAG_DATA_OUTRATE_20Hz + * 0X06 -> MAG_DATA_OUTRATE_25Hz + * 0X07 -> MAG_DATA_OUTRATE_30Hz + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_data_outrate( +unsigned char mag_data_outrate) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (mag_data_outrate + < BNO055_Eight_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_MAG_DATA_OUTPUT_RATE, + mag_data_outrate); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the operation mode of the mag + * + * + * + * + * \param unsigned char * mag_operation_mode: + * Pointer holding the operation mode of Mag + * mag_operation_mode -> + * 0x00 -> MAG_OPR_MODE_LOWPOWER + * 0x01 -> MAG_OPR_MODE_REGULAR + * 0x02 -> MAG_OPR_MODE_ENHANCED_REGULAR + * 0X03 -> MAG_OPR_MODE_HIGH_ACCURACY + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_operation_mode( +unsigned char *mag_operation_mode) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_OPR_MODE__REG, &v_data_u8r, 1); + *mag_operation_mode = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_MAG_OPR_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set operation mode of Mag + * + * + * + * + * \param unsigned char accel_bandwidth: The value of operation mode of Mag + * mag_operation_mode -> +* 0x00 -> MAG_OPR_MODE_LOWPOWER + * 0x01 -> MAG_OPR_MODE_REGULAR + * 0x02 -> MAG_OPR_MODE_ENHANCED_REGULAR + * 0X03 -> MAG_OPR_MODE_HIGH_ACCURACY + * + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_operation_mode( +unsigned char mag_operation_mode) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (mag_operation_mode + < BNO055_Five_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_OPR_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_MAG_OPR_MODE, + mag_operation_mode); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_OPR_MODE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the power mode of the mag + * + * + * + * + * \param unsigned char * mag_pw : Pointer holding + * the power mode of the mag + * mag_pw -> + * 0x00 -> MAG_POWER_MODE_NORMAL + * 0x01 -> MAG_POWER_MODE_SLEEP + * 0x02 -> MAG_POWER_MODE_SUSPEND + * 0X03 -> MAG_POWER_MODE_FORCE_MODE + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_powermode( +unsigned char *mag_pw) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_POWER_MODE__REG, &v_data_u8r, 1); + *mag_pw = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_MAG_POWER_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set power mode of the mag + * + * + * + * + * \param unsigned char mag_pw: The value of power mode of the mag + * mag_pw -> +* 0x00 -> MAG_POWER_MODE_NORMAL + * 0x01 -> MAG_POWER_MODE_SLEEP + * 0x02 -> MAG_POWER_MODE_SUSPEND + * 0X03 -> MAG_POWER_MODE_FORCE_MODE + * + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_powermode( +unsigned char mag_pw) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode(OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (mag_pw < BNO055_Five_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_POWER_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_MAG_POWER_MODE, mag_pw); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_MAG_POWER_MODE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the range of gyro + * + * + * + * + * \param unsigned char * gyro_range : Pointer holding + * the range of gyro + * -> gyro_range + * 0x00 -> GYRO_RANGE_2000rps + * 0x01 -> GYRO_RANGE_1000rps + * 0x02 -> GYRO_RANGE_500rps + * 0X03 -> GYRO_RANGE_250rps + * 0X04 -> GYRO_RANGE_125rps + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_range( +unsigned char *gyro_range) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_RANGE__REG, &v_data_u8r, 1); + *gyro_range = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_GYR_RANGE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set the range of gyro + * in the register 1Ah + * + * + * + * + * \param unsigned char gyro_range: The value of the range of gyro + * gyro_range -> + * 0x00 -> GYRO_RANGE_2000rps + * 0x01 -> GYRO_RANGE_1000rps + * 0x02 -> GYRO_RANGE_500rps + * 0X03 -> GYRO_RANGE_250rps + * 0X04 -> GYRO_RANGE_125rps + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_range( +unsigned char gyro_range) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (gyro_range < BNO055_Five_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_RANGE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_GYR_RANGE, + gyro_range); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_RANGE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set + * the bandwidth of gyro + * + * + * + * + * \param unsigned char * gyro_bw : Pointer holding + * the bandwidth of gyro + * -> gyro_bw + * 0x00 -> GYRO_BW_523Hz + * 0x01 -> GYRO_BW_230Hz + * 0x02 -> GYRO_BW_116Hz + * 0X03 -> GYRO_BW_47Hz + * 0X04 -> GYRO_BW_23Hz + * 0X05 -> GYRO_BW_12Hz + * 0X06 -> GYRO_BW_64Hz + * 0X07 -> GYRO_BW_32Hz + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_bandwidth( +unsigned char *gyro_bw) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_BANDWIDTH__REG, &v_data_u8r, 1); + *gyro_bw = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_GYR_BANDWIDTH); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set the range of gyro + * in the register 1Ah + * + * + * + * + * \param unsigned char gyro_bw: The value of data output rate of mag + * gyro_bw -> + * 0x00 -> GYRO_BW_523Hz + * 0x01 -> GYRO_BW_230Hz + * 0x02 -> GYRO_BW_116Hz + * 0X03 -> GYRO_BW_47Hz + * 0X04 -> GYRO_BW_23Hz + * 0X05 -> GYRO_BW_12Hz + * 0X06 -> GYRO_BW_64Hz + * 0X07 -> GYRO_BW_32Hz + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_bandwidth( +unsigned char gyro_bw) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + unsigned char gyro_opmode = BNO055_Zero_U8X; + unsigned char gyro_autosleepduration = BNO055_Zero_U8X; + unsigned char pg_status = BNO055_Zero_U8X; + unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if ((gyro_bw == BNO055_Zero_U8X || + gyro_bw > BNO055_Zero_U8X) && + gyro_bw < BNO055_Eight_U8X) { + bno055_get_gyro_operation_mode + (&gyro_opmode); + if (gyro_opmode == + GYRO_OPR_MODE_ADVANCE_POWERSAVE) { + bno055_get_gyro_autosleepdur + (&gyro_autosleepduration); + bno055_gyro_set_autosleepdur + (gyro_autosleepduration, + gyro_bw); + } + switch (gyro_bw) { + case GYRO_BW_523Hz: + gyro_bw = GYRO_BW_523Hz; + break; + case GYRO_BW_230Hz: + gyro_bw = GYRO_BW_230Hz; + break; + case GYRO_BW_116Hz: + gyro_bw = GYRO_BW_116Hz; + break; + case GYRO_BW_47Hz: + gyro_bw = GYRO_BW_47Hz; + break; + case GYRO_BW_23Hz: + gyro_bw = GYRO_BW_23Hz; + break; + case GYRO_BW_12Hz: + gyro_bw = GYRO_BW_12Hz; + break; + case GYRO_BW_64Hz: + gyro_bw = GYRO_BW_64Hz; + break; + case GYRO_BW_32Hz: + gyro_bw = GYRO_BW_32Hz; + break; + default: + break; + } + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_BANDWIDTH__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_GYR_BANDWIDTH, + gyro_bw); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_BANDWIDTH__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the operation mode of the gyro + * + * + * + * + * \param unsigned char * gyro_operation_mode: + * Pointer holding the operation mode of gyro + *gyro_operation_mode -> + * 0x00 -> GYRO_OPR_MODE_NORMAL + * 0x01 -> GYRO_OPR_MODE_FASTPOWERUP + * 0x02 -> GYRO_OPR_MODE_DEEPSUSPEND + * 0X03 -> GYRO_OPR_MODE_SUSPEND + * 0X04 -> GYRO_OPR_MODE_ADVANCE_POWERSAVE + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_operation_mode( +unsigned char *gyro_operation_mode) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_POWER_MODE__REG, + &v_data_u8r, 1); + *gyro_operation_mode = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_CONFIG_GYR_POWER_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set operation mode of Gyro + * + * + *param unsigned char gyro_operation_mode: + * The value of operation mode of Gyro + * + *gyro_operation_mode -> + * 0x00 -> GYRO_OPR_MODE_NORMAL + * 0x01 -> GYRO_OPR_MODE_FASTPOWERUP + * 0x02 -> GYRO_OPR_MODE_DEEPSUSPEND + * 0X03 -> GYRO_OPR_MODE_SUSPEND + * 0X04 -> GYRO_OPR_MODE_ADVANCE_POWERSAVE + * + * + * + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_operation_mode( +unsigned char gyro_operation_mode) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char gyro_autosleepduration = BNO055_Zero_U8X; +unsigned char gyro_bw = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if ((gyro_operation_mode == BNO055_Zero_U8X || + gyro_operation_mode > BNO055_Zero_U8X) && + gyro_operation_mode < BNO055_Five_U8X) { + switch (gyro_operation_mode) { + case GYRO_OPR_MODE_NORMAL: + gyro_operation_mode = + GYRO_OPR_MODE_NORMAL; + break; + case GYRO_OPR_MODE_FASTPOWERUP: + gyro_operation_mode = + GYRO_OPR_MODE_FASTPOWERUP; + break; + case GYRO_OPR_MODE_DEEPSUSPEND: + gyro_operation_mode = + GYRO_OPR_MODE_DEEPSUSPEND; + break; + case GYRO_OPR_MODE_SUSPEND: + gyro_operation_mode = + GYRO_OPR_MODE_SUSPEND; + break; + case GYRO_OPR_MODE_ADVANCE_POWERSAVE: + bno055_get_gyro_bandwidth + (&gyro_bw); + bno055_get_gyro_autosleepdur + (&gyro_autosleepduration); + bno055_gyro_set_autosleepdur + (gyro_autosleepduration, + gyro_bw); + status = + bno055_write_page_id(PAGE_ONE); + gyro_operation_mode = + GYRO_OPR_MODE_ADVANCE_POWERSAVE; + break; + default: + break; + } + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_POWER_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_CONFIG_GYR_POWER_MODE, + gyro_operation_mode); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_CONFIG_GYR_POWER_MODE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get + * the sleep timer mode status of Accel + * + * + * + * + * \param unsigned char *sleep_tmr : Pointer holding the sleep_tmr + * sleep_tmr -> [0:1] + * 0 => enable EventDrivenSampling(EDT) + * 1 => enable Equidistant sampling mode(EST) + * + * + * + * \return + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_sleeptmr_mode( +unsigned char *sleep_tmr) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + /*SLEEP TIMER MODE */ + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_SLEEP_MODE__REG, &v_data_u8r, 1); + *sleep_tmr = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ACC_SLEEP_MODE); + } else { + return ERROR1; + } + } + return comres; + } +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set + * the sleep timer mode status of Accel + * + * + * + * + * \param unsigned char sleep_tmr: The value of sleep timer mode status + * sleep_tmr -> [0:1] + * 0 => enable EventDrivenSampling(EDT) + * 1 => enable Equidistant sampling mode(EST) + * + * + * + * \return communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_sleeptmr_mode( +unsigned char sleep_tmr) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (sleep_tmr < BNO055_Two_U8X) { + /*SLEEP TIMER MODE*/ + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_SLEEP_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_ACC_SLEEP_MODE, + sleep_tmr); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_SLEEP_MODE__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/**************************************************************************** + * Description: *//**\brief This API is used to get + * the sleep duration status of the Accel + * + * + * + * + * \param unsigned char *sleep_dur : Pointer holding the sleep_dur time + * 0x05 -> BNO055_ACCEL_SLEEP_DUR_0_5MS + * 0x06 -> BNO055_ACCEL_SLEEP_DUR_1MS + * 0x07 -> BNO055_ACCEL_SLEEP_DUR_2MS + * 0x08 -> BNO055_ACCEL_SLEEP_DUR_4MS + * 0x09 -> BNO055_ACCEL_SLEEP_DUR_6MS + * 0x0A -> BNO055_ACCEL_SLEEP_DUR_10MS + * 0x0B -> BNO055_ACCEL_SLEEP_DUR_25MS + * 0x0C -> BNO055_ACCEL_SLEEP_DUR_50MS + * 0x0D -> BNO055_ACCEL_SLEEP_DUR_100MS + * 0x0E -> BNO055_ACCEL_SLEEP_DUR_500MS + * 0x0F -> BNO055_ACCEL_SLEEP_DUR_1S + * + * + * + * \return + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_sleep_dur( +unsigned char *sleep_dur) + { + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + /*SLEEP TIMER MODE */ + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_SLEEP_DUR__REG, &v_data_u8r, 1); + *sleep_dur = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ACC_SLEEP_DUR); + } else { + return ERROR1; + } + } + return comres; + } +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to set Sleep Duration of + * Accel + * + * + * + * \param unsigned char sleep_dur: The value of Sleep Duration time + * sleep_dur -> 0x05 -> BNO055_ACCEL_SLEEP_DUR_0_5MS + * 0x06 -> BNO055_ACCEL_SLEEP_DUR_1MS + * 0x07 -> BNO055_ACCEL_SLEEP_DUR_2MS + * 0x08 -> BNO055_ACCEL_SLEEP_DUR_4MS + * 0x09 -> BNO055_ACCEL_SLEEP_DUR_6MS + * 0x0A -> BNO055_ACCEL_SLEEP_DUR_10MS + * 0x0B -> BNO055_ACCEL_SLEEP_DUR_25MS + * 0x0C -> BNO055_ACCEL_SLEEP_DUR_50MS + * 0x0D -> BNO055_ACCEL_SLEEP_DUR_100MS + * 0x0E -> BNO055_ACCEL_SLEEP_DUR_500MS + * 0x0F -> BNO055_ACCEL_SLEEP_DUR_1S + * + * + * \return communication results + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_sleep_dur( +unsigned char sleep_dur) + { +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (sleep_dur < BNO055_Sixteen_U8X) { + /*SLEEP DURATION*/ + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_SLEEP_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_ACC_SLEEP_DUR, + sleep_dur); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_SLEEP_DUR__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to get data sleep duration of + * gyro + * + * + * + * \param unsigned char *sleep_dur : Pointer holding the sleep duration + * + * + * + * + * \return + * + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_sleepdur(unsigned char *sleep_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + /*SLEEP TIMER MODE */ + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_SLEEP_DUR__REG, &v_data_u8r, 1); + *sleep_dur = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_SLEEP_DUR); + } else { + return ERROR1; + } + } + return comres; + } +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set duration of gyro + * + * + * + * + * \param unsigned char sleep_dur: + * Value to be written passed as a parameter + * + * + * + * \return communication results + * + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_sleepdur(unsigned char sleep_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + if (sleep_dur < BNO055_Eight_U8X) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_SLEEP_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_SLEEP_DUR, + sleep_dur); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_SLEEP_DUR__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/***************************************************************************** + * Description: *//**\brief This API is used to get data auto sleep duration + * of gyro + * + * + * + * \param unsigned char *auto_duration : Pointer holding + * the auto sleep duration + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_autosleepdur( +unsigned char *auto_duration) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AUTO_SLEEP_DUR__REG, &v_data_u8r, 1); + *auto_duration = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AUTO_SLEEP_DUR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set auto sleep duration of + * gyro + * + * + * + * \param unsigned char auto_duration: + * Value to be written passed as a parameter + * + * + * + * \return communication results + * + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_gyro_set_autosleepdur( +unsigned char auto_duration, unsigned char bandwith) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char v_autosleepduration_u8r; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); +if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AUTO_SLEEP_DUR__REG, + &v_data_u8r, 1); + if (auto_duration < BNO055_Eight_U8X) { + switch (bandwith) { + case GYRO_BW_523Hz: + if (auto_duration > + BNO055_GYRO_4ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_4ms_AuSlpDur; + break; + case GYRO_BW_230Hz: + if (auto_duration > + BNO055_GYRO_4ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_4ms_AuSlpDur; + break; + case GYRO_BW_116Hz: + if (auto_duration > + BNO055_GYRO_4ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_4ms_AuSlpDur; + break; + case GYRO_BW_47Hz: + if (auto_duration > + BNO055_GYRO_5ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_5ms_AuSlpDur; + break; + case GYRO_BW_23Hz: + if (auto_duration > + BNO055_GYRO_10ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_10ms_AuSlpDur; + break; + case GYRO_BW_12Hz: + if (auto_duration > + BNO055_GYRO_20ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_20ms_AuSlpDur; + break; + case GYRO_BW_64Hz: + if (auto_duration > + BNO055_GYRO_10ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_10ms_AuSlpDur; + break; + case GYRO_BW_32Hz: + if (auto_duration > + BNO055_GYRO_20ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_20ms_AuSlpDur; + break; + default: + if (auto_duration > + BNO055_GYRO_4ms_AuSlpDur) + v_autosleepduration_u8r = + auto_duration; + else + v_autosleepduration_u8r = + BNO055_GYRO_4ms_AuSlpDur; + break; + } + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_AUTO_SLEEP_DUR, + v_autosleepduration_u8r); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AUTO_SLEEP_DUR__REG, + &v_data_u8r, 1); + } else { + comres = E_BNO055_OUT_OF_RANGE; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads magnetometer sleep mode + * + * + * + * + * + * \param + * unsigned char *sleep_mode : Pointer holding the + * magnetometer sleep mode + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_sleep_mode( +unsigned char *sleep_mode) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_SLEEP_MODE__REG, &v_data_u8r, 1); + *sleep_mode = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_MAG_SLEEP_MODE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the magnetometer sleep mode + * + * + * + * + * + * + * \param unsigned char sleep_mode + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_sleep_mode( +unsigned char sleep_mode) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_SLEEP_MODE__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_MAG_SLEEP_MODE, + sleep_mode); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_SLEEP_MODE__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads magnetometer sleep duration + * + * + * + * + * + * \param + * unsigned char *sleep_dur : Pointer holding the + * magnetometer sleep mode + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_sleep_duration( +unsigned char *sleep_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_SLEEP_DUR__REG, &v_data_u8r, 1); + *sleep_dur = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_MAG_SLEEP_DUR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the magnetometer sleep duration + * + * + * + * + * + * + * \param unsigned char sleep_dur + * + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_sleep_duration( +unsigned char sleep_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_MAG_SLEEP_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_MAG_SLEEP_DUR, sleep_dur); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_MAG_SLEEP_DUR__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro any motion interrupt mask + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *gyro_am : Pointer holding the + * gyro any motion interrupt mask + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_intmsk_gyro_anymotion( +unsigned char *gyro_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_INTMSK__REG, &v_data_u8r, 1); + *gyro_am = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_INTMSK); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro any motion interrupt mask + * + * + * + * + * \param unsigned char gyro_am + * + * gyro_am interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_intmsk_gyro_anymotion( +unsigned char gyro_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_INTMSK__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_INTMSK, gyro_am); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_INTMSK__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate interrupt mask + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *gyro_hr : Pointer holding the + * high rate interrupt mask + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_intmsk_gyro_highrate( +unsigned char *gyro_hr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HIGH_RATE_INTMSK__REG, + &v_data_u8r, 1); + *gyro_hr = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_HIGH_RATE_INTMSK); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate interrupt mask + * + * + * + * + * \param unsigned char gyro_hr + * + * gyro_hr interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_intmsk_gyro_highrate( +unsigned char gyro_hr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HIGH_RATE_INTMSK__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HIGH_RATE_INTMSK, gyro_hr); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HIGH_RATE_INTMSK__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel high g interrupt mask + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *accel_hg : Pointer holding the + * accel high g + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_intmsk_accel_high_g( +unsigned char *accel_hg) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_INTMSK__REG, &v_data_u8r, 1); + *accel_hg = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_INTMSK); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel high g interrupt mask + * + * + * + * + * \param unsigned char accel_hg + * + * accel_hg interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_intmsk_accel_high_g( +unsigned char accel_hg) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_INTMSK__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_INTMSK, accel_hg); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_INTMSK__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel any motion interrupt mask + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *accel_am : Pointer holding the + * accel any motion + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_intmsk_accel_anymotion( +unsigned char *accel_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_INTMSK__REG, &v_data_u8r, 1); + *accel_am = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_INTMSK); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel any motion interrupt mask + * + * + * + * + * \param unsigned char accel_am + * + * accel_am interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_intmsk_accel_anymotion( +unsigned char accel_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_INTMSK__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_INTMSK, accel_am); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_INTMSK__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel no motion interrupt mask + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *accel_nm : Pointer holding the + * accel no motion + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_intmsk_accel_nomotion( +unsigned char *accel_nm) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_INTMSK__REG, &v_data_u8r, 1); + *accel_nm = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_NM_INTMSK); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel no motion interrupt mask + * + * + * + * + * \param unsigned char accel_nm + * + * accel_nm interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_intmsk_accel_nomotion( +unsigned char accel_nm) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_INTMSK__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_NM_INTMSK, accel_nm); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_INTMSK__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro any motion interrupt + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *gyro_am : Pointer holding the + * gyro any motion interrupt + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_int_gyro_anymotion( +unsigned char *gyro_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_INT__REG, &v_data_u8r, 1); + *gyro_am = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_INT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro any motion interrupt + * + * + * + * + * \param unsigned char gyro_am + * + * gyro_am interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_int_gyro_anymotion( +unsigned char gyro_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_INT__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_INT, gyro_am); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_INT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate interrupt + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *gyro_hr : Pointer holding the + * high rate interrupt + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_int_gyro_highrate( +unsigned char *gyro_hr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HIGH_RATE_INT__REG, &v_data_u8r, 1); + *gyro_hr = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_HIGH_RATE_INT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate interrupt + * + * + * + * + * \param unsigned char gyro_hr + * + * gyro_hr interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_int_gyro_highrate( +unsigned char gyro_hr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HIGH_RATE_INT__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HIGH_RATE_INT, gyro_hr); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HIGH_RATE_INT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel high g interrupt + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *accel_hg : Pointer holding the + * accel high g + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_int_accel_high_g( +unsigned char *accel_hg) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_INT__REG, &v_data_u8r, 1); + *accel_hg = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_ACC_HIGH_G_INT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel high g interrupt + * + * + * + * + * \param unsigned char accel_hg + * + * accel_hg interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_int_accel_high_g( +unsigned char accel_hg) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_INT__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_INT, accel_hg); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_INT__REG, + &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel any motion interrupt + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *accel_am : Pointer holding the + * accel any motion + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_int_accel_anymotion( +unsigned char *accel_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_INT__REG, &v_data_u8r, 1); + *accel_am = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_INT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel any motion interrupt + * + * + * + * + * \param unsigned char accel_am + * + * accel_am interrupt msk + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_int_accel_anymotion( +unsigned char accel_am) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_INT__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_INT, accel_am); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_INT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel no motion interrupt + * register byte from 0Fh + * + * + * + * + * \param + * unsigned char *accel_nm : Pointer holding the + * accel no motion + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_int_accel_nomotion( +unsigned char *accel_nm) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_INT__REG, &v_data_u8r, 1); + *accel_nm = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_NM_INT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel no motion interrupt + * + * + * + * + * \param unsigned char accel_nm + * + * accel_nm interrupt + * 0 Disable + * 1 Enable + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_int_accel_nomotion( +unsigned char accel_nm) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_INT__REG, &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_NM_INT, accel_nm); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_INT__REG, &v_data_u8r, 1); + } else { + return ERROR1; + } + + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel any motion threshold + * register byte from 11h + * + * + * + * + * \param + * unsigned char *accel_am_thres : Pointer holding the + * accel any motion threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_anymotion_threshold( +unsigned char *accel_am_thres) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_THRES__REG, &v_data_u8r, 1); + *accel_am_thres = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_THRES); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel any motion threshold + * register 11h + * + * + * + * \param unsigned char accel_am_thres + * + * accel_am_thres interrupt + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_anymotion_threshold( +unsigned char accel_am_thres) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_THRES__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_THRES, + accel_am_thres); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_THRES__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel any motion duration + * register byte from 12h + * + * + * + * + * \param + * unsigned char *accel_am_dur : Pointer holding the + * accel any motion duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_anymotion_duration( +unsigned char *accel_am_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_DUR_SET__REG, &v_data_u8r, 1); + *accel_am_dur = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_DUR_SET); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel any motion duration + * + * + * + * + * \param unsigned char accel_am_dur + * + * accel_am_dur + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_anymotion_duration( +unsigned char accel_am_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_DUR_SET__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_AM_DUR_SET, + accel_am_dur); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AM_DUR_SET__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to get the status of Any Enable + * Channel X,Y,Z + * + * + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of Any Enable channel number + * channel : + * BNO055_ACCEL_AM_NM_X_AXIS -> 0 + * BNO055_ACCEL_AM_NM_Y_AXIS -> 1 + * BNO055_ACCEL_AM_NM_Z_AXIS -> 2 + * unsigned char *data: Pointer holding the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * \return + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_an_nm_axis_enable( +unsigned char channel, unsigned char *data) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + switch (channel) { + case BNO055_ACCEL_AM_NM_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_X_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AN_MOTION_X_AXIS); + break; + case BNO055_ACCEL_AM_NM_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_Y_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AN_MOTION_Y_AXIS); + break; + case BNO055_ACCEL_AM_NM_Z_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_Z_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_AN_MOTION_Z_AXIS); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set the status of Any Enable + * Channel X,Y,Z + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of Any Enable channel number + * channel : + * BNO055_ACCEL_AM_NM_X_AXIS -> 0 + * BNO055_ACCEL_AM_NM_Y_AXIS -> 1 + * BNO055_ACCEL_AM_NM_Z_AXIS -> 2 + * unsigned char *data: the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * + * + * + * \return communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_an_nm_axis_enable( +unsigned char channel, unsigned char data) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + switch (channel) { + case BNO055_ACCEL_AM_NM_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_X_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_ACC_AN_MOTION_X_AXIS, data); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_X_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_ACCEL_AM_NM_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_Y_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_ACC_AN_MOTION_Y_AXIS, data); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_Y_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_ACCEL_AM_NM_Z_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_Z_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_ACC_AN_MOTION_Z_AXIS, data); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_AN_MOTION_Z_AXIS__REG, + &v_data_u8r, 1); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode + (prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/*************************************************************************** + * Description:*//**\brief This API is used to get the status of High g Enable + * Channel X,Y,Z + * + * + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of Any Enable channel number + * channel : + * BNO055_ACCEL_HIGH_G_X_AXIS -> 0 + * BNO055_ACCEL_HIGH_G_Y_AXIS -> 1 + * BNO055_ACCEL_HIGH_G_Z_AXIS -> 2 + * unsigned char *data: Pointer holding the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * \return + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_high_g_axis_enable( +unsigned char channel, unsigned char *data) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + switch (channel) { + case BNO055_ACCEL_HIGH_G_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_X_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_X_AXIS); + break; + case BNO055_ACCEL_HIGH_G_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_Y_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_Y_AXIS); + break; + case BNO055_ACCEL_HIGH_G_Z_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_Z_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_Z_AXIS); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set the status of Any Enable + * Channel X,Y,Z + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of Any Enable channel number + * channel : + * BNO055_ACCEL_HIGH_G_X_AXIS -> 0 + * BNO055_ACCEL_HIGH_G_Y_AXIS -> 1 + * BNO055_ACCEL_HIGH_G_Z_AXIS -> 2 + * unsigned char *data: the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * + * + * + * \return communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_high_g_axis_enable( +unsigned char channel, unsigned char data) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + switch (channel) { + case BNO055_ACCEL_HIGH_G_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_X_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_X_AXIS, data); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_X_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_ACCEL_HIGH_G_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_Y_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_Y_AXIS, data); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_Y_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_ACCEL_HIGH_G_Z_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_Z_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_Z_AXIS, data); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_Z_AXIS__REG, + &v_data_u8r, 1); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel high g duration + * register byte from 13h + * + * + * + * + * \param + * unsigned char *accel_hg_dur : Pointer holding the + * accel high g duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_high_g_duration( +unsigned char *accel_hg_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_DURATION__REG, &v_data_u8r, 1); + *accel_hg_dur = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_DURATION); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel high g duration + * + * + * + * + * \param unsigned char accel_hg_dur + * + * accel_hg_dur + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_high_g_duration( +unsigned char accel_hg_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_DURATION__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_DURATION, + accel_hg_dur); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_DURATION__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel high g threshold + * register byte from 14h + * + * + * + * + * \param + * unsigned char *accel_hg_thr : Pointer holding the + * accel high g threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_high_g_threshold( +unsigned char *accel_hg_thr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_THRESHOLD__REG, + &v_data_u8r, 1); + *accel_hg_thr = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_THRESHOLD); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel high g threshold + * register byte from 14h + * + * + * + * \param unsigned char accel_hg_thr + * + * accel_hg_thr + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_high_g_threshold( +unsigned char accel_hg_thr) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_THRESHOLD__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_HIGH_G_THRESHOLD, + accel_hg_thr); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_HIGH_G_THRESHOLD__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +/***************************************************************************** + * Description: *//**\brief Reads accel slow no motion threshold + * register byte from 15h + * + * + * + * + * \param + * unsigned char *accel_slow_no_thr : Pointer holding the + * accel slow no motion threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_slow_no_threshold( +unsigned char *accel_slow_no_thr) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NS_THRESHOLD__REG, + &v_data_u8r, 1); + *accel_slow_no_thr = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_NS_THRESHOLD); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel slow no motion threshold + * + * + * + * + * \param unsigned char accel_slow_no_thr + * + * accel_slow_no_thr + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_slow_no_threshold( +unsigned char accel_slow_no_thr) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NS_THRESHOLD__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_NS_THRESHOLD, + accel_slow_no_thr); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NS_THRESHOLD__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel no slow motion enable + * register byte from 16h + * + * + * + * + * \param + * unsigned char *accel_slow_no_en : Pointer holding the + * accel no slow motion enable + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_slow_no_motion_enable( +unsigned char *accel_slow_no_en) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_SM_ENABLE__REG, + &v_data_u8r, 1); + *accel_slow_no_en = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_NM_SM_ENABLE); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel no slow motion enable + * + * + * + * + * \param unsigned char accel_slow_no_en + * + * accel_slow_no_en + * 0 slow motion + * 1 no motion + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_slow_no_motion_enable( +unsigned char accel_slow_no_en) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_SM_ENABLE__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_NM_SM_ENABLE, + accel_slow_no_en); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NM_SM_ENABLE__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads accel slow no motion duration + * register byte from 16h + * + * + * + * + * \param + * unsigned char *accel_slow_no_dur : Pointer holding the + * accel slow no motion duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_slow_no_duration( +unsigned char *accel_slow_no_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NS_DURATION__REG, &v_data_u8r, 1); + *accel_slow_no_dur = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_ACC_NS_DURATION); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the accel slow no motion threshold + * + * + * + * + * \param unsigned char accel_slow_no_dur + * + * accel_slow_no_dur + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_slow_no_duration( +unsigned char accel_slow_no_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NS_DURATION__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_ACC_NS_DURATION, + accel_slow_no_dur); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_ACC_NS_DURATION__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to get the status of gyro Any + * motion Channel X,Y,Z + * + * + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of Any Enable channel number + * channel : + * BNO055_GYRO_AM_X_AXIS -> 0 + * BNO055_GYRO_AM_Y_AXIS -> 1 + * BNO055_GYRO_AM_Z_AXIS -> 2 + * unsigned char *data: Pointer holding the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * \return + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_anymotion_axis_enable( +unsigned char channel, unsigned char *data) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + switch (channel) { + case BNO055_GYRO_AM_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_X_AXIS__REG, &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_X_AXIS); + break; + case BNO055_GYRO_AM_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_Y_AXIS__REG, &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_Y_AXIS); + break; + case BNO055_GYRO_AM_Z_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_Z_AXIS__REG, &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_Z_AXIS); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set the status of Any Enable + * Channel X,Y,Z + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of Any Enable channel number + * channel : + * BNO055_GYRO_AM_X_AXIS -> 0 + * BNO055_GYRO_AM_Y_AXIS -> 1 + * BNO055_GYRO_AM_Z_AXIS -> 2 + * unsigned char *data: the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * + * + * + * \return communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_anymotion_axis_enable( +unsigned char channel, unsigned char data) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + switch (channel) { + case BNO055_GYRO_AM_X_AXIS: + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_X_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_AM_X_AXIS, + data); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_X_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_GYRO_AM_Y_AXIS: + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_Y_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_AM_Y_AXIS, data); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_Y_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_GYRO_AM_Z_AXIS: + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_Z_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_AM_Z_AXIS, + data); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_Z_AXIS__REG, + &v_data_u8r, 1); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/*************************************************************************** + * Description: *//**\brief This API is used to get the status of gyro high + * rate Channel X,Y,Z + * + * + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of high rate Enable channel number + * channel : + * BNO055_GYRO_HR_X_AXIS -> 0 + * BNO055_GYRO_HR_Y_AXIS -> 1 + * BNO055_GYRO_HR_Z_AXIS -> 2 + * unsigned char *data: Pointer holding the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * \return + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_axis_enable( +unsigned char channel, unsigned char *data) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + switch (channel) { + case BNO055_GYRO_HR_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_X_AXIS); + break; + case BNO055_GYRO_HR_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Y_AXIS); + break; + case BNO055_GYRO_HR_Z_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_AXIS__REG, + &v_data_u8r, 1); + *data = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Z_AXIS); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API is used to set the status of High rate + * Channel X,Y,Z + * + * + ** * \param Pointer holding the unsigned char channel : + * The value of high rate channel number + * channel : + * BNO055_GYRO_HR_X_AXIS -> 0 + * BNO055_GYRO_HR_Y_AXIS -> 1 + * BNO055_GYRO_HR_Z_AXIS -> 2 + * unsigned char *data: the Any Enable value + * data : + * Enable -> 1 + * disable -> 0 + * + * + * + * + * \return communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_axis_enable( +unsigned char channel, unsigned char data) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + switch (channel) { + case BNO055_GYRO_HR_X_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_HR_X_AXIS, data); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_GYRO_HR_Y_AXIS: + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE( + v_data_u8r, BNO055_GYR_HR_Y_AXIS, data); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_AXIS__REG, + &v_data_u8r, 1); + break; + case BNO055_GYRO_HR_Z_AXIS: + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_AXIS__REG, + &v_data_u8r, 1); + v_data_u8r = BNO055_SET_BITSLICE + (v_data_u8r, + BNO055_GYR_HR_Z_AXIS, data); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_AXIS__REG, + &v_data_u8r, 1); + break; + default: + comres = E_BNO055_OUT_OF_RANGE; + break; + } + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro any motion filter + * register byte from 17h + * + * + * + * + * \param + * unsigned char *gyro_am_filter : Pointer holding the + * gyro any motion filter + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_anymotion_filter( +unsigned char *gyro_am_filter) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_FILT__REG, &v_data_u8r, 1); + *gyro_am_filter = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_AM_FILT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro any motion filter + * + * + * + * + * \param unsigned char gyro_am_filter + * + * gyro_am_filter + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_anymotion_filter( +unsigned char gyro_am_filter) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_FILT__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_FILT, gyro_am_filter); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_FILT__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate filter + * register byte from 17h + * + * + * + * + * \param + * unsigned char *gyro_hr_filter : Pointer holding the + * gyro high rate filter + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_filter( +unsigned char *gyro_hr_filter) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_FILT__REG, &v_data_u8r, 1); + *gyro_hr_filter = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_FILT); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate filter + * + * + * + * + * \param unsigned char gyro_hr_filter + * + * gyro_hr_filter + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_filter( +unsigned char gyro_hr_filter) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = + p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_FILT__REG, + &v_data_u8r, + 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_FILT, gyro_hr_filter); + comres = + p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_FILT__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate X threshold + * register byte from 18h + * + * + * + * + * \param + * unsigned char *gyro_hr_x_thres : Pointer holding the + * gyro high rate X threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_x_threshold( +unsigned char *gyro_hr_x_thres) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_THRESH__REG, &v_data_u8r, 1); + *gyro_hr_x_thres = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_X_THRESH); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate X axis threshold + * + * + * + * + * \param unsigned char gyro_hr_x_thres + * + * gyro_hr_x_thres + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_x_threshold( +unsigned char gyro_hr_x_thres) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_THRESH__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_X_THRESH, + gyro_hr_x_thres); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_THRESH__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate X hysteresis + * register byte from 18h + * + * + * + * + * \param + * unsigned char *gyro_hr_x_hys : Pointer holding the + * gyro high rate X hysteresis + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_x_hysteresis( +unsigned char *gyro_hr_x_hys) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_HYST__REG, &v_data_u8r, 1); + *gyro_hr_x_hys = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_X_HYST); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate X axis hysteresis + * + * + * + * + * \param unsigned char gyro_hr_x_hys + * + * gyro_hr_x_hys + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_x_hysteresis( +unsigned char gyro_hr_x_hys) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_HYST__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_X_HYST, gyro_hr_x_hys); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_HYST__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate X duration + * register byte from 18h + * + * + * + * + * \param + * unsigned char *gyro_hr_x_dur : Pointer holding the + * gyro high rate X duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_x_duration( +unsigned char *gyro_hr_x_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_DUR__REG, &v_data_u8r, 1); + *gyro_hr_x_dur = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_X_DUR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate X axis duration + * + * + * + * + * \param unsigned char gyro_hr_x_dur + * + * gyro_hr_x_dur + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_x_duration( +unsigned char gyro_hr_x_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_X_DUR, + gyro_hr_x_dur); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_X_DUR__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate Y threshold + * register byte from 1Ah + * + * + * + * + * \param + * unsigned char *gyro_hr_y_thres : Pointer holding the + * gyro high rate Y threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_y_threshold( +unsigned char *gyro_hr_y_thres) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_THRESH__REG, &v_data_u8r, 1); + *gyro_hr_y_thres = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_Y_THRESH); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate Y axis threshold + * + * + * + * + * \param unsigned char gyro_hr_y_thres + * + * gyro_hr_y_thres + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_y_threshold( +unsigned char gyro_hr_y_thres) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_THRESH__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Y_THRESH, + gyro_hr_y_thres); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_THRESH__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate Y hysteresis + * register byte from 1Ah + * + * + * + * + * \param + * unsigned char *gyro_hr_y_hys : Pointer holding the + * gyro high rate Y hysteresis + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_y_hysteresis( +unsigned char *gyro_hr_y_hys) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_HYST__REG, &v_data_u8r, 1); + *gyro_hr_y_hys = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_Y_HYST); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate Y axis hysteresis + * + * + * + * + * \param unsigned char gyro_hr_y_hys + * + * gyro_hr_y_hys + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_y_hysteresis( +unsigned char gyro_hr_y_hys) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_HYST__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Y_HYST, gyro_hr_y_hys); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_HYST__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate Y duration + * register byte from 1Bh + * + * + * + * + * \param + * unsigned char *gyro_hr_y_dur : Pointer holding the + * gyro high rate Y duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_y_duration( +unsigned char *gyro_hr_y_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_DUR__REG, &v_data_u8r, 1); + *gyro_hr_y_dur = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_Y_DUR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate Y axis duration + * + * + * + * + * \param unsigned char gyro_hr_y_dur + * + * gyro_hr_y_dur + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_y_duration( +unsigned char gyro_hr_y_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Y_DUR, gyro_hr_y_dur); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Y_DUR__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate Z threshold + * register byte from 1Ch + * + * + * + * + * \param + * unsigned char *gyro_hr_z_thres : Pointer holding the + * gyro high rate Z threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_z_threshold( +unsigned char *gyro_hr_z_thres) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_THRESH__REG, &v_data_u8r, 1); + *gyro_hr_z_thres = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_Z_THRESH); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate Z axis threshold + * + * + * + * + * \param unsigned char gyro_hr_z_thres + * + * gyro_hr_z_thres + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_z_threshold( +unsigned char gyro_hr_z_thres) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_THRESH__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Z_THRESH, + gyro_hr_z_thres); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_THRESH__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate Z hysteresis + * register byte from 1Ch + * + * + * + * + * \param + * unsigned char *gyro_hr_z_hys : Pointer holding the + * gyro high rate Z hysteresis + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_z_hysteresis( +unsigned char *gyro_hr_z_hys) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_HYST__REG, &v_data_u8r, 1); + *gyro_hr_z_hys = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_HR_Z_HYST); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate Z axis hysteresis + * + * + * + * + * \param unsigned char gyro_hr_z_hys + * + * gyro_hr_z_hys + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_z_hysteresis( +unsigned char gyro_hr_z_hys) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_HYST__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Z_HYST, + gyro_hr_z_hys); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_HYST__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro high rate Z duration + * register byte from 1Dh + * + * + * + * + * \param + * unsigned char *gyro_hr_z_dur : Pointer holding the + * gyro high rate Z duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_z_duration( +unsigned char *gyro_hr_z_dur) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_DUR__REG, &v_data_u8r, 1); + *gyro_hr_z_dur = + BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Z_DUR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro high rate Z axis duration + * + * + * + * + * \param unsigned char gyro_hr_z_dur + * + * gyro_hr_z_dur + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_z_duration( +unsigned char gyro_hr_z_dur) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_HR_Z_DUR, gyro_hr_z_dur); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_HR_Z_DUR__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro any motion threshold + * register byte from 1Eh + * + * + * + * + * \param + * unsigned char *gyro_am_thres : Pointer holding the + * gyro any motion threshold + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_anymotion_threshold( +unsigned char *gyro_am_thres) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_THRES__REG, &v_data_u8r, 1); + *gyro_am_thres = + BNO055_GET_BITSLICE(v_data_u8r, BNO055_GYR_AM_THRES); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro any motion threshold + * + * + * + * + * \param unsigned char gyro_am_thres + * + * gyro_am_thres + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_anymotion_threshold( +unsigned char gyro_am_thres) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_THRES__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_AM_THRES, gyro_am_thres); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AM_THRES__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro any motion slope samples + * register byte from 1Fh + * + * + * + * + * \param + * unsigned char *gyro_am_slp : Pointer holding the + * gyro any motion slope samples + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_anymotion_slope_samples( +unsigned char *gyro_am_slp) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_SLOPE_SAMPLES__REG, &v_data_u8r, 1); + *gyro_am_slp = BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_SLOPE_SAMPLES); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro any motion slope samples + * + * + * + * + * \param unsigned char gyro_am_slp + * + * gyro_am_slp + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_anymotion_slope_samples( +unsigned char gyro_am_slp) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_SLOPE_SAMPLES__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_SLOPE_SAMPLES, gyro_am_slp); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_SLOPE_SAMPLES__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) + /* set the operation mode of + previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief Reads gyro any motion Awake duration + * register byte from 1Fh + * + * + * + * + * \param + * unsigned char *gyro_am_awk : Pointer holding the + * gyro any motion Awake duration + * + * + * \return + * Result of bus communication function + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_anymotion_awake_duration( +unsigned char *gyro_am_awk) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + unsigned char v_data_u8r = BNO055_Zero_U8X; + unsigned char status = BNO055_Zero_U8X; + if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; + } else { + status = bno055_write_page_id(PAGE_ONE); + if (status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AWAKE_DUR__REG, &v_data_u8r, 1); + *gyro_am_awk = BNO055_GET_BITSLICE(v_data_u8r, + BNO055_GYR_AWAKE_DUR); + } else { + return ERROR1; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/***************************************************************************** + * Description: *//**\brief This API sets the gyro any motion awake duration + * + * + * + * + * \param unsigned char gyro_am_awk + * + * gyro_am_awk + * + * + * + * \return Communication results + * + * + ***************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_anymotion_awake_duration( +unsigned char gyro_am_awk) +{ +BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; +unsigned char v_data_u8r = BNO055_Zero_U8X; +unsigned char status = BNO055_Zero_U8X; +unsigned char pg_status = BNO055_Zero_U8X; +unsigned char prev_opmode = BNO055_Zero_U8X; +if (p_bno055 == BNO055_Zero_U8X) { + return E_NULL_PTR; +} else { + status = bno055_get_operation_mode(&prev_opmode); + if (status == SUCCESS) { + if (prev_opmode != OPERATION_MODE_CONFIG) + status = bno055_set_operation_mode + (OPERATION_MODE_CONFIG); + if (status == SUCCESS) { + pg_status = bno055_write_page_id(PAGE_ONE); + if (pg_status == SUCCESS) { + comres = p_bno055->BNO055_BUS_READ_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AWAKE_DUR__REG, + &v_data_u8r, 1); + v_data_u8r = + BNO055_SET_BITSLICE(v_data_u8r, + BNO055_GYR_AWAKE_DUR, gyro_am_awk); + comres = p_bno055->BNO055_BUS_WRITE_FUNC + (p_bno055->dev_addr, + BNO055_GYR_AWAKE_DUR__REG, + &v_data_u8r, 1); + } else { + comres = ERROR1; + } + } else { + return ERROR1; + } + } else { + return ERROR1; + } + } + if (prev_opmode != OPERATION_MODE_CONFIG) { + /* set the operation mode + of previous operation mode*/ + bno055_set_operation_mode(prev_opmode); + } else { + return ERROR1; + } + return comres; +} diff --git a/arduino_libraries/BNO055-master/BNO055.h b/arduino_libraries/BNO055-master/BNO055.h new file mode 100644 index 0000000..fe92a1e --- /dev/null +++ b/arduino_libraries/BNO055-master/BNO055.h @@ -0,0 +1,2296 @@ +/* + *************************************************************************** + * + * bno055.h - part of sample SW for using BNO055 with Arduino + * + * Usage: BNO055 Sensor Driver Header File + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + + /****************************************************************************/ +/*! \file BNO050.h + \brief BNO055 Sensor Driver Support Header File */ + +#ifndef __BNO055_H__ +#define __BNO055_H__ + +#include /* needed to test integer limits */ + + +/* find correct data type for signed/unsigned 16 bit + variables by checking max of unsigned variant */ +#if USHRT_MAX == 0xFFFF + /* 16 bit achieved with short */ + #define BNO055_U16 unsigned short + #define BNO055_S16 signed short +#elif UINT_MAX == 0xFFFF + /* 16 bit achieved with int */ + #define BNO055_U16 unsigned int + #define BNO055_S16 signed int +#else + #error BNO055_U16 and BNO055_S16 could not be defined automatically, please do so manually +#endif + +/* For Enabling and Disabling the floating point API's */ +#define ENABLE_FLOAT + +#define BNO055_U16 unsigned short +#define BNO055_S16 signed short +#define BNO055_S32 signed int + + +#define BNO055_WR_FUNC_PTR int (*bus_write)(unsigned char, unsigned char , unsigned char *, unsigned char) + +#define BNO055_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len)bus_write(dev_addr, reg_addr, reg_data, wr_len) + +#define BNO055_RD_FUNC_PTR int (*bus_read)(unsigned char, unsigned char , unsigned char *, unsigned char) + +#define BNO055_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, r_len)bus_read(dev_addr, reg_addr, reg_data, r_len) + + + +#define BNO055_DELAY_RETURN_TYPE void + +#define BNO055_DELAY_PARAM_TYPES unsigned int + +#define BNO055_DELAY_FUNC(delay_in_msec)\ + delay_func(delay_in_msec) + + +/* bno055 I2C Address */ +#define BNO055_I2C_ADDR1 0x28 +#define BNO055_I2C_ADDR2 0x29 +#define BNO055_I2C_ADDR BNO055_I2C_ADDR1 + + +/* PAGE0 REGISTER DEFINITION START*/ +#define BNO055_CHIP_ID_ADDR 0x00 +#define BNO055_ACC_REV_ID_ADDR 0x01 +#define BNO055_MAG_REV_ID_ADDR 0x02 +#define BNO055_GYR_REV_ID_ADDR 0x03 +#define BNO055_SW_REV_ID_LSB_ADDR 0x04 +#define BNO055_SW_REV_ID_MSB_ADDR 0x05 +#define BNO055_BL_Rev_ID_ADDR 0X06 +#define BNO055_Page_ID_ADDR 0X07 + +/* Accel data register*/ +#define BNO055_ACC_DATA_X_LSB_ADDR 0X08 +#define BNO055_ACC_DATA_X_MSB_ADDR 0X09 +#define BNO055_ACC_DATA_Y_LSB_ADDR 0X0A +#define BNO055_ACC_DATA_Y_MSB_ADDR 0X0B +#define BNO055_ACC_DATA_Z_LSB_ADDR 0X0C +#define BNO055_ACC_DATA_Z_MSB_ADDR 0X0D + +/*Mag data register*/ +#define BNO055_MAG_DATA_X_LSB_ADDR 0X0E +#define BNO055_MAG_DATA_X_MSB_ADDR 0X0F +#define BNO055_MAG_DATA_Y_LSB_ADDR 0X10 +#define BNO055_MAG_DATA_Y_MSB_ADDR 0X11 +#define BNO055_MAG_DATA_Z_LSB_ADDR 0X12 +#define BNO055_MAG_DATA_Z_MSB_ADDR 0X13 + +/*Gyro data registers*/ +#define BNO055_GYR_DATA_X_LSB_ADDR 0X14 +#define BNO055_GYR_DATA_X_MSB_ADDR 0X15 +#define BNO055_GYR_DATA_Y_LSB_ADDR 0X16 +#define BNO055_GYR_DATA_Y_MSB_ADDR 0X17 +#define BNO055_GYR_DATA_Z_LSB_ADDR 0X18 +#define BNO055_GYR_DATA_Z_MSB_ADDR 0X19 + +/*Euler data registers*/ +#define BNO055_EUL_HEADING_LSB_ADDR 0X1A +#define BNO055_EUL_HEADING_MSB_ADDR 0X1B + +#define BNO055_EUL_ROLL_LSB_ADDR 0X1C +#define BNO055_EUL_ROLL_MSB_ADDR 0X1D + +#define BNO055_EUL_PITCH_LSB_ADDR 0X1E +#define BNO055_EUL_PITCH_MSB_ADDR 0X1F + +/*Quaternion data registers*/ +#define BNO055_QUA_DATA_W_LSB_ADDR 0X20 +#define BNO055_QUA_DATA_W_MSB_ADDR 0X21 +#define BNO055_QUA_DATA_X_LSB_ADDR 0X22 +#define BNO055_QUA_DATA_X_MSB_ADDR 0X23 +#define BNO055_QUA_DATA_Y_LSB_ADDR 0X24 +#define BNO055_QUA_DATA_Y_MSB_ADDR 0X25 +#define BNO055_QUA_DATA_Z_LSB_ADDR 0X26 +#define BNO055_QUA_DATA_Z_MSB_ADDR 0X27 + +/* Linear acceleration data registers*/ +#define BNO055_LIA_DATA_X_LSB_ADDR 0X28 +#define BNO055_LIA_DATA_X_MSB_ADDR 0X29 +#define BNO055_LIA_DATA_Y_LSB_ADDR 0X2A +#define BNO055_LIA_DATA_Y_MSB_ADDR 0X2B +#define BNO055_LIA_DATA_Z_LSB_ADDR 0X2C +#define BNO055_LIA_DATA_Z_MSB_ADDR 0X2D + +/*Gravity data registers*/ +#define BNO055_GRV_DATA_X_LSB_ADDR 0X2E +#define BNO055_GRV_DATA_X_MSB_ADDR 0X2F +#define BNO055_GRV_DATA_Y_LSB_ADDR 0X30 +#define BNO055_GRV_DATA_Y_MSB_ADDR 0X31 +#define BNO055_GRV_DATA_Z_LSB_ADDR 0X32 +#define BNO055_GRV_DATA_Z_MSB_ADDR 0X33 + +/* Temperature data register*/ + +#define BNO055_TEMP_ADDR 0X34 + +/* Status registers*/ +#define BNO055_CALIB_STAT_ADDR 0X35 +#define BNO055_ST_RESULT_ADDR 0X36 +#define BNO055_INT_STA_ADDR 0X37 +#define BNO055_SYS_STATUS_ADDR 0X39 +#define BNO055_SYS_ERR_ADDR 0X3A + +/* Unit selection register*/ +#define BNO055_UNIT_SEL_ADDR 0X3B +#define BNO055_DATA_SEL_ADDR 0X3C + +/* Mode registers*/ +#define BNO055_OPR_MODE_ADDR 0X3D +#define BNO055_PWR_MODE_ADDR 0X3E + +#define BNO055_SYS_TRIGGER_ADDR 0X3F +#define BNO055_TEMP_SOURCE_ADDR 0X40 +/* Axis remap registers*/ +#define BNO055_AXIS_MAP_CONFIG_ADDR 0X41 +#define BNO055_AXIS_MAP_SIGN_ADDR 0X42 + +/* SIC registers*/ +#define BNO055_SIC_MATRIX_0_LSB_ADDR 0X43 +#define BNO055_SIC_MATRIX_0_MSB_ADDR 0X44 +#define BNO055_SIC_MATRIX_1_LSB_ADDR 0X45 +#define BNO055_SIC_MATRIX_1_MSB_ADDR 0X46 +#define BNO055_SIC_MATRIX_2_LSB_ADDR 0X47 +#define BNO055_SIC_MATRIX_2_MSB_ADDR 0X48 +#define BNO055_SIC_MATRIX_3_LSB_ADDR 0X49 +#define BNO055_SIC_MATRIX_3_MSB_ADDR 0X4A +#define BNO055_SIC_MATRIX_4_LSB_ADDR 0X4B +#define BNO055_SIC_MATRIX_4_MSB_ADDR 0X4C +#define BNO055_SIC_MATRIX_5_LSB_ADDR 0X4D +#define BNO055_SIC_MATRIX_5_MSB_ADDR 0X4E +#define BNO055_SIC_MATRIX_6_LSB_ADDR 0X4F +#define BNO055_SIC_MATRIX_6_MSB_ADDR 0X50 +#define BNO055_SIC_MATRIX_7_LSB_ADDR 0X51 +#define BNO055_SIC_MATRIX_7_MSB_ADDR 0X52 +#define BNO055_SIC_MATRIX_8_LSB_ADDR 0X53 +#define BNO055_SIC_MATRIX_8_MSB_ADDR 0X54 + +/* Accelerometer Offset registers*/ +#define ACC_OFFSET_X_LSB_ADDR 0X55 +#define ACC_OFFSET_X_MSB_ADDR 0X56 +#define ACC_OFFSET_Y_LSB_ADDR 0X57 +#define ACC_OFFSET_Y_MSB_ADDR 0X58 +#define ACC_OFFSET_Z_LSB_ADDR 0X59 +#define ACC_OFFSET_Z_MSB_ADDR 0X5A + +/* Magnetometer Offset registers*/ +#define MAG_OFFSET_X_LSB_ADDR 0X5B +#define MAG_OFFSET_X_MSB_ADDR 0X5C +#define MAG_OFFSET_Y_LSB_ADDR 0X5D +#define MAG_OFFSET_Y_MSB_ADDR 0X5E +#define MAG_OFFSET_Z_LSB_ADDR 0X5F +#define MAG_OFFSET_Z_MSB_ADDR 0X60 + +/* Gyroscope Offset registers*/ +#define GYRO_OFFSET_X_LSB_ADDR 0X61 +#define GYRO_OFFSET_X_MSB_ADDR 0X62 +#define GYRO_OFFSET_Y_LSB_ADDR 0X63 +#define GYRO_OFFSET_Y_MSB_ADDR 0X64 +#define GYRO_OFFSET_Z_LSB_ADDR 0X65 +#define GYRO_OFFSET_Z_MSB_ADDR 0X66 + +/* PAGE0 REGISTERS DEFINITION END*/ + +/* PAGE1 REGISTERS DEFINITION START*/ +/* Configuration registers*/ +#define ACC_CONFIG_ADDR 0X08 +#define MAG_CONFIG_ADDR 0X09 +#define GYRO_CONFIG_ADDR 0X0A +#define GYRO_MODE_CONFIG_ADDR 0X0B +#define ACC_SLEEP_CONFIG_ADDR 0X0C +#define GYR_SLEEP_CONFIG_ADDR 0X0D +#define MAG_SLEEP_CONFIG_ADDR 0x0E + +/* Interrupt registers*/ +#define INT_MSK_ADDR 0X0F +#define INT_ADDR 0X10 +#define ACC_AM_THRES_ADDR 0X11 +#define ACC_INT_SETTINGS_ADDR 0X12 +#define ACC_HG_DURATION_ADDR 0X13 +#define ACC_HG_THRES_ADDR 0X14 +#define ACC_NM_THRES_ADDR 0X15 +#define ACC_NM_SET_ADDR 0X16 +#define GYR_INT_SETING_ADDR 0X17 +#define GYR_HR_X_SET_ADDR 0X18 +#define GYR_DUR_X_ADDR 0X19 +#define GYR_HR_Y_SET_ADDR 0X1A +#define GYR_DUR_Y_ADDR 0X1B +#define GYR_HR_Z_SET_ADDR 0X1C +#define GYR_DUR_Z_ADDR 0X1D +#define GYR_AM_THRES_ADDR 0X1E +#define GYR_AM_SET_ADDR 0X1F +/* PAGE1 REGISTERS DEFINITION END*/ + + +#define BNO055_MDELAY_DATA_TYPE unsigned int + +/*< This refers BNO055 return type as int */ +#define BNO055_RETURN_FUNCTION_TYPE int + + +/*BNO055-STRUCT*/ +struct bno055_t { +unsigned char chip_id; +unsigned char sw_revision_id; +unsigned char page_id; +unsigned char accel_revision_id; +unsigned char mag_revision_id; +unsigned char gyro_revision_id; +unsigned char bootloader_revision_id; +unsigned char dev_addr; +BNO055_WR_FUNC_PTR; +BNO055_RD_FUNC_PTR; +void (*delay_msec)(BNO055_MDELAY_DATA_TYPE); +}; + +/*BNO055-Accel x,y,z*/ +struct bno055_accel { +BNO055_S16 x; +BNO055_S16 y; +BNO055_S16 z; + +}; + +/*BNO055-mag x,y,z*/ +struct bno055_mag { +BNO055_S16 x; +BNO055_S16 y; +BNO055_S16 z; + +}; + +/*BNO055-Gyro x,y,z*/ +struct bno055_gyro { +BNO055_S16 x; +BNO055_S16 y; +BNO055_S16 z; + +}; + +/*BNO055-Euler h,r,p*/ +struct bno055_euler { +BNO055_S16 h; +BNO055_S16 r; +BNO055_S16 p; + +}; + +/*BNO055-quaternion w,x,y,z*/ +struct bno055_quaternion { +BNO055_S16 w; +BNO055_S16 x; +BNO055_S16 y; +BNO055_S16 z; + +}; + +/*BNO055-Linear Accel x,y,z*/ +struct bno055_linear_accel { +BNO055_S16 x; +BNO055_S16 y; +BNO055_S16 z; + +}; + +/*BNO055-Gravity x,y,z*/ +struct bno055_gravity { +BNO055_S16 x; +BNO055_S16 y; +BNO055_S16 z; + +}; + + +#define BNO055_Zero_U8X (unsigned char)0 +#define BNO055_Two_U8X (unsigned char)2 +#define BNO055_Four_U8X (unsigned char)4 +#define BNO055_Five_U8X (unsigned char)5 +#define BNO055_Six_U8X (unsigned char)6 +#define BNO055_Seven_U8X (unsigned char)7 +#define BNO055_Eleven_U8X (unsigned char)11 +#define BNO055_Sixteen_U8X (unsigned char)16 +#define BNO055_Eight_U8X (unsigned char)8 + + +#define BNO055_SHIFT_8_POSITION (unsigned char)8 + + +/* BNO055 API error codes */ +#define E_NULL_PTR (char)(-127) +#define E_BNO055_OUT_OF_RANGE (signed char)(-2) +#define SUCCESS (unsigned char)0 +#define ERROR1 (signed char)(-1) + +/* Page ID */ +#define PAGE_ZERO 0X00 +#define PAGE_ONE 0X01 + + +/* Operation mode settings*/ +#define OPERATION_MODE_CONFIG 0X00 +#define OPERATION_MODE_ACCONLY 0X01 +#define OPERATION_MODE_MAGONLY 0X02 +#define OPERATION_MODE_GYRONLY 0X03 +#define OPERATION_MODE_ACCMAG 0X04 +#define OPERATION_MODE_ACCGYRO 0X05 +#define OPERATION_MODE_MAGGYRO 0X06 +#define OPERATION_MODE_AMG 0X07 +#define OPERATION_MODE_IMUPLUS 0X08 +#define OPERATION_MODE_COMPASS 0X09 +#define OPERATION_MODE_M4G 0X0A +#define OPERATION_MODE_NDOF_FMC_OFF 0X0B +#define OPERATION_MODE_NDOF 0X0C + +/* BNO055 Power mode settings*/ +#define POWER_MODE_NORMAL 0x00 +#define POWER_MODE_LOW_POWER 0x01 +#define POWER_MODE_SUSPEND 0x02 + +/* Data output rates*/ +#define FASTEST_MODE_1 0X00 +#define FASTEST_MODE_2 0X01 +#define GAME_MODE 0X02 +#define UI_MODE 0X04 +#define NORMAL_MODE 0X05 + +/* PAGE-1 definitions*/ +/* Accel Range */ + +#define ACCEL_RANGE_2G 0X00 +#define ACCEL_RANGE_4G 0X01 +#define ACCEL_RANGE_8G 0X02 +#define ACCEL_RANGE_16G 0X03 + +/* Accel Bandwidth*/ +#define ACCEL_BW_7_81Hz 0x00 +#define ACCEL_BW_15_63Hz 0x01 +#define ACCEL_BW_31_25Hz 0x02 +#define ACCEL_BW_62_5Hz 0X03 +#define ACCEL_BW_125Hz 0X04 +#define ACCEL_BW_250Hz 0X05 +#define ACCEL_BW_500Hz 0X06 +#define ACCEL_BW_1000Hz 0X07 + +/* Accel Power mode*/ +#define ACCEL_NORMAL 0X00 +#define ACCEL_SUSPEND 0X01 +#define ACCEL_LOWPOWER_1 0X02 +#define ACCEL_STANDBY 0X03 +#define ACCEL_LOWPOWER_2 0X04 +#define ACCEL_DEEPSUSPEND 0X05 + +/* Mag data output rate*/ +#define MAG_DATA_OUTRATE_2Hz 0X00 +#define MAG_DATA_OUTRATE_6Hz 0X01 +#define MAG_DATA_OUTRATE_8Hz 0X02 +#define MAG_DATA_OUTRATE_10Hz 0X03 +#define MAG_DATA_OUTRATE_15Hz 0X04 +#define MAG_DATA_OUTRATE_20Hz 0X05 +#define MAG_DATA_OUTRATE_25Hz 0X06 +#define MAG_DATA_OUTRATE_30Hz 0X07 + +/* Mag Operation mode*/ +#define MAG_OPR_MODE_LOWPOWER 0X00 +#define MAG_OPR_MODE_REGULAR 0X01 +#define MAG_OPR_MODE_ENHANCED_REGULAR 0X02 +#define MAG_OPR_MODE_HIGH_ACCURACY 0X03 + +/* Mag power mode*/ +#define MAG_POWER_MODE_NORMAL 0X00 +#define MAG_POWER_MODE_SLEEP 0X01 +#define MAG_POWER_MODE_SUSPEND 0X02 +#define MAG_POWER_MODE_FORCE_MODE 0X03 + +/* Gyro range*/ +#define GYRO_RANGE_2000rps 0x00 +#define GYRO_RANGE_1000rps 0x01 +#define GYRO_RANGE_500rps 0x02 +#define GYRO_RANGE_250rps 0x03 +#define GYRO_RANGE_125rps 0x04 + +/* Gyro Bandwidth*/ +#define GYRO_BW_523Hz 0x00 +#define GYRO_BW_230Hz 0x01 +#define GYRO_BW_116Hz 0x02 +#define GYRO_BW_47Hz 0x03 +#define GYRO_BW_23Hz 0x04 +#define GYRO_BW_12Hz 0x05 +#define GYRO_BW_64Hz 0x06 +#define GYRO_BW_32Hz 0x07 + +/* Gyro Operation mode*/ +#define GYRO_OPR_MODE_NORMAL 0X00 +#define GYRO_OPR_MODE_FASTPOWERUP 0X01 +#define GYRO_OPR_MODE_DEEPSUSPEND 0X02 +#define GYRO_OPR_MODE_SUSPEND 0X03 +#define GYRO_OPR_MODE_ADVANCE_POWERSAVE 0X04 + +/* Accel Sleep Duration */ + +#define BNO055_ACCEL_SLEEP_DUR_0_5MS 0x05 +/* sets sleep duration to 0.5 ms */ +#define BNO055_ACCEL_SLEEP_DUR_1MS 0x06 +/* sets sleep duration to 1 ms */ +#define BNO055_ACCEL_SLEEP_DUR_2MS 0x07 +/* sets sleep duration to 2 ms */ +#define BNO055_ACCEL_SLEEP_DUR_4MS 0x08 +/* sets sleep duration to 4 ms */ +#define BNO055_ACCEL_SLEEP_DUR_6MS 0x09 +/* sets sleep duration to 6 ms*/ +#define BNO055_ACCEL_SLEEP_DUR_10MS 0x0A +/* sets sleep duration to 10 ms */ +#define BNO055_ACCEL_SLEEP_DUR_25MS 0x0B + /* sets sleep duration to 25 ms */ +#define BNO055_ACCEL_SLEEP_DUR_50MS 0x0C + /* sets sleep duration to 50 ms */ +#define BNO055_ACCEL_SLEEP_DUR_100MS 0x0D + /* sets sleep duration to 100 ms */ +#define BNO055_ACCEL_SLEEP_DUR_500MS 0x0E + /* sets sleep duration to 500 ms */ +#define BNO055_ACCEL_SLEEP_DUR_1S 0x0F +/* sets sleep duration to 1 s */ + +/* Gyro Auto sleep duration*/ +#define BNO055_GYRO_No_AuSlpDur 0x00 +#define BNO055_GYRO_4ms_AuSlpDur 0x01 +#define BNO055_GYRO_5ms_AuSlpDur 0x02 +#define BNO055_GYRO_8ms_AuSlpDur 0x03 +#define BNO055_GYRO_10ms_AuSlpDur 0x04 +#define BNO055_GYRO_15ms_AuSlpDur 0x05 +#define BNO055_GYRO_20ms_AuSlpDur 0x06 +#define BNO055_GYRO_40ms_AuSlpDur 0x07 + +/* Accel Any/No motion axis selection*/ +#define BNO055_ACCEL_AM_NM_X_AXIS 0 +#define BNO055_ACCEL_AM_NM_Y_AXIS 1 +#define BNO055_ACCEL_AM_NM_Z_AXIS 2 + +/* Accel High g axis selection*/ +#define BNO055_ACCEL_HIGH_G_X_AXIS 0 +#define BNO055_ACCEL_HIGH_G_Y_AXIS 1 +#define BNO055_ACCEL_HIGH_G_Z_AXIS 2 + +/* Gyro Any motion axis selection*/ +#define BNO055_GYRO_AM_X_AXIS 0 +#define BNO055_GYRO_AM_Y_AXIS 1 +#define BNO055_GYRO_AM_Z_AXIS 2 + + +/* Gyro High rate axis selection*/ +#define BNO055_GYRO_HR_X_AXIS 0 +#define BNO055_GYRO_HR_Y_AXIS 1 +#define BNO055_GYRO_HR_Z_AXIS 2 + +/* Axis remap values*/ +#define REMAP_X_Y 0X21 +#define REMAP_Y_Z 0X18 +#define REMAP_Z_X 0X06 +#define REMAP_X_Y_Z_TYPE0 0X12 +#define REMAP_X_Y_Z_TYPE1 0X09 +#define DEFAULT_AXIS 0X24 + + +/* PAGE0 DATA REGISTERS DEFINITION START*/ +/* Chip ID*/ +#define BNO055_CHIP_ID__POS 0 +#define BNO055_CHIP_ID__MSK 0xFF +#define BNO055_CHIP_ID__LEN 8 +#define BNO055_CHIP_ID__REG BNO055_CHIP_ID_ADDR + +/* Accel revision id*/ +#define BNO055_ACC_REV_ID__POS 0 +#define BNO055_ACC_REV_ID__MSK 0xFF +#define BNO055_ACC_REV_ID__LEN 8 +#define BNO055_ACC_REV_ID__REG BNO055_ACC_REV_ID_ADDR + +/* Mag revision id*/ +#define BNO055_MAG_REV_ID__POS 0 +#define BNO055_MAG_REV_ID__MSK 0xFF +#define BNO055_MAG_REV_ID__LEN 8 +#define BNO055_MAG_REV_ID__REG BNO055_MAG_REV_ID_ADDR + +/* Gyro revision id*/ +#define BNO055_GYR_REV_ID__POS 0 +#define BNO055_GYR_REV_ID__MSK 0xFF +#define BNO055_GYR_REV_ID__LEN 8 +#define BNO055_GYR_REV_ID__REG BNO055_GYR_REV_ID_ADDR + +/*Software revision id LSB*/ +#define BNO055_SW_REV_ID_LSB__POS 0 +#define BNO055_SW_REV_ID_LSB__MSK 0xFF +#define BNO055_SW_REV_ID_LSB__LEN 8 +#define BNO055_SW_REV_ID_LSB__REG BNO055_SW_REV_ID_LSB_ADDR + +/*Software revision id MSB*/ +#define BNO055_SW_REV_ID_MSB__POS 0 +#define BNO055_SW_REV_ID_MSB__MSK 0xFF +#define BNO055_SW_REV_ID_MSB__LEN 8 +#define BNO055_SW_REV_ID_MSB__REG BNO055_SW_REV_ID_MSB_ADDR + +/* BOOTLOADER revision id*/ +#define BNO055_BL_Rev_ID__POS 0 +#define BNO055_BL_Rev_ID__MSK 0xFF +#define BNO055_BL_Rev_ID__LEN 8 +#define BNO055_BL_Rev_ID__REG BNO055_BL_Rev_ID_ADDR + +/*Page id*/ +#define BNO055_Page_ID__POS 0 +#define BNO055_Page_ID__MSK 0xFF +#define BNO055_Page_ID__LEN 8 +#define BNO055_Page_ID__REG BNO055_Page_ID_ADDR + +/* Accel data X-LSB register*/ +#define BNO055_ACC_DATA_X_LSB_VALUEX__POS 0 +#define BNO055_ACC_DATA_X_LSB_VALUEX__MSK 0xFF +#define BNO055_ACC_DATA_X_LSB_VALUEX__LEN 8 +#define BNO055_ACC_DATA_X_LSB_VALUEX__REG BNO055_ACC_DATA_X_LSB_ADDR + +/* Accel data X-MSB register*/ +#define BNO055_ACC_DATA_X_MSB_VALUEX__POS 0 +#define BNO055_ACC_DATA_X_MSB_VALUEX__MSK 0xFF +#define BNO055_ACC_DATA_X_MSB_VALUEX__LEN 8 +#define BNO055_ACC_DATA_X_MSB_VALUEX__REG BNO055_ACC_DATA_X_MSB_ADDR + +/* Accel data Y-LSB register*/ +#define BNO055_ACC_DATA_Y_LSB_VALUEY__POS 0 +#define BNO055_ACC_DATA_Y_LSB_VALUEY__MSK 0xFF +#define BNO055_ACC_DATA_Y_LSB_VALUEY__LEN 8 +#define BNO055_ACC_DATA_Y_LSB_VALUEY__REG BNO055_ACC_DATA_Y_LSB_ADDR + +/* Accel data Y-MSB register*/ +#define BNO055_ACC_DATA_Y_MSB_VALUEY__POS 0 +#define BNO055_ACC_DATA_Y_MSB_VALUEY__MSK 0xFF +#define BNO055_ACC_DATA_Y_MSB_VALUEY__LEN 8 +#define BNO055_ACC_DATA_Y_MSB_VALUEY__REG BNO055_ACC_DATA_Y_MSB_ADDR + +/* Accel data Z-LSB register*/ +#define BNO055_ACC_DATA_Z_LSB_VALUEZ__POS 0 +#define BNO055_ACC_DATA_Z_LSB_VALUEZ__MSK 0xFF +#define BNO055_ACC_DATA_Z_LSB_VALUEZ__LEN 8 +#define BNO055_ACC_DATA_Z_LSB_VALUEZ__REG BNO055_ACC_DATA_Z_LSB_ADDR + +/* Accel data Z-MSB register*/ +#define BNO055_ACC_DATA_Z_MSB_VALUEZ__POS 0 +#define BNO055_ACC_DATA_Z_MSB_VALUEZ__MSK 0xFF +#define BNO055_ACC_DATA_Z_MSB_VALUEZ__LEN 8 +#define BNO055_ACC_DATA_Z_MSB_VALUEZ__REG BNO055_ACC_DATA_Z_MSB_ADDR + +/* Mag data X-LSB register*/ +#define BNO055_MAG_DATA_X_LSB_VALUEX__POS 0 +#define BNO055_MAG_DATA_X_LSB_VALUEX__MSK 0xFF +#define BNO055_MAG_DATA_X_LSB_VALUEX__LEN 8 +#define BNO055_MAG_DATA_X_LSB_VALUEX__REG BNO055_MAG_DATA_X_LSB_ADDR + +/* Mag data X-MSB register*/ +#define BNO055_MAG_DATA_X_MSB_VALUEX__POS 0 +#define BNO055_MAG_DATA_X_MSB_VALUEX__MSK 0xFF +#define BNO055_MAG_DATA_X_MSB_VALUEX__LEN 8 +#define BNO055_MAG_DATA_X_MSB_VALUEX__REG BNO055_MAG_DATA_X_MSB_ADDR + +/* Mag data Y-LSB register*/ +#define BNO055_MAG_DATA_Y_LSB_VALUEY__POS 0 +#define BNO055_MAG_DATA_Y_LSB_VALUEY__MSK 0xFF +#define BNO055_MAG_DATA_Y_LSB_VALUEY__LEN 8 +#define BNO055_MAG_DATA_Y_LSB_VALUEY__REG BNO055_MAG_DATA_Y_LSB_ADDR + +/* Mag data Y-MSB register*/ +#define BNO055_MAG_DATA_Y_MSB_VALUEY__POS 0 +#define BNO055_MAG_DATA_Y_MSB_VALUEY__MSK 0xFF +#define BNO055_MAG_DATA_Y_MSB_VALUEY__LEN 8 +#define BNO055_MAG_DATA_Y_MSB_VALUEY__REG BNO055_MAG_DATA_Y_MSB_ADDR + +/* Mag data Z-LSB register*/ +#define BNO055_MAG_DATA_Z_LSB_VALUEZ__POS 0 +#define BNO055_MAG_DATA_Z_LSB_VALUEZ__MSK 0xFF +#define BNO055_MAG_DATA_Z_LSB_VALUEZ__LEN 8 +#define BNO055_MAG_DATA_Z_LSB_VALUEZ__REG BNO055_MAG_DATA_Z_LSB_ADDR + +/* Mag data Z-MSB register*/ +#define BNO055_MAG_DATA_Z_MSB_VALUEZ__POS 0 +#define BNO055_MAG_DATA_Z_MSB_VALUEZ__MSK 0xFF +#define BNO055_MAG_DATA_Z_MSB_VALUEZ__LEN 8 +#define BNO055_MAG_DATA_Z_MSB_VALUEZ__REG BNO055_MAG_DATA_Z_MSB_ADDR + +/* Gyro data X-LSB register*/ +#define BNO055_GYR_DATA_X_LSB_VALUEX__POS 0 +#define BNO055_GYR_DATA_X_LSB_VALUEX__MSK 0xFF +#define BNO055_GYR_DATA_X_LSB_VALUEX__LEN 8 +#define BNO055_GYR_DATA_X_LSB_VALUEX__REG BNO055_GYR_DATA_X_LSB_ADDR + +/* Gyro data X-MSB register*/ +#define BNO055_GYR_DATA_X_MSB_VALUEX__POS 0 +#define BNO055_GYR_DATA_X_MSB_VALUEX__MSK 0xFF +#define BNO055_GYR_DATA_X_MSB_VALUEX__LEN 8 +#define BNO055_GYR_DATA_X_MSB_VALUEX__REG BNO055_GYR_DATA_X_MSB_ADDR + +/* Gyro data Y-LSB register*/ +#define BNO055_GYR_DATA_Y_LSB_VALUEY__POS 0 +#define BNO055_GYR_DATA_Y_LSB_VALUEY__MSK 0xFF +#define BNO055_GYR_DATA_Y_LSB_VALUEY__LEN 8 +#define BNO055_GYR_DATA_Y_LSB_VALUEY__REG BNO055_GYR_DATA_Y_LSB_ADDR + +/* Gyro data Y-MSB register*/ +#define BNO055_GYR_DATA_Y_MSB_VALUEY__POS 0 +#define BNO055_GYR_DATA_Y_MSB_VALUEY__MSK 0xFF +#define BNO055_GYR_DATA_Y_MSB_VALUEY__LEN 8 +#define BNO055_GYR_DATA_Y_MSB_VALUEY__REG BNO055_GYR_DATA_Y_MSB_ADDR + +/* Gyro data Z-LSB register*/ +#define BNO055_GYR_DATA_Z_LSB_VALUEZ__POS 0 +#define BNO055_GYR_DATA_Z_LSB_VALUEZ__MSK 0xFF +#define BNO055_GYR_DATA_Z_LSB_VALUEZ__LEN 8 +#define BNO055_GYR_DATA_Z_LSB_VALUEZ__REG BNO055_GYR_DATA_Z_LSB_ADDR + +/* Gyro data Z-MSB register*/ +#define BNO055_GYR_DATA_Z_MSB_VALUEZ__POS 0 +#define BNO055_GYR_DATA_Z_MSB_VALUEZ__MSK 0xFF +#define BNO055_GYR_DATA_Z_MSB_VALUEZ__LEN 8 +#define BNO055_GYR_DATA_Z_MSB_VALUEZ__REG BNO055_GYR_DATA_Z_MSB_ADDR + +/* Euler data HEADING-LSB register*/ +#define BNO055_EUL_HEADING_LSB_VALUEH__POS 0 +#define BNO055_EUL_HEADING_LSB_VALUEH__MSK 0xFF +#define BNO055_EUL_HEADING_LSB_VALUEH__LEN 8 +#define BNO055_EUL_HEADING_LSB_VALUEH__REG BNO055_EUL_HEADING_LSB_ADDR + +/* Euler data HEADING-MSB register*/ +#define BNO055_EUL_HEADING_MSB_VALUEH__POS 0 +#define BNO055_EUL_HEADING_MSB_VALUEH__MSK 0xFF +#define BNO055_EUL_HEADING_MSB_VALUEH__LEN 8 +#define BNO055_EUL_HEADING_MSB_VALUEH__REG BNO055_EUL_HEADING_MSB_ADDR + +/* Euler data ROLL-LSB register*/ +#define BNO055_EUL_ROLL_LSB_VALUER__POS 0 +#define BNO055_EUL_ROLL_LSB_VALUER__MSK 0xFF +#define BNO055_EUL_ROLL_LSB_VALUER__LEN 8 +#define BNO055_EUL_ROLL_LSB_VALUER__REG BNO055_EUL_ROLL_LSB_ADDR + +/* Euler data ROLL-MSB register*/ +#define BNO055_EUL_ROLL_MSB_VALUER__POS 0 +#define BNO055_EUL_ROLL_MSB_VALUER__MSK 0xFF +#define BNO055_EUL_ROLL_MSB_VALUER__LEN 8 +#define BNO055_EUL_ROLL_MSB_VALUER__REG BNO055_EUL_ROLL_MSB_ADDR + +/* Euler data PITCH-LSB register*/ +#define BNO055_EUL_PITCH_LSB_VALUEP__POS 0 +#define BNO055_EUL_PITCH_LSB_VALUEP__MSK 0xFF +#define BNO055_EUL_PITCH_LSB_VALUEP__LEN 8 +#define BNO055_EUL_PITCH_LSB_VALUEP__REG BNO055_EUL_PITCH_LSB_ADDR + +/* Euler data HEADING-MSB register*/ +#define BNO055_EUL_PITCH_MSB_VALUEP__POS 0 +#define BNO055_EUL_PITCH_MSB_VALUEP__MSK 0xFF +#define BNO055_EUL_PITCH_MSB_VALUEP__LEN 8 +#define BNO055_EUL_PITCH_MSB_VALUEP__REG BNO055_EUL_PITCH_MSB_ADDR + +/* Quaternion data W-LSB register*/ +#define BNO055_QUA_DATA_W_LSB_VALUEW__POS 0 +#define BNO055_QUA_DATA_W_LSB_VALUEW__MSK 0xFF +#define BNO055_QUA_DATA_W_LSB_VALUEW__LEN 8 +#define BNO055_QUA_DATA_W_LSB_VALUEW__REG BNO055_QUA_DATA_W_LSB_ADDR + +/* Quaternion data W-MSB register*/ +#define BNO055_QUA_DATA_W_MSB_VALUEW__POS 0 +#define BNO055_QUA_DATA_W_MSB_VALUEW__MSK 0xFF +#define BNO055_QUA_DATA_W_MSB_VALUEW__LEN 8 +#define BNO055_QUA_DATA_W_MSB_VALUEW__REG BNO055_QUA_DATA_W_MSB_ADDR + +/* Quaternion data X-LSB register*/ +#define BNO055_QUA_DATA_X_LSB_VALUEX__POS 0 +#define BNO055_QUA_DATA_X_LSB_VALUEX__MSK 0xFF +#define BNO055_QUA_DATA_X_LSB_VALUEX__LEN 8 +#define BNO055_QUA_DATA_X_LSB_VALUEX__REG BNO055_QUA_DATA_X_LSB_ADDR + +/* Quaternion data X-MSB register*/ +#define BNO055_QUA_DATA_X_MSB_VALUEX__POS 0 +#define BNO055_QUA_DATA_X_MSB_VALUEX__MSK 0xFF +#define BNO055_QUA_DATA_X_MSB_VALUEX__LEN 8 +#define BNO055_QUA_DATA_X_MSB_VALUEX__REG BNO055_QUA_DATA_X_MSB_ADDR + +/* Quaternion data Y-LSB register*/ +#define BNO055_QUA_DATA_Y_LSB_VALUEY__POS 0 +#define BNO055_QUA_DATA_Y_LSB_VALUEY__MSK 0xFF +#define BNO055_QUA_DATA_Y_LSB_VALUEY__LEN 8 +#define BNO055_QUA_DATA_Y_LSB_VALUEY__REG BNO055_QUA_DATA_Y_LSB_ADDR + +/* Quaternion data Y-MSB register*/ +#define BNO055_QUA_DATA_Y_MSB_VALUEY__POS 0 +#define BNO055_QUA_DATA_Y_MSB_VALUEY__MSK 0xFF +#define BNO055_QUA_DATA_Y_MSB_VALUEY__LEN 8 +#define BNO055_QUA_DATA_Y_MSB_VALUEY__REG BNO055_QUA_DATA_Y_MSB_ADDR + +/* Quaternion data Z-LSB register*/ +#define BNO055_QUA_DATA_Z_LSB_VALUEZ__POS 0 +#define BNO055_QUA_DATA_Z_LSB_VALUEZ__MSK 0xFF +#define BNO055_QUA_DATA_Z_LSB_VALUEZ__LEN 8 +#define BNO055_QUA_DATA_Z_LSB_VALUEZ__REG BNO055_QUA_DATA_Z_LSB_ADDR + +/* Quaternion data Z-MSB register*/ +#define BNO055_QUA_DATA_Z_MSB_VALUEZ__POS 0 +#define BNO055_QUA_DATA_Z_MSB_VALUEZ__MSK 0xFF +#define BNO055_QUA_DATA_Z_MSB_VALUEZ__LEN 8 +#define BNO055_QUA_DATA_Z_MSB_VALUEZ__REG BNO055_QUA_DATA_Z_MSB_ADDR + +/* Linear acceleration data X-LSB register*/ +#define BNO055_LIA_DATA_X_LSB_VALUEX__POS 0 +#define BNO055_LIA_DATA_X_LSB_VALUEX__MSK 0xFF +#define BNO055_LIA_DATA_X_LSB_VALUEX__LEN 8 +#define BNO055_LIA_DATA_X_LSB_VALUEX__REG BNO055_LIA_DATA_X_LSB_ADDR + +/* Linear acceleration data X-MSB register*/ +#define BNO055_LIA_DATA_X_MSB_VALUEX__POS 0 +#define BNO055_LIA_DATA_X_MSB_VALUEX__MSK 0xFF +#define BNO055_LIA_DATA_X_MSB_VALUEX__LEN 8 +#define BNO055_LIA_DATA_X_MSB_VALUEX__REG BNO055_LIA_DATA_X_MSB_ADDR + +/* Linear acceleration data Y-LSB register*/ +#define BNO055_LIA_DATA_Y_LSB_VALUEY__POS 0 +#define BNO055_LIA_DATA_Y_LSB_VALUEY__MSK 0xFF +#define BNO055_LIA_DATA_Y_LSB_VALUEY__LEN 8 +#define BNO055_LIA_DATA_Y_LSB_VALUEY__REG BNO055_LIA_DATA_Y_LSB_ADDR + +/* Linear acceleration data Y-MSB register*/ +#define BNO055_LIA_DATA_Y_MSB_VALUEY__POS 0 +#define BNO055_LIA_DATA_Y_MSB_VALUEY__MSK 0xFF +#define BNO055_LIA_DATA_Y_MSB_VALUEY__LEN 8 +#define BNO055_LIA_DATA_Y_MSB_VALUEY__REG BNO055_LIA_DATA_Y_MSB_ADDR + +/* Linear acceleration data Z-LSB register*/ +#define BNO055_LIA_DATA_Z_LSB_VALUEZ__POS 0 +#define BNO055_LIA_DATA_Z_LSB_VALUEZ__MSK 0xFF +#define BNO055_LIA_DATA_Z_LSB_VALUEZ__LEN 8 +#define BNO055_LIA_DATA_Z_LSB_VALUEZ__REG BNO055_LIA_DATA_Z_LSB_ADDR + +/* Linear acceleration data Z-MSB register*/ +#define BNO055_LIA_DATA_Z_MSB_VALUEZ__POS 0 +#define BNO055_LIA_DATA_Z_MSB_VALUEZ__MSK 0xFF +#define BNO055_LIA_DATA_Z_MSB_VALUEZ__LEN 8 +#define BNO055_LIA_DATA_Z_MSB_VALUEZ__REG BNO055_LIA_DATA_Z_MSB_ADDR + +/* Gravity data X-LSB register*/ +#define BNO055_GRV_DATA_X_LSB_VALUEX__POS 0 +#define BNO055_GRV_DATA_X_LSB_VALUEX__MSK 0xFF +#define BNO055_GRV_DATA_X_LSB_VALUEX__LEN 8 +#define BNO055_GRV_DATA_X_LSB_VALUEX__REG BNO055_GRV_DATA_X_LSB_ADDR + +/* Gravity data X-MSB register*/ +#define BNO055_GRV_DATA_X_MSB_VALUEX__POS 0 +#define BNO055_GRV_DATA_X_MSB_VALUEX__MSK 0xFF +#define BNO055_GRV_DATA_X_MSB_VALUEX__LEN 8 +#define BNO055_GRV_DATA_X_MSB_VALUEX__REG BNO055_GRV_DATA_X_MSB_ADDR + +/* Gravity data Y-LSB register*/ +#define BNO055_GRV_DATA_Y_LSB_VALUEY__POS 0 +#define BNO055_GRV_DATA_Y_LSB_VALUEY__MSK 0xFF +#define BNO055_GRV_DATA_Y_LSB_VALUEY__LEN 8 +#define BNO055_GRV_DATA_Y_LSB_VALUEY__REG BNO055_GRV_DATA_Y_LSB_ADDR + +/* Gravity data Y-MSB register*/ +#define BNO055_GRV_DATA_Y_MSB_VALUEY__POS 0 +#define BNO055_GRV_DATA_Y_MSB_VALUEY__MSK 0xFF +#define BNO055_GRV_DATA_Y_MSB_VALUEY__LEN 8 +#define BNO055_GRV_DATA_Y_MSB_VALUEY__REG BNO055_GRV_DATA_Y_MSB_ADDR + +/* Gravity data Z-LSB register*/ +#define BNO055_GRV_DATA_Z_LSB_VALUEZ__POS 0 +#define BNO055_GRV_DATA_Z_LSB_VALUEZ__MSK 0xFF +#define BNO055_GRV_DATA_Z_LSB_VALUEZ__LEN 8 +#define BNO055_GRV_DATA_Z_LSB_VALUEZ__REG BNO055_GRV_DATA_Z_LSB_ADDR + +/* Gravity data Z-MSB register*/ +#define BNO055_GRV_DATA_Z_MSB_VALUEZ__POS 0 +#define BNO055_GRV_DATA_Z_MSB_VALUEZ__MSK 0xFF +#define BNO055_GRV_DATA_Z_MSB_VALUEZ__LEN 8 +#define BNO055_GRV_DATA_Z_MSB_VALUEZ__REG BNO055_GRV_DATA_Z_MSB_ADDR + +/* Temperature register*/ +#define BNO055_TEMP__POS 0 +#define BNO055_TEMP__MSK 0xFF +#define BNO055_TEMP__LEN 8 +#define BNO055_TEMP__REG BNO055_TEMP_ADDR + +/*Mag_Calib status register*/ +#define BNO055_MAG_CALIB_STAT__POS 0 +#define BNO055_MAG_CALIB_STAT__MSK 0X03 +#define BNO055_MAG_CALIB_STAT__LEN 2 +#define BNO055_MAG_CALIB_STAT__REG BNO055_CALIB_STAT_ADDR + +/*Acc_Calib status register*/ +#define BNO055_ACC_CALIB_STAT__POS 2 +#define BNO055_ACC_CALIB_STAT__MSK 0X0C +#define BNO055_ACC_CALIB_STAT__LEN 2 +#define BNO055_ACC_CALIB_STAT__REG BNO055_CALIB_STAT_ADDR + +/*Gyro_Calib status register*/ +#define BNO055_GYR_CALIB_STAT__POS 4 +#define BNO055_GYR_CALIB_STAT__MSK 0X30 +#define BNO055_GYR_CALIB_STAT__LEN 2 +#define BNO055_GYR_CALIB_STAT__REG BNO055_CALIB_STAT_ADDR + +/*Sys_Calib status register*/ +#define BNO055_SYS_CALIB_STAT__POS 6 +#define BNO055_SYS_CALIB_STAT__MSK 0XC0 +#define BNO055_SYS_CALIB_STAT__LEN 2 +#define BNO055_SYS_CALIB_STAT__REG BNO055_CALIB_STAT_ADDR + +/*ST_ACCEL register*/ +#define BNO055_ST_ACC__POS 0 +#define BNO055_ST_ACC__MSK 0X01 +#define BNO055_ST_ACC__LEN 1 +#define BNO055_ST_ACC__REG BNO055_ST_RESULT_ADDR + +/*ST_MAG register*/ +#define BNO055_ST_MAG__POS 1 +#define BNO055_ST_MAG__MSK 0X02 +#define BNO055_ST_MAG__LEN 1 +#define BNO055_ST_MAG__REG BNO055_ST_RESULT_ADDR + +/*ST_GYRO register*/ +#define BNO055_ST_GYR__POS 2 +#define BNO055_ST_GYR__MSK 0X04 +#define BNO055_ST_GYR__LEN 1 +#define BNO055_ST_GYR__REG BNO055_ST_RESULT_ADDR + +/*ST_MCU register*/ +#define BNO055_ST_MCU__POS 3 +#define BNO055_ST_MCU__MSK 0X08 +#define BNO055_ST_MCU__LEN 1 +#define BNO055_ST_MCU__REG BNO055_ST_RESULT_ADDR + +/*Interrupt status registers*/ +#define BNO055_INT_STAT_GYRO_AM__POS 2 +#define BNO055_INT_STAT_GYRO_AM__MSK 0X04 +#define BNO055_INT_STAT_GYRO_AM__LEN 1 +#define BNO055_INT_STAT_GYRO_AM__REG BNO055_INT_STA_ADDR + +#define BNO055_INT_STAT_GYRO_HIGH_RATE__POS 3 +#define BNO055_INT_STAT_GYRO_HIGH_RATE__MSK 0X08 +#define BNO055_INT_STAT_GYRO_HIGH_RATE__LEN 1 +#define BNO055_INT_STAT_GYRO_HIGH_RATE__REG BNO055_INT_STA_ADDR + +#define BNO055_INT_STAT_ACC_HIGH_G__POS 5 +#define BNO055_INT_STAT_ACC_HIGH_G__MSK 0X20 +#define BNO055_INT_STAT_ACC_HIGH_G__LEN 1 +#define BNO055_INT_STAT_ACC_HIGH_G__REG BNO055_INT_STA_ADDR + +#define BNO055_INT_STAT_ACC_AM__POS 6 +#define BNO055_INT_STAT_ACC_AM__MSK 0X40 +#define BNO055_INT_STAT_ACC_AM__LEN 1 +#define BNO055_INT_STAT_ACC_AM__REG BNO055_INT_STA_ADDR + +#define BNO055_INT_STAT_ACC_NM__POS 7 +#define BNO055_INT_STAT_ACC_NM__MSK 0X80 +#define BNO055_INT_STAT_ACC_NM__LEN 1 +#define BNO055_INT_STAT_ACC_NM__REG BNO055_INT_STA_ADDR + +/* System registers*/ +#define BNO055_SYSTEM_STATUS_CODE__POS 0 +#define BNO055_SYSTEM_STATUS_CODE__MSK 0XFF +#define BNO055_SYSTEM_STATUS_CODE__LEN 8 +#define BNO055_SYSTEM_STATUS_CODE__REG BNO055_SYS_STATUS_ADDR + +#define BNO055_SYSTEM_ERROR_CODE__POS 0 +#define BNO055_SYSTEM_ERROR_CODE__MSK 0XFF +#define BNO055_SYSTEM_ERROR_CODE__LEN 8 +#define BNO055_SYSTEM_ERROR_CODE__REG BNO055_SYS_ERR_ADDR + +/* Accel_Unit register*/ +#define BNO055_ACC_UNIT__POS 0 +#define BNO055_ACC_UNIT__MSK 0X01 +#define BNO055_ACC_UNIT__LEN 1 +#define BNO055_ACC_UNIT__REG BNO055_UNIT_SEL_ADDR + +/* Gyro_Unit register*/ +#define BNO055_GYR_UNIT__POS 1 +#define BNO055_GYR_UNIT__MSK 0X02 +#define BNO055_GYR_UNIT__LEN 1 +#define BNO055_GYR_UNIT__REG BNO055_UNIT_SEL_ADDR + +/* Euler_Unit register*/ +#define BNO055_EUL_UNIT__POS 2 +#define BNO055_EUL_UNIT__MSK 0X04 +#define BNO055_EUL_UNIT__LEN 1 +#define BNO055_EUL_UNIT__REG BNO055_UNIT_SEL_ADDR + +/* Tilt_Unit register*/ +#define BNO055_TILT_UNIT__POS 3 +#define BNO055_TILT_UNIT__MSK 0X08 +#define BNO055_TILT_UNIT__LEN 1 +#define BNO055_TILT_UNIT__REG BNO055_UNIT_SEL_ADDR + +/* Temperature_Unit register*/ +#define BNO055_TEMP_UNIT__POS 4 +#define BNO055_TEMP_UNIT__MSK 0X10 +#define BNO055_TEMP_UNIT__LEN 1 +#define BNO055_TEMP_UNIT__REG BNO055_UNIT_SEL_ADDR + +/* ORI android-windows register*/ +#define BNO055_DATA_OUTPUT_FORMAT__POS 7 +#define BNO055_DATA_OUTPUT_FORMAT__MSK 0X80 +#define BNO055_DATA_OUTPUT_FORMAT__LEN 1 +#define BNO055_DATA_OUTPUT_FORMAT__REG BNO055_UNIT_SEL_ADDR + +/*Data Select register*/ +/* Accel data select*/ +#define BNO055_DATA_SEL_ACC__POS 0 +#define BNO055_DATA_SEL_ACC__MSK 0X01 +#define BNO055_DATA_SEL_ACC__LEN 1 +#define BNO055_DATA_SEL_ACC__REG BNO055_DATA_SEL_ADDR + +/* Mag data select*/ +#define BNO055_DATA_SEL_MAG__POS 1 +#define BNO055_DATA_SEL_MAG__MSK 0X02 +#define BNO055_DATA_SEL_MAG__LEN 1 +#define BNO055_DATA_SEL_MAG__REG BNO055_DATA_SEL_ADDR + +/* Gyro data select*/ +#define BNO055_DATA_SEL_GYR__POS 2 +#define BNO055_DATA_SEL_GYR__MSK 0X04 +#define BNO055_DATA_SEL_GYR__LEN 1 +#define BNO055_DATA_SEL_GYR__REG BNO055_DATA_SEL_ADDR + +/* Euler data select*/ +#define BNO055_DATA_SEL_EUL__POS 3 +#define BNO055_DATA_SEL_EUL__MSK 0X08 +#define BNO055_DATA_SEL_EUL__LEN 1 +#define BNO055_DATA_SEL_EUL__REG BNO055_DATA_SEL_ADDR + +/* Quaternion data select*/ +#define BNO055_DATA_SEL_QUA__POS 4 +#define BNO055_DATA_SEL_QUA__MSK 0X10 +#define BNO055_DATA_SEL_QUA__LEN 1 +#define BNO055_DATA_SEL_QUA__REG BNO055_DATA_SEL_ADDR + +/* Linear Accel data select*/ +#define BNO055_DATA_SEL_LINEAR_ACC__POS 5 +#define BNO055_DATA_SEL_LINEAR_ACC__MSK 0X20 +#define BNO055_DATA_SEL_LINEAR_ACC__LEN 1 +#define BNO055_DATA_SEL_LINEAR_ACC__REG BNO055_DATA_SEL_ADDR + +/* Gravity data select*/ +#define BNO055_DATA_SEL_GRV__POS 6 +#define BNO055_DATA_SEL_GRV__MSK 0X40 +#define BNO055_DATA_SEL_GRV__LEN 1 +#define BNO055_DATA_SEL_GRV__REG BNO055_DATA_SEL_ADDR + +/* Temperature data select*/ +#define BNO055_DATA_SEL_TEMP__POS 7 +#define BNO055_DATA_SEL_TEMP__MSK 0X80 +#define BNO055_DATA_SEL_TEMP__LEN 1 +#define BNO055_DATA_SEL_TEMP__REG BNO055_DATA_SEL_ADDR + +/*Operation Mode data register*/ +#define BNO055_OPERATION_MODE__POS 0 +#define BNO055_OPERATION_MODE__MSK 0X0F +#define BNO055_OPERATION_MODE__LEN 4 +#define BNO055_OPERATION_MODE__REG BNO055_OPR_MODE_ADDR + +/* output data rate register*/ +#define BNO055_OUTPUT_DATA_RATE__POS 4 +#define BNO055_OUTPUT_DATA_RATE__MSK 0X70 +#define BNO055_OUTPUT_DATA_RATE__LEN 3 +#define BNO055_OUTPUT_DATA_RATE__REG BNO055_OPR_MODE_ADDR + +/* Power Mode register*/ +#define BNO055_POWER_MODE__POS 0 +#define BNO055_POWER_MODE__MSK 0X03 +#define BNO055_POWER_MODE__LEN 2 +#define BNO055_POWER_MODE__REG BNO055_PWR_MODE_ADDR + +/*Self Test register*/ +#define BNO055_SELF_TEST__POS 0 +#define BNO055_SELF_TEST__MSK 0X01 +#define BNO055_SELF_TEST__LEN 1 +#define BNO055_SELF_TEST__REG BNO055_SYS_TRIGGER_ADDR + +/* RST_SYS register*/ +#define BNO055_RST_SYS__POS 5 +#define BNO055_RST_SYS__MSK 0X20 +#define BNO055_RST_SYS__LEN 1 +#define BNO055_RST_SYS__REG BNO055_SYS_TRIGGER_ADDR + +/* RST_INT register*/ +#define BNO055_RST_INT__POS 6 +#define BNO055_RST_INT__MSK 0X40 +#define BNO055_RST_INT__LEN 1 +#define BNO055_RST_INT__REG BNO055_SYS_TRIGGER_ADDR + +/* Temp source register*/ +#define BNO055_TEMP_SOURCE__POS 0 +#define BNO055_TEMP_SOURCE__MSK 0X03 +#define BNO055_TEMP_SOURCE__LEN 2 +#define BNO055_TEMP_SOURCE__REG BNO055_TEMP_SOURCE_ADDR + +/* Axis remap value register*/ +#define BNO055_REMAP_AXIS_VALUE__POS 0 +#define BNO055_REMAP_AXIS_VALUE__MSK 0X3F +#define BNO055_REMAP_AXIS_VALUE__LEN 6 +#define BNO055_REMAP_AXIS_VALUE__REG BNO055_AXIS_MAP_CONFIG_ADDR + +/* Axis sign value register*/ +#define BNO055_REMAP_Z_SIGN__POS 0 +#define BNO055_REMAP_Z_SIGN__MSK 0X01 +#define BNO055_REMAP_Z_SIGN__LEN 1 +#define BNO055_REMAP_Z_SIGN__REG BNO055_AXIS_MAP_SIGN_ADDR + +#define BNO055_REMAP_Y_SIGN__POS 1 +#define BNO055_REMAP_Y_SIGN__MSK 0X02 +#define BNO055_REMAP_Y_SIGN__LEN 1 +#define BNO055_REMAP_Y_SIGN__REG BNO055_AXIS_MAP_SIGN_ADDR + +#define BNO055_REMAP_X_SIGN__POS 2 +#define BNO055_REMAP_X_SIGN__MSK 0X04 +#define BNO055_REMAP_X_SIGN__LEN 1 +#define BNO055_REMAP_X_SIGN__REG BNO055_AXIS_MAP_SIGN_ADDR + +/* Soft Iron Calibration matrix register*/ +#define BNO055_SIC_MATRIX_0_LSB__POS 0 +#define BNO055_SIC_MATRIX_0_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_0_LSB__LEN 8 +#define BNO055_SIC_MATRIX_0_LSB__REG BNO055_SIC_MATRIX_0_LSB_ADDR + +#define BNO055_SIC_MATRIX_0_MSB__POS 0 +#define BNO055_SIC_MATRIX_0_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_0_MSB__LEN 8 +#define BNO055_SIC_MATRIX_0_MSB__REG BNO055_SIC_MATRIX_0_MSB_ADDR + +#define BNO055_SIC_MATRIX_1_LSB__POS 0 +#define BNO055_SIC_MATRIX_1_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_1_LSB__LEN 8 +#define BNO055_SIC_MATRIX_1_LSB__REG BNO055_SIC_MATRIX_1_LSB_ADDR + +#define BNO055_SIC_MATRIX_1_MSB__POS 0 +#define BNO055_SIC_MATRIX_1_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_1_MSB__LEN 8 +#define BNO055_SIC_MATRIX_1_MSB__REG BNO055_SIC_MATRIX_1_MSB_ADDR + +#define BNO055_SIC_MATRIX_2_LSB__POS 0 +#define BNO055_SIC_MATRIX_2_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_2_LSB__LEN 8 +#define BNO055_SIC_MATRIX_2_LSB__REG BNO055_SIC_MATRIX_2_LSB_ADDR + +#define BNO055_SIC_MATRIX_2_MSB__POS 0 +#define BNO055_SIC_MATRIX_2_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_2_MSB__LEN 8 +#define BNO055_SIC_MATRIX_2_MSB__REG BNO055_SIC_MATRIX_2_MSB_ADDR + +#define BNO055_SIC_MATRIX_3_LSB__POS 0 +#define BNO055_SIC_MATRIX_3_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_3_LSB__LEN 8 +#define BNO055_SIC_MATRIX_3_LSB__REG BNO055_SIC_MATRIX_3_LSB_ADDR + +#define BNO055_SIC_MATRIX_3_MSB__POS 0 +#define BNO055_SIC_MATRIX_3_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_3_MSB__LEN 8 +#define BNO055_SIC_MATRIX_3_MSB__REG BNO055_SIC_MATRIX_3_MSB_ADDR + +#define BNO055_SIC_MATRIX_4_LSB__POS 0 +#define BNO055_SIC_MATRIX_4_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_4_LSB__LEN 8 +#define BNO055_SIC_MATRIX_4_LSB__REG BNO055_SIC_MATRIX_4_LSB_ADDR + +#define BNO055_SIC_MATRIX_4_MSB__POS 0 +#define BNO055_SIC_MATRIX_4_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_4_MSB__LEN 8 +#define BNO055_SIC_MATRIX_4_MSB__REG BNO055_SIC_MATRIX_4_MSB_ADDR + +#define BNO055_SIC_MATRIX_5_LSB__POS 0 +#define BNO055_SIC_MATRIX_5_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_5_LSB__LEN 8 +#define BNO055_SIC_MATRIX_5_LSB__REG BNO055_SIC_MATRIX_5_LSB_ADDR + +#define BNO055_SIC_MATRIX_5_MSB__POS 0 +#define BNO055_SIC_MATRIX_5_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_5_MSB__LEN 8 +#define BNO055_SIC_MATRIX_5_MSB__REG BNO055_SIC_MATRIX_5_MSB_ADDR + +#define BNO055_SIC_MATRIX_6_LSB__POS 0 +#define BNO055_SIC_MATRIX_6_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_6_LSB__LEN 8 +#define BNO055_SIC_MATRIX_6_LSB__REG BNO055_SIC_MATRIX_6_LSB_ADDR + +#define BNO055_SIC_MATRIX_6_MSB__POS 0 +#define BNO055_SIC_MATRIX_6_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_6_MSB__LEN 8 +#define BNO055_SIC_MATRIX_6_MSB__REG BNO055_SIC_MATRIX_6_MSB_ADDR + +#define BNO055_SIC_MATRIX_7_LSB__POS 0 +#define BNO055_SIC_MATRIX_7_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_7_LSB__LEN 8 +#define BNO055_SIC_MATRIX_7_LSB__REG BNO055_SIC_MATRIX_7_LSB_ADDR + +#define BNO055_SIC_MATRIX_7_MSB__POS 0 +#define BNO055_SIC_MATRIX_7_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_7_MSB__LEN 8 +#define BNO055_SIC_MATRIX_7_MSB__REG BNO055_SIC_MATRIX_7_MSB_ADDR + +#define BNO055_SIC_MATRIX_8_LSB__POS 0 +#define BNO055_SIC_MATRIX_8_LSB__MSK 0XFF +#define BNO055_SIC_MATRIX_8_LSB__LEN 8 +#define BNO055_SIC_MATRIX_8_LSB__REG BNO055_SIC_MATRIX_8_LSB_ADDR + +#define BNO055_SIC_MATRIX_8_MSB__POS 0 +#define BNO055_SIC_MATRIX_8_MSB__MSK 0XFF +#define BNO055_SIC_MATRIX_8_MSB__LEN 8 +#define BNO055_SIC_MATRIX_8_MSB__REG BNO055_SIC_MATRIX_8_MSB_ADDR + +/*Accel Offset registers*/ +#define BNO055_ACC_OFFSET_X_LSB__POS 0 +#define BNO055_ACC_OFFSET_X_LSB__MSK 0XFF +#define BNO055_ACC_OFFSET_X_LSB__LEN 8 +#define BNO055_ACC_OFFSET_X_LSB__REG ACC_OFFSET_X_LSB_ADDR + +#define BNO055_ACC_OFFSET_X_MSB__POS 0 +#define BNO055_ACC_OFFSET_X_MSB__MSK 0XFF +#define BNO055_ACC_OFFSET_X_MSB__LEN 8 +#define BNO055_ACC_OFFSET_X_MSB__REG ACC_OFFSET_X_MSB_ADDR + +#define BNO055_ACC_OFFSET_Y_LSB__POS 0 +#define BNO055_ACC_OFFSET_Y_LSB__MSK 0XFF +#define BNO055_ACC_OFFSET_Y_LSB__LEN 8 +#define BNO055_ACC_OFFSET_Y_LSB__REG ACC_OFFSET_Y_LSB_ADDR + +#define BNO055_ACC_OFFSET_Y_MSB__POS 0 +#define BNO055_ACC_OFFSET_Y_MSB__MSK 0XFF +#define BNO055_ACC_OFFSET_Y_MSB__LEN 8 +#define BNO055_ACC_OFFSET_Y_MSB__REG ACC_OFFSET_Y_MSB_ADDR + +#define BNO055_ACC_OFFSET_Z_LSB__POS 0 +#define BNO055_ACC_OFFSET_Z_LSB__MSK 0XFF +#define BNO055_ACC_OFFSET_Z_LSB__LEN 8 +#define BNO055_ACC_OFFSET_Z_LSB__REG ACC_OFFSET_Z_LSB_ADDR + +#define BNO055_ACC_OFFSET_Z_MSB__POS 0 +#define BNO055_ACC_OFFSET_Z_MSB__MSK 0XFF +#define BNO055_ACC_OFFSET_Z_MSB__LEN 8 +#define BNO055_ACC_OFFSET_Z_MSB__REG ACC_OFFSET_Z_MSB_ADDR + +/*Mag Offset registers*/ +#define BNO055_MAG_OFFSET_X_LSB__POS 0 +#define BNO055_MAG_OFFSET_X_LSB__MSK 0XFF +#define BNO055_MAG_OFFSET_X_LSB__LEN 8 +#define BNO055_MAG_OFFSET_X_LSB__REG MAG_OFFSET_X_LSB_ADDR + +#define BNO055_MAG_OFFSET_X_MSB__POS 0 +#define BNO055_MAG_OFFSET_X_MSB__MSK 0XFF +#define BNO055_MAG_OFFSET_X_MSB__LEN 8 +#define BNO055_MAG_OFFSET_X_MSB__REG MAG_OFFSET_X_MSB_ADDR + +#define BNO055_MAG_OFFSET_Y_LSB__POS 0 +#define BNO055_MAG_OFFSET_Y_LSB__MSK 0XFF +#define BNO055_MAG_OFFSET_Y_LSB__LEN 8 +#define BNO055_MAG_OFFSET_Y_LSB__REG MAG_OFFSET_Y_LSB_ADDR + +#define BNO055_MAG_OFFSET_Y_MSB__POS 0 +#define BNO055_MAG_OFFSET_Y_MSB__MSK 0XFF +#define BNO055_MAG_OFFSET_Y_MSB__LEN 8 +#define BNO055_MAG_OFFSET_Y_MSB__REG MAG_OFFSET_Y_MSB_ADDR + +#define BNO055_MAG_OFFSET_Z_LSB__POS 0 +#define BNO055_MAG_OFFSET_Z_LSB__MSK 0XFF +#define BNO055_MAG_OFFSET_Z_LSB__LEN 8 +#define BNO055_MAG_OFFSET_Z_LSB__REG MAG_OFFSET_Z_LSB_ADDR + +#define BNO055_MAG_OFFSET_Z_MSB__POS 0 +#define BNO055_MAG_OFFSET_Z_MSB__MSK 0XFF +#define BNO055_MAG_OFFSET_Z_MSB__LEN 8 +#define BNO055_MAG_OFFSET_Z_MSB__REG MAG_OFFSET_Z_MSB_ADDR + +/* Gyro Offset registers*/ +#define BNO055_GYR_OFFSET_X_LSB__POS 0 +#define BNO055_GYR_OFFSET_X_LSB__MSK 0XFF +#define BNO055_GYR_OFFSET_X_LSB__LEN 8 +#define BNO055_GYR_OFFSET_X_LSB__REG GYRO_OFFSET_X_LSB_ADDR + +#define BNO055_GYR_OFFSET_X_MSB__POS 0 +#define BNO055_GYR_OFFSET_X_MSB__MSK 0XFF +#define BNO055_GYR_OFFSET_X_MSB__LEN 8 +#define BNO055_GYR_OFFSET_X_MSB__REG GYRO_OFFSET_X_MSB_ADDR + +#define BNO055_GYR_OFFSET_Y_LSB__POS 0 +#define BNO055_GYR_OFFSET_Y_LSB__MSK 0XFF +#define BNO055_GYR_OFFSET_Y_LSB__LEN 8 +#define BNO055_GYR_OFFSET_Y_LSB__REG GYRO_OFFSET_Y_LSB_ADDR + +#define BNO055_GYR_OFFSET_Y_MSB__POS 0 +#define BNO055_GYR_OFFSET_Y_MSB__MSK 0XFF +#define BNO055_GYR_OFFSET_Y_MSB__LEN 8 +#define BNO055_GYR_OFFSET_Y_MSB__REG GYRO_OFFSET_Y_MSB_ADDR + +#define BNO055_GYR_OFFSET_Z_LSB__POS 0 +#define BNO055_GYR_OFFSET_Z_LSB__MSK 0XFF +#define BNO055_GYR_OFFSET_Z_LSB__LEN 8 +#define BNO055_GYR_OFFSET_Z_LSB__REG GYRO_OFFSET_Z_LSB_ADDR + +#define BNO055_GYR_OFFSET_Z_MSB__POS 0 +#define BNO055_GYR_OFFSET_Z_MSB__MSK 0XFF +#define BNO055_GYR_OFFSET_Z_MSB__LEN 8 +#define BNO055_GYR_OFFSET_Z_MSB__REG GYRO_OFFSET_Z_MSB_ADDR +/* PAGE0 DATA REGISTERS DEFINITION END*/ + +/* PAGE1 DATA REGISTERS DEFINITION START*/ +/* Configuration registers*/ +/* Accel range configuration register*/ +#define BNO055_CONFIG_ACC_RANGE__POS 0 +#define BNO055_CONFIG_ACC_RANGE__MSK 0X03 +#define BNO055_CONFIG_ACC_RANGE__LEN 2 +#define BNO055_CONFIG_ACC_RANGE__REG ACC_CONFIG_ADDR + +/* Accel bandwidth configuration register*/ +#define BNO055_CONFIG_ACC_BW__POS 2 +#define BNO055_CONFIG_ACC_BW__MSK 0X1C +#define BNO055_CONFIG_ACC_BW__LEN 3 +#define BNO055_CONFIG_ACC_BW__REG ACC_CONFIG_ADDR + +/* Accel power mode configuration register*/ +#define BNO055_CONFIG_ACC_PWR_MODE__POS 5 +#define BNO055_CONFIG_ACC_PWR_MODE__MSK 0XE0 +#define BNO055_CONFIG_ACC_PWR_MODE__LEN 3 +#define BNO055_CONFIG_ACC_PWR_MODE__REG ACC_CONFIG_ADDR + +/* Mag data output rate configuration register*/ +#define BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__POS 0 +#define BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__MSK 0X07 +#define BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__LEN 3 +#define BNO055_CONFIG_MAG_DATA_OUTPUT_RATE__REG MAG_CONFIG_ADDR + +/* Mag operation mode configuration register*/ +#define BNO055_CONFIG_MAG_OPR_MODE__POS 3 +#define BNO055_CONFIG_MAG_OPR_MODE__MSK 0X18 +#define BNO055_CONFIG_MAG_OPR_MODE__LEN 2 +#define BNO055_CONFIG_MAG_OPR_MODE__REG MAG_CONFIG_ADDR + +/* Mag power mode configuration register*/ +#define BNO055_CONFIG_MAG_POWER_MODE__POS 5 +#define BNO055_CONFIG_MAG_POWER_MODE__MSK 0X60 +#define BNO055_CONFIG_MAG_POWER_MODE__LEN 2 +#define BNO055_CONFIG_MAG_POWER_MODE__REG MAG_CONFIG_ADDR + +/* Gyro range configuration register*/ +#define BNO055_CONFIG_GYR_RANGE__POS 0 +#define BNO055_CONFIG_GYR_RANGE__MSK 0X07 +#define BNO055_CONFIG_GYR_RANGE__LEN 3 +#define BNO055_CONFIG_GYR_RANGE__REG GYRO_CONFIG_ADDR + +/* Gyro bandwidth configuration register*/ +#define BNO055_CONFIG_GYR_BANDWIDTH__POS 3 +#define BNO055_CONFIG_GYR_BANDWIDTH__MSK 0X38 +#define BNO055_CONFIG_GYR_BANDWIDTH__LEN 3 +#define BNO055_CONFIG_GYR_BANDWIDTH__REG GYRO_CONFIG_ADDR + +/* Gyro power mode configuration register*/ +#define BNO055_CONFIG_GYR_POWER_MODE__POS 0 +#define BNO055_CONFIG_GYR_POWER_MODE__MSK 0X07 +#define BNO055_CONFIG_GYR_POWER_MODE__LEN 3 +#define BNO055_CONFIG_GYR_POWER_MODE__REG GYRO_MODE_CONFIG_ADDR + +/* Sleep configuration registers*/ +/* Accel sleep mode configuration register*/ +#define BNO055_ACC_SLEEP_MODE__POS 0 +#define BNO055_ACC_SLEEP_MODE__MSK 0X01 +#define BNO055_ACC_SLEEP_MODE__LEN 1 +#define BNO055_ACC_SLEEP_MODE__REG ACC_SLEEP_CONFIG_ADDR + +/* Accel sleep duration configuration register*/ +#define BNO055_ACC_SLEEP_DUR__POS 1 +#define BNO055_ACC_SLEEP_DUR__MSK 0X1E +#define BNO055_ACC_SLEEP_DUR__LEN 4 +#define BNO055_ACC_SLEEP_DUR__REG ACC_SLEEP_CONFIG_ADDR + +/* Gyro sleep duration configuration register*/ +#define BNO055_GYR_SLEEP_DUR__POS 0 +#define BNO055_GYR_SLEEP_DUR__MSK 0X07 +#define BNO055_GYR_SLEEP_DUR__LEN 3 +#define BNO055_GYR_SLEEP_DUR__REG GYR_SLEEP_CONFIG_ADDR + +/* Gyro auto sleep duration configuration register*/ +#define BNO055_GYR_AUTO_SLEEP_DUR__POS 3 +#define BNO055_GYR_AUTO_SLEEP_DUR__MSK 0X38 +#define BNO055_GYR_AUTO_SLEEP_DUR__LEN 3 +#define BNO055_GYR_AUTO_SLEEP_DUR__REG GYR_SLEEP_CONFIG_ADDR + +/* Mag sleep mode configuration register*/ +#define BNO055_MAG_SLEEP_MODE__POS 0 +#define BNO055_MAG_SLEEP_MODE__MSK 0X01 +#define BNO055_MAG_SLEEP_MODE__LEN 1 +#define BNO055_MAG_SLEEP_MODE__REG MAG_SLEEP_CONFIG_ADDR + +/* Mag sleep duration configuration register*/ +#define BNO055_MAG_SLEEP_DUR__POS 1 +#define BNO055_MAG_SLEEP_DUR__MSK 0X1E +#define BNO055_MAG_SLEEP_DUR__LEN 4 +#define BNO055_MAG_SLEEP_DUR__REG MAG_SLEEP_CONFIG_ADDR + +/* Interrupt registers*/ +/* Gyro any motion interrupt msk register*/ +#define BNO055_GYR_AM_INTMSK__POS 2 +#define BNO055_GYR_AM_INTMSK__MSK 0X04 +#define BNO055_GYR_AM_INTMSK__LEN 1 +#define BNO055_GYR_AM_INTMSK__REG INT_MSK_ADDR + +/* Gyro high rate interrupt msk register*/ +#define BNO055_GYR_HIGH_RATE_INTMSK__POS 3 +#define BNO055_GYR_HIGH_RATE_INTMSK__MSK 0X08 +#define BNO055_GYR_HIGH_RATE_INTMSK__LEN 1 +#define BNO055_GYR_HIGH_RATE_INTMSK__REG INT_MSK_ADDR + +/* Accel high g interrupt msk register*/ +#define BNO055_ACC_HIGH_G_INTMSK__POS 5 +#define BNO055_ACC_HIGH_G_INTMSK__MSK 0X20 +#define BNO055_ACC_HIGH_G_INTMSK__LEN 1 +#define BNO055_ACC_HIGH_G_INTMSK__REG INT_MSK_ADDR + +/* Accel any motion interrupt msk register*/ +#define BNO055_ACC_AM_INTMSK__POS 6 +#define BNO055_ACC_AM_INTMSK__MSK 0X40 +#define BNO055_ACC_AM_INTMSK__LEN 1 +#define BNO055_ACC_AM_INTMSK__REG INT_MSK_ADDR + +/* Accel any motion interrupt msk register*/ +#define BNO055_ACC_NM_INTMSK__POS 7 +#define BNO055_ACC_NM_INTMSK__MSK 0X80 +#define BNO055_ACC_NM_INTMSK__LEN 1 +#define BNO055_ACC_NM_INTMSK__REG INT_MSK_ADDR + +/* Gyro any motion interrupt register*/ +#define BNO055_GYR_AM_INT__POS 2 +#define BNO055_GYR_AM_INT__MSK 0X04 +#define BNO055_GYR_AM_INT__LEN 1 +#define BNO055_GYR_AM_INT__REG INT_ADDR + +/* Gyro high rate interrupt register*/ +#define BNO055_GYR_HIGH_RATE_INT__POS 3 +#define BNO055_GYR_HIGH_RATE_INT__MSK 0X08 +#define BNO055_GYR_HIGH_RATE_INT__LEN 1 +#define BNO055_GYR_HIGH_RATE_INT__REG INT_ADDR + +/* Accel high g interrupt register*/ +#define BNO055_ACC_HIGH_G_INT__POS 5 +#define BNO055_ACC_HIGH_G_INT__MSK 0X20 +#define BNO055_ACC_HIGH_G_INT__LEN 1 +#define BNO055_ACC_HIGH_G_INT__REG INT_ADDR + +/* Accel any motion interrupt register*/ +#define BNO055_ACC_AM_INT__POS 6 +#define BNO055_ACC_AM_INT__MSK 0X40 +#define BNO055_ACC_AM_INT__LEN 1 +#define BNO055_ACC_AM_INT__REG INT_ADDR + +/*Accel any motion interrupt register*/ +#define BNO055_ACC_NM_INT__POS 7 +#define BNO055_ACC_NM_INT__MSK 0X80 +#define BNO055_ACC_NM_INT__LEN 1 +#define BNO055_ACC_NM_INT__REG INT_ADDR + +/*Accel any motion threshold setting*/ +#define BNO055_ACC_AM_THRES__POS 0 +#define BNO055_ACC_AM_THRES__MSK 0XFF +#define BNO055_ACC_AM_THRES__LEN 8 +#define BNO055_ACC_AM_THRES__REG ACC_AM_THRES_ADDR + +/*Accel interrupt setting register*/ +#define BNO055_ACC_AM_DUR_SET__POS 0 +#define BNO055_ACC_AM_DUR_SET__MSK 0X03 +#define BNO055_ACC_AM_DUR_SET__LEN 2 +#define BNO055_ACC_AM_DUR_SET__REG ACC_INT_SETTINGS_ADDR + +/* Accel AM/NM axis selection register*/ +#define BNO055_ACC_AN_MOTION_X_AXIS__POS 2 +#define BNO055_ACC_AN_MOTION_X_AXIS__MSK 0X04 +#define BNO055_ACC_AN_MOTION_X_AXIS__LEN 1 +#define BNO055_ACC_AN_MOTION_X_AXIS__REG ACC_INT_SETTINGS_ADDR + +#define BNO055_ACC_AN_MOTION_Y_AXIS__POS 3 +#define BNO055_ACC_AN_MOTION_Y_AXIS__MSK 0X08 +#define BNO055_ACC_AN_MOTION_Y_AXIS__LEN 1 +#define BNO055_ACC_AN_MOTION_Y_AXIS__REG ACC_INT_SETTINGS_ADDR + +#define BNO055_ACC_AN_MOTION_Z_AXIS__POS 4 +#define BNO055_ACC_AN_MOTION_Z_AXIS__MSK 0X10 +#define BNO055_ACC_AN_MOTION_Z_AXIS__LEN 1 +#define BNO055_ACC_AN_MOTION_Z_AXIS__REG ACC_INT_SETTINGS_ADDR + +/* Accel high g axis selection register*/ +#define BNO055_ACC_HIGH_G_X_AXIS__POS 5 +#define BNO055_ACC_HIGH_G_X_AXIS__MSK 0X20 +#define BNO055_ACC_HIGH_G_X_AXIS__LEN 1 +#define BNO055_ACC_HIGH_G_X_AXIS__REG ACC_INT_SETTINGS_ADDR + +#define BNO055_ACC_HIGH_G_Y_AXIS__POS 6 +#define BNO055_ACC_HIGH_G_Y_AXIS__MSK 0X40 +#define BNO055_ACC_HIGH_G_Y_AXIS__LEN 1 +#define BNO055_ACC_HIGH_G_Y_AXIS__REG ACC_INT_SETTINGS_ADDR + +#define BNO055_ACC_HIGH_G_Z_AXIS__POS 7 +#define BNO055_ACC_HIGH_G_Z_AXIS__MSK 0X80 +#define BNO055_ACC_HIGH_G_Z_AXIS__LEN 1 +#define BNO055_ACC_HIGH_G_Z_AXIS__REG ACC_INT_SETTINGS_ADDR + +/* Accel High g duration setting register*/ +#define BNO055_ACC_HIGH_G_DURATION__POS 0 +#define BNO055_ACC_HIGH_G_DURATION__MSK 0XFF +#define BNO055_ACC_HIGH_G_DURATION__LEN 8 +#define BNO055_ACC_HIGH_G_DURATION__REG ACC_HG_DURATION_ADDR + +/* Accel High g threshold setting register*/ +#define BNO055_ACC_HIGH_G_THRESHOLD__POS 0 +#define BNO055_ACC_HIGH_G_THRESHOLD__MSK 0XFF +#define BNO055_ACC_HIGH_G_THRESHOLD__LEN 8 +#define BNO055_ACC_HIGH_G_THRESHOLD__REG ACC_HG_THRES_ADDR + +/* Accel no/slow motion threshold setting*/ +#define BNO055_ACC_NS_THRESHOLD__POS 0 +#define BNO055_ACC_NS_THRESHOLD__MSK 0XFF +#define BNO055_ACC_NS_THRESHOLD__LEN 8 +#define BNO055_ACC_NS_THRESHOLD__REG ACC_NM_THRES_ADDR + +/* Accel no/slow motion enable setting*/ +#define BNO055_ACC_NM_SM_ENABLE__POS 0 +#define BNO055_ACC_NM_SM_ENABLE__MSK 0X01 +#define BNO055_ACC_NM_SM_ENABLE__LEN 1 +#define BNO055_ACC_NM_SM_ENABLE__REG ACC_NM_SET_ADDR + +/* Accel no/slow motion duration setting*/ +#define BNO055_ACC_NS_DURATION__POS 1 +#define BNO055_ACC_NS_DURATION__MSK 0X7E +#define BNO055_ACC_NS_DURATION__LEN 6 +#define BNO055_ACC_NS_DURATION__REG ACC_NM_SET_ADDR + +/*Gyro interrupt setting register*/ +/*Gyro any motion axis setting*/ +#define BNO055_GYR_AM_X_AXIS__POS 0 +#define BNO055_GYR_AM_X_AXIS__MSK 0X01 +#define BNO055_GYR_AM_X_AXIS__LEN 1 +#define BNO055_GYR_AM_X_AXIS__REG GYR_INT_SETING_ADDR + +#define BNO055_GYR_AM_Y_AXIS__POS 1 +#define BNO055_GYR_AM_Y_AXIS__MSK 0X02 +#define BNO055_GYR_AM_Y_AXIS__LEN 1 +#define BNO055_GYR_AM_Y_AXIS__REG GYR_INT_SETING_ADDR + +#define BNO055_GYR_AM_Z_AXIS__POS 2 +#define BNO055_GYR_AM_Z_AXIS__MSK 0X04 +#define BNO055_GYR_AM_Z_AXIS__LEN 1 +#define BNO055_GYR_AM_Z_AXIS__REG GYR_INT_SETING_ADDR + +/*Gyro high rate axis setting*/ +#define BNO055_GYR_HR_X_AXIS__POS 3 +#define BNO055_GYR_HR_X_AXIS__MSK 0X08 +#define BNO055_GYR_HR_X_AXIS__LEN 1 +#define BNO055_GYR_HR_X_AXIS__REG GYR_INT_SETING_ADDR + +#define BNO055_GYR_HR_Y_AXIS__POS 4 +#define BNO055_GYR_HR_Y_AXIS__MSK 0X10 +#define BNO055_GYR_HR_Y_AXIS__LEN 1 +#define BNO055_GYR_HR_Y_AXIS__REG GYR_INT_SETING_ADDR + +#define BNO055_GYR_HR_Z_AXIS__POS 5 +#define BNO055_GYR_HR_Z_AXIS__MSK 0X20 +#define BNO055_GYR_HR_Z_AXIS__LEN 1 +#define BNO055_GYR_HR_Z_AXIS__REG GYR_INT_SETING_ADDR + +/* Gyro filter setting*/ +#define BNO055_GYR_AM_FILT__POS 6 +#define BNO055_GYR_AM_FILT__MSK 0X40 +#define BNO055_GYR_AM_FILT__LEN 1 +#define BNO055_GYR_AM_FILT__REG GYR_INT_SETING_ADDR + +#define BNO055_GYR_HR_FILT__POS 7 +#define BNO055_GYR_HR_FILT__MSK 0X80 +#define BNO055_GYR_HR_FILT__LEN 1 +#define BNO055_GYR_HR_FILT__REG GYR_INT_SETING_ADDR + +/* Gyro high rate X axis settings*/ +#define BNO055_GYR_HR_X_THRESH__POS 0 +#define BNO055_GYR_HR_X_THRESH__MSK 0X1F +#define BNO055_GYR_HR_X_THRESH__LEN 5 +#define BNO055_GYR_HR_X_THRESH__REG GYR_HR_X_SET_ADDR + +#define BNO055_GYR_HR_X_HYST__POS 5 +#define BNO055_GYR_HR_X_HYST__MSK 0X60 +#define BNO055_GYR_HR_X_HYST__LEN 2 +#define BNO055_GYR_HR_X_HYST__REG GYR_HR_X_SET_ADDR + +#define BNO055_GYR_HR_X_DUR__POS 0 +#define BNO055_GYR_HR_X_DUR__MSK 0XFF +#define BNO055_GYR_HR_X_DUR__LEN 8 +#define BNO055_GYR_HR_X_DUR__REG GYR_DUR_X_ADDR + +/* Gyro high rate Y axis settings*/ +#define BNO055_GYR_HR_Y_THRESH__POS 0 +#define BNO055_GYR_HR_Y_THRESH__MSK 0X1F +#define BNO055_GYR_HR_Y_THRESH__LEN 5 +#define BNO055_GYR_HR_Y_THRESH__REG GYR_HR_Y_SET_ADDR + +#define BNO055_GYR_HR_Y_HYST__POS 5 +#define BNO055_GYR_HR_Y_HYST__MSK 0X60 +#define BNO055_GYR_HR_Y_HYST__LEN 2 +#define BNO055_GYR_HR_Y_HYST__REG GYR_HR_Y_SET_ADDR + +#define BNO055_GYR_HR_Y_DUR__POS 0 +#define BNO055_GYR_HR_Y_DUR__MSK 0XFF +#define BNO055_GYR_HR_Y_DUR__LEN 8 +#define BNO055_GYR_HR_Y_DUR__REG GYR_DUR_Y_ADDR + +/* Gyro high rate Z axis settings*/ +#define BNO055_GYR_HR_Z_THRESH__POS 0 +#define BNO055_GYR_HR_Z_THRESH__MSK 0X1F +#define BNO055_GYR_HR_Z_THRESH__LEN 5 +#define BNO055_GYR_HR_Z_THRESH__REG GYR_HR_Z_SET_ADDR + +#define BNO055_GYR_HR_Z_HYST__POS 5 +#define BNO055_GYR_HR_Z_HYST__MSK 0X60 +#define BNO055_GYR_HR_Z_HYST__LEN 2 +#define BNO055_GYR_HR_Z_HYST__REG GYR_HR_Z_SET_ADDR + +#define BNO055_GYR_HR_Z_DUR__POS 0 +#define BNO055_GYR_HR_Z_DUR__MSK 0XFF +#define BNO055_GYR_HR_Z_DUR__LEN 8 +#define BNO055_GYR_HR_Z_DUR__REG GYR_DUR_Z_ADDR + +/*Gyro any motion threshold setting*/ +#define BNO055_GYR_AM_THRES__POS 0 +#define BNO055_GYR_AM_THRES__MSK 0X7F +#define BNO055_GYR_AM_THRES__LEN 7 +#define BNO055_GYR_AM_THRES__REG GYR_AM_THRES_ADDR + +/* Gyro any motion slope sample setting*/ +#define BNO055_GYR_SLOPE_SAMPLES__POS 0 +#define BNO055_GYR_SLOPE_SAMPLES__MSK 0X03 +#define BNO055_GYR_SLOPE_SAMPLES__LEN 2 +#define BNO055_GYR_SLOPE_SAMPLES__REG GYR_AM_SET_ADDR + +/* Gyro awake duration setting*/ +#define BNO055_GYR_AWAKE_DUR__POS 2 +#define BNO055_GYR_AWAKE_DUR__MSK 0X0C +#define BNO055_GYR_AWAKE_DUR__LEN 2 +#define BNO055_GYR_AWAKE_DUR__REG GYR_AM_SET_ADDR + +/* PAGE1 DATA REGISTERS DEFINITION END*/ + +#define BNO055_GET_BITSLICE(regvar, bitname)\ +((regvar & bitname##__MSK) >> bitname##__POS) + + +#define BNO055_SET_BITSLICE(regvar, bitname, val)\ +((regvar & ~bitname##__MSK) | ((val<. + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" + +/***************************************************************************** + * Description: *//**\brief + * This function initialises the structure pointer, receives + * and assigns the I2C address. + * + * + * + * + * + * \param bno055_t *bno055 structure pointer. + * + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE BNO_Init(struct bno055_t *bno055) +{ + + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + //Link the function pointers for communication (late-binding) + bno055->bus_read = BNO055_I2C_bus_read; + bno055->bus_write = BNO055_I2C_bus_write; + bno055->delay_msec = _delay; + //Initialization from the BNO055 API + comres = bno055_init(bno055); + return comres; + +} + + + + +/***************************************************************************** + * Description: *//**\brief + * This function is called when data has to be read over the I2C bus + * + * + * + * + * + * \param unsigned char dev_addr holds the device address + * unsigned char reg_addr holds the register address + * unsigned char *reg_data holds the pointer for the start of the + * data structure + * unsigned char cnt holds the count of the number of bytes to be + * read + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE BNO055_I2C_bus_read(unsigned char dev_addr,unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + Wire.beginTransmission(dev_addr); //Start of transmission + Wire.write(reg_addr); //Desired start register + Wire.endTransmission(); //Stop of transmission + delayMicroseconds(150); + Wire.requestFrom(dev_addr, cnt); //Request data + while(Wire.available()) //The slave device may send less than requested + { + *reg_data = Wire.read(); //Receive a byte + reg_data++; //Increment pointer + } + return comres; +} + + + + + +/***************************************************************************** + * Description: *//**\brief + * This function is called when data has to be written over + * I2C bus + * + * + * + * + * + * \param unsigned char dev_addr holds the device address + * unsigned char reg_addr holds the register address + * unsigned char *reg_data holds the pointer for the start of the + * data structure + * unsigned char cnt holds the count of the number of bytes to be + * written + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE BNO055_I2C_bus_write(unsigned char dev_addr,unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt) +{ + BNO055_RETURN_FUNCTION_TYPE comres = BNO055_Zero_U8X; + Wire.beginTransmission(dev_addr); //Start of transmission + Wire.write(reg_addr); //Desired start register + for(unsigned char index = 0; index < cnt; index++) + { + Wire.write(*reg_data); //Write the data + reg_data++; //Increment pointer + } + Wire.endTransmission(); //Stop of transmission + delayMicroseconds(150); + return comres; +} + +/***************************************************************************** + * Description: *//**\brief + * This function is a mirror for the delay function for type casting + * + * + * + * + * + * \param unsigned int + * + * + * \return none + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +void _delay(unsigned int period) +{ + delay(long(period)); +} + + + + diff --git a/arduino_libraries/BNO055-master/BNO055_support.h b/arduino_libraries/BNO055-master/BNO055_support.h new file mode 100644 index 0000000..4e1c16e --- /dev/null +++ b/arduino_libraries/BNO055-master/BNO055_support.h @@ -0,0 +1,174 @@ +/* + *************************************************************************** + * + * bno055_support.h - part of sample SW for using BNO055 with Arduino + * + * Usage: BNO055 Sensor Driver Support header File + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#ifndef __BNO055_SUPPORT_H__ +#define __BNO055_SUPPORT_H__ + +extern "C" { +#include "BNO055.h" +} +#include +#include "Arduino.h" + +/***************************************************************************** + * Description: *//**\brief + * This function initialises the structure pointer, receives + * and assigns the I2C address. + * + * + * + * + * + * \param bno055_t *bno055 structure pointer. + * + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE BNO_Init(struct bno055_t *); + + + + + +/***************************************************************************** + * Description: *//**\brief + * This function is called when data has to be read over the I2C bus + * + * + * + * + * + * \param unsigned char dev_addr holds the device address + * unsigned char reg_addr holds the register address + * unsigned char *reg_data holds the pointer for the start of the + * data structure + * unsigned char cnt holds the count of the number of bytes to be + * read + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE BNO055_I2C_bus_read(unsigned char,unsigned char, unsigned char*, unsigned char); + + + + + + +/***************************************************************************** + * Description: *//**\brief + * This function is called when data has to be written over + * I2C bus + * + * + * + * + * + * \param unsigned char dev_addr holds the device address + * unsigned char reg_addr holds the register address + * unsigned char *reg_data holds the pointer for the start of the + * data structure + * unsigned char cnt holds the count of the number of bytes to be + * written + * + * + * \return communication results. + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BNO055_RETURN_FUNCTION_TYPE BNO055_I2C_bus_write(unsigned char ,unsigned char , unsigned char* , unsigned char ); + +/***************************************************************************** + * Description: *//**\brief + * This function is a mirror for the delay function for type casting + * + * + * + * + * + * \param unsigned int + * + * + * \return none + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +void _delay(unsigned int); +#endif + + + + + diff --git a/arduino_libraries/BNO055-master/README.md b/arduino_libraries/BNO055-master/README.md new file mode 100644 index 0000000..6a8e1bc Binary files /dev/null and b/arduino_libraries/BNO055-master/README.md differ diff --git a/arduino_libraries/BNO055-master/examples/Basic/Basic.ino b/arduino_libraries/BNO055-master/examples/Basic/Basic.ino new file mode 100644 index 0000000..85acfec --- /dev/null +++ b/arduino_libraries/BNO055-master/examples/Basic/Basic.ino @@ -0,0 +1,99 @@ +/* + *************************************************************************** + * + * Basic.pde - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); + + //Read out device information + Serial.print("Chip ID: "); + Serial.println(myBNO.chip_id); + + //Read out the software revision ID + Serial.print("Software Revision ID: "); + Serial.println(myBNO.sw_revision_id); + + //Read out the page ID + Serial.print("Page ID: "); + Serial.println(myBNO.page_id); + + //Read out the accelerometer revision ID + Serial.print("Accelerometer Revision ID: "); + Serial.println(myBNO.accel_revision_id); + + //Read out the gyroscope revision ID + Serial.print("Gyroscope Revision ID: "); + Serial.println(myBNO.gyro_revision_id); + + //Read out the magnetometer revision ID + Serial.print("Magnetometer Revision ID: "); + Serial.println(myBNO.mag_revision_id); + + //Read out the bootloader revision ID + Serial.print("Bootloader Revision ID: "); + Serial.println(myBNO.bootloader_revision_id); + + //Read out the device address + Serial.print("Device Address: "); + Serial.println(myBNO.dev_addr); +} + +void loop() //This code is looped forever +{ + //Blank +} \ No newline at end of file diff --git a/arduino_libraries/BNO055-master/examples/Command_Line_Configuration/Command_Line_Configuration.ino b/arduino_libraries/BNO055-master/examples/Command_Line_Configuration/Command_Line_Configuration.ino new file mode 100644 index 0000000..8f1939f --- /dev/null +++ b/arduino_libraries/BNO055-master/examples/Command_Line_Configuration/Command_Line_Configuration.ino @@ -0,0 +1,253 @@ +/* + *************************************************************************** + * + * Command_Line_Configuration.pde - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +//Variables and Flags +unsigned long lastTime = 0; +bool streamReqd = false; //Flag to indicate the requirement for streaming of data + +//Function Prototypes +void streamData(void); //Function to stream data +void getCommand(void); //Function to receive the command and parse it +void execCommand(char ,int); //Function to execute relevant functions depending on the command + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode (Currently defaulted to NDoF) + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); + + //Indication on the Serial Monitor that the Initialization is complete + Serial.println("Initialization Complete"); + Serial.println("Set the terminal character to newline and baud rate to 115200"); + Serial.println("List of commands:"); + Serial.println("s toggles streaming of Euler data"); + Serial.println("c0 to c12 changes the Operation mode"); + Serial.println("p0 to p2 changes the Power mode"); +} + +void loop() //This code is looped forever +{ + if(streamReqd) //If data needs to be streamed then stream data + streamData(); + getCommand();//To look for incoming UART commands and call relevant functions +} + +void streamData(void) +{ + if((millis()-lastTime) >= 100) //To stream at 10Hz without using additional timers + { + lastTime = millis(); + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h)/16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r)/16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p)/16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} + +void getCommand(void) +{ + int commPos = 0;//Register used to keep track of the index of the command + char par1 = 0;//To store the first parameter of the command + int par2 = 0;//To store the seconds parameter of the command + char command[10] = {0};//Array to store the incoming commands + int index; + for(index = 0; index < 10; index++)//Initialize the command array to NULL + command[index] = 0; + if(Serial.available()) + { + int commLen = Serial.readBytesUntil('\n', &command[0], 10);//Store the command in an array and store the length of the incoming command + for(index = 0; index < 10; index++)//Echo the incoming command + Serial.print(command[index]); + Serial.println(); + par1 = command[0]; //Store the first parameter of the command + commPos++; + while((command[commPos] >= '0') && (command[commPos] <= '9'))//To process digits [0-9]+ and store in par2 + { + par2 *= 10;//Shift the digit position + par2 += command[commPos] - '0';//Convert ASCII to Integer + commPos++;//Increment the position of the array + } + execCommand(par1, par2); + } +} + +void execCommand(char head, int tail) +{ + switch(head) + { + case 's': //Command to toggle Streaming of data + streamReqd = !streamReqd; + if(streamReqd) + Serial.println("Streaming ON"); + else + Serial.println("Streaming OFF"); + break; + + case 'c': //Command to change the operation mode + streamReqd = false; //Comment this line if you want to data streaming to be kept on + switch(tail) + { + case 0: + Serial.println("Set into Configuration Mode"); + bno055_set_operation_mode(OPERATION_MODE_CONFIG); + break; + + case 1: + Serial.println("Set into Accelerometer Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCONLY); + break; + + case 2: + Serial.println("Set into Magnetometer Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_MAGONLY); + break; + + case 3: + Serial.println("Set into Gyroscope Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_GYRONLY); + break; + + case 4: + Serial.println("Set into Accelerometer and Magnetometer Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCMAG); + break; + + case 5: + Serial.println("Set into Accelerometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCGYRO); + break; + + case 6: + Serial.println("Set into Magnetometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_MAGGYRO); + break; + + case 7: + Serial.println("Set into Accelerometer, Magnetometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_AMG); + break; + + case 8: + Serial.println("Set into Sensor Fusion IMU Plus Mode"); + bno055_set_operation_mode(OPERATION_MODE_IMUPLUS); + break; + + case 9: + Serial.println("Set into Sensor Fusion Compass Mode"); + bno055_set_operation_mode(OPERATION_MODE_COMPASS); + break; + + case 10: + Serial.println("Set into Sensor Fusion Magnetometer for Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_M4G); + break; + + case 11: + Serial.println("Set into Sensor Fusion NDoF Mode with Fast Magnetometer Calibration Off"); + bno055_set_operation_mode(OPERATION_MODE_NDOF_FMC_OFF); + break; + + case 12: + Serial.println("Set into Sensor Fusion NDoF Mode"); + bno055_set_operation_mode(OPERATION_MODE_NDOF); + break; + + default: + Serial.println("Invalid Configuration Mode"); + } + break; + + case 'p': //To change power modes + streamReqd = false; //Comment this line if you want to data streaming to be kept on + switch(tail) + { + case 0: + Serial.println("Set into Normal Power Mode"); + bno055_set_powermode(POWER_MODE_NORMAL); + break; + + case 1: + Serial.println("Set into Low Power Mode"); + bno055_set_operation_mode(POWER_MODE_LOW_POWER); + break; + + case 2: + Serial.println("Set into Suspend Power Mode"); + bno055_set_operation_mode(POWER_MODE_SUSPEND); + break; + + default: + Serial.println("Invalid Power Mode"); + } + break; + + default: + Serial.println("Invalid Command"); + } + +} \ No newline at end of file diff --git a/arduino_libraries/BNO055-master/examples/Command_Line_Configuration/desktop.ini b/arduino_libraries/BNO055-master/examples/Command_Line_Configuration/desktop.ini new file mode 100644 index 0000000..309dea2 --- /dev/null +++ b/arduino_libraries/BNO055-master/examples/Command_Line_Configuration/desktop.ini @@ -0,0 +1,5 @@ +[.ShellClassInfo] +InfoTip=This folder is shared online. +IconFile=C:\Program Files (x86)\Google\Drive\googledrivesync.exe +IconIndex=16 + \ No newline at end of file diff --git a/arduino_libraries/BNO055-master/examples/Euler_Streaming/Euler_Streaming.ino b/arduino_libraries/BNO055-master/examples/Euler_Streaming/Euler_Streaming.ino new file mode 100644 index 0000000..91d407d --- /dev/null +++ b/arduino_libraries/BNO055-master/examples/Euler_Streaming/Euler_Streaming.ino @@ -0,0 +1,89 @@ +/* + *************************************************************************** + + Euler_Streaming.pde - part of sample SW for using BNO055 with Arduino + + (C) All rights reserved by ROBERT BOSCH GMBH + + Copyright (C) 2014 Bosch Sensortec GmbH + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + **************************************************************************/ +/* Date: 2014/01/07 + Revision: 1.2 + +*/ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 100) //To stream at 10Hz without using additional timers + { + lastTime = millis(); + + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} diff --git a/arduino_libraries/BNO055-master/examples/Sensor_Calibration/Sensor_Calibration.ino b/arduino_libraries/BNO055-master/examples/Sensor_Calibration/Sensor_Calibration.ino new file mode 100644 index 0000000..63de48c --- /dev/null +++ b/arduino_libraries/BNO055-master/examples/Sensor_Calibration/Sensor_Calibration.ino @@ -0,0 +1,97 @@ +/* + *************************************************************************** + * + * Sensor_Calibration.pde - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +unsigned char accelCalibStatus = 0; //Variable to hold the calibration status of the Accelerometer +unsigned char magCalibStatus = 0; //Variable to hold the calibration status of the Magnetometer +unsigned char gyroCalibStatus = 0; //Variable to hold the calibration status of the Gyroscope +unsigned char sysCalibStatus = 0; //Variable to hold the calibration status of the System (BNO055's MCU) + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if((millis()-lastTime) >= 200) //To read calibration status at 5Hz without using additional timers + { + lastTime = millis(); + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + bno055_get_accelcalib_status(&accelCalibStatus); + Serial.print("Accelerometer Calibration Status: "); //To read out the Accelerometer Calibration Status (0-3) + Serial.println(accelCalibStatus); + + bno055_get_magcalib_status(&magCalibStatus); + Serial.print("Magnetometer Calibration Status: "); //To read out the Magnetometer Calibration Status (0-3) + Serial.println(magCalibStatus); + + bno055_get_magcalib_status(&gyroCalibStatus); + Serial.print("Gyroscope Calibration Status: "); //To read out the Gyroscope Calibration Status (0-3) + Serial.println(gyroCalibStatus); + + bno055_get_syscalib_status(&sysCalibStatus); + Serial.print("System Calibration Status: "); //To read out the Magnetometer Calibration Status (0-3) + Serial.println(sysCalibStatus); + + Serial.println(); //To separate between packets + } +} \ No newline at end of file diff --git a/arduino_libraries/BNO055-master/examples/Sensor_Calibration/desktop.ini b/arduino_libraries/BNO055-master/examples/Sensor_Calibration/desktop.ini new file mode 100644 index 0000000..309dea2 --- /dev/null +++ b/arduino_libraries/BNO055-master/examples/Sensor_Calibration/desktop.ini @@ -0,0 +1,5 @@ +[.ShellClassInfo] +InfoTip=This folder is shared online. +IconFile=C:\Program Files (x86)\Google\Drive\googledrivesync.exe +IconIndex=16 + \ No newline at end of file diff --git a/arduino_libraries/BNO055-master/examples/desktop.ini b/arduino_libraries/BNO055-master/examples/desktop.ini new file mode 100644 index 0000000..2bcc7f8 Binary files /dev/null and b/arduino_libraries/BNO055-master/examples/desktop.ini differ diff --git a/arduino_libraries/BNO055-master/library.properties b/arduino_libraries/BNO055-master/library.properties new file mode 100644 index 0000000..d70af2d --- /dev/null +++ b/arduino_libraries/BNO055-master/library.properties @@ -0,0 +1,9 @@ +name=BNO055 +version=1.2.1 +author= ROBERT BOSCH GMBH +maintainer=Arduino +sentence=Allows to use the IMU MKR Shield +paragraph=Allows to use the IMU MKR Shield +category=Sensors +url=http://www.arduino.cc/en/Reference/ +architectures=samd diff --git a/arduino_libraries/SPIMemory-2.6.0/.gitignore b/arduino_libraries/SPIMemory-2.6.0/.gitignore new file mode 100644 index 0000000..d56e8e7 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/.gitignore @@ -0,0 +1,6 @@ +*.development + +#OS specific ignores + +*.DS_Store +Thumbs.db diff --git a/arduino_libraries/SPIMemory-2.6.0/.travis.yml b/arduino_libraries/SPIMemory-2.6.0/.travis.yml new file mode 100644 index 0000000..dbf6268 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/.travis.yml @@ -0,0 +1,20 @@ +language: c++ +sudo: false +before_install: + - source <(curl -SLs https://raw.githubusercontent.com/Marzogh/Travis-CI/master/install.sh) +script: + #- build_main_platforms + - build_platform uno + - build_platform due + #- build_platform zero + - build_platform esp8266 + - build_platform leonardo + - build_platform rtl8195a + - build_platform simblee + - build_platform mega + - build_platform fio + - build_platform micro +notifications: + email: + on_success: change + on_failure: change diff --git a/arduino_libraries/SPIMemory-2.6.0/LICENSE b/arduino_libraries/SPIMemory-2.6.0/LICENSE new file mode 100644 index 0000000..733c072 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/LICENSE @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/arduino_libraries/SPIMemory-2.6.0/README.md b/arduino_libraries/SPIMemory-2.6.0/README.md new file mode 100644 index 0000000..71473cf --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/README.md @@ -0,0 +1,254 @@ + +# SPIFlash [![Build Status](https://travis-ci.org/Marzogh/SPIFlash.svg?branch=master)](https://travis-ci.org/Marzogh/SPIFlash) [![DOI](https://zenodo.org/badge/18908/Marzogh/SPIFlash.svg)](https://zenodo.org/badge/latestdoi/18908/Marzogh/SPIFlash) +### Arduino library for Winbond Flash Memory Chips + Download the latest stable release (v2.6.0) from here. Please report any bugs in issues. + +This Arduino library is for use with Winbond serial flash memory chips. In its current form it supports identifying the flash chip and its various features; automatic address allocation and management; reading and writing bytes/chars/ints/longs/floats/Strings from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes/chars; sector, block and chip erase; and powering down for low power operation. + +- For details of the Winbond Flash chips compatible with this library please refer to the Excel spreadsheet in the Extras folder. + +#### Compatibility + +##### Arduino IDEs supported (actually tested with) +- IDE v1.5.x +- IDE v1.6.0-v1.6.5 +- IDE v1.6.9-v1.6.12 +- IDE v1.8.2 + +##### Boards + +###### Completely supported +- Arduino Uno +- Arduino Leonardo +- Arduino Micro +- Arduino Fio +- Arduino Mega +- Arduino Due +- ESP8266 Boards (On the Arduino IDE) +- Simblee Boards (On the Arduino IDE) + +###### In BETA +- ESP32 Boards (Tested on the Sparkfun ESP32 thing) The library is known to work with the ESP32 core as of the current commit 7d0968c on 16.04.2017. ```ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.``` + +#### Installation + +##### Option 1 +- Open the Arduino IDE. +- Go to Sketch > Include Library > Manage libraries. +- Search for SPIFlash. +- Install the latest version. + +##### Option 2 +- Click on the 'Clone or download' button above the list of files on this page . +- Select Download ZIP. A .zip file will download to your computer. +- Unzip the archive and rename resulting folder to 'SPIFlash' +- Move the folder to your libraries folder (~/sketches/libraries) + +#### Usage + +The library is called by declaring the```SPIFLASH flash(csPin)``` constructor where 'flash' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the flash module. +Make sure to include ```#include``` when you include ```#include```. +Also make sure to include ```flash.begin(CHIPSIZE*)``` in ```void setup()```. This enables the library to detect the type of flash chip installed and load the right parameters. +* Optional + +###### Notes on Address overflow and Error checking +- The library has Address overflow enabled by default - i.e. if the last address read/written from/to, in any function, is 0xFFFFF then, the next address read/written from/to is 0x00000. This can be disabled by setting the optional last 'overflow' argument in the constructor to NOOVERFLOW - For eg. call the constructor ```SPIFlash(csPin, NOOVERFLOW)``` instead of ```SPIFlash(csPin)```. (Address overflow only works for Read / Write functions. Erase functions erase only a set number of blocks/sectors irrespective of overflow.) +- All write functions have Error checking turned on by default - i.e. every byte written to the flash memory will be checked against the data stored on the Arduino. Users who require greater write speeds can disable this function by setting an optional last 'errorCheck' argument in any write function to NOERRCHK - For eg. call the function ```writeByte(address, *data_buffer, NOERRCHK)``` instead of ```writeByte(address, *data_buffer)```. + +The library enables the following functions: +
+ +##### Primary commands + +###### begin(_chipsize*) +Must be called at the start in setup(). This function detects the type of chip being used and sets parameters accordingly. An optional CHIPSIZE parameter can be declared as an argument with this function. For supported CHIPSIZE values, please refer to the appropriate [wiki section](https://github.com/Marzogh/SPIFlash/wiki/begin()) or look at defines.h . + +###### setClock(clockSpeed) +Must be called straight after begin(). This function takes a 32-bit number as replacement for the default maximum clock speed (104MHz for Winbond NOR flash) thereby initiating future SPI transactions with the user-defined clock speed. Use with care. + +###### error(_verbosity) +Returns the (8-bit) error code generated by the function called immediately before this is called. If the optional VERBOSE argument is used, a verbose troubleshooting report is printed to Serial. Refer to the [Error reporting](https://github.com/Marzogh/SPIFlash/wiki/Error-reporting) section the Wiki for further reference. + +###### getMANID() +Returns the Manufacturer ID as a 16-bit value. + +###### getJEDECID() +Returns the JEDEC ID as a 32-bit value. + +###### getCapacity() +Returns the capacity in bytes as a 32-bit value. + +###### getmaxPage() +Returns the maximum number of pages in the flash memory as a 32-bit value. + +###### getAddress() +Gets the next available address for use. Has two variants: +* Takes the size of the data as an argument and returns a 32-bit address +* Takes a three variables, the size of the data and two other variables to return a page number value & an offset into. + +All addresses in the in the sketch must be obtained via this function or not at all. +###### sizeofStr() +Use this function to find the size of a String to use as the argument in getAddress(size). Using size = sizeof(String) will cause the getAddress(size) function to fail. + +size = sizeof(variable) can be used for all types of data but String objects. +
+ +###### All read/write commands can take a 32-bit address variable in the place of the 16-bit page number & 8-bit offset variables. +
+ +##### Read commands +All read commands take a last boolean argument 'fastRead'. This argument defaults to FALSE, but when set to TRUE carries out the Fast Read instruction so data can be read at up to the memory's maximum frequency. + +All read commands can take a 32-bit address variable instead of the 16-bit page number & 8-bit offset variables + +###### readAnything(page_number, offset, value) +Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data back to, as arguments. + +###### readByte(page_number, offset) +Reads a _byte_ (unsigned 8 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the byte within page (0-255) as arguments. + +###### readChar(page_number, offset) +Reads a _char_ (signed 8 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the char within page (0-255) as arguments. + +###### readWord(page_number, offset) +Reads a _word_ (unsigned 16 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the word within page (0-255) as arguments. + +###### readShort(page_number, offset) +Reads a _short_ (signed 16 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the short within page (0-255) as arguments. + +###### readULong(page_number, offset) +Reads an _unsigned long_ (unsigned 32 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the unsigned long within page (0-255) as arguments. + +###### readLong(page_number, offset) +Reads a _long_ (signed 32 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the long within page (0-255) as arguments. + +###### readFloat(page_number, offset) +Reads a _float_ (decimal value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the float within page (0-255) as arguments. + +###### readStr(page_number, offset, outputStr) +Reads a _string_ (String Object) to a specific location on a page to an outputStr variable. Takes the page number (0-maxPage), the offset of the String within page (0-255) and a String as arguments. + +###### readPage(page_number, *data_buffer) +Reads a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. + +###### readAnything(page_number, offset, value) +Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data to, as arguments. +
+ +##### Write commands +All write commands take a boolean last argument 'errorCheck'. This argument defaults to TRUE, but when set to FALSE will more than double the writing speed. This however comes at the cost of checking for writing errors. Use with care. + +All write commands can take a 32-bit address variable instead of the 16-bit page number & 8-bit offset variables + +###### writeByte(page, offset, data) +Writes a byte of data to a specific location on a page. Takes the page number (0-maxPage), offset of data byte within page (0-255) and one byte of data as arguments. + +###### writeChar(page_number, offset, data) +Writes a _char_ (signed 8 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the char within page (0-255) and one char of data as arguments. + +###### writeWord(page_number, offset, data) +Writes a _word_ (unsigned 16 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the word within page (0-255) and one word of data as arguments. + +###### writeShort(page_number, offset, data) +Writes a _short_ (signed 16 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the short within page (0-255) and one short of data as arguments. + +###### writeULong(page_number, offset, data) +Writes an _unsigned long_ (unsigned 32 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the unsigned long within page (0-255) and one unsigned long of data as arguments. + +###### writeLong(page_number, offset, data) +Writes a _long_ (signed 32 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the long within page (0-255) and one long of data as arguments. + +###### writeFloat(page_number, offset, data) +Writes a _float_ (decimal value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the float within page (0-255) and one float of data as arguments. + +###### writeStr(page_number, offset, data) +Writes a _string_ (String Object) to a specific location on a page. Takes the page number (0-maxPage), the offset of the String within page (0-255) and a String as arguments. + +###### writePage(page_number, *data_buffer) +Writes a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. + +###### writeAnything(page_number, offset, value) +Writes _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data from, as arguments. +
+ +##### Continuous read/write commands +All write commands take a boolean last argument 'errorCheck'. This argument defaults to TRUE, but when set to FALSE will more than double the writing speed. This however comes at the cost of checking for writing errors. Use with care. + +###### readByteArray(page_number, offset, *data_buffer, bufferSize) +Reads an array of bytes starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of bytes to be read from the flash memory - and size of the array as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of n **bytes**. 'n' is determined by the amount of RAM available on the Arduino board. + +###### writeByteArray(page_number, offset, *data_buffer, bufferSize) +Writes an array of bytes starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of bytes to be written to the flash memory - and size of the array as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of 'n' **bytes**. The number of bytes - 'n' - is determined by the amount of RAM available on the Arduino board. + +###### readCharArray(page_number, offset, *data_buffer, bufferSize) +Reads an array of chars starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of chars to be read from the flash memory - and size of the array as arguments. ```char data_buffer[n];``` The data buffer **must** be an array of n **chars**. 'n' is determined by the amount of RAM available on the Arduino board. + +###### writeCharArray(page_number, offset, *data_buffer, bufferSize) +Writes an array of chars starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of chars to be written to the flash memory - and size of the array as arguments. ```char data_buffer[n];``` The data buffer **must** be an array of 'n' **chars**. The number of chars - 'n' - is determined by the amount of RAM available on the Arduino board. +
+ +##### Erase commands +All erase commands can take a 32-bit address variable instead of the 16-bit page number & 8-bit offset variables + +###### eraseSector(page_number, offset) +Erases one 4KB sector - 16 pages - containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each. +Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255, and so on... + +###### eraseBlock32K(page_number, offset) +Erases one 32KB block - 128 pages - containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each. +Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31, and so on... + +###### eraseBlock64K(page_number, offset) +Erases one 64KB block - 256 pages - containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each. +// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15, and so on... + +###### eraseChip() +Erases entire chip. Use with care. +
+ +##### Suspend/Resume commands + +###### suspendProg() +Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). Page Program, Write Status Register, Erase instructions are not allowed. Erase suspend is only allowed during Block/Sector erase. Program suspend is only allowed during Page/Quad Page Program + +###### resumeProg() +Resumes previously suspended Block Erase/Sector Erase/Page Program. +
+ +##### Power operation commands + +###### powerDown() +Puts device in low power state. Useful for battery powered operations. Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4). In powerDown() the chip will only respond to powerUp() + +###### powerUp() +Wakes chip from low power state. +
+ +##### Error codes explained + +* **0x00** - Action completed successfully. No Error. +* **0x01** - *constructor_of_choice*.begin() was not called in void setup() +* **0x02** - Unable to identify chip. Are you sure this is a Winbond Flash chip? Please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with your chip type and I will try to add support to your chip +* **0x03** - Unable to identify capacity. Please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with your chip type and I will work on adding support to your chip +* **0x04** - Chip is busy. Make sure all pins have been connected properly. If it still doesn't work,please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred +* **0x05** - Page overflow has been disabled and the address called exceeds the memory +* **0x06** - Unable to Enable Writing to chip. Please make sure the HOLD & WRITEPROTECT pins are connected properly to VCC & GND respectively. If you are still facing issues, please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred +* **0x07** - This sector already contains data. Please make sure the sectors being written to are erased. If you are still facing issues, please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred. +* **0x08** - You are running low on SRAM. Please optimise your program for better RAM usage +* **0x09** - Unable to suspend/resume operation. +* **0x0A** - This function is not supported by the current flash IC. +* **0x0B** - Write Function has failed errorcheck. +* **0x0C** - Check your wiring. Flash chip is non-responsive. +* **0xFE** - Unknown error. Please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred +
+ +###### How to get data off Flash memory via Serial +(Works only for Unix based Operating Systems) + + - Make sure you include code to let you dump entire flash memory/specific page's content to Serial (Refer to the code in the _TestFlash.h_ for details on how to do this) + - Connect your Arduino board to the computer. + - Open the Arduino IDE, the IDE's Serial Monitor, and an OSX POSIX terminal. + - Type the following command into the terminal window. ```% tail -f /dev/tty.usbmodem1411 > FlashDump.txt``` Make sure to replace the _/dev/tty.usbmodem1411_ with the port your arduino is connected to. (You can find this in Tools --> Ports in Arduino IDE 1.6.x) + - Then type the command to read all pages into the Serial console. If you use my code from the example file the command is ```read_all_pages``` + - Wait a few seconds before typing ```Ctrl+C``` to end the tail process + - Check that you have actually recieved all the data by typing ```% cat FlashDump.txt```. This should output the entire textfile into your terminal window. diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/.gitignore b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/.gitignore new file mode 100644 index 0000000..d56e8e7 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/.gitignore @@ -0,0 +1,6 @@ +*.development + +#OS specific ignores + +*.DS_Store +Thumbs.db diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/.travis.yml b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/.travis.yml new file mode 100644 index 0000000..dbf6268 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/.travis.yml @@ -0,0 +1,20 @@ +language: c++ +sudo: false +before_install: + - source <(curl -SLs https://raw.githubusercontent.com/Marzogh/Travis-CI/master/install.sh) +script: + #- build_main_platforms + - build_platform uno + - build_platform due + #- build_platform zero + - build_platform esp8266 + - build_platform leonardo + - build_platform rtl8195a + - build_platform simblee + - build_platform mega + - build_platform fio + - build_platform micro +notifications: + email: + on_success: change + on_failure: change diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/LICENSE b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/LICENSE new file mode 100644 index 0000000..733c072 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/LICENSE @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/README.md b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/README.md new file mode 100644 index 0000000..71473cf --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/README.md @@ -0,0 +1,254 @@ + +# SPIFlash [![Build Status](https://travis-ci.org/Marzogh/SPIFlash.svg?branch=master)](https://travis-ci.org/Marzogh/SPIFlash) [![DOI](https://zenodo.org/badge/18908/Marzogh/SPIFlash.svg)](https://zenodo.org/badge/latestdoi/18908/Marzogh/SPIFlash) +### Arduino library for Winbond Flash Memory Chips + Download the latest stable release (v2.6.0) from here. Please report any bugs in issues. + +This Arduino library is for use with Winbond serial flash memory chips. In its current form it supports identifying the flash chip and its various features; automatic address allocation and management; reading and writing bytes/chars/ints/longs/floats/Strings from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes/chars; sector, block and chip erase; and powering down for low power operation. + +- For details of the Winbond Flash chips compatible with this library please refer to the Excel spreadsheet in the Extras folder. + +#### Compatibility + +##### Arduino IDEs supported (actually tested with) +- IDE v1.5.x +- IDE v1.6.0-v1.6.5 +- IDE v1.6.9-v1.6.12 +- IDE v1.8.2 + +##### Boards + +###### Completely supported +- Arduino Uno +- Arduino Leonardo +- Arduino Micro +- Arduino Fio +- Arduino Mega +- Arduino Due +- ESP8266 Boards (On the Arduino IDE) +- Simblee Boards (On the Arduino IDE) + +###### In BETA +- ESP32 Boards (Tested on the Sparkfun ESP32 thing) The library is known to work with the ESP32 core as of the current commit 7d0968c on 16.04.2017. ```ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.``` + +#### Installation + +##### Option 1 +- Open the Arduino IDE. +- Go to Sketch > Include Library > Manage libraries. +- Search for SPIFlash. +- Install the latest version. + +##### Option 2 +- Click on the 'Clone or download' button above the list of files on this page . +- Select Download ZIP. A .zip file will download to your computer. +- Unzip the archive and rename resulting folder to 'SPIFlash' +- Move the folder to your libraries folder (~/sketches/libraries) + +#### Usage + +The library is called by declaring the```SPIFLASH flash(csPin)``` constructor where 'flash' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the flash module. +Make sure to include ```#include``` when you include ```#include```. +Also make sure to include ```flash.begin(CHIPSIZE*)``` in ```void setup()```. This enables the library to detect the type of flash chip installed and load the right parameters. +* Optional + +###### Notes on Address overflow and Error checking +- The library has Address overflow enabled by default - i.e. if the last address read/written from/to, in any function, is 0xFFFFF then, the next address read/written from/to is 0x00000. This can be disabled by setting the optional last 'overflow' argument in the constructor to NOOVERFLOW - For eg. call the constructor ```SPIFlash(csPin, NOOVERFLOW)``` instead of ```SPIFlash(csPin)```. (Address overflow only works for Read / Write functions. Erase functions erase only a set number of blocks/sectors irrespective of overflow.) +- All write functions have Error checking turned on by default - i.e. every byte written to the flash memory will be checked against the data stored on the Arduino. Users who require greater write speeds can disable this function by setting an optional last 'errorCheck' argument in any write function to NOERRCHK - For eg. call the function ```writeByte(address, *data_buffer, NOERRCHK)``` instead of ```writeByte(address, *data_buffer)```. + +The library enables the following functions: +
+ +##### Primary commands + +###### begin(_chipsize*) +Must be called at the start in setup(). This function detects the type of chip being used and sets parameters accordingly. An optional CHIPSIZE parameter can be declared as an argument with this function. For supported CHIPSIZE values, please refer to the appropriate [wiki section](https://github.com/Marzogh/SPIFlash/wiki/begin()) or look at defines.h . + +###### setClock(clockSpeed) +Must be called straight after begin(). This function takes a 32-bit number as replacement for the default maximum clock speed (104MHz for Winbond NOR flash) thereby initiating future SPI transactions with the user-defined clock speed. Use with care. + +###### error(_verbosity) +Returns the (8-bit) error code generated by the function called immediately before this is called. If the optional VERBOSE argument is used, a verbose troubleshooting report is printed to Serial. Refer to the [Error reporting](https://github.com/Marzogh/SPIFlash/wiki/Error-reporting) section the Wiki for further reference. + +###### getMANID() +Returns the Manufacturer ID as a 16-bit value. + +###### getJEDECID() +Returns the JEDEC ID as a 32-bit value. + +###### getCapacity() +Returns the capacity in bytes as a 32-bit value. + +###### getmaxPage() +Returns the maximum number of pages in the flash memory as a 32-bit value. + +###### getAddress() +Gets the next available address for use. Has two variants: +* Takes the size of the data as an argument and returns a 32-bit address +* Takes a three variables, the size of the data and two other variables to return a page number value & an offset into. + +All addresses in the in the sketch must be obtained via this function or not at all. +###### sizeofStr() +Use this function to find the size of a String to use as the argument in getAddress(size). Using size = sizeof(String) will cause the getAddress(size) function to fail. + +size = sizeof(variable) can be used for all types of data but String objects. +
+ +###### All read/write commands can take a 32-bit address variable in the place of the 16-bit page number & 8-bit offset variables. +
+ +##### Read commands +All read commands take a last boolean argument 'fastRead'. This argument defaults to FALSE, but when set to TRUE carries out the Fast Read instruction so data can be read at up to the memory's maximum frequency. + +All read commands can take a 32-bit address variable instead of the 16-bit page number & 8-bit offset variables + +###### readAnything(page_number, offset, value) +Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data back to, as arguments. + +###### readByte(page_number, offset) +Reads a _byte_ (unsigned 8 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the byte within page (0-255) as arguments. + +###### readChar(page_number, offset) +Reads a _char_ (signed 8 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the char within page (0-255) as arguments. + +###### readWord(page_number, offset) +Reads a _word_ (unsigned 16 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the word within page (0-255) as arguments. + +###### readShort(page_number, offset) +Reads a _short_ (signed 16 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the short within page (0-255) as arguments. + +###### readULong(page_number, offset) +Reads an _unsigned long_ (unsigned 32 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the unsigned long within page (0-255) as arguments. + +###### readLong(page_number, offset) +Reads a _long_ (signed 32 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the long within page (0-255) as arguments. + +###### readFloat(page_number, offset) +Reads a _float_ (decimal value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the float within page (0-255) as arguments. + +###### readStr(page_number, offset, outputStr) +Reads a _string_ (String Object) to a specific location on a page to an outputStr variable. Takes the page number (0-maxPage), the offset of the String within page (0-255) and a String as arguments. + +###### readPage(page_number, *data_buffer) +Reads a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. + +###### readAnything(page_number, offset, value) +Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data to, as arguments. +
+ +##### Write commands +All write commands take a boolean last argument 'errorCheck'. This argument defaults to TRUE, but when set to FALSE will more than double the writing speed. This however comes at the cost of checking for writing errors. Use with care. + +All write commands can take a 32-bit address variable instead of the 16-bit page number & 8-bit offset variables + +###### writeByte(page, offset, data) +Writes a byte of data to a specific location on a page. Takes the page number (0-maxPage), offset of data byte within page (0-255) and one byte of data as arguments. + +###### writeChar(page_number, offset, data) +Writes a _char_ (signed 8 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the char within page (0-255) and one char of data as arguments. + +###### writeWord(page_number, offset, data) +Writes a _word_ (unsigned 16 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the word within page (0-255) and one word of data as arguments. + +###### writeShort(page_number, offset, data) +Writes a _short_ (signed 16 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the short within page (0-255) and one short of data as arguments. + +###### writeULong(page_number, offset, data) +Writes an _unsigned long_ (unsigned 32 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the unsigned long within page (0-255) and one unsigned long of data as arguments. + +###### writeLong(page_number, offset, data) +Writes a _long_ (signed 32 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the long within page (0-255) and one long of data as arguments. + +###### writeFloat(page_number, offset, data) +Writes a _float_ (decimal value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the float within page (0-255) and one float of data as arguments. + +###### writeStr(page_number, offset, data) +Writes a _string_ (String Object) to a specific location on a page. Takes the page number (0-maxPage), the offset of the String within page (0-255) and a String as arguments. + +###### writePage(page_number, *data_buffer) +Writes a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. + +###### writeAnything(page_number, offset, value) +Writes _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data from, as arguments. +
+ +##### Continuous read/write commands +All write commands take a boolean last argument 'errorCheck'. This argument defaults to TRUE, but when set to FALSE will more than double the writing speed. This however comes at the cost of checking for writing errors. Use with care. + +###### readByteArray(page_number, offset, *data_buffer, bufferSize) +Reads an array of bytes starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of bytes to be read from the flash memory - and size of the array as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of n **bytes**. 'n' is determined by the amount of RAM available on the Arduino board. + +###### writeByteArray(page_number, offset, *data_buffer, bufferSize) +Writes an array of bytes starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of bytes to be written to the flash memory - and size of the array as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of 'n' **bytes**. The number of bytes - 'n' - is determined by the amount of RAM available on the Arduino board. + +###### readCharArray(page_number, offset, *data_buffer, bufferSize) +Reads an array of chars starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of chars to be read from the flash memory - and size of the array as arguments. ```char data_buffer[n];``` The data buffer **must** be an array of n **chars**. 'n' is determined by the amount of RAM available on the Arduino board. + +###### writeCharArray(page_number, offset, *data_buffer, bufferSize) +Writes an array of chars starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255), a data_buffer - i.e. an array of chars to be written to the flash memory - and size of the array as arguments. ```char data_buffer[n];``` The data buffer **must** be an array of 'n' **chars**. The number of chars - 'n' - is determined by the amount of RAM available on the Arduino board. +
+ +##### Erase commands +All erase commands can take a 32-bit address variable instead of the 16-bit page number & 8-bit offset variables + +###### eraseSector(page_number, offset) +Erases one 4KB sector - 16 pages - containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each. +Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255, and so on... + +###### eraseBlock32K(page_number, offset) +Erases one 32KB block - 128 pages - containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each. +Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31, and so on... + +###### eraseBlock64K(page_number, offset) +Erases one 64KB block - 256 pages - containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each. +// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15, and so on... + +###### eraseChip() +Erases entire chip. Use with care. +
+ +##### Suspend/Resume commands + +###### suspendProg() +Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). Page Program, Write Status Register, Erase instructions are not allowed. Erase suspend is only allowed during Block/Sector erase. Program suspend is only allowed during Page/Quad Page Program + +###### resumeProg() +Resumes previously suspended Block Erase/Sector Erase/Page Program. +
+ +##### Power operation commands + +###### powerDown() +Puts device in low power state. Useful for battery powered operations. Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4). In powerDown() the chip will only respond to powerUp() + +###### powerUp() +Wakes chip from low power state. +
+ +##### Error codes explained + +* **0x00** - Action completed successfully. No Error. +* **0x01** - *constructor_of_choice*.begin() was not called in void setup() +* **0x02** - Unable to identify chip. Are you sure this is a Winbond Flash chip? Please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with your chip type and I will try to add support to your chip +* **0x03** - Unable to identify capacity. Please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with your chip type and I will work on adding support to your chip +* **0x04** - Chip is busy. Make sure all pins have been connected properly. If it still doesn't work,please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred +* **0x05** - Page overflow has been disabled and the address called exceeds the memory +* **0x06** - Unable to Enable Writing to chip. Please make sure the HOLD & WRITEPROTECT pins are connected properly to VCC & GND respectively. If you are still facing issues, please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred +* **0x07** - This sector already contains data. Please make sure the sectors being written to are erased. If you are still facing issues, please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred. +* **0x08** - You are running low on SRAM. Please optimise your program for better RAM usage +* **0x09** - Unable to suspend/resume operation. +* **0x0A** - This function is not supported by the current flash IC. +* **0x0B** - Write Function has failed errorcheck. +* **0x0C** - Check your wiring. Flash chip is non-responsive. +* **0xFE** - Unknown error. Please raise an issue [here](http://www.github.com/Marzogh/SPIFlash/issues) with the details of what your were doing when this error occurred +
+ +###### How to get data off Flash memory via Serial +(Works only for Unix based Operating Systems) + + - Make sure you include code to let you dump entire flash memory/specific page's content to Serial (Refer to the code in the _TestFlash.h_ for details on how to do this) + - Connect your Arduino board to the computer. + - Open the Arduino IDE, the IDE's Serial Monitor, and an OSX POSIX terminal. + - Type the following command into the terminal window. ```% tail -f /dev/tty.usbmodem1411 > FlashDump.txt``` Make sure to replace the _/dev/tty.usbmodem1411_ with the port your arduino is connected to. (You can find this in Tools --> Ports in Arduino IDE 1.6.x) + - Then type the command to read all pages into the Serial console. If you use my code from the example file the command is ```read_all_pages``` + - Wait a few seconds before typing ```Ctrl+C``` to end the tail process + - Check that you have actually recieved all the data by typing ```% cat FlashDump.txt```. This should output the entire textfile into your terminal window. diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostic_functions.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostic_functions.ino new file mode 100644 index 0000000..399a231 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostic_functions.ino @@ -0,0 +1,863 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | FlashDiagnostic_functions.ino | + | SPIFlash library | + | v 2.6.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 13.11.2016 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | For a full diagnostics rundown - with error codes and details of the errors | + | uncomment #define RUNDIAGNOSTIC in SPIFlash.cpp in the library before compiling | + | and loading this application onto your Arduino. | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ + +void getID() { + char printBuffer[128]; + printLine(); + for (uint8_t i = 0; i < 68; i++) { + Serial.print(F(" ")); + } + Serial.print(F("SPIFlash Library version")); +#ifdef LIBVER + uint8_t _ver, _subver, _bugfix; + flash.libver(&_ver, &_subver, &_bugfix); + clearprintBuffer(&printBuffer[1]); + sprintf(printBuffer, ": %d.%d.%d", _ver, _subver, _bugfix); + Serial.println(printBuffer); +#else + Serial.println(F("< 2.5.0")); +#endif + printLine(); + + for (uint8_t i = 0; i < 80; i++) { + Serial.print(F(" ")); + } + Serial.println(F("Get ID")); + printLine(); + uint8_t b1, b2; + uint16_t b3; + uint32_t JEDEC = flash.getJEDECID(); + uint32_t maxPage = flash.getMaxPage(); + uint32_t capacity = flash.getCapacity(); + b1 = (JEDEC >> 16); + b2 = (JEDEC >> 8); + b3 = (JEDEC >> 0); + + + printLine(); + //---------------------------------------------------------------------------------------------// + + clearprintBuffer(&printBuffer[1]); + sprintf(printBuffer, "\t\t\tJEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); + clearprintBuffer(&printBuffer[1]); + sprintf(printBuffer, "\t\t\tManufacturer ID: %02xh\n\t\t\tMemory Type: %02xh\n\t\t\tCapacity: %lu bytes\n\t\t\tMaximum pages: %lu", b1, b2, capacity, maxPage); + Serial.println(printBuffer); +} + +bool checkPage(uint8_t *data_buffer) { + for (int i = 0; i < 256; i++) { + if (data_buffer[i] != i) + return false; + } + return true; +} + +void diagnose() { + printLine(); + for (uint8_t i = 0; i < 79; i++) { + Serial.print(F(" ")); + } + Serial.println(F("Data Check")); + printLine(); + + Serial.println(F("\tData Written\t||\tData Read\t||\tResult\t\t||\tWrite Time\t||\tRead Time\t||\tWrite Time\t||\tFast Read Time")); + Serial.print(F("\t\t\t||\t\t\t||\t\t\t||\t\t\t||\t\t\t||")); + Serial.println(F("\t(No Error Chk)\t||")); + printLine(); + byteDiag(); + charDiag(); + wordDiag(); + shortDiag(); + uLongDiag(); + longDiag(); + floatDiag(); + stringDiag(); + structDiag(); + pageDiag(); + powerFuncDiag(); + +} + +void byteDiag(void) { + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Byte // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + uint8_t _byte = 35; + uint8_t _b; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeByte(addr, _byte); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _b = flash.readByte(addr); + rTime = micros() - startTime; + //Print result + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_byte); + printTab(2, 1); + Serial.print(_b); + printTab(2, 1); + if (_byte == _b) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeByte(addr, _byte, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _b = flash.readByte(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void charDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Char // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + int8_t _char = -110; + int8_t _c; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeChar(addr, _char); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _c = flash.readChar(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_char); + printTab(2, 1); + Serial.print(_c); + printTab(2, 1); + if (_char == _c) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeChar(addr, _char, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _c = flash.readChar(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void wordDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Word // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + uint16_t _word = 4520; + uint16_t _w; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeWord(addr, _word); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _w = flash.readWord(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_word); + printTab(2, 1); + Serial.print(_w); + printTab(2, 1); + if (_word == _w) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeWord(addr, _word, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _w = flash.readWord(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void shortDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Short // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + int16_t _short = -1250; + int16_t _s; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeShort(addr, _short); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _s = flash.readShort(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_short); + printTab(2, 1); + Serial.print(_s); + printTab(2, 1); + if (_short == _s) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeShort(addr, _short, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _s = flash.readShort(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void uLongDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Ulong // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + uint32_t _uLong = 876532; + uint32_t _uL; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeULong(addr, _uLong); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _uL = flash.readULong(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_uLong); + printTab(2, 1); + Serial.print(_uL); + printTab(2, 1); + if (_uLong == _uL) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeULong(addr, _uLong, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _uL = flash.readULong(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void longDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Long // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + int32_t _long = -10959; + int32_t _l; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeLong(addr, _long); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _l = flash.readLong(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_long); + printTab(2, 1); + Serial.print(_l); + printTab(2, 1); + if (_long == _l) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeLong(addr, _long, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _l = flash.readLong(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void floatDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Float // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + float _float = 3.1415; + float _f; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeFloat(addr, _float)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _f = flash.readFloat(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_float); + printTab(2, 1); + Serial.print(_f); + printTab(2, 1); + if (_float == _f) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeFloat(addr, _float, false)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _f = flash.readFloat(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void stringDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // String // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + String _string = "123 Test !@#"; + String _str = ""; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeStr(addr, _string)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + if (flash.readStr(addr, _str)) { + rTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_string); + printTab(1, 1); + Serial.print(_str); + printTab(1, 1); + if (_string == _str) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeStr(addr, _string, false)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + if (flash.readStr(addr, _str, true)) { + rTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void structDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Struct // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + struct Test { + word s1; + float s2; + long s3; + bool s4; + byte s5; + }; + Test inputStruct; + Test outputStruct; + + inputStruct.s1 = 31325; + inputStruct.s2 = 4.84; + inputStruct.s3 = 880932; + inputStruct.s4 = true; + inputStruct.s5 = 5; + + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeAnything(addr, inputStruct); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + flash.readAnything(addr, outputStruct); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(F("inputStruct")); + printTab(1, 1); + Serial.print(F("outputStruct")); + printTab(1, 1); + if (inputStruct.s1 == outputStruct.s1 && inputStruct.s2 == outputStruct.s2 && inputStruct.s3 == outputStruct.s3 && inputStruct.s4 == outputStruct.s4 && inputStruct.s5 == outputStruct.s5) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeAnything(addr, inputStruct, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + flash.readAnything(addr, outputStruct, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void pageDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Page // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + float startTime; + uint32_t addr, wTime, rTime; + uint8_t pageBuffer[PAGESIZE]; + + for (int i = 0; i < PAGESIZE; ++i) { + pageBuffer[i] = i; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, flash.getMaxPage()); + startTime = micros(); + while (!flash.writeByteArray(addr, pageBuffer, PAGESIZE)); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read & Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + for (int i = 0; i < PAGESIZE; ++i) { + pageBuffer[i] = 0; + } + startTime = micros(); + printTab(1, 0); + Serial.print(F("0 - ")); + Serial.print(PAGESIZE - 1); + printTab(2, 1); + startTime = micros(); + + flash.readByteArray(addr, pageBuffer, PAGESIZE); + rTime = micros() - startTime; + bool _pass; + for (uint16_t i = 0; i < 256; i++) { + if (pageBuffer [i] != i) { + _pass = false; + break; + } + else { + _pass = true; + } + } + + if (_pass) { + Serial.print(F("0 - ")); + Serial.print(PAGESIZE - 1); + printTab(2, 1); + printPass(); + } + else { + Serial.print(F("Unknown")); + printTab(2, 1); + printFail(); + } + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + for (int i = 0; i < 256; ++i) { + pageBuffer[i] = i; + } + addr = random(0, flash.getMaxPage()); + startTime = micros(); + flash.writeByteArray(addr, pageBuffer, PAGESIZE, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read & Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + for (int i = 0; i < 256; ++i) { + pageBuffer[i] = 0; + } + startTime = micros(); + flash.readByteArray(addr, pageBuffer, PAGESIZE, true); + rTime = micros() - startTime; + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void powerFuncDiag(void) { + String _string = "123 Test !@#"; + float wTime; + + printLine(); + for (uint8_t i = 0; i < 72; i++) { + Serial.print(" "); + } + Serial.println(F("Check Other Functions")); + printLine(); + Serial.println(F("\t\t\t\t\tFunction\t\t||\t\tResult\t\t\t||\t\tTime")); + printLine(); + Serial.flush(); + + uint32_t capacity = flash.getCapacity(); + if (!Serial) + Serial.begin(115200); + uint32_t stringAddress1 = random(0, capacity); + uint32_t stringAddress2 = random(0, capacity); + uint32_t stringAddress3 = random(0, capacity); + + printTab(5, 0); + Serial.print(F("powerDown")); + printTab(2, 2); + //if (flash.writeStr(stringAddress1, _string)) { + wTime = micros(); + if (flash.powerDown()) { + wTime = micros() - wTime; + printPass(); + } + else { + wTime = micros() - wTime; + printFail(); + } + //} + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("powerUp")); + printTab(3, 2); + wTime = micros(); + if (flash.powerUp()) { + wTime = micros() - wTime; + //if (flash.writeStr(stringAddress3, _string)) { + printPass(); + } + else { + printFail(); + } + //} + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseSector")); + wTime = micros(); + printTab(2, 2); + if (flash.eraseSector(stringAddress1)) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + wTime = wTime / 3; + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseBlock32K")); + wTime = micros(); + printTab(2, 2); + if (flash.eraseBlock32K(stringAddress2)) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + wTime = wTime / 3; + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseBlock64K")); + wTime = micros(); + printTab(2, 2); + if (flash.eraseBlock64K(stringAddress3)) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + wTime = wTime / 3; + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseChip")); + printTab(2, 2); + wTime = micros(); + if (flash.eraseChip()) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + + + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printLine(); +} diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostics.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostics.ino new file mode 100644 index 0000000..0528dfe --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostics.ino @@ -0,0 +1,131 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | FlashDiagnostics.ino | + | SPIFlash library | + | v 2.6.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 16.04.2017 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | For a full diagnostics rundown - with error codes and details of the errors | + | uncomment #define RUNDIAGNOSTIC in SPIFlash.cpp in the library before compiling | + | and loading this application onto your Arduino. | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ + +#include + +//Define a flash memory size (if using non-Winbond memory) according to the list in defines.h +//#define CHIPSIZE MB64 + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#define RANDPIN 1 +#else +#define BAUD_RATE 115200 +#define RANDPIN A0 +#endif + +SPIFlash flash; + +void setup() { + Serial.begin(BAUD_RATE); +#if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) + while (!Serial) ; // Wait for Serial monitor to open +#endif + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); +#if defined (CHIPSIZE) + flash.begin(CHIPSIZE); //use flash.begin(CHIPSIZE) if using non-Winbond flash (Refer to '#define CHIPSIZE' above) +#else + flash.begin(); +#endif + Serial.println(); + Serial.println(); + +#if defined (ARDUINO_ARCH_ESP32) + randomSeed(65535537); +#else + randomSeed(analogRead(RANDPIN)); +#endif + getID(); + diagnose(); +} + +void loop() { + +} + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Serial Print Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +void clearprintBuffer(char *bufPtr) +{ + for (uint8_t i = 0; i < 128; i++) { + //printBuffer[i] = 0; + *bufPtr++ = 0; + } +} + +void printLine() { + for (uint8_t i = 0; i < 230; i++) { + Serial.print(F("-")); + } + Serial.println(); +} + +void printPass() { + Serial.print(F("Pass")); +} + +void printFail() { + Serial.print(F("Fail")); +} + +void printTab(uint8_t a, uint8_t b) { + for (uint8_t i = 0; i < a; i++) { + Serial.print(F("\t")); + } + if (b > 0) { + Serial.print("||"); + for (uint8_t i = 0; i < b; i++) { + Serial.print(F("\t")); + } + } +} + +void printTime(uint32_t _wTime, uint32_t _rTime) { + printTab(2, 1); + printTimer(_wTime); + printTab(2, 1); + printTimer(_rTime); +} + +void printTimer(uint32_t _us) { + + if (_us > 1000000) { + float _s = _us / (float)1000000; + Serial.print(_s, 4); + Serial.print(" s"); + } + else if (_us > 10000) { + float _ms = _us / (float)1000; + Serial.print(_ms, 4); + Serial.print(" ms"); + } + else { + Serial.print(_us); + Serial.print(F(" us")); + } +} diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/Struct_writer/Struct_writer.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/Struct_writer/Struct_writer.ino new file mode 100644 index 0000000..e33e2d8 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/Struct_writer/Struct_writer.ino @@ -0,0 +1,144 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Struct_writer.ino | + | SPIFlash library | + | v 2.6.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 16.04.2017 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | This program writes a struct to a random location on your flash memory chip and reads it back. | + | Uncomment #define SENSOR below to get real world readings. Real world readings require a Light dependant resistor hooked up to A0. | + | For information on how to hook up an LDR to an Arduino, please refer to Adafruit's excellent tutorial at | + | https://learn.adafruit.com/photocells/using-a-photocell | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ + +#include + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#else +#define BAUD_RATE 115200 +#endif + +/* + Uncomment the #define below if you would like real world readings. + For real world readings, hook up a light dependant resistor to A1. + +*/ +//#define SENSOR +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#define LDR 1 +#else +#define BAUD_RATE 115200 +#define LDR A0 +#endif + + + +SPIFlash flash; + + +struct Configuration { + float lux; + float vOut; // Voltage ouput from potential divider to Analog input + float RLDR; // Resistance calculation of potential divider with LDR + bool light; + uint8_t adc; +}; +Configuration configuration; + +void setup() { + Serial.begin(BAUD_RATE); +#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__) + while (!Serial) ; // Wait for Serial monitor to open +#endif + #if defined (ARDUINO_ARCH_ESP32) + randomSeed(65535537); +#else + randomSeed(analogRead(LDR)); +#endif + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + Serial.println(); + flash.begin(); + + + uint32_t _addr = random(0, 1677215); + +#ifndef SENSOR + configuration.lux = 98.43; + configuration.vOut = 4.84; + configuration.RLDR = 889.32; + configuration.light = true; + configuration.adc = 5; +#endif + +#ifdef SENSOR + readLDR(); +#endif + + if (flash.writeAnything(_addr, configuration)) + Serial.println ("Data write successful"); + else + Serial.println ("Data write failed"); + + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + + Serial.println("Saved!"); + configuration.lux = 0; + configuration.vOut = 0; + configuration.RLDR = 0; + configuration.light = 0; + configuration.adc = 0; + Serial.println(); + Serial.println("Local values set to 0"); + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + Serial.println(); + flash.readAnything(_addr, configuration); + flash.eraseSector(_addr, 0); + + Serial.println("After reading"); + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + +} + +void loop() { + delay(1000); +} + +#ifdef SENSOR +void readLDR() +{ + configuration.adc = analogRead(LDR); + configuration.vOut = (configuration.adc * 0.0048828125); // vOut = Output voltage from potential Divider. [vOut = ADC * (Vin / 1024)] + configuration.RLDR = (10.0 * (5 - configuration.vOut)) / configuration.vOut; // Equation to calculate Resistance of LDR, [R-LDR =(R1 (Vin - vOut))/ vOut]. R1 is in KOhms + // R1 = 10 KOhms , Vin = 5.0 Vdc. + configuration.lux = (500 / configuration.RLDR); +} +#endif diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/TestFlash/TestFlash.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/TestFlash/TestFlash.ino new file mode 100644 index 0000000..6af1df5 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/TestFlash/TestFlash.ino @@ -0,0 +1,596 @@ +/* + ---------------------------------------------------------------------------------------------------------------------------------- + | Winbond Flash | + | SPIFlash library test v2.4.0 | + |----------------------------------------------------------------------------------------------------------------------------------| + | Marzogh | + | 16.11.2016 | + |----------------------------------------------------------------------------------------------------------------------------------| + | (Please make sure your Serial monitor is set to 'No Line Ending') | + | ***************************************************************** | + | | + | # Please pick from the following commands and type the command number into the Serial console # | + | For example - to write a byte of data, you would have to use the write_byte function - so type '3' into the serial console. | + | -------------------------------- | + | | + | 1. getID | + | '1' gets the JEDEC ID of the chip | + | | + | 2. writeByte [page] [offset] [byte] | + | '2' followed by '100' and then by '20' and then by '224' writes the byte 224 to page 100 position 20 | + | | + | 3. readByte [page] [offset] | + | '3' followed by '100' and then by '20' returns the byte from page 100 position 20 | + | | + | 4. writeWord [page] [offset] | + | '4' followed by '55' and then by '35' and then by '633' writes the int 633 to page 5 position 35 | + | | + | 5. readWord [page] [offset] | + | '5' followed by '200' and then by '30' returns the int from page 200 position 30 | + | | + | 6. writeStr [page] [offset] [inputString] | + | '6' followed by '345' and then by '65' and then by 'Test String 1!' writes the String 'Test String 1! to page 345 position 65 | + | | + | 7. readStr [page] [offset] [outputString] | + | '7' followed by '2050' and then by '73' reds the String from page 2050 position 73 into the outputString | + | | + | 8. writePage [page] | + | '8' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33 | + | | + | 9. printPage [page] | + | '9' followed by 33 reads & prints page 33. To just read a page to a data buffer, refer | + | to 'ReadMe.md' in the library folder. | + | | + | 10. printAllPages | + | '10' reads all 4096 pages and outputs them to the serial console | + | This function is to extract data from a flash chip onto a computer as a text file. | + | Refer to 'Read me.md' in the library for details. | + | | + | 11. Erase 4KB sector | + | '11' followed by 2 erases a 4KB sector containing the page to be erased | + | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | + | | + | 12. Erase 32KB block | + | '12' followed by 2 erases a 32KB block containing the page to be erased | + | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | + | | + | 13. Erase 64KB block | + | '13' followed by 2 erases a 64KB block containing the page to be erased | + | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | + | | + | 14. Erase Chip | + | '14' erases the entire chip | + | | + ^----------------------------------------------------------------------------------------------------------------------------------^ +*/ + + + +#include +uint8_t pageBuffer[256]; +String serialCommand; +char printBuffer[128]; +uint16_t page; +uint8_t offset, dataByte; +uint16_t dataInt; +String inputString, outputString; + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#else +#define BAUD_RATE 115200 +#endif + +SPIFlash flash; + +void setup() { + delay(10); + Serial.begin(BAUD_RATE); + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + flash.begin(); + Serial.println(); + Serial.println(); + commandList(); +} + +void loop() { + while (Serial.available() > 0) { + uint8_t commandNo = Serial.parseInt(); + if (commandNo == 0) { + commandList(); + } + else if (commandNo == 1) { + printLine(); + Serial.println(F(" Function 1 : Get JEDEC ID ")); + printLine(); + printLine(); + uint8_t b1, b2, b3; + uint32_t JEDEC = flash.getJEDECID(); + //uint16_t ManID = flash.getManID(); + b1 = (JEDEC >> 16); + b2 = (JEDEC >> 8); + b3 = (JEDEC >> 0); + clearprintBuffer(); + sprintf(printBuffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3); + Serial.println(printBuffer); + clearprintBuffer(); + sprintf(printBuffer, "JEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); + printLine(); + printNextCMD(); + } + else if (commandNo == 2) { + printLine(); + Serial.println(F(" Function 2 : Write Byte ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page you wish to modify: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to modify: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.print(F("Please enter the value of the byte (0-255) you wish to save: ")); + while (!Serial.available()) { + } + dataByte = Serial.parseInt(); + Serial.println(dataByte); + if (flash.writeByte(page, offset, dataByte)) { + clearprintBuffer(); + sprintf(printBuffer, "%d has been written to position %d on page %d", dataByte, offset, page); + Serial.println(printBuffer); + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 3) { + printLine(); + Serial.println(F(" Function 3 : Read Byte ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page the byte you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the byte on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The byte at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + Serial.println(flash.readByte(page, offset)); + printLine(); + printNextCMD(); + } + else if (commandNo == 4) { + printLine(); + Serial.println(F(" Function 4 : Write Word ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page you wish to modify: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to modify: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.print(F("Please enter the value of the word (>255) you wish to save: ")); + while (!Serial.available()) { + } + dataInt = Serial.parseInt(); + Serial.println(dataInt); + if (flash.writeWord(page, offset, dataInt)) { + clearprintBuffer(); + sprintf(printBuffer, "%d has been written to position %d on page %d", dataInt, offset, page); + Serial.println(printBuffer); + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 5) { + printLine(); + Serial.println(F(" Function 5 : Read Word ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page the byte you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the word on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The unsigned int at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + Serial.println(flash.readWord(page, offset)); + printLine(); + printNextCMD(); + } + else if (commandNo == 6) { + printLine(); + Serial.println(F(" Function 6 : Write String ")); + printSplash(); + printLine(); + Serial.println(F("This function will write a String of your choice to the page selected.")); + Serial.print(F("Please enter the number of the page you wish to write to: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to write to: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.println(F("Please enter the String you wish to save: ")); + while (!Serial.available()) { + } + readSerialStr(inputString); + if (flash.writeStr(page, offset, inputString)) { + clearprintBuffer(); + Serial.print(F("String '")); + Serial.print(inputString); + sprintf(printBuffer, "' has been written to position %d on page %d", offset, page); + Serial.println(printBuffer); + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 7) { + printLine(); + Serial.println(F(" Function 7 : Read String ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page the String you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the String on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The String at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + flash.readStr(page, offset, outputString); + Serial.println(outputString); + printLine(); + printNextCMD(); + } + else if (commandNo == 8) { + printLine(); + Serial.println(F(" Function 8 : Write Page ")); + printSplash(); + printLine(); + Serial.println(F("This function will write a sequence of bytes (0-255) to the page selected.")); + Serial.print(F("Please enter the number of the page you wish to write to: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + for (uint16_t i = 0; i < PAGESIZE; ++i) { + pageBuffer[i] = i; + } + if (flash.writeByteArray(page, 0, &pageBuffer[0], PAGESIZE)) { + clearprintBuffer(); + sprintf(printBuffer, "Values from 0 to 255 have been written to the page %d", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 9) { + printLine(); + Serial.println(F(" Function 9 : Read Page ")); + printSplash(); + printLine(); + Serial.println(F("This function will read the entire page selected.")); + Serial.print(F("Please enter the number of the page you wish to read: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + printLine(); + printNextCMD(); + } + else if (commandNo == 10) { + printLine(); + Serial.println(F(" Function 10 : Read All Pages ")); + printSplash(); + printLine(); + Serial.println(F("This function will read the entire flash memory.")); + Serial.println(F("This will take a long time and might result in memory issues. Do you wish to continue? (Y/N)")); + char c; + while (!Serial.available()) { + } + c = (char)Serial.read(); + if (c == 'Y' || c == 'y') { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printAllPages(outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 11) { + printLine(); + Serial.println(F(" Function 11 : Erase 4KB sector ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase a 4KB sector.")); + Serial.print(F("Please enter the number of the page you wish to erase: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + flash.eraseSector(page, 0); + clearprintBuffer(); + sprintf(printBuffer, "A 4KB sector containing page %d has been erased", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 12) { + printLine(); + Serial.println(F(" Function 12 : Erase 32KB Block ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase a 32KB block.")); + Serial.print(F("Please enter the number of the page you wish to erase: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + flash.eraseBlock32K(page, 0); + clearprintBuffer(); + sprintf(printBuffer, "A 32KB block containing page %d has been erased", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 13) { + printLine(); + Serial.println(F(" Function 13 : Erase 64KB Block ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase a 64KB block.")); + Serial.print(F("Please enter the number of the page you wish to erase: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + flash.eraseBlock64K(page, 0); + clearprintBuffer(); + sprintf(printBuffer, "A 64KB block containing page %d has been erased", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 14) { + printLine(); + Serial.println(F(" Function 14 : Erase Chip ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase the entire flash memory.")); + Serial.println(F("Do you wish to continue? (Y/N)")); + char c; + while (!Serial.available()) { + } + c = (char)Serial.read(); + if (c == 'Y' || c == 'y') { + if (flash.eraseChip()) + Serial.println(F("Chip erased")); + else + Serial.println(F("Error erasing chip")); + } + printLine(); + printNextCMD(); + } + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +void clearprintBuffer() +{ + for (uint8_t i = 0; i < 128; i++) { + printBuffer[i] = 0; + } +} + +//Reads a string from Serial +bool readSerialStr(String &inputStr) { + if (!Serial) + Serial.begin(115200); + while (Serial.available()) { + inputStr = Serial.readStringUntil('\n'); + return true; + } + return false; +} + +//Prints hex/dec formatted data from page reads - for debugging +void _printPageBytes(uint8_t *data_buffer, uint8_t outputType) { + char buffer[10]; + for (int a = 0; a < 16; ++a) { + for (int b = 0; b < 16; ++b) { + if (outputType == 1) { + sprintf(buffer, "%02x", data_buffer[a * 16 + b]); + Serial.print(buffer); + } + else if (outputType == 2) { + uint8_t x = data_buffer[a * 16 + b]; + if (x < 10) Serial.print("0"); + if (x < 100) Serial.print("0"); + Serial.print(x); + Serial.print(','); + } + } + Serial.println(); + } +} + +//Reads a page of data and prints it to Serial stream. Make sure the sizeOf(uint8_t data_buffer[]) == 256. +void printPage(uint16_t page_number, uint8_t outputType) { + if (!Serial) + Serial.begin(115200); + + char buffer[24]; + sprintf(buffer, "Reading page (%04x)", page_number); + Serial.println(buffer); + + uint8_t data_buffer[PAGESIZE]; + flash.readByteArray(page_number, 0, &data_buffer[0], PAGESIZE); + _printPageBytes(data_buffer, outputType); +} + +//Reads all pages on Flash chip and dumps it to Serial stream. +//This function is useful when extracting data from a flash chip onto a computer as a text file. +void printAllPages(uint8_t outputType) { + if (!Serial) + Serial.begin(115200); + + Serial.println("Reading all pages"); + uint8_t data_buffer[256]; + + uint32_t maxPage = flash.getMaxPage(); + for (int a = 0; a < maxPage; a++) { + flash.readByteArray(a, 0, &data_buffer[0], 256); + _printPageBytes(data_buffer, outputType); + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Print commands~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +void printLine() +{ + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); +} + +void printSplash() +{ + Serial.println(F(" SPIFlash library test ")); +} + +void printNextCMD() +{ + Serial.println(F("Please type the next command. Type 0 to get the list of commands")); +} + +void printOutputChoice() +{ + Serial.print("Would you like your output in decimal or hexadecimal? Please indicate with '1' for HEX or '2' for DEC: "); +} + +void printReadChoice() +{ + Serial.print("Type 1 to read the page you have just modified. Type 0 to continue: "); +} + +void writeSuccess() +{ + Serial.println("Data write successful"); +} + +void writeFail() +{ + Serial.println("Data write failed"); +} diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/TestFlash/command_list.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/TestFlash/command_list.ino new file mode 100644 index 0000000..7ac5e30 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/TestFlash/command_list.ino @@ -0,0 +1,63 @@ +void commandList() { + Serial.println(F("-----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Winbond Flash ")); + Serial.println(F(" SPIFlash library test v2.5.0 ")); + Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Marzogh ")); + Serial.println(F(" 24.11.2015 ")); + Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" (Please make sure your Serial monitor is set to 'No Line Ending') ")); + Serial.println(F(" ***************************************************************** ")); + Serial.println(F(" ")); + Serial.println(F(" # Please pick from the following commands and type the command number into the Serial console # ")); + Serial.println(F(" For example - to write a byte of data, you would have to use the Write Byte function - so type '3' into the serial console. ")); + Serial.println(F(" -------------------------------- ")); + Serial.println(); + Serial.println(F(" 1. getID")); + Serial.print(F("\t\t")); + Serial.println(F("'1' gets the JEDEC ID of the chip")); + Serial.println(F(" 2. writeByte [page] [offset] [byte]")); + Serial.print(F("\t\t")); + Serial.println(F("'2' followed by '100' and then by '20' and then by '224' writes the byte 224 to page 100 position 20")); + Serial.println(F(" 3. readByte [page] [offset]")); + Serial.print(F("\t\t")); + Serial.println(F("'3' followed by '100' and then by '20' returns the byte from page 100 position 20")); + Serial.println(F(" 4. writeWord [page] [offset]")); + Serial.print(F("\t\t")); + Serial.println(F("'4' followed by '55' and then by '35' and then by '633' writes the int 633 to page 5 position 35")); + Serial.println(F(" 5. readWord [page] [offset]")); + Serial.print(F("\t\t")); + Serial.println(F("'5' followed by '200' and then by '30' returns the int from page 200 position 30")); + Serial.println(F(" 6. writeStr [page] [offset] [inputString]")); + Serial.print(F("\t\t")); + Serial.println(F("'6' followed by '345' and then by '65' and then by 'Test String 1!' writes the String 'Test String 1! to page 345 position 65")); + Serial.println(F(" 7. readStr [page] [offset] [outputString]")); + Serial.print(F("\t\t")); + Serial.println(F("'7' followed by '2050' and then by '73' reads the String from page 2050 position 73 into the outputString")); + Serial.println(F(" 8. writePage [page]")); + Serial.print(F("\t\t")); + Serial.println(F("'8' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33")); + Serial.println(F(" 9. readPage [page]")); + Serial.print(F("\t\t")); + Serial.println(F("'9' followed by 33 reads page 33")); + Serial.println(F(" 10. readAllPages")); + Serial.print(F("\t\t")); + Serial.println(F("'10' reads all 4096 pages and outputs them to the serial console")); + Serial.print(F("\t\t")); + Serial.println(F("This function is to extract data from a flash chip onto a computer as a text file")); + Serial.print(F("\t\t")); + Serial.println(F("Refer to 'Read me.md' in the library for details")); + Serial.println(F(" 11. eraseSector")); + Serial.print(F("\t\t")); + Serial.println(F("'11' followed by '3' erases a 4KB sector (Sector 0) containing the page 3")); + Serial.println(F(" 12. eraseBlock32K")); + Serial.print(F("\t\t")); + Serial.println(F("'12' followed by '132' erases a 32KB sector (Sector 1) containing the page 132")); + Serial.println(F(" 13. eraseBlock64K")); + Serial.print(F("\t\t")); + Serial.println(F("'13' followed by '543' erases a 64KB sector (Sector 2) containing the page 543")); + Serial.println(F(" 14. eraseChip")); + Serial.print(F("\t\t")); + Serial.println(F("'14' erases the entire chip")); + Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); +} diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/getAddressEx/getAddressEx.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/getAddressEx/getAddressEx.ino new file mode 100644 index 0000000..d391801 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/getAddressEx/getAddressEx.ino @@ -0,0 +1,122 @@ +/* +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +| getAddressEx.ino | +| SPIFlash library | +| v 2.5.0 | +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +| Marzogh | +| 16.11.2016 | +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +| | +| This program shows the method to use the getAddress() function to automate | +| the process of address allocation when using a flash memory module. Please note | +| the special function used to get the size of the String object. | +| | +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ +#include + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#else +#define BAUD_RATE 115200 +#endif + +#define arrayLen(x) sizeof(x)/sizeof(x[0]) +uint32_t strAddr[3], floatAddr[2], byteAddr[4]; +String testStr[] = { + "Test String 0", + "Test String 1", + "Test String 2" +}; +float testFloat[] = { + 3.1415, 6.283 +}; +byte testByte[] = { + 3, 245, 84, 100 +}; + +SPIFlash flash; + +void getAddresses(); +void writeData(); + +void setup() { + Serial.begin(BAUD_RATE); + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + flash.begin(); + Serial.println(); + Serial.println(); + + getAddresses(); + writeData(); + flash.eraseChip(); +} + +void loop() { + +} + +// Function to get adresses for various variables +void getAddresses() { + for (uint8_t i = 0; i < arrayLen(byteAddr); i++) { + byteAddr[i] = flash.getAddress(sizeof(byte)); + Serial.print("Byte Address "); + Serial.print(i); + Serial.print(" : "); + Serial.println(byteAddr[i]); + } + + for (uint8_t i = 0; i < arrayLen(floatAddr); i++) { + floatAddr[i] = flash.getAddress(sizeof(float)); + Serial.print("Float Address "); + Serial.print(i); + Serial.print(" : "); + Serial.println(floatAddr[i]); + } + + for (uint8_t i = 0; i < arrayLen(strAddr); i++) { + strAddr[i] = flash.getAddress(flash.sizeofStr(testStr[i])); + Serial.print("String Address "); + Serial.print(i); + Serial.print(" : "); + Serial.println(strAddr[i]); + } +} + +// Function to write data +void writeData() { + for (uint8_t i = 0; i < arrayLen(byteAddr); i++) { + if (flash.writeByte(byteAddr[i], testByte[i])) { + Serial.print(testByte[i]); + Serial.print(" written to "); + Serial.println(byteAddr[i]); + } + } + + for (uint8_t i = 0; i < arrayLen(floatAddr); i++) { + if (flash.writeFloat(floatAddr[i], testFloat[i])) { + Serial.print(testFloat[i]); + Serial.print(" written to "); + Serial.println(floatAddr[i]); + } + } + + for (uint8_t i = 0; i < arrayLen(strAddr); i++) { + if (flash.writeStr(strAddr[i], testStr[i])) { + Serial.print(testStr[i]); + Serial.print(" written to "); + Serial.println(strAddr[i]); + } + } +} diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/readWriteString/readWriteString.ino b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/readWriteString/readWriteString.ino new file mode 100644 index 0000000..0d16942 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/examples/readWriteString/readWriteString.ino @@ -0,0 +1,94 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | readWriteString.ino | + | SPIFlash library | + | v 2.5.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 16.11.2016 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | This program shows the method of reading a string from the console and saving it to flash memory | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ +#include + +int strPage, strSize; +byte strOffset; + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#define RANDPIN 1 +#else +#define BAUD_RATE 115200 +#define RANDPIN A0 +#endif + +SPIFlash flash; + +bool readSerialStr(String &inputStr); + +void setup() { +#ifndef __AVR_ATtiny85__ + Serial.begin(BAUD_RATE); +#endif +#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__) + while (!Serial) ; // Wait for Serial monitor to open +#endif + + flash.begin(); + +#if defined (ARDUINO_ARCH_ESP32) || defined __AVR_ATtiny85__ + randomSeed(65535537); +#else + randomSeed(analogRead(RANDPIN)); +#endif + strPage = random(0, 4095); + strOffset = random(0, 255); + String inputString = "This is a test String"; + flash.writeStr(strPage, strOffset, inputString); +#ifndef __AVR_ATtiny85__ + Serial.print(F("Written string: ")); + Serial.print(inputString); + Serial.print(F(" to page ")); + Serial.print(strPage); + Serial.print(F(", at offset ")); + Serial.println(strOffset); +#endif + String outputString = ""; + if (flash.readStr(strPage, strOffset, outputString)) { +#ifndef __AVR_ATtiny85__ + Serial.print(F("Read string: ")); + Serial.print(outputString); + Serial.print(F(" from page ")); + Serial.print(strPage); + Serial.print(F(", at offset ")); + Serial.println(strOffset); +#endif + } + while (!flash.eraseSector(strPage, 0)); +} + +void loop() { + +} + +#ifndef __AVR_ATtiny85__ +//Reads a string from Serial +bool readSerialStr(String &inputStr) { + if (!Serial) + Serial.begin(115200); + while (Serial.available()) { + inputStr = Serial.readStringUntil('\n'); + Serial.println(inputStr); + return true; + } + return false; +} +#endif diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Changes.log b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Changes.log new file mode 100644 index 0000000..dcba22b --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Changes.log @@ -0,0 +1,189 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// SPIFlash Library // +// Changes log // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.6.0 // +// Author: Prajwal Bhattaram // +// 16.04.2017 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs Squashed: +--> Fixed issue with reading status register 2 and the Suspend operation where the library was not checking the suspend status correctly. + +Deletions: +--> flash.getChipName() has been removed as it is superfluous now that the library is now on its way to multi-chip compatibility. +--> Library is not compatible with the ATTiny85 anymore. Currently working on a fix which will hopefully be rolled out in v2.7.0 + +New Boards supported: +--> RTL8195A compatibility tested and enabled by @boseji on 02.03.17. Code modified to fit with the library structure by Prajwal Bhattaram on 14.04.17. +--> Compatible with the ESP32 core for Arduino as of the current commit 7d0968c on 16.04.2017. The ESP32 core currently does not support analogRead and so randomSeed(AnalogRead(A0)) cannot be used. Also, for some unknown reason, SPI clock speeds higher than board speed/4 are not stable and so, the clock speed for ESP32 dev boards has currently been throttled to 20MHz. +--> Added support for the Simblee module. + +Enhancements: +--> flash.error() now takes an optional argument 'VERBOSE'. By default the verbosity argument is set to 'false' and calling flash.error() still returns the latest error code as an unsigned byte. However, running flash.error(VERBOSE) will not only return the latest error code, but will also print it to serial. This - especially in boards with resources to spare - will result in a detailed error report printed to serial. +--> flash.begin() now returns a boolean value to indicate establishment of successful comms with the flash chip. Usercode can be made more efficient now by calling ```if (!flash.begin()) { Serial.println(flash.error(VERBOSE)); }``` to identify a problem as soon as the library code is run. +--> The internal _addressCheck() function now locks up usercode with appropriate error codes if + a) flash.begin() has not been called (or) + b) There is a possible issue with the wiring - i.e. the flash chip is non-responsive (or) + c) If the chip's capacity either cannot be identified & the user has not defined a chipSize in flash.begin(). +--> Fixed powerDown() to be more efficient. The chip now powers down much faster than before. +--> Added a new error code. Library can now detect non-responsive chips - bad wiring or otherwise. +--> Streamlined variables to make code structure better. +--> Changed library structure to enable the addition of multi-flash compatibility in the near future. +--> moved `#define RUNDIAGNOSTIC` & `#define HIGHSPEED` to SPIFlash.h from SPIFlash.cpp. +--> Now works with other Winbond modules (not in the official supported module list) (beta) by taking the flash memory size in bits as an argument in flash.begin(_chipSize); +--> Formatted code to be better human readable. +--> Changed the internal _troubleshoot() function to use fewer resources. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.5.0 // +// Author: Prajwal Bhattaram // +// 13.11.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs Squashed: +--> Errorchecking on writeByteArray() and writeCharArray() was broken in 2.4.0 and is fixed now. +--> Previous versions (< 2.5.0) suffered from the inability to write datasets that spanned page boundaries. This has now been fixed (Ref. Enhancements section below) + +Deletions: +--> flash.writePage() & flash.readPage() have been retired as they can be duplicated - more effectively - by other functions. Refer to pageDiag() in Diagnostics.ino to see how the same results can be obtained by using flash.writeByteArray() & flash.readByteArray(). + +Enhancements: +--> Added support for SPI Transactions. +--> Added an upgrade for Arduino Due users to read and write large arrays of data at very high speeds - previously reading 60kb of data would take ~108ms - it now takes ~525uS. In this mode, the time between consecutive reads has been reduced to <12ms (needs more work!). +--> Completely re-written writeByteArray() and writeCharArray() functions. They no longer breakdown when writing arrays that span multiple pages. +--> All functions that write more than 1 byte of data now take into account page boundaries when writing across pages. In previous versions writing across a page boundary would cause the remainder of the data to wrap around to the beginning of the page. Now the data is written seamlessly from one page over to the next. +--> Calling flash.begin() now instantiates the SPI bus. Comms with other SPI slaves do not need to call SPI.begin() if flash.begin() has already been called first in the user's code. +--> Sped up _beginSPI(). Code in _beginSPI() instantiates the SPI bus if another SPI comms library has shut it down. +--> Added function allowing setting SPI clock speeds - call the function ```flash.setClock(uint32_t clockSpeed);``` straight after ```begin();```. +--> Made _beginSPI() & _nextByte() shorter and faster. +--> Replaced all calls to SPI.transfer() with xfer() to make the code more human readable and to enable simplicity when switching platforms. +--> Added the ability to change Chip Erase wait times depending on the chip (supported chips only). +--> Don't need to ```#include ``` in user code anymore. Just ```#include``` will do. Examples are now updated. +--> Now supports & uses SPI.transfer(*buf, count) along with the standard SPI.transfer(), speeding up the read/write of anything larger than an byte (AVR Boards only) +--> Reduces the program storage space in the uC's flash (AVR Boards) + +To-do +--> Need to find a way to better identify _notPrevWritten(); +--> Need to fix up eraseBlock32K, eraseBlock64K and eraseSector times +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.4.0 // +// Author: Prajwal Bhattaram // +// 11.09.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs Squashed: +--> Fixed bug preventing writing to Address 0x00 +--> Fixed bug in _notPrevWritten() which did did not perform a thorough enough check to see if a location had been previously written to. +--> Fixed errorchecking bug - it now works for all data types - not just byte/char as previously. +Enhancements & Optimizations: +--> Added a function 'error()' to enable users to check for errors generated at any point in their program. +--> Optimized writePage() so it doesn't depend on other functions and so runs faster than before. +--> Diagnostics.ino now outputs time taken for each function as a part of its and provides additional diagnostic data. +--> Now have a common set of private functions - _prep(), _beginSPI(), _nextByte() & _endSPI() - to replace _prepWrite(), _prepRead(), _beginRead(), _readNextByte(), _beginWrite(), _writeNextByte() & _endProcess(); +--> Changed the way _addressCheck() works. It now checks all addresses involved in writing the data rather than one address block at a time and returns the correct address to write to in case overflow is enabled. Also, this function is now built into _prep(). +--> Reading and writing using page numbers + offset has been optimised to be faster than before. +--> Optimized the way address and error checking is done so its more efficient and uses few system resources and runs faster. +--> Using this library with an ESP8266 board defaults to using GPIO15 as the Slave Select - unless something different is explicitly specified in the constructor. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.3.1 // +// Author: Prajwal Bhattaram // +// 19.06.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> W25Q256FV support added. (Thanks Stanislav-Povolotsky!) +--> Cleaned up redundant code in TestFlash.ino and SPIFlash.h +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.3.0 // +// Author: Prajwal Bhattaram // +// 04.06.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> ESP8266 compatibility added +--> Compatible with Arduino Fio and Micro +--> Now compatible with Arduino IDE v1.6.9 +--> Compatible with Arduino-Makefile. (Thanks Raphael!) +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.2.0 // +// Author: Prajwal Bhattaram // +// 24.11.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> When #RUNDIAGNOSTIC is uncommented, the _troubleshoot() function is now optimised for different µCs +--> Added the ability to check if the address has been previously written to before initiating a write + operation. +--> Added a sizeofStr() function to get sizes of String objects, to use with the getAddress() function +--> Fixed a bug with getAddress() +--> Added the ability get the chip's name via getChipName() +--> Diagnostics.ino has been made more and efficient and provides a cleaner Serial output +--> Added getAddressEx.ino to show how getAdress() works. + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.1.1 // +// Author: Prajwal Bhattaram // +// 24.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Fixed bugs that prevented the following functions from working properly + A. powerDown() + B. powerUp() + C. suspendProg() + D. resumeProg() + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.1.0 // +// Author: Prajwal Bhattaram // +// 18.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Arduino Due compatible - refer to wiki for further details +--> Fixed bug with write/readByteArray +--> Added write/readCharArray +--> Added a proper error checking function that gets called when #ifdef RUNDIAGNOSTIC is uncommented in SPIFlash.cpp. + This function returns a verbose error message to the Serial console instead of the terse error codes of the previous version. +--> The following functions have been changed to enable bug fixes and uniformity in coding style. + A. writeBytes() + B. readBytes() + They have been replaced with readByteArray() and writeByteArray(). + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.0.0 // +// Author: Prajwal Bhattaram // +// 12.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Sped up all functions atleast 25x +--> Compatible with ATTiny85 +--> All Read/Write/Erase functions can now take either (page number & offset) or (address) as arguments + (Except readPage() & printPage()) +--> getAddress() can now return either a 32-bit address or a page number & offset - Refer to Readme.md +--> Error codes explained: + 0x00 SUCCESS Operation successful. + 0x01 CALLBEGIN Please make sure .begin() has been called in setup(). + 0x02 UNKNOWNCHIP Unknown chip manufacturer. + 0x03 UNKNOWNCAP Unknown chip capacity. + 0x04 CHIPBUSY Chip busy. + 0x05 OUTOFBOUNDS Address out of bounds. Please check if .begin() has been called in setup(). + 0x06 CANTENWRITE Unable to _writeEnable. Check wiring/chip. + 0x07 OUTOFMEM Pagenumber outside maximum. + 0x08 OUTOFPAGE Offset is outside page. +--> The following functions are deprecated to enable compatibility with other AVR chips. + + A. _printPageBytes() + B. printPage() + C. printAllPages() + D. readSerialStr() + + They can be used by uncommenting them in the SPIFlash.cpp file. However, be warned, this particular block of code has only + been tested with the Arduino IDE (1.6.5) and only with 8-bit AVR based Arduino boards and will not be supported any further. + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 1.3.2 // +// Author: Prajwal Bhattaram // +// 09.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Added the ability to read and write String objects with a simple high level function readStr() & writeStr() +--> Added the ability to getAddress() +--> Added the ability to fastRead to every read function as the last boolean argument (defaults to FALSE) +--> Changed the example code as given below: + --> Modified TestFlash.ino to use 25% less memory + --> Struct_writer.ino now writes struct to a random location on the Flash Memory chip. + --> Added instructions for real world data storage to Struct_writer.ino + --> Diagnostics.ino now provides a cleaner diagnostic readout diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Library speed comparisons.xlsx b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Library speed comparisons.xlsx new file mode 100644 index 0000000..ee60855 Binary files /dev/null and b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Library speed comparisons.xlsx differ diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/SPI pinouts.md b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/SPI pinouts.md new file mode 100644 index 0000000..0b185f4 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/SPI pinouts.md @@ -0,0 +1,24 @@ +/* +* ESP8266 (Adafruit HUZZAH) SPI pinout is as follows: +* _______________________________________ +* |Pin Name | GPIO # | HSPI Function | +* |---------|------------|----------------| +* | MTDI | GPIO12 | MISO (DIN) | +* | MTCK | GPIO13 | MOSI (DOUT) | +* | MTMS | GPIO14 | CLOCK | +* | MTDO | GPIO15 | CS / SS | +* |_________|____________|________________| +* +* +* ESP32 Thing SPI pinout is as follows: +* _____________________________ +* | GPIO # | HSPI Function | +* |------------|----------------| +* | GPIO19 | MISO (DIN) | +* | GPIO23 | MOSI (DOUT) | +* | GPIO18 | CLOCK | +* | GPIO2 | CS / SS | +* |____________|________________| +* +* +*/ diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Winbond Flash Instructions - Comparison.xlsx b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Winbond Flash Instructions - Comparison.xlsx new file mode 100644 index 0000000..b8a4b33 Binary files /dev/null and b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/extras/Winbond Flash Instructions - Comparison.xlsx differ diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/keywords.txt b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/keywords.txt new file mode 100644 index 0000000..74841cb --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/keywords.txt @@ -0,0 +1,58 @@ +####################################### +# Syntax Coloring Map SPI +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SPIFlash KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +setClock KEYWORD2 +error KEYWORD2 +libver KEYWORD2 +getJEDECID KEYWORD2 +getManID KEYWORD2 +getAddress KEYWORD2 +getCapacity KEYWORD2 +getMaxPage KEYWORD2 +sizeofStr KEYWORD2 +readByte KEYWORD2 +readByteArray KEYWORD2 +readChar KEYWORD2 +readCharArray KEYWORD2 +readWord KEYWORD2 +readShort KEYWORD2 +readLong KEYWORD2 +readULong KEYWORD2 +readFloat KEYWORD2 +readStr KEYWORD2 +readAnything KEYWORD2 +writeByte KEYWORD2 +writeByteArray KEYWORD2 +writeChar KEYWORD2 +writeCharArray KEYWORD2 +writeWord KEYWORD2 +writeShort KEYWORD2 +writeLong KEYWORD2 +writeULong KEYWORD2 +writeFloat KEYWORD2 +writeStr KEYWORD2 +writeAnything KEYWORD2 +eraseSector KEYWORD2 +eraseBlock32K KEYWORD2 +eraseBlock64K KEYWORD2 +eraseChip KEYWORD2 +suspendProg KEYWORD2 +resumeProg KEYWORD2 +powerUp KEYWORD2 +powerDown KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/library.properties b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/library.properties new file mode 100644 index 0000000..8a2dcb3 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/library.properties @@ -0,0 +1,10 @@ +name=SPIFlash +version=2.6.0 +author=Prajwal Bhattaram +maintainer=Prajwal Bhattaram +sentence=Winbond SPI flash library for Arduino. +paragraph=This library enables read, write, erase and power functions on the following Winbond NOR Flash chips - W25X05CL, W25X10BV, W25X20BV, W25X40BV, W25Q80BV, W25Q16BV, W25Q32BV, W25Q64BV & W25Q128BV. All other Winbond flash chips can also be used with this library from v2.6.0 onwards. Refer to change log for further information about this release. +category=Data Storage +url=https://github.com/Marzogh/SPIFlash +architectures=avr,sam,samd,esp8266,esp32,simblee,rtl8195a +includes=SPIFlash.h diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/DMASPI.cpp b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/DMASPI.cpp new file mode 100644 index 0000000..a92b824 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/DMASPI.cpp @@ -0,0 +1,300 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 30/09/2016 + * Modified by Prajwal Bhattaram - 14/04/2017 + * Original code from @manitou48 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ +#if defined (ARDUINO_ARCH_SAM) +#include "SPIFlash.h" + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Private functions used by Arduino Due DMA operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Disable DMA Controller +void SPIFlash::_dmac_disable() { + DMAC->DMAC_EN &= (~DMAC_EN_ENABLE); +} +// Enable DMA Controller. +void SPIFlash::_dmac_enable() { + DMAC->DMAC_EN = DMAC_EN_ENABLE; +} +// Disable DMA Channel +void SPIFlash::_dmac_channel_disable(uint32_t ul_num) { + DMAC->DMAC_CHDR = DMAC_CHDR_DIS0 << ul_num; +} +// Enable DMA Channel +void SPIFlash::_dmac_channel_enable(uint32_t ul_num) { + DMAC->DMAC_CHER = DMAC_CHER_ENA0 << ul_num; +} +// Poll for transfer complete +bool SPIFlash::_dmac_channel_transfer_done(uint32_t ul_num) { + return (DMAC->DMAC_CHSR & (DMAC_CHSR_ENA0 << ul_num)) ? false : true; +} +// start RX DMA +void SPIFlash::_dueSPIDmaRX(uint8_t* dst, uint16_t count) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_SADDR = (uint32_t)&SPI0->SPI_RDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DADDR = (uint32_t)dst; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_PER2MEM_DMA_FC | + DMAC_CTRLB_SRC_INCR_FIXED | DMAC_CTRLB_DST_INCR_INCREMENTING; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CFG = DMAC_CFG_SRC_PER(SPI_RX_IDX) | + DMAC_CFG_SRC_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ASAP_CFG; + _dmac_channel_enable(SPI_DMAC_RX_CH); +} +void SPIFlash::_dueSPIDmaRX(char* dst, uint16_t count) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_SADDR = (uint32_t)&SPI0->SPI_RDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DADDR = (uint32_t)dst; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_PER2MEM_DMA_FC | + DMAC_CTRLB_SRC_INCR_FIXED | DMAC_CTRLB_DST_INCR_INCREMENTING; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CFG = DMAC_CFG_SRC_PER(SPI_RX_IDX) | + DMAC_CFG_SRC_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ASAP_CFG; + _dmac_channel_enable(SPI_DMAC_RX_CH); +} +// start TX DMA +void SPIFlash::_dueSPIDmaTX(const uint8_t* src, uint16_t count) { + static uint8_t ff = 0XFF; + uint32_t src_incr = DMAC_CTRLB_SRC_INCR_INCREMENTING; + if (!src) { + src = &ff; + src_incr = DMAC_CTRLB_SRC_INCR_FIXED; + } + _dmac_channel_disable(SPI_DMAC_TX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_SADDR = (uint32_t)src; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DADDR = (uint32_t)&SPI0->SPI_TDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_MEM2PER_DMA_FC | + src_incr | DMAC_CTRLB_DST_INCR_FIXED; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CFG = DMAC_CFG_DST_PER(SPI_TX_IDX) | + DMAC_CFG_DST_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ALAP_CFG; + + _dmac_channel_enable(SPI_DMAC_TX_CH); +} + +void SPIFlash::_dueSPIDmaCharTX(const char* src, uint16_t count) { + static char ff = 0XFF; + uint32_t src_incr = DMAC_CTRLB_SRC_INCR_INCREMENTING; + if (!src) { + src = &ff; + src_incr = DMAC_CTRLB_SRC_INCR_FIXED; + } + _dmac_channel_disable(SPI_DMAC_TX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_SADDR = (uint32_t)src; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DADDR = (uint32_t)&SPI0->SPI_TDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_MEM2PER_DMA_FC | + src_incr | DMAC_CTRLB_DST_INCR_FIXED; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CFG = DMAC_CFG_DST_PER(SPI_TX_IDX) | + DMAC_CFG_DST_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ALAP_CFG; + + _dmac_channel_enable(SPI_DMAC_TX_CH); +} + +void SPIFlash::_dueSPIBegin() { + PIO_Configure( + g_APinDescription[PIN_SPI_MOSI].pPort, + g_APinDescription[PIN_SPI_MOSI].ulPinType, + g_APinDescription[PIN_SPI_MOSI].ulPin, + g_APinDescription[PIN_SPI_MOSI].ulPinConfiguration); + PIO_Configure( + g_APinDescription[PIN_SPI_MISO].pPort, + g_APinDescription[PIN_SPI_MISO].ulPinType, + g_APinDescription[PIN_SPI_MISO].ulPin, + g_APinDescription[PIN_SPI_MISO].ulPinConfiguration); + PIO_Configure( + g_APinDescription[PIN_SPI_SCK].pPort, + g_APinDescription[PIN_SPI_SCK].ulPinType, + g_APinDescription[PIN_SPI_SCK].ulPin, + g_APinDescription[PIN_SPI_SCK].ulPinConfiguration); + pmc_enable_periph_clk(ID_SPI0); +#if USE_SAM3X_DMAC + pmc_enable_periph_clk(ID_DMAC); + _dmac_disable(); + DMAC->DMAC_GCFG = DMAC_GCFG_ARB_CFG_FIXED; + _dmac_enable(); +#if USE_SAM3X_BUS_MATRIX_FIX + MATRIX->MATRIX_WPMR = 0x4d415400; + MATRIX->MATRIX_MCFG[1] = 1; + MATRIX->MATRIX_MCFG[2] = 1; + MATRIX->MATRIX_SCFG[0] = 0x01000010; + MATRIX->MATRIX_SCFG[1] = 0x01000010; + MATRIX->MATRIX_SCFG[7] = 0x01000010; +#endif // USE_SAM3X_BUS_MATRIX_FIX +#endif // USE_SAM3X_DMAC +} +// initialize SPI controller +void SPIFlash::_dueSPIInit(uint8_t dueSckDivisor) { +#if ENABLE_SPI_TRANSACTIONS + SPI.beginTransaction(SPISettings()); +#endif // ENABLE_SPI_TRANSACTIONS + uint8_t scbr = dueSckDivisor; + Spi* pSpi = SPI0; + // disable SPI + pSpi->SPI_CR = SPI_CR_SPIDIS; + // reset SPI + pSpi->SPI_CR = SPI_CR_SWRST; + // no mode fault detection, set master mode + pSpi->SPI_MR = SPI_PCS(SPI_CHIP_SEL) | SPI_MR_MODFDIS | SPI_MR_MSTR; + // mode 0, 8-bit, + pSpi->SPI_CSR[SPI_CHIP_SEL] = SPI_CSR_SCBR(scbr) | SPI_CSR_NCPHA; + // enable SPI + pSpi->SPI_CR |= SPI_CR_SPIEN; +} +uint8_t SPIFlash::_dueSPITransfer(uint8_t b) { + Spi* pSpi = SPI0; + + pSpi->SPI_TDR = b; + while ((pSpi->SPI_SR & SPI_SR_RDRF) == 0) {} + b = pSpi->SPI_RDR; + return b; +} +// SPI receive a byte +uint8_t SPIFlash::_dueSPIRecByte() { + return _dueSPITransfer(0XFF); +} +// SPI receive multiple bytes +uint8_t SPIFlash::_dueSPIRecByte(uint8_t* buf, size_t len) { + Spi* pSpi = SPI0; + int rtn = 0; +#if USE_SAM3X_DMAC + // clear overrun error + uint32_t s = pSpi->SPI_SR; + + _dueSPIDmaRX(buf, len); + _dueSPIDmaTX(0, len); + + uint32_t m = millis(); + while (!_dmac_channel_transfer_done(SPI_DMAC_RX_CH)) { + if ((millis() - m) > SAM3X_DMA_TIMEOUT) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + _dmac_channel_disable(SPI_DMAC_TX_CH); + rtn = 2; + break; + } + } + if (pSpi->SPI_SR & SPI_SR_OVRES) rtn |= 1; +#else // USE_SAM3X_DMAC + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = 0XFF; + while ((pSpi->SPI_SR & SPI_SR_RDRF) == 0) {} + buf[i] = pSpi->SPI_RDR; + } +#endif // USE_SAM3X_DMAC + return rtn; +} +// SPI receive a char +int8_t SPIFlash::_dueSPIRecChar() { + return _dueSPITransfer(0XFF); +} +// SPI receive multiple chars +int8_t SPIFlash::_dueSPIRecChar(char* buf, size_t len) { + Spi* pSpi = SPI0; + char rtn = 0; +#if USE_SAM3X_DMAC + // clear overrun error + uint32_t s = pSpi->SPI_SR; + + _dueSPIDmaRX(buf, len); + _dueSPIDmaTX(0, len); + + uint32_t m = millis(); + while (!_dmac_channel_transfer_done(SPI_DMAC_RX_CH)) { + if ((millis() - m) > SAM3X_DMA_TIMEOUT) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + _dmac_channel_disable(SPI_DMAC_TX_CH); + rtn = 2; + break; + } + } + if (pSpi->SPI_SR & SPI_SR_OVRES) rtn |= 1; +#else // USE_SAM3X_DMAC + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = 0XFF; + while ((pSpi->SPI_SR & SPI_SR_RDRF) == 0) {} + buf[i] = pSpi->SPI_RDR; + } +#endif // USE_SAM3X_DMAC + return rtn; +} +// SPI send a byte +void SPIFlash::_dueSPISendByte(uint8_t b) { + _dueSPITransfer(b); +} + +void SPIFlash::_dueSPISendByte(const uint8_t* buf, size_t len) { + Spi* pSpi = SPI0; +#if USE_SAM3X_DMAC + _dueSPIDmaTX(buf, len); + while (!_dmac_channel_transfer_done(SPI_DMAC_TX_CH)) {} +#else // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = buf[i]; + while ((pSpi->SPI_SR & SPI_SR_TDRE) == 0) {} + } +#endif // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + // leave RDR empty + uint8_t b = pSpi->SPI_RDR; +} +// SPI send a char +void SPIFlash::_dueSPISendChar(char b) { + _dueSPITransfer(b); +} +//SPI send multiple chars +void SPIFlash::_dueSPISendChar(const char* buf, size_t len) { + Spi* pSpi = SPI0; +#if USE_SAM3X_DMAC + _dueSPIDmaCharTX(buf, len); + while (!_dmac_channel_transfer_done(SPI_DMAC_TX_CH)) {} +#else // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = buf[i]; + while ((pSpi->SPI_SR & SPI_SR_TDRE) == 0) {} + } +#endif // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + // leave RDR empty + char b = pSpi->SPI_RDR; +} + +#endif diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/SPIFlash.cpp b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/SPIFlash.cpp new file mode 100644 index 0000000..ac778d8 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/SPIFlash.cpp @@ -0,0 +1,1838 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 19/05/2015 + * Modified by @boseji - 02/03/2017 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + +#include "SPIFlash.h" + +// Constructor +#if defined (ARDUINO_ARCH_AVR) +SPIFlash::SPIFlash(uint8_t cs, bool overflow) { + csPin = cs; +#ifndef __AVR_ATtiny85__ + cs_port = portOutputRegister(digitalPinToPort(csPin)); +#endif + cs_mask = digitalPinToBitMask(csPin); + pageOverflow = overflow; + pinMode(csPin, OUTPUT); +} +// Adding Low level HAL API to initialize the Chip select pinMode on RTL8195A - @boseji 2nd March 2017 +#elif defined (BOARD_RTL8195A) +SPIFlash::SPIFlash(PinName cs, bool overflow) { + gpio_init(&csPin, cs); + gpio_dir(&csPin, PIN_OUTPUT); + gpio_mode(&csPin, PullNone); + gpio_write(&csPin, 1); + pageOverflow = overflow; +} +#else +SPIFlash::SPIFlash(uint8_t cs, bool overflow) { + csPin = cs; + pageOverflow = overflow; + pinMode(csPin, OUTPUT); +} +#endif +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Private functions used by read, write and erase operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Double checks all parameters before calling a read or write. Comes in two variants +//Variant A: Takes address and returns the address if true, else returns false. Throws an error if there is a problem. +bool SPIFlash::_prep(uint8_t opcode, uint32_t address, uint32_t size) { + switch (opcode) { + case PAGEPROG: + if (!_addressCheck(address, size)) { + return false; + } + if(!_notBusy() || !_writeEnable()){ + return false; + } + #ifndef HIGHSPEED + if(!_notPrevWritten(address, size)) { + return false; + } + #endif + return true; + break; + + default: + if (!_addressCheck(address, size)) { + return false; + } + if (!_notBusy()){ + return false; + } + return true; + break; + } +} + +//Variant B: Take the opcode, page number, offset and size of data block as arguments +bool SPIFlash::_prep(uint8_t opcode, uint32_t page_number, uint8_t offset, uint32_t size) { + uint32_t address = _getAddress(page_number, offset); + return _prep(opcode, address, size); +} + +bool SPIFlash::_transferAddress(void) { + _nextByte(_currentAddress >> 16); + _nextByte(_currentAddress >> 8); + _nextByte(_currentAddress); +} + +bool SPIFlash::_startSPIBus(void) { +#ifndef SPI_HAS_TRANSACTION + noInterrupts(); +#endif + +#if defined (ARDUINO_ARCH_SAM) + _dueSPIInit(DUE_SPI_CLK); +#else + #if defined (ARDUINO_ARCH_AVR) + //save current SPI settings + _SPCR = SPCR; + _SPSR = SPSR; + #endif + #ifdef SPI_HAS_TRANSACTION + SPI.beginTransaction(_settings); + #else + SPI.setClockDivider(SPI_CLOCK_DIV_4) + SPI.setDataMode(SPI_MODE0); + SPI.setBitOrder(MSBFIRST); + #endif +#endif + SPIBusState = true; + return true; +} + +//Initiates SPI operation - but data is not transferred yet. Always call _prep() before this function (especially when it involves writing or reading to/from an address) +bool SPIFlash::_beginSPI(uint8_t opcode) { + if (!SPIBusState) { + //Serial.println("Starting SPI Bus"); + _startSPIBus(); + } + CHIP_SELECT + switch (opcode) { + case FASTREAD: + _nextByte(opcode); + _nextByte(DUMMYBYTE); + _transferAddress(); + break; + + case READDATA: + _nextByte(opcode); + _transferAddress(); + break; + + case PAGEPROG: + _nextByte(opcode); + _transferAddress(); + break; + + default: + _nextByte(opcode); + break; + } + return true; +} +//SPI data lines are left open until _endSPI() is called + +//Reads/Writes next byte. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() +uint8_t SPIFlash::_nextByte(uint8_t data) { +#if defined (ARDUINO_ARCH_SAM) + return _dueSPITransfer(data); +#else + return xfer(data); +#endif +} + +//Reads/Writes next int. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() +uint16_t SPIFlash::_nextInt(uint16_t data) { + //return xfer16(data); + return SPI.transfer16(data); +} + +//Reads/Writes next data buffer. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() +void SPIFlash::_nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size) { + uint8_t *_dataAddr = &(*data_buffer); + switch (opcode) { + case READDATA: + #if defined (ARDUINO_ARCH_SAM) + _dueSPIRecByte(&(*data_buffer), size); + #elif defined (ARDUINO_ARCH_AVR) + SPI.transfer(&data_buffer[0], size); + #else + for (uint16_t i = 0; i < size; i++) { + *_dataAddr = xfer(NULLBYTE); + _dataAddr++; + } + #endif + break; + + case PAGEPROG: + #if defined (ARDUINO_ARCH_SAM) + _dueSPISendByte(&(*data_buffer), size); + #elif defined (ARDUINO_ARCH_AVR) + SPI.transfer(&(*data_buffer), size); + #else + for (uint16_t i = 0; i < size; i++) { + xfer(*_dataAddr); + _dataAddr++; + } + #endif + break; + } +} + +//Stops all operations. Should be called after all the required data is read/written from repeated _nextByte() calls +void SPIFlash::_endSPI(void) { + CHIP_DESELECT + #ifdef SPI_HAS_TRANSACTION + SPI.endTransaction(); + #else + interrupts(); + #endif + + #if defined (ARDUINO_ARCH_AVR) + SPCR = _SPCR; + SPSR = _SPSR; + #endif + SPIBusState = false; +} + +// Checks if status register 1 can be accessed - used during powerdown and power up and for debugging +uint8_t SPIFlash::_readStat1(void) { + _beginSPI(READSTAT1); + uint8_t stat1 = _nextByte(); + CHIP_DESELECT + return stat1; +} + +// Checks if status register 2 can be accessed, if yes, reads and returns it +uint8_t SPIFlash::_readStat2(void) { + _beginSPI(READSTAT2); + uint8_t stat2 = _nextByte(); + stat2 = _nextByte(); + CHIP_DESELECT + return stat2; +} + +// Checks the erase/program suspend flag before enabling/disabling a program/erase suspend operation +bool SPIFlash::_noSuspend(void) { + switch (_chip.manufacturerID) { + case WINBOND_MANID: + if(_readStat2() & SUS) { + errorcode = SYSSUSPEND; + return false; + } + return true; + break; + + case MICROCHIP_MANID: + if(_readStat1() & WSE || _readStat1() & WSP) { + errorcode = SYSSUSPEND; + return false; + } + return true; + } + +} + +// Polls the status register 1 until busy flag is cleared or timeout +bool SPIFlash::_notBusy(uint32_t timeout) { + uint32_t startTime = millis(); + + do { + state = _readStat1(); + if((millis()-startTime) > timeout){ + errorcode = CHIPBUSY; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + _endSPI(); + return false; + } + } while(state & BUSY); + return true; +} + +//Enables writing to chip by setting the WRITEENABLE bit +bool SPIFlash::_writeEnable(uint32_t timeout) { + uint32_t startTime = millis(); + if (!(state & WRTEN)) { + do { + _beginSPI(WRITEENABLE); + CHIP_DESELECT + state = _readStat1(); + if((millis()-startTime) > timeout) { + errorcode = CANTENWRITE; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + _endSPI(); + return false; + } + } while (!(state & WRTEN)); + } + return true; +} + +//Disables writing to chip by setting the Write Enable Latch (WEL) bit in the Status Register to 0 +//_writeDisable() is not required under the following conditions because the Write Enable Latch (WEL) flag is cleared to 0 +// i.e. to write disable state: +// Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, Chip Erase, Write Status Register, +// Erase Security Register and Program Security register +bool SPIFlash::_writeDisable(void) { + _beginSPI(WRITEDISABLE); + CHIP_DESELECT + return true; +} + +//Gets address from page number and offset. Takes two arguments: +// 1. page_number --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +uint32_t SPIFlash::_getAddress(uint16_t page_number, uint8_t offset) { + uint32_t address = page_number; + return ((address << 8) + offset); +} + +//Checks the device ID to establish storage parameters +bool SPIFlash::_getManId(uint8_t *b1, uint8_t *b2) { + if(!_notBusy()) + return false; + _beginSPI(MANID); + _nextByte(); + _nextByte(); + _nextByte(); + *b1 = _nextByte(); + *b2 = _nextByte(); + CHIP_DESELECT + return true; +} + +//Checks for presence of chip by requesting JEDEC ID +bool SPIFlash::_getJedecId(void) { + if(!_notBusy()) { + return false; + } + _beginSPI(JEDECID); + _chip.manufacturerID = _nextByte(NULLBYTE); // manufacturer id + _chip.memoryTypeID = _nextByte(NULLBYTE); // memory type + _chip.capacityID = _nextByte(NULLBYTE); // capacity + CHIP_DESELECT + if (!_chip.manufacturerID || !_chip.memoryTypeID || !_chip.capacityID) { + errorcode = NORESPONSE; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + else { + return true; + } +} + +bool SPIFlash::_getSFDP(void) { + if(!_notBusy()) { + return false; + } + _beginSPI(READSFDP); + _currentAddress = 0x00; + _transferAddress(); + _nextByte(DUMMYBYTE); + for (uint8_t i = 0; i < 4; i++) { + _chip.sfdp += (_nextByte() << (8*i)); + } + CHIP_DESELECT + if (_chip.sfdp = 0x50444653) { + //Serial.print("_chip.sfdp: "); + //Serial.println(_chip.sfdp, HEX); + return true; + } + else { + return false; + } +} + +//Identifies the chip +bool SPIFlash::_chipID(void) { + //Get Manfucturer/Device ID so the library can identify the chip + _getSFDP(); + if (!_getJedecId()) { + return false; + } + + // If no capacity is defined in user code + if (!_chip.capacity) { + _chip.supported = _chip.manufacturerID; + if (_chip.supported == WINBOND_MANID || _chip.supported == MICROCHIP_MANID) { + //Identify capacity + for (uint8_t i = 0; i < sizeof(_capID); i++) + { + if (_chip.capacityID == _capID[i]) { + _chip.capacity = (_memSize[i]); + _chip.eraseTime = _eraseTime[i]; + } + } + return true; + } + else { + errorcode = UNKNOWNCAP; //Error code for unidentified capacity + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + } + else { + // If a custom chip size is defined + _chip.eraseTime = _chip.capacity/KB8; + _chip.supported = false;// This chip is not officially supported + errorcode = UNKNOWNCHIP; //Error code for unidentified chip + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + //while(1); //Enable this if usercode is not meant to be run on unsupported chips + } + return true; +} + +//Checks to see if pageOverflow is permitted and assists with determining next address to read/write. +//Sets the global address variable +bool SPIFlash::_addressCheck(uint32_t address, uint32_t size) { + if (errorcode == UNKNOWNCAP || errorcode == NORESPONSE) { + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + if (!_chip.eraseTime) { + errorcode = CALLBEGIN; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + + for (uint32_t i = 0; i < size; i++) { + if (address + i >= _chip.capacity) { + if (!pageOverflow) { + errorcode = OUTOFBOUNDS; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; // At end of memory - (!pageOverflow) + } + else { + _currentAddress = 0x00; + return true; // At end of memory - (pageOverflow) + } + } + } + _currentAddress = address; + return true; // Not at end of memory if (address < _chip.capacity) +} + +bool SPIFlash::_notPrevWritten(uint32_t address, uint32_t size) { + _beginSPI(READDATA); + for (uint16_t i = 0; i < size; i++) { + if (_nextByte() != 0xFF) { + CHIP_DESELECT; + return false; + } + } + CHIP_DESELECT + return true; +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Public functions used for read, write and erase operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Identifies chip and establishes parameters +bool SPIFlash::begin(uint32_t _chipSize) { + if (_chipSize) { + _chip.capacity = _chipSize/8; + } + BEGIN_SPI +#ifdef SPI_HAS_TRANSACTION + //Define the settings to be used by the SPI bus + _settings = SPISettings(SPI_CLK, MSBFIRST, SPI_MODE0); +#endif + if(!_chipID()) { + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } +} + +//Allows the setting of a custom clock speed for the SPI bus to communicate with the chip. +//Only works if the SPI library in use supports SPI Transactions +#ifdef SPI_HAS_TRANSACTION +void SPIFlash::setClock(uint32_t clockSpeed) { + _settings = SPISettings(clockSpeed, MSBFIRST, SPI_MODE0); +} +#endif + +uint8_t SPIFlash::error(bool _verbosity) { + if (!_verbosity) { + return errorcode; + } + else { + _troubleshoot(); + return errorcode; + } +} + +//Returns capacity of chip +uint32_t SPIFlash::getCapacity(void) { + return _chip.capacity; +} + +//Returns maximum number of pages +uint32_t SPIFlash::getMaxPage(void) { + return (_chip.capacity / PAGESIZE); +} + +//Returns the library version as a string +bool SPIFlash::libver(uint8_t *b1, uint8_t *b2, uint8_t *b3) { + *b1 = LIBVER; + *b2 = LIBSUBVER; + *b3 = BUGFIXVER; + return true; +} + +//Checks for and initiates the chip by requesting the Manufacturer ID which is returned as a 16 bit int +uint16_t SPIFlash::getManID(void) { + uint8_t b1, b2; + _getManId(&b1, &b2); + uint32_t id = b1; + id = (id << 8)|(b2 << 0); + return id; +} + +//Returns JEDEC ID which is returned as a 32 bit int +uint32_t SPIFlash::getJEDECID(void) { + uint32_t id = _chip.manufacturerID; + id = (id << 8)|(_chip.memoryTypeID << 0); + id = (id << 8)|(_chip.capacityID << 0); + return id; +} + +//Gets the next available address for use. Has two variants: +// A. Takes the size of the data as an argument and returns a 32-bit address +// B. Takes a three variables, the size of the data and two other variables to return a page number value & an offset into. +// All addresses in the in the sketch must be obtained via this function or not at all. +// Variant A +uint32_t SPIFlash::getAddress(uint16_t size) { + if (!_addressCheck(currentAddress, size)){ + errorcode = OUTOFBOUNDS; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + else { + uint32_t address = currentAddress; + currentAddress+=size; + return address; + } +} +// Variant B +bool SPIFlash::getAddress(uint16_t size, uint16_t &page_number, uint8_t &offset) { + uint32_t address = getAddress(size); + offset = (address >> 0); + page_number = (address >> 8); + return true; +} + +//Function for returning the size of the string (only to be used for the getAddress() function) +uint16_t SPIFlash::sizeofStr(String &inputStr) { + uint16_t size; + size = (sizeof(char)*(inputStr.length()+1)); + size+=sizeof(inputStr.length()+1); + + return size; +} + +// Reads a byte of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +uint8_t SPIFlash::readByte(uint32_t address, bool fastRead) { + uint8_t data; + + if (!_prep(READDATA, address, sizeof(data))) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + data = _nextByte(); + _endSPI(); + return data; +} +// Variant B +uint8_t SPIFlash::readByte(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readByte(address, fastRead); +} + +// Reads a char of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +int8_t SPIFlash::readChar(uint32_t address, bool fastRead) { + int8_t data; + if (!_prep(READDATA, address, sizeof(data))) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + data = _nextByte(); + _endSPI(); + return data; +} +// Variant B +int8_t SPIFlash::readChar(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readChar(address, fastRead); +} + +// Reads an array of bytes starting from a specific location in a page.// Has two variants: +// A. Takes three arguments +// 1. address --> Any address from 0 to capacity +// 2. data_buffer --> The array of bytes to be read from the flash memory - starting at the address indicated +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes four arguments +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data_buffer --> The array of bytes to be read from the flash memory - starting at the offset on the page indicated +// 4. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +bool SPIFlash::readByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) { + if (!_prep(READDATA, address, bufferSize)) { + return false; + } + if(fastRead) { + _beginSPI(FASTREAD); + } + else { + _beginSPI(READDATA); + } + _nextBuf(READDATA, &(*data_buffer), bufferSize); + _endSPI(); + return true; +} +// Variant B +bool SPIFlash::readByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readByteArray(address, data_buffer, bufferSize, fastRead); +} + +// Reads an array of chars starting from a specific location in a page.// Has two variants: +// A. Takes three arguments +// 1. address --> Any address from 0 to capacity +// 2. data_buffer --> The array of bytes to be read from the flash memory - starting at the address indicated +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes four arguments +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data_buffer --> The array of bytes to be read from the flash memory - starting at the offset on the page indicated +// 4. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +bool SPIFlash::readCharArray(uint32_t address, char *data_buffer, uint16_t bufferSize, bool fastRead) { + if (!_prep(READDATA, address, bufferSize)) { + return false; + } + if(fastRead) { + _beginSPI(FASTREAD); + } + else { + _beginSPI(READDATA); + } + _nextBuf(READDATA, (uint8_t*) &(*data_buffer), bufferSize); + _endSPI(); + return true; +} +// Variant B +bool SPIFlash::readCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t bufferSize, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readCharArray(address, data_buffer, bufferSize, fastRead); +} + +// Reads an unsigned int of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +uint16_t SPIFlash::readWord(uint32_t address, bool fastRead) { + const uint8_t size = sizeof(uint16_t); + union + { + uint8_t b[size]; + uint16_t I; + } data; + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.I; +} +// Variant B +uint16_t SPIFlash::readWord(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readWord(address, fastRead); +} + +// Reads a signed int of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +int16_t SPIFlash::readShort(uint32_t address, bool fastRead) { + const uint8_t size = sizeof(int16_t); + union + { + byte b[size]; + int16_t s; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.s; +} +// Variant B +int16_t SPIFlash::readShort(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readShort(address, fastRead); +} + +// Reads an unsigned long of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +uint32_t SPIFlash::readULong(uint32_t address, bool fastRead) { + const uint8_t size = (sizeof(uint32_t)); + union + { + uint8_t b[size]; + uint32_t l; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.l; +} +// Variant B +uint32_t SPIFlash::readULong(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readULong(address, fastRead); +} + +// Reads a signed long of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +int32_t SPIFlash::readLong(uint32_t address, bool fastRead) { + const uint8_t size = (sizeof(int32_t)); + union + { + byte b[size]; + int32_t l; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.l; +} +// Variant B +int32_t SPIFlash::readLong(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readLong(address, fastRead); +} + +// Reads a signed long of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +float SPIFlash::readFloat(uint32_t address, bool fastRead) { + const uint8_t size = (sizeof(float)); + union + { + byte b[size]; + float f; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.f; +} +// Variant B +float SPIFlash::readFloat(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readFloat(address, fastRead); +} + +// Reads a string from a specific location on a page. +// Has two variants: +// A. Takes three arguments +// 1. address --> Any address from 0 to capacity +// 2. outputString --> String variable to write the output to +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes four arguments +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. outputString --> String variable to write the output to +// 4. fastRead --> defaults to false - executes _beginFastRead() if set to true +// This function first reads a short from the address to figure out the size of the String object stored and +// then reads the String object data +// Variant A +bool SPIFlash::readStr(uint32_t address, String &outStr, bool fastRead) { + uint16_t strLen; + //_delay_us(20); + strLen = readWord(address); + address+=(sizeof(strLen)); + char outputChar[strLen]; + + readCharArray(address, outputChar, strLen, fastRead); + + outStr = String(outputChar); + return true; +} +// Variant B +bool SPIFlash::readStr(uint16_t page_number, uint8_t offset, String &outStr, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + return readStr(address, outStr, fastRead); +} + +// Writes a byte of data to a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One byte of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One byte of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeByte(uint32_t address, uint8_t data, bool errorCheck) { + if(!_prep(PAGEPROG, address, sizeof(data))) { + return false; + } + + _beginSPI(PAGEPROG); + _nextByte(data); + CHIP_DESELECT + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeByte(address, data, errorCheck); +} + +// Writes a char of data to a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One char of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One char of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeChar(uint32_t address, int8_t data, bool errorCheck) { + if(!_prep(PAGEPROG, address, sizeof(data))) { + return false; + } + + _beginSPI(PAGEPROG); + _nextByte(data); + CHIP_DESELECT + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeChar(address, data, errorCheck); +} + +// Writes an array of bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> An array of bytes to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An array of bytes to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck) { + if (!_prep(PAGEPROG, address, bufferSize)) { + return false; + } + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t length = bufferSize; + uint16_t writeBufSz; + uint16_t data_offset = 0; + + while (length > 0) + { + writeBufSz = (length<=maxBytes) ? length : maxBytes; + + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(data_buffer[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + length -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + if (!_notBusy()) { + return false; + } + _currentAddress = address; + CHIP_SELECT + _nextByte(READDATA); + _transferAddress(); + for (uint16_t j = 0; j < bufferSize; j++) { + if (_nextByte(NULLBYTE) != data_buffer[j]) { + return false; + } + } + _endSPI(); + return true; + } +} +// Variant B +bool SPIFlash::writeByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeByteArray(address, data_buffer, bufferSize, errorCheck); +} + +// Writes an array of bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> An array of chars to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An array of chars to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeCharArray(uint32_t address, char *data_buffer, uint16_t bufferSize, bool errorCheck) { + uint16_t writeBufSz; + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t data_offset = 0; + uint16_t length = bufferSize; + if (!_prep(PAGEPROG, address, bufferSize)) { + return false; + } + + while (length > 0) + { + writeBufSz = (length<=maxBytes) ? length : maxBytes; + + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(data_buffer[data_offset + i]); + Serial.print(data_buffer[data_offset + i]); + Serial.print(", "); + } + Serial.println(); + _currentAddress += writeBufSz; + data_offset += writeBufSz; + length -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + if (!_notBusy()) { + return false; + } + _currentAddress = address; + CHIP_SELECT + _nextByte(READDATA); + _transferAddress(); + for (uint16_t j = 0; j < bufferSize; j++) { + if (_nextByte(NULLBYTE) != data_buffer[j]) { + return false; + } + } + _endSPI(); + return true; + } +} +// Variant B +bool SPIFlash::writeCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t bufferSize, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeCharArray(address, data_buffer, bufferSize, errorCheck); +} + +// Writes an unsigned int as two bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One unsigned int of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One unsigned int of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeWord(uint32_t address, uint16_t data, bool errorCheck) { + const uint8_t size = sizeof(uint16_t); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + uint16_t w; + } var; + var.w = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else + return _writeErrorCheck(address, data); +} +// Variant B +bool SPIFlash::writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeWord(address, data, errorCheck); +} + +// Writes a signed int as two bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One signed int of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One signed int of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeShort(uint32_t address, int16_t data, bool errorCheck) { + const uint8_t size = sizeof(data); + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + int16_t s; + } var; + var.s = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else + return _writeErrorCheck(address, data); +} +// Variant B +bool SPIFlash::writeShort(uint16_t page_number, uint8_t offset, int16_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeShort(address, data, errorCheck); +} + +// Writes an unsigned long as four bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One unsigned long of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One unsigned long of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeULong(uint32_t address, uint32_t data, bool errorCheck) { + const uint8_t size = (sizeof(data)); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + uint32_t l; + } var; + var.l = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck){ + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeULong(uint16_t page_number, uint8_t offset, uint32_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeULong(address, data, errorCheck); +} + +// Writes a signed long as four bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One signed long of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One signed long of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeLong(uint32_t address, int32_t data, bool errorCheck) { +const uint8_t size = sizeof(data); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + int32_t l; + } var; + var.l = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck){ + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeLong(uint16_t page_number, uint8_t offset, int32_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeLong(address, data, errorCheck); +} + +// Writes a float as four bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One float of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One float of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeFloat(uint32_t address, float data, bool errorCheck) { + const uint8_t size = (sizeof(data)); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + union + { + uint8_t b[size]; + float f; + } var; + var.f = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeFloat(uint16_t page_number, uint8_t offset, float data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeFloat(address, data, errorCheck); +} + +// Reads a string from a specific location on a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. inputString --> String variable to write the data from +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. inputString --> String variable to write the data from +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// This function first writes the size of the string as an unsigned int to the address to figure out the size of the String object stored and +// then writes the String object data. Therefore it takes up two bytes more than the size of the String itself. +// Variant A +bool SPIFlash::writeStr(uint32_t address, String &inputStr, bool errorCheck) { + uint16_t inStrLen = inputStr.length() +1; + if(!_prep(PAGEPROG, address, inStrLen)) { + return false; + } + + const uint16_t size = sizeof(inStrLen); + union + { + uint8_t b[size]; + uint16_t w; + } var; + + var.w = inStrLen; + char inputChar[inStrLen]; + inputStr.toCharArray(inputChar, inStrLen); + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > inStrLen) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + _nextBuf(PAGEPROG, (uint8_t*)&inputChar, inStrLen); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + bool strLenWritten = false; + + while (inStrLen > 0) + { + writeBufSz = (inStrLen<=maxBytes) ? inStrLen : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + if(!strLenWritten) { + for (uint8_t j = 0; j < size; j++) { + _nextByte(var.b[j]); + } + strLenWritten = true; + } + _nextByte(inputChar[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + inStrLen -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + String tempStr; + readStr(address, tempStr); + return inputStr.equals(tempStr); + } +} +// Variant B +bool SPIFlash::writeStr(uint16_t page_number, uint8_t offset, String &inputStr, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + return writeStr(address, inputStr, errorCheck); +} + + +//Erases one 4k sector. Has two variants: +// A. Takes the address as the argument and erases the sector containing the address. +// B. Takes page to be erased as the argument and erases the sector containing the page. +// The sectors are numbered 0 - 255 containing 16 pages each. +// Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 +// Variant A +bool SPIFlash::eraseSector(uint32_t address) { + if(!_notBusy()||!_writeEnable()) + return false; + + _beginSPI(SECTORERASE); + _nextByte(address >> 16); + _nextByte(address >> 8); + _nextByte(0); + _endSPI(); + + if(!_notBusy(500L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, ``Sector Erase``, Block Erase, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} +// Variant B +bool SPIFlash::eraseSector(uint16_t page_number, uint8_t offset) { + uint32_t address = _getAddress(page_number, offset); + return eraseSector(address); +} + +//Erases one 32k block. Has two variants: +// A. Takes the address as the argument and erases the block containing the address. +// B. Takes page to be erased as the argument and erases the block containing the page. +// The blocks are numbered 0 - 31 containing 128 pages each. +// Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31 +// Variant A +bool SPIFlash::eraseBlock32K(uint32_t address) { + if(!_notBusy()||!_writeEnable()) { + return false; + } + _beginSPI(BLOCK32ERASE); + _nextByte(address >> 16); + _nextByte(address >> 8); + _nextByte(0); + _endSPI(); + + if(!_notBusy(1*S)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} +// Variant B +bool SPIFlash::eraseBlock32K(uint16_t page_number, uint8_t offset) { + uint32_t address = _getAddress(page_number, offset); + return eraseBlock32K(address); +} + +//Erases one 64k block. Has two variants: +// A. Takes the address as the argument and erases the block containing the address. +// B. Takes page to be erased as the argument and erases the block containing the page. +// The blocks are numbered 0 - 15 containing 256 pages each. +// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15 +// Variant A +bool SPIFlash::eraseBlock64K(uint32_t address) { + if(!_notBusy()||!_writeEnable()) { + return false; + } + _beginSPI(BLOCK64ERASE); + _nextByte(address >> 16); + _nextByte(address >> 8); + _nextByte(0); + _endSPI(); + + if(!_notBusy(1200L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} +// Variant B +bool SPIFlash::eraseBlock64K(uint16_t page_number, uint8_t offset) { + uint32_t address = _getAddress(page_number, offset); + return eraseBlock64K(address); +} + +//Erases whole chip. Think twice before using. +bool SPIFlash::eraseChip(void) { + if(!_notBusy()||!_writeEnable()) + return false; + + _beginSPI(CHIPERASE); + _endSPI(); + if(!_notBusy(_chip.eraseTime)) + return false; //Datasheet says erasing chip takes 6s max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, ``Chip Erase``, Write Status Register, + // Erase Security Register and Program Security register + + return true; + +} + +//Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). +//Page Program, Write Status Register, Erase instructions are not allowed. +//Erase suspend is only allowed during Block/Sector erase. +//Program suspend is only allowed during Page/Quad Page Program +bool SPIFlash::suspendProg(void) { + if(_notBusy()) { + return false; + } + + if(!_noSuspend()) { + return true; + } + + else { + _beginSPI(SUSPEND); + _endSPI(); + _delay_us(20); + if(!_notBusy(50) || _noSuspend()) { //Max suspend Enable time according to datasheet + return false; + } + return true; + } +} + +//Resumes previously suspended Block Erase/Sector Erase/Page Program. +bool SPIFlash::resumeProg(void) { + if(!_notBusy() || _noSuspend()) { + return false; + } + + _beginSPI(RESUME); + _endSPI(); + + _delay_us(20); + + if(_notBusy(10) || !_noSuspend()) { + return false; + } + return true; + +} + +//Puts device in low power state. Good for battery powered operations. +//Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4) +//In powerDown() the chip will only respond to powerUp() +bool SPIFlash::powerDown(void) { + if(!_notBusy(20)) + return false; + + _beginSPI(POWERDOWN); + _endSPI(); + + _delay_us(5); + + _beginSPI(WRITEENABLE); + CHIP_DESELECT + if (_readStat1() & WRTEN) { + _endSPI(); + return false; + } + else { + + return true; + } +} + +//Wakes chip from low power state. +bool SPIFlash::powerUp(void) { + _beginSPI(RELEASE); + _endSPI(); + _delay_us(3); //Max release enable time according to the Datasheet + + _beginSPI(WRITEENABLE); + CHIP_DESELECT + if (_readStat1() & WRTEN) { + _endSPI(); + return true; + } + else { + + return false; + } +} diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/SPIFlash.h b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/SPIFlash.h new file mode 100644 index 0000000..d8f9667 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/SPIFlash.h @@ -0,0 +1,446 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 19/05/2015 + * Modified by @boseji - 02/03/2017 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + +#ifndef SPIFLASH_H +#define SPIFLASH_H + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Uncomment the code below to run a diagnostic if your flash // +// does not respond // +// // +// Error codes will be generated and returned on functions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//#define RUNDIAGNOSTIC // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Uncomment the code below to increase the speed of the library // +// by disabling _notPrevWritten() // +// // +// Make sure the sectors being written to have been erased beforehand // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//#define HIGHSPEED // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#include +#include "defines.h" + +#if defined (ARDUINO_ARCH_SAM) + #include + #include + #include +#endif + +#ifndef __AVR_ATtiny85__ + #include +#endif + +#if defined (ARDUINO_ARCH_SAM) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_ESP8266) || defined (SIMBLEE) || defined (ARDUINO_ARCH_ESP32) || defined (BOARD_RTL8195A) +// RTL8195A included - @boseji 02.03.17 + #define _delay_us(us) delayMicroseconds(us) +#else + #include +#endif +// Includes specific to RTL8195A to access GPIO HAL - @boseji 02.03.17 +#if defined (BOARD_RTL8195A) +#ifdef __cplusplus +extern "C" { +#endif + +#include "gpio_api.h" +#include "PinNames.h" + +#ifdef __cplusplus +} +#endif + +#endif + +#ifdef ARDUINO_ARCH_AVR + #ifdef __AVR_ATtiny85__ + #define CHIP_SELECT PORTB &= ~cs_mask; + #define CHIP_DESELECT PORTB |= cs_mask; + #define SPIBIT \ + USICR = ((1< 02.03.17 +#elif defined (BOARD_RTL8195A) + #define CHIP_SELECT gpio_write(&csPin, 0); + #define CHIP_DESELECT gpio_write(&csPin, 1); + #define xfer(n) SPI.transfer(n) + #define BEGIN_SPI SPI.begin(); +#else //#elif defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_ARCH_SAMD) + #define CHIP_SELECT digitalWrite(csPin, LOW); + #define CHIP_DESELECT digitalWrite(csPin, HIGH); + #define xfer(n) SPI.transfer(n) + #define BEGIN_SPI SPI.begin(); +#endif + +#define LIBVER 2 +#define LIBSUBVER 6 +#define BUGFIXVER 0 + +#if defined (ARDUINO_ARCH_SAM) + extern char _end; + extern "C" char *sbrk(int i); + //char *ramstart=(char *)0x20070000; + //char *ramend=(char *)0x20088000; +#endif + +class SPIFlash { +public: + //----------------------------------------------Constructor----------------------------------------------- + //New Constructor to Accept the PinNames as a Chip select Parameter - @boseji 02.03.17 + #if !defined (BOARD_RTL8195A) + SPIFlash(uint8_t cs = CS, bool overflow = true); + #else + SPIFlash(PinName cs = CS, bool overflow = true); + #endif + //----------------------------------------Initial / Chip Functions----------------------------------------// + bool begin(uint32_t _chipSize = 0); + void setClock(uint32_t clockSpeed); + bool libver(uint8_t *b1, uint8_t *b2, uint8_t *b3); + uint8_t error(bool verbosity = false); + uint16_t getManID(void); + uint32_t getJEDECID(void); + bool getAddress(uint16_t size, uint16_t &page_number, uint8_t &offset); + uint32_t getAddress(uint16_t size); + //uint16_t getChipName(void); + uint16_t sizeofStr(String &inputStr); + uint32_t getCapacity(void); + uint32_t getMaxPage(void); + //-------------------------------------------Write / Read Bytes-------------------------------------------// + bool writeByte(uint32_t address, uint8_t data, bool errorCheck = true); + bool writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck = true); + uint8_t readByte(uint16_t page_number, uint8_t offset, bool fastRead = false); + uint8_t readByte(uint32_t address, bool fastRead = false); + //----------------------------------------Write / Read Byte Arrays----------------------------------------// + bool writeByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool writeByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool readByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead = false); + bool readByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead = false); + //-------------------------------------------Write / Read Chars-------------------------------------------// + bool writeChar(uint32_t address, int8_t data, bool errorCheck = true); + bool writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck = true); + int8_t readChar(uint32_t address, bool fastRead = false); + int8_t readChar(uint16_t page_number, uint8_t offset, bool fastRead = false); + //----------------------------------------Write / Read Char Arrays----------------------------------------// + bool writeCharArray(uint32_t address, char *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool writeCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool readCharArray(uint32_t address, char *data_buffer, uint16_t buffer_size, bool fastRead = false); + bool readCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t buffer_size, bool fastRead = false); + //------------------------------------------Write / Read Shorts------------------------------------------// + bool writeShort(uint32_t address, int16_t data, bool errorCheck = true); + bool writeShort(uint16_t page_number, uint8_t offset, int16_t data, bool errorCheck = true); + int16_t readShort(uint32_t address, bool fastRead = false); + int16_t readShort(uint16_t page_number, uint8_t offset, bool fastRead = false); + //-------------------------------------------Write / Read Words-------------------------------------------// + bool writeWord(uint32_t address, uint16_t data, bool errorCheck = true); + bool writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bool errorCheck = true); + uint16_t readWord(uint32_t address, bool fastRead = false); + uint16_t readWord(uint16_t page_number, uint8_t offset, bool fastRead = false); + //-------------------------------------------Write / Read Longs-------------------------------------------// + bool writeLong(uint32_t address, int32_t data, bool errorCheck = true); + bool writeLong(uint16_t page_number, uint8_t offset, int32_t data, bool errorCheck = true); + int32_t readLong(uint32_t address, bool fastRead = false); + int32_t readLong(uint16_t page_number, uint8_t offset, bool fastRead = false); + //--------------------------------------Write / Read Unsigned Longs---------------------------------------// + bool writeULong(uint32_t address, uint32_t data, bool errorCheck = true); + bool writeULong(uint16_t page_number, uint8_t offset, uint32_t data, bool errorCheck = true); + uint32_t readULong(uint32_t address, bool fastRead = false); + uint32_t readULong(uint16_t page_number, uint8_t offset, bool fastRead = false); + //-------------------------------------------Write / Read Floats------------------------------------------// + bool writeFloat(uint32_t address, float data, bool errorCheck = true); + bool writeFloat(uint16_t page_number, uint8_t offset, float data, bool errorCheck = true); + float readFloat(uint32_t address, bool fastRead = false); + float readFloat(uint16_t page_number, uint8_t offset, bool fastRead = false); + //------------------------------------------Write / Read Strings------------------------------------------// + bool writeStr(uint32_t address, String &inputStr, bool errorCheck = true); + bool writeStr(uint16_t page_number, uint8_t offset, String &inputStr, bool errorCheck = true); + bool readStr(uint32_t address, String &outStr, bool fastRead = false); + bool readStr(uint16_t page_number, uint8_t offset, String &outStr, bool fastRead = false); + //------------------------------------------Write / Read Anything-----------------------------------------// + template bool writeAnything(uint32_t address, const T& value, bool errorCheck = true); + template bool writeAnything(uint16_t page_number, uint8_t offset, const T& value, bool errorCheck = true); + template bool readAnything(uint32_t address, T& value, bool fastRead = false); + template bool readAnything(uint16_t page_number, uint8_t offset, T& value, bool fastRead = false); + //--------------------------------------------Erase functions---------------------------------------------// + bool eraseSector(uint32_t address); + bool eraseSector(uint16_t page_number, uint8_t offset); + bool eraseBlock32K(uint32_t address); + bool eraseBlock32K(uint16_t page_number, uint8_t offset); + bool eraseBlock64K(uint32_t address); + bool eraseBlock64K(uint16_t page_number, uint8_t offset); + bool eraseChip(void); + //---------------------------------------------Power functions--------------------------------------------// + bool suspendProg(void); + bool resumeProg(void); + bool powerDown(void); + bool powerUp(void); + //-------------------------------------Public Arduino Due Functions---------------------------------------// +//#if defined (ARDUINO_ARCH_SAM) + //uint32_t freeRAM(void); +//#endif + //-------------------------------------------Public variables---------------------------------------------// + +private: +#if defined (ARDUINO_ARCH_SAM) + //-------------------------------------Private Arduino Due Functions--------------------------------------// + void _dmac_disable(void); + void _dmac_enable(void); + void _dmac_channel_disable(uint32_t ul_num); + void _dmac_channel_enable(uint32_t ul_num); + bool _dmac_channel_transfer_done(uint32_t ul_num); + void _dueSPIDmaRX(uint8_t* dst, uint16_t count); + void _dueSPIDmaRX(char* dst, uint16_t count); + void _dueSPIDmaTX(const uint8_t* src, uint16_t count); + void _dueSPIDmaCharTX(const char* src, uint16_t count); + void _dueSPIBegin(void); + void _dueSPIInit(uint8_t dueSckDivisor); + uint8_t _dueSPITransfer(uint8_t b); + uint8_t _dueSPIRecByte(void); + uint8_t _dueSPIRecByte(uint8_t* buf, size_t len); + int8_t _dueSPIRecChar(void); + int8_t _dueSPIRecChar(char* buf, size_t len); + void _dueSPISendByte(uint8_t b); + void _dueSPISendByte(const uint8_t* buf, size_t len); + void _dueSPISendChar(char b); + void _dueSPISendChar(const char* buf, size_t len); +#endif + //--------------------------------------------Private functions-------------------------------------------// + void _troubleshoot(void); + void _printErrorCode(void); + void _printSupportLink(void); + void _endSPI(void); + bool _prep(uint8_t opcode, uint32_t address, uint32_t size); + bool _prep(uint8_t opcode, uint32_t page_number, uint8_t offset, uint32_t size); + bool _startSPIBus(void); + bool _beginSPI(uint8_t opcode); + bool _noSuspend(void); + bool _notBusy(uint32_t timeout = BUSY_TIMEOUT); + bool _notPrevWritten(uint32_t address, uint32_t size = 1); + bool _writeEnable(uint32_t timeout = 10L); + bool _writeDisable(void); + bool _getJedecId(void); + bool _getManId(uint8_t *b1, uint8_t *b2); + bool _getSFDP(void); + bool _chipID(void); + bool _transferAddress(void); + bool _addressCheck(uint32_t address, uint32_t size = 1); + uint8_t _nextByte(uint8_t data = NULLBYTE); + uint16_t _nextInt(uint16_t = NULLINT); + void _nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size); + uint8_t _readStat1(void); + uint8_t _readStat2(void); + uint32_t _getAddress(uint16_t page_number, uint8_t offset = 0); + template bool _writeErrorCheck(uint32_t address, const T& value); + //-------------------------------------------Private variables------------------------------------------// + #ifdef SPI_HAS_TRANSACTION + SPISettings _settings; + #endif + volatile uint8_t *cs_port; + + #if !defined (BOARD_RTL8195A) + uint8_t csPin; + #else + // Object declaration for the GPIO HAL type for csPin - @boseji 02.03.17 + gpio_t csPin; + #endif + + bool pageOverflow, SPIBusState; + uint8_t cs_mask, errorcode, state, _SPCR, _SPSR; + struct chipID { + uint8_t manufacturerID; + uint8_t memoryTypeID; + uint8_t capacityID; + uint16_t supported; + uint32_t sfdp; + uint32_t capacity; + uint32_t eraseTime; + }; + chipID _chip; + uint32_t currentAddress, _currentAddress = 0; + const uint8_t _capID[11] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x43}; + const uint32_t _memSize[11] = {64L * K, 128L * K, 256L * K, 512L * K, 1L * M, 2L * M, 4L * M, 8L * M, + 16L * M, 32L * M, 8L * M}; + const uint32_t _eraseTime[11] = {1L * S, 2L * S, 2L * S, 4L * S, 6L * S, 10L * S, 15L * S, 100L * S, 200L * S, 400L * S, 50L}; //Erase time in milliseconds +}; + +//--------------------------------------------Templates-------------------------------------------// + +// Writes any type of data to a specific location in the flash memory. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to maxAddress +// 2. T& value --> Variable to write data from +// 4. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. const T& value --> Variable with the data to be written +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +template bool SPIFlash::writeAnything(uint32_t address, const T& value, bool errorCheck) { + if (!_prep(PAGEPROG, address, sizeof(value))) { + return false; + } + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t length = sizeof(value); + + //if (maxBytes > length) { + uint32_t writeBufSz; + uint16_t data_offset = 0; + const uint8_t* p = ((const uint8_t*)(const void*)&value); + + if (!SPIBusState) { + _startSPIBus(); + } + while (length > 0) + { + writeBufSz = (length<=maxBytes) ? length : maxBytes; + + if(!_notBusy() || !_writeEnable()){ + return false; + } + + CHIP_SELECT + (void)xfer(PAGEPROG); + _transferAddress(); + + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(*p++); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + length -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, value); + } +} +// Variant B +template bool SPIFlash::writeAnything(uint16_t page_number, uint8_t offset, const T& value, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + return writeAnything(address, value, errorCheck); +} + +// Reads any type of data from a specific location in the flash memory. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to maxAddress +// 2. T& value --> Variable to return data into +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. T& value --> Variable to return data into +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +template bool SPIFlash::readAnything(uint32_t address, T& value, bool fastRead) { + if (!_prep(READDATA, address, sizeof(value))) + return false; + + uint8_t* p = (uint8_t*)(void*)&value; + if(!fastRead) + _beginSPI(READDATA); + else + _beginSPI(FASTREAD); + for (uint16_t i = 0; i < sizeof(value); i++) { + *p++ =_nextByte(); + } + _endSPI(); + return true; +} +// Variant B +template bool SPIFlash::readAnything(uint16_t page_number, uint8_t offset, T& value, bool fastRead) +{ + uint32_t address = _getAddress(page_number, offset); + return readAnything(address, value, fastRead); +} + +// Private template to check for errors in writing to flash memory +template bool SPIFlash::_writeErrorCheck(uint32_t address, const T& value) { +if (!_prep(READDATA, address, sizeof(value)) && !_notBusy()) { + return false; +} + + const uint8_t* p = (const uint8_t*)(const void*)&value; + _beginSPI(READDATA); + uint8_t _v; + for(uint16_t i = 0; i < sizeof(value);i++) + { +#if defined (ARDUINO_ARCH_SAM) + if(*p++ != _dueSPIRecByte()) + { + return false; + } +#else + if(*p++ != _nextByte()) + { + errorcode = ERRORCHKFAIL; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } +#endif + } + _endSPI(); + return true; +} + +#endif // _SPIFLASH_H_ diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/defines.h b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/defines.h new file mode 100644 index 0000000..3dd9da0 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/defines.h @@ -0,0 +1,191 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 19/05/2015 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Common Instructions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +#define MANID 0x90 +#define PAGEPROG 0x02 +#define READDATA 0x03 +#define FASTREAD 0x0B +#define WRITEDISABLE 0x04 +#define READSTAT1 0x05 +#define READSTAT2 0x35 +#define WRITESTAT 0x01 +#define WRITEENABLE 0x06 +#define SECTORERASE 0x20 +#define BLOCK32ERASE 0x52 +#define CHIPERASE 0xC7 +#define SUSPEND 0x75 +#define ID 0x90 +#define RESUME 0x7A +#define JEDECID 0x9F +#define RELEASE 0xAB +#define POWERDOWN 0xB9 +#define BLOCK64ERASE 0xD8 +#define READSFDP 0x5A + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// General size definitions // +// B = Bytes; KB = Kilo bits; MB = Mega bits // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#define B1 1L +#define B2 2L +#define B4 4L +#define B8 8L +#define B16 16L +#define B32 32L +#define B64 64L +#define B80 80L +#define B128 128L +#define B256 256L +#define B512 512L +#define KB1 B1 * K +#define KB2 B2 * K +#define KB4 B4 * K +#define KB8 B8 * K +#define KB16 B16 * K +#define KB32 B32 * K +#define KB64 B64 * K +#define KB128 B128 * K +#define KB256 B256 * K +#define KB512 B512 * K +#define MB1 B1 * M +#define MB2 B2 * M +#define MB4 B4 * M +#define MB8 B8 * M +#define MB16 B16 * M +#define MB32 B32 * M +#define MB64 B64 * M +#define MB128 B128 * M +#define MB256 B256 * M +#define MB512 B512 * M +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Chip specific instructions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + + //~~~~~~~~~~~~~~~~~~~~~~~~~ Winbond ~~~~~~~~~~~~~~~~~~~~~~~~~// + #define WINBOND_MANID 0xEF + #define PAGESIZE 0x100 + + //~~~~~~~~~~~~~~~~~~~~~~~~ Microchip ~~~~~~~~~~~~~~~~~~~~~~~~// + #define MICROCHIP_MANID 0xBF +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Definitions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +#define BUSY 0x01 +#if defined (ARDUINO_ARCH_ESP32) +#define SPI_CLK 20000000 +#else +#define SPI_CLK 104000000 //Hex equivalent of 104MHz +#endif +#define WRTEN 0x02 +#define SUS 0x80 +#define WSE 0x04 +#define WSP 0x08 +#define DUMMYBYTE 0xEE +#define NULLBYTE 0x00 +#define NULLINT 0x0000 +#define NO_CONTINUE 0x00 +#define PASS 0x01 +#define FAIL 0x00 +#define NOOVERFLOW false +#define NOERRCHK false +#define VERBOSE true +#if defined (SIMBLEE) +#define BUSY_TIMEOUT 100L +#else +#define BUSY_TIMEOUT 10L +#endif +#define arrayLen(x) (sizeof(x) / sizeof(*x)) +#define lengthOf(x) (sizeof(x))/sizeof(byte) +#define K 1024L +#define M K * K +#define S 1000L + +#if defined (ARDUINO_ARCH_ESP8266) +#define CS 15 +#elif defined (ARDUINO_ARCH_SAMD) +#define CS 10 +#elif defined __AVR_ATtiny85__ +#define CS 5 +/********************************************************************************************* +// Declaration of the Default Chip select pin name for RTL8195A +// Note: This has been shifted due to a bug identified in the HAL layer SPI driver +// @ref http://www.amebaiot.com/en/questions/forum/facing-issues-with-spi-interface-to-w25q32/ +// Note: Please use any pin other than GPIOC_0 which is the D10 marked in the kit +// Original edit by @boseji 02.03.17 +// Modified by Prajwal Bhattaram 14.4.17 +**********************************************************************************************/ +#elif defined (BOARD_RTL8195A) +#define CS PC_4 +#else +#define CS SS +#endif + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Arduino Due DMA definitions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Use SAM3X DMAC if nonzero +#define USE_SAM3X_DMAC 1 +// Use extra Bus Matrix arbitration fix if nonzero +#define USE_SAM3X_BUS_MATRIX_FIX 0 +// Time in ms for DMA receive timeout +#define SAM3X_DMA_TIMEOUT 100 +// chip select register number +#define SPI_CHIP_SEL 3 +// DMAC receive channel +#define SPI_DMAC_RX_CH 1 +// DMAC transmit channel +#define SPI_DMAC_TX_CH 0 +// DMAC Channel HW Interface Number for SPI TX. +#define SPI_TX_IDX 1 +// DMAC Channel HW Interface Number for SPI RX. +#define SPI_RX_IDX 2 +// Set DUE SPI clock div (any integer from 2 - 255) +#define DUE_SPI_CLK 2 +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// List of Error codes // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + + #define SUCCESS 0x00 + #define CALLBEGIN 0x01 + #define UNKNOWNCHIP 0x02 + #define UNKNOWNCAP 0x03 + #define CHIPBUSY 0x04 + #define OUTOFBOUNDS 0x05 + #define CANTENWRITE 0x06 + #define PREVWRITTEN 0x07 + #define LOWRAM 0x08 + #define SYSSUSPEND 0x09 + #define UNSUPPORTED 0x0A + #define ERRORCHKFAIL 0x0B + #define NORESPONSE 0x0C + #define UNKNOWNERROR 0xFE + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// diff --git a/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/troubleshoot.cpp b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/troubleshoot.cpp new file mode 100644 index 0000000..6255150 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/SPIMemory-2.6.0/src/troubleshoot.cpp @@ -0,0 +1,184 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 14/11/2016 + * Modified by @boseji - 02/03/2017 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + + #include "SPIFlash.h" + + //Subfunctions for troubleshooting function + void SPIFlash::_printErrorCode(void) { + Serial.print("Error code: 0x"); + if (errorcode < 0x10) { + Serial.print("0"); + } + Serial.println(errorcode, HEX); + } + + void SPIFlash::_printSupportLink(void) { + Serial.print("If this does not help resolve/clarify this issue, "); + Serial.println("please raise an issue at http://www.github.com/Marzogh/SPIFlash/issues with the details of what your were doing when this error occurred"); + } + //Troubleshooting function. Called when #ifdef RUNDIAGNOSTIC is uncommented at the top of this file. + void SPIFlash::_troubleshoot(void) { + + switch (errorcode) { + case SUCCESS: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Action completed successfully"); + #endif + break; + + case NORESPONSE: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Check your wiring. Flash chip is non-responsive."); + _printSupportLink(); + #endif + break; + + case CALLBEGIN: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("*constructor_of_choice*.begin() was not called in void setup()"); + _printSupportLink(); + #endif + break; + + case UNKNOWNCHIP: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + Serial.print("Error code: 0x0"); + Serial.println(UNKNOWNCHIP, HEX); + #else + Serial.println("Unable to identify chip. Are you sure this chip is supported?"); + _printSupportLink(); + #endif + Serial.println("Chip details:"); + Serial.print("manufacturer ID: 0x"); Serial.println(_chip.manufacturerID, HEX); + Serial.print("capacity ID: 0x");Serial.println(_chip.memoryTypeID, HEX); + Serial.print("device ID: 0x");Serial.println(_chip.capacityID, HEX); + break; + + case UNKNOWNCAP: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unable to identify capacity. Is this chip officially supported? If not, please define a `CAPACITY` constant and include it in flash.begin(CAPACITY)."); + _printSupportLink(); + #endif + break; + + case CHIPBUSY: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Chip is busy."); + Serial.println("Make sure all pins have been connected properly"); + _printSupportLink(); + #endif + break; + + case OUTOFBOUNDS: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Page overflow has been disabled and the address called exceeds the memory"); + _printSupportLink(); + #endif + break; + + case CANTENWRITE: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unable to Enable Writing to chip."); + Serial.println("Please make sure the HOLD & WRITEPROTECT pins are pulled up to VCC"); + _printSupportLink(); + #endif + break; + + case PREVWRITTEN: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("This sector already contains data."); + Serial.println("Please make sure the sectors being written to are erased."); + _printSupportLink(); + #endif + break; + + case LOWRAM: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("You are running low on SRAM. Please optimise your program for better RAM usage"); + /*#if defined (ARDUINO_ARCH_SAM) + Serial.print("Current Free SRAM: "); + Serial.println(freeRAM()); + #endif*/ + _printSupportLink(); + #endif + break; + + case SYSSUSPEND: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unable to suspend/resume operation."); + _printSupportLink(); + #endif + break; + + case UNSUPPORTED: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("This function is not supported by the current flash IC."); + _printSupportLink(); + #endif + break; + + case ERRORCHKFAIL: +#if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); +#else + Serial.println("Write Function has failed errorcheck."); + _printSupportLink(); +#endif + break; + + default: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unknown error"); + _printSupportLink(); + #endif + break; + } + } diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostic_functions.ino b/arduino_libraries/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostic_functions.ino new file mode 100644 index 0000000..399a231 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostic_functions.ino @@ -0,0 +1,863 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | FlashDiagnostic_functions.ino | + | SPIFlash library | + | v 2.6.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 13.11.2016 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | For a full diagnostics rundown - with error codes and details of the errors | + | uncomment #define RUNDIAGNOSTIC in SPIFlash.cpp in the library before compiling | + | and loading this application onto your Arduino. | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ + +void getID() { + char printBuffer[128]; + printLine(); + for (uint8_t i = 0; i < 68; i++) { + Serial.print(F(" ")); + } + Serial.print(F("SPIFlash Library version")); +#ifdef LIBVER + uint8_t _ver, _subver, _bugfix; + flash.libver(&_ver, &_subver, &_bugfix); + clearprintBuffer(&printBuffer[1]); + sprintf(printBuffer, ": %d.%d.%d", _ver, _subver, _bugfix); + Serial.println(printBuffer); +#else + Serial.println(F("< 2.5.0")); +#endif + printLine(); + + for (uint8_t i = 0; i < 80; i++) { + Serial.print(F(" ")); + } + Serial.println(F("Get ID")); + printLine(); + uint8_t b1, b2; + uint16_t b3; + uint32_t JEDEC = flash.getJEDECID(); + uint32_t maxPage = flash.getMaxPage(); + uint32_t capacity = flash.getCapacity(); + b1 = (JEDEC >> 16); + b2 = (JEDEC >> 8); + b3 = (JEDEC >> 0); + + + printLine(); + //---------------------------------------------------------------------------------------------// + + clearprintBuffer(&printBuffer[1]); + sprintf(printBuffer, "\t\t\tJEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); + clearprintBuffer(&printBuffer[1]); + sprintf(printBuffer, "\t\t\tManufacturer ID: %02xh\n\t\t\tMemory Type: %02xh\n\t\t\tCapacity: %lu bytes\n\t\t\tMaximum pages: %lu", b1, b2, capacity, maxPage); + Serial.println(printBuffer); +} + +bool checkPage(uint8_t *data_buffer) { + for (int i = 0; i < 256; i++) { + if (data_buffer[i] != i) + return false; + } + return true; +} + +void diagnose() { + printLine(); + for (uint8_t i = 0; i < 79; i++) { + Serial.print(F(" ")); + } + Serial.println(F("Data Check")); + printLine(); + + Serial.println(F("\tData Written\t||\tData Read\t||\tResult\t\t||\tWrite Time\t||\tRead Time\t||\tWrite Time\t||\tFast Read Time")); + Serial.print(F("\t\t\t||\t\t\t||\t\t\t||\t\t\t||\t\t\t||")); + Serial.println(F("\t(No Error Chk)\t||")); + printLine(); + byteDiag(); + charDiag(); + wordDiag(); + shortDiag(); + uLongDiag(); + longDiag(); + floatDiag(); + stringDiag(); + structDiag(); + pageDiag(); + powerFuncDiag(); + +} + +void byteDiag(void) { + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Byte // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + uint8_t _byte = 35; + uint8_t _b; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeByte(addr, _byte); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _b = flash.readByte(addr); + rTime = micros() - startTime; + //Print result + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_byte); + printTab(2, 1); + Serial.print(_b); + printTab(2, 1); + if (_byte == _b) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeByte(addr, _byte, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _b = flash.readByte(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void charDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Char // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + int8_t _char = -110; + int8_t _c; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeChar(addr, _char); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _c = flash.readChar(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_char); + printTab(2, 1); + Serial.print(_c); + printTab(2, 1); + if (_char == _c) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeChar(addr, _char, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _c = flash.readChar(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void wordDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Word // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + uint16_t _word = 4520; + uint16_t _w; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeWord(addr, _word); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _w = flash.readWord(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_word); + printTab(2, 1); + Serial.print(_w); + printTab(2, 1); + if (_word == _w) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeWord(addr, _word, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _w = flash.readWord(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void shortDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Short // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + int16_t _short = -1250; + int16_t _s; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeShort(addr, _short); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _s = flash.readShort(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_short); + printTab(2, 1); + Serial.print(_s); + printTab(2, 1); + if (_short == _s) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeShort(addr, _short, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _s = flash.readShort(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void uLongDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Ulong // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + uint32_t _uLong = 876532; + uint32_t _uL; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeULong(addr, _uLong); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _uL = flash.readULong(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_uLong); + printTab(2, 1); + Serial.print(_uL); + printTab(2, 1); + if (_uLong == _uL) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeULong(addr, _uLong, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _uL = flash.readULong(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void longDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Long // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + int32_t _long = -10959; + int32_t _l; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeLong(addr, _long); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _l = flash.readLong(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_long); + printTab(2, 1); + Serial.print(_l); + printTab(2, 1); + if (_long == _l) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeLong(addr, _long, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _l = flash.readLong(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void floatDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Float // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + float _float = 3.1415; + float _f; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeFloat(addr, _float)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _f = flash.readFloat(addr); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_float); + printTab(2, 1); + Serial.print(_f); + printTab(2, 1); + if (_float == _f) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeFloat(addr, _float, false)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + _f = flash.readFloat(addr, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void stringDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // String // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + String _string = "123 Test !@#"; + String _str = ""; + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeStr(addr, _string)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + if (flash.readStr(addr, _str)) { + rTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(_string); + printTab(1, 1); + Serial.print(_str); + printTab(1, 1); + if (_string == _str) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + if (flash.writeStr(addr, _string, false)) { + wTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + if (flash.readStr(addr, _str, true)) { + rTime = micros() - startTime; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void structDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Struct // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + struct Test { + word s1; + float s2; + long s3; + bool s4; + byte s5; + }; + Test inputStruct; + Test outputStruct; + + inputStruct.s1 = 31325; + inputStruct.s2 = 4.84; + inputStruct.s3 = 880932; + inputStruct.s4 = true; + inputStruct.s5 = 5; + + float startTime; + uint32_t addr, wTime, rTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeAnything(addr, inputStruct); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + flash.readAnything(addr, outputStruct); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTab(1, 0); + Serial.print(F("inputStruct")); + printTab(1, 1); + Serial.print(F("outputStruct")); + printTab(1, 1); + if (inputStruct.s1 == outputStruct.s1 && inputStruct.s2 == outputStruct.s2 && inputStruct.s3 == outputStruct.s3 && inputStruct.s4 == outputStruct.s4 && inputStruct.s5 == outputStruct.s5) + printPass(); + else + printFail(); + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, 0xFFFFF); + startTime = micros(); + flash.writeAnything(addr, inputStruct, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + startTime = micros(); + flash.readAnything(addr, outputStruct, true); + rTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void pageDiag(void) { + //-----------------------------------------------------------------------------------------------------------------------------------------------------// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Page // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + float startTime; + uint32_t addr, wTime, rTime; + uint8_t pageBuffer[PAGESIZE]; + + for (int i = 0; i < PAGESIZE; ++i) { + pageBuffer[i] = i; + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + addr = random(0, flash.getMaxPage()); + startTime = micros(); + while (!flash.writeByteArray(addr, pageBuffer, PAGESIZE)); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Read & Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + for (int i = 0; i < PAGESIZE; ++i) { + pageBuffer[i] = 0; + } + startTime = micros(); + printTab(1, 0); + Serial.print(F("0 - ")); + Serial.print(PAGESIZE - 1); + printTab(2, 1); + startTime = micros(); + + flash.readByteArray(addr, pageBuffer, PAGESIZE); + rTime = micros() - startTime; + bool _pass; + for (uint16_t i = 0; i < 256; i++) { + if (pageBuffer [i] != i) { + _pass = false; + break; + } + else { + _pass = true; + } + } + + if (_pass) { + Serial.print(F("0 - ")); + Serial.print(PAGESIZE - 1); + printTab(2, 1); + printPass(); + } + else { + Serial.print(F("Unknown")); + printTab(2, 1); + printFail(); + } + printTime(wTime, rTime); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Write (No Error) // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + for (int i = 0; i < 256; ++i) { + pageBuffer[i] = i; + } + addr = random(0, flash.getMaxPage()); + startTime = micros(); + flash.writeByteArray(addr, pageBuffer, PAGESIZE, false); + wTime = micros() - startTime; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + // Fast Read & Print Result // + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + for (int i = 0; i < 256; ++i) { + pageBuffer[i] = 0; + } + startTime = micros(); + flash.readByteArray(addr, pageBuffer, PAGESIZE, true); + rTime = micros() - startTime; + printTime(wTime, rTime); + Serial.println(); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //-----------------------------------------------------------------------------------------------------------------------------------------------------// +} + +void powerFuncDiag(void) { + String _string = "123 Test !@#"; + float wTime; + + printLine(); + for (uint8_t i = 0; i < 72; i++) { + Serial.print(" "); + } + Serial.println(F("Check Other Functions")); + printLine(); + Serial.println(F("\t\t\t\t\tFunction\t\t||\t\tResult\t\t\t||\t\tTime")); + printLine(); + Serial.flush(); + + uint32_t capacity = flash.getCapacity(); + if (!Serial) + Serial.begin(115200); + uint32_t stringAddress1 = random(0, capacity); + uint32_t stringAddress2 = random(0, capacity); + uint32_t stringAddress3 = random(0, capacity); + + printTab(5, 0); + Serial.print(F("powerDown")); + printTab(2, 2); + //if (flash.writeStr(stringAddress1, _string)) { + wTime = micros(); + if (flash.powerDown()) { + wTime = micros() - wTime; + printPass(); + } + else { + wTime = micros() - wTime; + printFail(); + } + //} + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("powerUp")); + printTab(3, 2); + wTime = micros(); + if (flash.powerUp()) { + wTime = micros() - wTime; + //if (flash.writeStr(stringAddress3, _string)) { + printPass(); + } + else { + printFail(); + } + //} + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseSector")); + wTime = micros(); + printTab(2, 2); + if (flash.eraseSector(stringAddress1)) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + wTime = wTime / 3; + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseBlock32K")); + wTime = micros(); + printTab(2, 2); + if (flash.eraseBlock32K(stringAddress2)) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + wTime = wTime / 3; + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseBlock64K")); + wTime = micros(); + printTab(2, 2); + if (flash.eraseBlock64K(stringAddress3)) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + wTime = wTime / 3; + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printTab(5, 0); + Serial.print(F("eraseChip")); + printTab(2, 2); + wTime = micros(); + if (flash.eraseChip()) { + wTime = micros() - wTime; + printPass(); + } + else { + printFail(); + } + + + printTab(3, 2); + printTimer(wTime); + Serial.println(); + + printLine(); +} diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostics.ino b/arduino_libraries/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostics.ino new file mode 100644 index 0000000..0528dfe --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/FlashDiagnostics/FlashDiagnostics.ino @@ -0,0 +1,131 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | FlashDiagnostics.ino | + | SPIFlash library | + | v 2.6.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 16.04.2017 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | For a full diagnostics rundown - with error codes and details of the errors | + | uncomment #define RUNDIAGNOSTIC in SPIFlash.cpp in the library before compiling | + | and loading this application onto your Arduino. | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ + +#include + +//Define a flash memory size (if using non-Winbond memory) according to the list in defines.h +//#define CHIPSIZE MB64 + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#define RANDPIN 1 +#else +#define BAUD_RATE 115200 +#define RANDPIN A0 +#endif + +SPIFlash flash; + +void setup() { + Serial.begin(BAUD_RATE); +#if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) + while (!Serial) ; // Wait for Serial monitor to open +#endif + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); +#if defined (CHIPSIZE) + flash.begin(CHIPSIZE); //use flash.begin(CHIPSIZE) if using non-Winbond flash (Refer to '#define CHIPSIZE' above) +#else + flash.begin(); +#endif + Serial.println(); + Serial.println(); + +#if defined (ARDUINO_ARCH_ESP32) + randomSeed(65535537); +#else + randomSeed(analogRead(RANDPIN)); +#endif + getID(); + diagnose(); +} + +void loop() { + +} + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Serial Print Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +void clearprintBuffer(char *bufPtr) +{ + for (uint8_t i = 0; i < 128; i++) { + //printBuffer[i] = 0; + *bufPtr++ = 0; + } +} + +void printLine() { + for (uint8_t i = 0; i < 230; i++) { + Serial.print(F("-")); + } + Serial.println(); +} + +void printPass() { + Serial.print(F("Pass")); +} + +void printFail() { + Serial.print(F("Fail")); +} + +void printTab(uint8_t a, uint8_t b) { + for (uint8_t i = 0; i < a; i++) { + Serial.print(F("\t")); + } + if (b > 0) { + Serial.print("||"); + for (uint8_t i = 0; i < b; i++) { + Serial.print(F("\t")); + } + } +} + +void printTime(uint32_t _wTime, uint32_t _rTime) { + printTab(2, 1); + printTimer(_wTime); + printTab(2, 1); + printTimer(_rTime); +} + +void printTimer(uint32_t _us) { + + if (_us > 1000000) { + float _s = _us / (float)1000000; + Serial.print(_s, 4); + Serial.print(" s"); + } + else if (_us > 10000) { + float _ms = _us / (float)1000; + Serial.print(_ms, 4); + Serial.print(" ms"); + } + else { + Serial.print(_us); + Serial.print(F(" us")); + } +} diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/Struct_writer/Struct_writer.ino b/arduino_libraries/SPIMemory-2.6.0/examples/Struct_writer/Struct_writer.ino new file mode 100644 index 0000000..e33e2d8 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/Struct_writer/Struct_writer.ino @@ -0,0 +1,144 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Struct_writer.ino | + | SPIFlash library | + | v 2.6.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 16.04.2017 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | This program writes a struct to a random location on your flash memory chip and reads it back. | + | Uncomment #define SENSOR below to get real world readings. Real world readings require a Light dependant resistor hooked up to A0. | + | For information on how to hook up an LDR to an Arduino, please refer to Adafruit's excellent tutorial at | + | https://learn.adafruit.com/photocells/using-a-photocell | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ + +#include + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#else +#define BAUD_RATE 115200 +#endif + +/* + Uncomment the #define below if you would like real world readings. + For real world readings, hook up a light dependant resistor to A1. + +*/ +//#define SENSOR +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#define LDR 1 +#else +#define BAUD_RATE 115200 +#define LDR A0 +#endif + + + +SPIFlash flash; + + +struct Configuration { + float lux; + float vOut; // Voltage ouput from potential divider to Analog input + float RLDR; // Resistance calculation of potential divider with LDR + bool light; + uint8_t adc; +}; +Configuration configuration; + +void setup() { + Serial.begin(BAUD_RATE); +#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__) + while (!Serial) ; // Wait for Serial monitor to open +#endif + #if defined (ARDUINO_ARCH_ESP32) + randomSeed(65535537); +#else + randomSeed(analogRead(LDR)); +#endif + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + Serial.println(); + flash.begin(); + + + uint32_t _addr = random(0, 1677215); + +#ifndef SENSOR + configuration.lux = 98.43; + configuration.vOut = 4.84; + configuration.RLDR = 889.32; + configuration.light = true; + configuration.adc = 5; +#endif + +#ifdef SENSOR + readLDR(); +#endif + + if (flash.writeAnything(_addr, configuration)) + Serial.println ("Data write successful"); + else + Serial.println ("Data write failed"); + + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + + Serial.println("Saved!"); + configuration.lux = 0; + configuration.vOut = 0; + configuration.RLDR = 0; + configuration.light = 0; + configuration.adc = 0; + Serial.println(); + Serial.println("Local values set to 0"); + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + Serial.println(); + flash.readAnything(_addr, configuration); + flash.eraseSector(_addr, 0); + + Serial.println("After reading"); + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + +} + +void loop() { + delay(1000); +} + +#ifdef SENSOR +void readLDR() +{ + configuration.adc = analogRead(LDR); + configuration.vOut = (configuration.adc * 0.0048828125); // vOut = Output voltage from potential Divider. [vOut = ADC * (Vin / 1024)] + configuration.RLDR = (10.0 * (5 - configuration.vOut)) / configuration.vOut; // Equation to calculate Resistance of LDR, [R-LDR =(R1 (Vin - vOut))/ vOut]. R1 is in KOhms + // R1 = 10 KOhms , Vin = 5.0 Vdc. + configuration.lux = (500 / configuration.RLDR); +} +#endif diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/TestFlash/TestFlash.ino b/arduino_libraries/SPIMemory-2.6.0/examples/TestFlash/TestFlash.ino new file mode 100644 index 0000000..6af1df5 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/TestFlash/TestFlash.ino @@ -0,0 +1,596 @@ +/* + ---------------------------------------------------------------------------------------------------------------------------------- + | Winbond Flash | + | SPIFlash library test v2.4.0 | + |----------------------------------------------------------------------------------------------------------------------------------| + | Marzogh | + | 16.11.2016 | + |----------------------------------------------------------------------------------------------------------------------------------| + | (Please make sure your Serial monitor is set to 'No Line Ending') | + | ***************************************************************** | + | | + | # Please pick from the following commands and type the command number into the Serial console # | + | For example - to write a byte of data, you would have to use the write_byte function - so type '3' into the serial console. | + | -------------------------------- | + | | + | 1. getID | + | '1' gets the JEDEC ID of the chip | + | | + | 2. writeByte [page] [offset] [byte] | + | '2' followed by '100' and then by '20' and then by '224' writes the byte 224 to page 100 position 20 | + | | + | 3. readByte [page] [offset] | + | '3' followed by '100' and then by '20' returns the byte from page 100 position 20 | + | | + | 4. writeWord [page] [offset] | + | '4' followed by '55' and then by '35' and then by '633' writes the int 633 to page 5 position 35 | + | | + | 5. readWord [page] [offset] | + | '5' followed by '200' and then by '30' returns the int from page 200 position 30 | + | | + | 6. writeStr [page] [offset] [inputString] | + | '6' followed by '345' and then by '65' and then by 'Test String 1!' writes the String 'Test String 1! to page 345 position 65 | + | | + | 7. readStr [page] [offset] [outputString] | + | '7' followed by '2050' and then by '73' reds the String from page 2050 position 73 into the outputString | + | | + | 8. writePage [page] | + | '8' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33 | + | | + | 9. printPage [page] | + | '9' followed by 33 reads & prints page 33. To just read a page to a data buffer, refer | + | to 'ReadMe.md' in the library folder. | + | | + | 10. printAllPages | + | '10' reads all 4096 pages and outputs them to the serial console | + | This function is to extract data from a flash chip onto a computer as a text file. | + | Refer to 'Read me.md' in the library for details. | + | | + | 11. Erase 4KB sector | + | '11' followed by 2 erases a 4KB sector containing the page to be erased | + | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | + | | + | 12. Erase 32KB block | + | '12' followed by 2 erases a 32KB block containing the page to be erased | + | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | + | | + | 13. Erase 64KB block | + | '13' followed by 2 erases a 64KB block containing the page to be erased | + | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | + | | + | 14. Erase Chip | + | '14' erases the entire chip | + | | + ^----------------------------------------------------------------------------------------------------------------------------------^ +*/ + + + +#include +uint8_t pageBuffer[256]; +String serialCommand; +char printBuffer[128]; +uint16_t page; +uint8_t offset, dataByte; +uint16_t dataInt; +String inputString, outputString; + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#else +#define BAUD_RATE 115200 +#endif + +SPIFlash flash; + +void setup() { + delay(10); + Serial.begin(BAUD_RATE); + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + flash.begin(); + Serial.println(); + Serial.println(); + commandList(); +} + +void loop() { + while (Serial.available() > 0) { + uint8_t commandNo = Serial.parseInt(); + if (commandNo == 0) { + commandList(); + } + else if (commandNo == 1) { + printLine(); + Serial.println(F(" Function 1 : Get JEDEC ID ")); + printLine(); + printLine(); + uint8_t b1, b2, b3; + uint32_t JEDEC = flash.getJEDECID(); + //uint16_t ManID = flash.getManID(); + b1 = (JEDEC >> 16); + b2 = (JEDEC >> 8); + b3 = (JEDEC >> 0); + clearprintBuffer(); + sprintf(printBuffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3); + Serial.println(printBuffer); + clearprintBuffer(); + sprintf(printBuffer, "JEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); + printLine(); + printNextCMD(); + } + else if (commandNo == 2) { + printLine(); + Serial.println(F(" Function 2 : Write Byte ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page you wish to modify: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to modify: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.print(F("Please enter the value of the byte (0-255) you wish to save: ")); + while (!Serial.available()) { + } + dataByte = Serial.parseInt(); + Serial.println(dataByte); + if (flash.writeByte(page, offset, dataByte)) { + clearprintBuffer(); + sprintf(printBuffer, "%d has been written to position %d on page %d", dataByte, offset, page); + Serial.println(printBuffer); + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 3) { + printLine(); + Serial.println(F(" Function 3 : Read Byte ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page the byte you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the byte on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The byte at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + Serial.println(flash.readByte(page, offset)); + printLine(); + printNextCMD(); + } + else if (commandNo == 4) { + printLine(); + Serial.println(F(" Function 4 : Write Word ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page you wish to modify: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to modify: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.print(F("Please enter the value of the word (>255) you wish to save: ")); + while (!Serial.available()) { + } + dataInt = Serial.parseInt(); + Serial.println(dataInt); + if (flash.writeWord(page, offset, dataInt)) { + clearprintBuffer(); + sprintf(printBuffer, "%d has been written to position %d on page %d", dataInt, offset, page); + Serial.println(printBuffer); + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 5) { + printLine(); + Serial.println(F(" Function 5 : Read Word ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page the byte you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the word on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The unsigned int at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + Serial.println(flash.readWord(page, offset)); + printLine(); + printNextCMD(); + } + else if (commandNo == 6) { + printLine(); + Serial.println(F(" Function 6 : Write String ")); + printSplash(); + printLine(); + Serial.println(F("This function will write a String of your choice to the page selected.")); + Serial.print(F("Please enter the number of the page you wish to write to: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to write to: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.println(F("Please enter the String you wish to save: ")); + while (!Serial.available()) { + } + readSerialStr(inputString); + if (flash.writeStr(page, offset, inputString)) { + clearprintBuffer(); + Serial.print(F("String '")); + Serial.print(inputString); + sprintf(printBuffer, "' has been written to position %d on page %d", offset, page); + Serial.println(printBuffer); + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 7) { + printLine(); + Serial.println(F(" Function 7 : Read String ")); + printSplash(); + printLine(); + Serial.print(F("Please enter the number of the page the String you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the String on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The String at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + flash.readStr(page, offset, outputString); + Serial.println(outputString); + printLine(); + printNextCMD(); + } + else if (commandNo == 8) { + printLine(); + Serial.println(F(" Function 8 : Write Page ")); + printSplash(); + printLine(); + Serial.println(F("This function will write a sequence of bytes (0-255) to the page selected.")); + Serial.print(F("Please enter the number of the page you wish to write to: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + for (uint16_t i = 0; i < PAGESIZE; ++i) { + pageBuffer[i] = i; + } + if (flash.writeByteArray(page, 0, &pageBuffer[0], PAGESIZE)) { + clearprintBuffer(); + sprintf(printBuffer, "Values from 0 to 255 have been written to the page %d", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + } + else { + writeFail(); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 9) { + printLine(); + Serial.println(F(" Function 9 : Read Page ")); + printSplash(); + printLine(); + Serial.println(F("This function will read the entire page selected.")); + Serial.print(F("Please enter the number of the page you wish to read: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + printLine(); + printNextCMD(); + } + else if (commandNo == 10) { + printLine(); + Serial.println(F(" Function 10 : Read All Pages ")); + printSplash(); + printLine(); + Serial.println(F("This function will read the entire flash memory.")); + Serial.println(F("This will take a long time and might result in memory issues. Do you wish to continue? (Y/N)")); + char c; + while (!Serial.available()) { + } + c = (char)Serial.read(); + if (c == 'Y' || c == 'y') { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printAllPages(outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 11) { + printLine(); + Serial.println(F(" Function 11 : Erase 4KB sector ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase a 4KB sector.")); + Serial.print(F("Please enter the number of the page you wish to erase: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + flash.eraseSector(page, 0); + clearprintBuffer(); + sprintf(printBuffer, "A 4KB sector containing page %d has been erased", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 12) { + printLine(); + Serial.println(F(" Function 12 : Erase 32KB Block ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase a 32KB block.")); + Serial.print(F("Please enter the number of the page you wish to erase: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + flash.eraseBlock32K(page, 0); + clearprintBuffer(); + sprintf(printBuffer, "A 32KB block containing page %d has been erased", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 13) { + printLine(); + Serial.println(F(" Function 13 : Erase 64KB Block ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase a 64KB block.")); + Serial.print(F("Please enter the number of the page you wish to erase: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + flash.eraseBlock64K(page, 0); + clearprintBuffer(); + sprintf(printBuffer, "A 64KB block containing page %d has been erased", page); + Serial.println(printBuffer); + printReadChoice(); + while (!Serial.available()) { + } + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(page, outputType); + } + printLine(); + printNextCMD(); + } + else if (commandNo == 14) { + printLine(); + Serial.println(F(" Function 14 : Erase Chip ")); + printSplash(); + printLine(); + Serial.println(F("This function will erase the entire flash memory.")); + Serial.println(F("Do you wish to continue? (Y/N)")); + char c; + while (!Serial.available()) { + } + c = (char)Serial.read(); + if (c == 'Y' || c == 'y') { + if (flash.eraseChip()) + Serial.println(F("Chip erased")); + else + Serial.println(F("Error erasing chip")); + } + printLine(); + printNextCMD(); + } + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +void clearprintBuffer() +{ + for (uint8_t i = 0; i < 128; i++) { + printBuffer[i] = 0; + } +} + +//Reads a string from Serial +bool readSerialStr(String &inputStr) { + if (!Serial) + Serial.begin(115200); + while (Serial.available()) { + inputStr = Serial.readStringUntil('\n'); + return true; + } + return false; +} + +//Prints hex/dec formatted data from page reads - for debugging +void _printPageBytes(uint8_t *data_buffer, uint8_t outputType) { + char buffer[10]; + for (int a = 0; a < 16; ++a) { + for (int b = 0; b < 16; ++b) { + if (outputType == 1) { + sprintf(buffer, "%02x", data_buffer[a * 16 + b]); + Serial.print(buffer); + } + else if (outputType == 2) { + uint8_t x = data_buffer[a * 16 + b]; + if (x < 10) Serial.print("0"); + if (x < 100) Serial.print("0"); + Serial.print(x); + Serial.print(','); + } + } + Serial.println(); + } +} + +//Reads a page of data and prints it to Serial stream. Make sure the sizeOf(uint8_t data_buffer[]) == 256. +void printPage(uint16_t page_number, uint8_t outputType) { + if (!Serial) + Serial.begin(115200); + + char buffer[24]; + sprintf(buffer, "Reading page (%04x)", page_number); + Serial.println(buffer); + + uint8_t data_buffer[PAGESIZE]; + flash.readByteArray(page_number, 0, &data_buffer[0], PAGESIZE); + _printPageBytes(data_buffer, outputType); +} + +//Reads all pages on Flash chip and dumps it to Serial stream. +//This function is useful when extracting data from a flash chip onto a computer as a text file. +void printAllPages(uint8_t outputType) { + if (!Serial) + Serial.begin(115200); + + Serial.println("Reading all pages"); + uint8_t data_buffer[256]; + + uint32_t maxPage = flash.getMaxPage(); + for (int a = 0; a < maxPage; a++) { + flash.readByteArray(a, 0, &data_buffer[0], 256); + _printPageBytes(data_buffer, outputType); + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Print commands~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +void printLine() +{ + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); +} + +void printSplash() +{ + Serial.println(F(" SPIFlash library test ")); +} + +void printNextCMD() +{ + Serial.println(F("Please type the next command. Type 0 to get the list of commands")); +} + +void printOutputChoice() +{ + Serial.print("Would you like your output in decimal or hexadecimal? Please indicate with '1' for HEX or '2' for DEC: "); +} + +void printReadChoice() +{ + Serial.print("Type 1 to read the page you have just modified. Type 0 to continue: "); +} + +void writeSuccess() +{ + Serial.println("Data write successful"); +} + +void writeFail() +{ + Serial.println("Data write failed"); +} diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/TestFlash/command_list.ino b/arduino_libraries/SPIMemory-2.6.0/examples/TestFlash/command_list.ino new file mode 100644 index 0000000..7ac5e30 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/TestFlash/command_list.ino @@ -0,0 +1,63 @@ +void commandList() { + Serial.println(F("-----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Winbond Flash ")); + Serial.println(F(" SPIFlash library test v2.5.0 ")); + Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Marzogh ")); + Serial.println(F(" 24.11.2015 ")); + Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" (Please make sure your Serial monitor is set to 'No Line Ending') ")); + Serial.println(F(" ***************************************************************** ")); + Serial.println(F(" ")); + Serial.println(F(" # Please pick from the following commands and type the command number into the Serial console # ")); + Serial.println(F(" For example - to write a byte of data, you would have to use the Write Byte function - so type '3' into the serial console. ")); + Serial.println(F(" -------------------------------- ")); + Serial.println(); + Serial.println(F(" 1. getID")); + Serial.print(F("\t\t")); + Serial.println(F("'1' gets the JEDEC ID of the chip")); + Serial.println(F(" 2. writeByte [page] [offset] [byte]")); + Serial.print(F("\t\t")); + Serial.println(F("'2' followed by '100' and then by '20' and then by '224' writes the byte 224 to page 100 position 20")); + Serial.println(F(" 3. readByte [page] [offset]")); + Serial.print(F("\t\t")); + Serial.println(F("'3' followed by '100' and then by '20' returns the byte from page 100 position 20")); + Serial.println(F(" 4. writeWord [page] [offset]")); + Serial.print(F("\t\t")); + Serial.println(F("'4' followed by '55' and then by '35' and then by '633' writes the int 633 to page 5 position 35")); + Serial.println(F(" 5. readWord [page] [offset]")); + Serial.print(F("\t\t")); + Serial.println(F("'5' followed by '200' and then by '30' returns the int from page 200 position 30")); + Serial.println(F(" 6. writeStr [page] [offset] [inputString]")); + Serial.print(F("\t\t")); + Serial.println(F("'6' followed by '345' and then by '65' and then by 'Test String 1!' writes the String 'Test String 1! to page 345 position 65")); + Serial.println(F(" 7. readStr [page] [offset] [outputString]")); + Serial.print(F("\t\t")); + Serial.println(F("'7' followed by '2050' and then by '73' reads the String from page 2050 position 73 into the outputString")); + Serial.println(F(" 8. writePage [page]")); + Serial.print(F("\t\t")); + Serial.println(F("'8' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33")); + Serial.println(F(" 9. readPage [page]")); + Serial.print(F("\t\t")); + Serial.println(F("'9' followed by 33 reads page 33")); + Serial.println(F(" 10. readAllPages")); + Serial.print(F("\t\t")); + Serial.println(F("'10' reads all 4096 pages and outputs them to the serial console")); + Serial.print(F("\t\t")); + Serial.println(F("This function is to extract data from a flash chip onto a computer as a text file")); + Serial.print(F("\t\t")); + Serial.println(F("Refer to 'Read me.md' in the library for details")); + Serial.println(F(" 11. eraseSector")); + Serial.print(F("\t\t")); + Serial.println(F("'11' followed by '3' erases a 4KB sector (Sector 0) containing the page 3")); + Serial.println(F(" 12. eraseBlock32K")); + Serial.print(F("\t\t")); + Serial.println(F("'12' followed by '132' erases a 32KB sector (Sector 1) containing the page 132")); + Serial.println(F(" 13. eraseBlock64K")); + Serial.print(F("\t\t")); + Serial.println(F("'13' followed by '543' erases a 64KB sector (Sector 2) containing the page 543")); + Serial.println(F(" 14. eraseChip")); + Serial.print(F("\t\t")); + Serial.println(F("'14' erases the entire chip")); + Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); +} diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/getAddressEx/getAddressEx.ino b/arduino_libraries/SPIMemory-2.6.0/examples/getAddressEx/getAddressEx.ino new file mode 100644 index 0000000..d391801 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/getAddressEx/getAddressEx.ino @@ -0,0 +1,122 @@ +/* +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +| getAddressEx.ino | +| SPIFlash library | +| v 2.5.0 | +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +| Marzogh | +| 16.11.2016 | +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +| | +| This program shows the method to use the getAddress() function to automate | +| the process of address allocation when using a flash memory module. Please note | +| the special function used to get the size of the String object. | +| | +|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ +#include + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#else +#define BAUD_RATE 115200 +#endif + +#define arrayLen(x) sizeof(x)/sizeof(x[0]) +uint32_t strAddr[3], floatAddr[2], byteAddr[4]; +String testStr[] = { + "Test String 0", + "Test String 1", + "Test String 2" +}; +float testFloat[] = { + 3.1415, 6.283 +}; +byte testByte[] = { + 3, 245, 84, 100 +}; + +SPIFlash flash; + +void getAddresses(); +void writeData(); + +void setup() { + Serial.begin(BAUD_RATE); + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + flash.begin(); + Serial.println(); + Serial.println(); + + getAddresses(); + writeData(); + flash.eraseChip(); +} + +void loop() { + +} + +// Function to get adresses for various variables +void getAddresses() { + for (uint8_t i = 0; i < arrayLen(byteAddr); i++) { + byteAddr[i] = flash.getAddress(sizeof(byte)); + Serial.print("Byte Address "); + Serial.print(i); + Serial.print(" : "); + Serial.println(byteAddr[i]); + } + + for (uint8_t i = 0; i < arrayLen(floatAddr); i++) { + floatAddr[i] = flash.getAddress(sizeof(float)); + Serial.print("Float Address "); + Serial.print(i); + Serial.print(" : "); + Serial.println(floatAddr[i]); + } + + for (uint8_t i = 0; i < arrayLen(strAddr); i++) { + strAddr[i] = flash.getAddress(flash.sizeofStr(testStr[i])); + Serial.print("String Address "); + Serial.print(i); + Serial.print(" : "); + Serial.println(strAddr[i]); + } +} + +// Function to write data +void writeData() { + for (uint8_t i = 0; i < arrayLen(byteAddr); i++) { + if (flash.writeByte(byteAddr[i], testByte[i])) { + Serial.print(testByte[i]); + Serial.print(" written to "); + Serial.println(byteAddr[i]); + } + } + + for (uint8_t i = 0; i < arrayLen(floatAddr); i++) { + if (flash.writeFloat(floatAddr[i], testFloat[i])) { + Serial.print(testFloat[i]); + Serial.print(" written to "); + Serial.println(floatAddr[i]); + } + } + + for (uint8_t i = 0; i < arrayLen(strAddr); i++) { + if (flash.writeStr(strAddr[i], testStr[i])) { + Serial.print(testStr[i]); + Serial.print(" written to "); + Serial.println(strAddr[i]); + } + } +} diff --git a/arduino_libraries/SPIMemory-2.6.0/examples/readWriteString/readWriteString.ino b/arduino_libraries/SPIMemory-2.6.0/examples/readWriteString/readWriteString.ino new file mode 100644 index 0000000..0d16942 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/examples/readWriteString/readWriteString.ino @@ -0,0 +1,94 @@ +/* + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | readWriteString.ino | + | SPIFlash library | + | v 2.5.0 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | Marzogh | + | 16.11.2016 | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + | | + | This program shows the method of reading a string from the console and saving it to flash memory | + | | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| +*/ +#include + +int strPage, strSize; +byte strOffset; + +#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) +// Required for Serial on Zero based boards +#define Serial SERIAL_PORT_USBVIRTUAL +#endif + +#if defined (SIMBLEE) +#define BAUD_RATE 250000 +#define RANDPIN 1 +#else +#define BAUD_RATE 115200 +#define RANDPIN A0 +#endif + +SPIFlash flash; + +bool readSerialStr(String &inputStr); + +void setup() { +#ifndef __AVR_ATtiny85__ + Serial.begin(BAUD_RATE); +#endif +#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__) + while (!Serial) ; // Wait for Serial monitor to open +#endif + + flash.begin(); + +#if defined (ARDUINO_ARCH_ESP32) || defined __AVR_ATtiny85__ + randomSeed(65535537); +#else + randomSeed(analogRead(RANDPIN)); +#endif + strPage = random(0, 4095); + strOffset = random(0, 255); + String inputString = "This is a test String"; + flash.writeStr(strPage, strOffset, inputString); +#ifndef __AVR_ATtiny85__ + Serial.print(F("Written string: ")); + Serial.print(inputString); + Serial.print(F(" to page ")); + Serial.print(strPage); + Serial.print(F(", at offset ")); + Serial.println(strOffset); +#endif + String outputString = ""; + if (flash.readStr(strPage, strOffset, outputString)) { +#ifndef __AVR_ATtiny85__ + Serial.print(F("Read string: ")); + Serial.print(outputString); + Serial.print(F(" from page ")); + Serial.print(strPage); + Serial.print(F(", at offset ")); + Serial.println(strOffset); +#endif + } + while (!flash.eraseSector(strPage, 0)); +} + +void loop() { + +} + +#ifndef __AVR_ATtiny85__ +//Reads a string from Serial +bool readSerialStr(String &inputStr) { + if (!Serial) + Serial.begin(115200); + while (Serial.available()) { + inputStr = Serial.readStringUntil('\n'); + Serial.println(inputStr); + return true; + } + return false; +} +#endif diff --git a/arduino_libraries/SPIMemory-2.6.0/extras/Changes.log b/arduino_libraries/SPIMemory-2.6.0/extras/Changes.log new file mode 100644 index 0000000..dcba22b --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/extras/Changes.log @@ -0,0 +1,189 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// SPIFlash Library // +// Changes log // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.6.0 // +// Author: Prajwal Bhattaram // +// 16.04.2017 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs Squashed: +--> Fixed issue with reading status register 2 and the Suspend operation where the library was not checking the suspend status correctly. + +Deletions: +--> flash.getChipName() has been removed as it is superfluous now that the library is now on its way to multi-chip compatibility. +--> Library is not compatible with the ATTiny85 anymore. Currently working on a fix which will hopefully be rolled out in v2.7.0 + +New Boards supported: +--> RTL8195A compatibility tested and enabled by @boseji on 02.03.17. Code modified to fit with the library structure by Prajwal Bhattaram on 14.04.17. +--> Compatible with the ESP32 core for Arduino as of the current commit 7d0968c on 16.04.2017. The ESP32 core currently does not support analogRead and so randomSeed(AnalogRead(A0)) cannot be used. Also, for some unknown reason, SPI clock speeds higher than board speed/4 are not stable and so, the clock speed for ESP32 dev boards has currently been throttled to 20MHz. +--> Added support for the Simblee module. + +Enhancements: +--> flash.error() now takes an optional argument 'VERBOSE'. By default the verbosity argument is set to 'false' and calling flash.error() still returns the latest error code as an unsigned byte. However, running flash.error(VERBOSE) will not only return the latest error code, but will also print it to serial. This - especially in boards with resources to spare - will result in a detailed error report printed to serial. +--> flash.begin() now returns a boolean value to indicate establishment of successful comms with the flash chip. Usercode can be made more efficient now by calling ```if (!flash.begin()) { Serial.println(flash.error(VERBOSE)); }``` to identify a problem as soon as the library code is run. +--> The internal _addressCheck() function now locks up usercode with appropriate error codes if + a) flash.begin() has not been called (or) + b) There is a possible issue with the wiring - i.e. the flash chip is non-responsive (or) + c) If the chip's capacity either cannot be identified & the user has not defined a chipSize in flash.begin(). +--> Fixed powerDown() to be more efficient. The chip now powers down much faster than before. +--> Added a new error code. Library can now detect non-responsive chips - bad wiring or otherwise. +--> Streamlined variables to make code structure better. +--> Changed library structure to enable the addition of multi-flash compatibility in the near future. +--> moved `#define RUNDIAGNOSTIC` & `#define HIGHSPEED` to SPIFlash.h from SPIFlash.cpp. +--> Now works with other Winbond modules (not in the official supported module list) (beta) by taking the flash memory size in bits as an argument in flash.begin(_chipSize); +--> Formatted code to be better human readable. +--> Changed the internal _troubleshoot() function to use fewer resources. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.5.0 // +// Author: Prajwal Bhattaram // +// 13.11.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs Squashed: +--> Errorchecking on writeByteArray() and writeCharArray() was broken in 2.4.0 and is fixed now. +--> Previous versions (< 2.5.0) suffered from the inability to write datasets that spanned page boundaries. This has now been fixed (Ref. Enhancements section below) + +Deletions: +--> flash.writePage() & flash.readPage() have been retired as they can be duplicated - more effectively - by other functions. Refer to pageDiag() in Diagnostics.ino to see how the same results can be obtained by using flash.writeByteArray() & flash.readByteArray(). + +Enhancements: +--> Added support for SPI Transactions. +--> Added an upgrade for Arduino Due users to read and write large arrays of data at very high speeds - previously reading 60kb of data would take ~108ms - it now takes ~525uS. In this mode, the time between consecutive reads has been reduced to <12ms (needs more work!). +--> Completely re-written writeByteArray() and writeCharArray() functions. They no longer breakdown when writing arrays that span multiple pages. +--> All functions that write more than 1 byte of data now take into account page boundaries when writing across pages. In previous versions writing across a page boundary would cause the remainder of the data to wrap around to the beginning of the page. Now the data is written seamlessly from one page over to the next. +--> Calling flash.begin() now instantiates the SPI bus. Comms with other SPI slaves do not need to call SPI.begin() if flash.begin() has already been called first in the user's code. +--> Sped up _beginSPI(). Code in _beginSPI() instantiates the SPI bus if another SPI comms library has shut it down. +--> Added function allowing setting SPI clock speeds - call the function ```flash.setClock(uint32_t clockSpeed);``` straight after ```begin();```. +--> Made _beginSPI() & _nextByte() shorter and faster. +--> Replaced all calls to SPI.transfer() with xfer() to make the code more human readable and to enable simplicity when switching platforms. +--> Added the ability to change Chip Erase wait times depending on the chip (supported chips only). +--> Don't need to ```#include ``` in user code anymore. Just ```#include``` will do. Examples are now updated. +--> Now supports & uses SPI.transfer(*buf, count) along with the standard SPI.transfer(), speeding up the read/write of anything larger than an byte (AVR Boards only) +--> Reduces the program storage space in the uC's flash (AVR Boards) + +To-do +--> Need to find a way to better identify _notPrevWritten(); +--> Need to fix up eraseBlock32K, eraseBlock64K and eraseSector times +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.4.0 // +// Author: Prajwal Bhattaram // +// 11.09.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs Squashed: +--> Fixed bug preventing writing to Address 0x00 +--> Fixed bug in _notPrevWritten() which did did not perform a thorough enough check to see if a location had been previously written to. +--> Fixed errorchecking bug - it now works for all data types - not just byte/char as previously. +Enhancements & Optimizations: +--> Added a function 'error()' to enable users to check for errors generated at any point in their program. +--> Optimized writePage() so it doesn't depend on other functions and so runs faster than before. +--> Diagnostics.ino now outputs time taken for each function as a part of its and provides additional diagnostic data. +--> Now have a common set of private functions - _prep(), _beginSPI(), _nextByte() & _endSPI() - to replace _prepWrite(), _prepRead(), _beginRead(), _readNextByte(), _beginWrite(), _writeNextByte() & _endProcess(); +--> Changed the way _addressCheck() works. It now checks all addresses involved in writing the data rather than one address block at a time and returns the correct address to write to in case overflow is enabled. Also, this function is now built into _prep(). +--> Reading and writing using page numbers + offset has been optimised to be faster than before. +--> Optimized the way address and error checking is done so its more efficient and uses few system resources and runs faster. +--> Using this library with an ESP8266 board defaults to using GPIO15 as the Slave Select - unless something different is explicitly specified in the constructor. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.3.1 // +// Author: Prajwal Bhattaram // +// 19.06.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> W25Q256FV support added. (Thanks Stanislav-Povolotsky!) +--> Cleaned up redundant code in TestFlash.ino and SPIFlash.h +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.3.0 // +// Author: Prajwal Bhattaram // +// 04.06.2016 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> ESP8266 compatibility added +--> Compatible with Arduino Fio and Micro +--> Now compatible with Arduino IDE v1.6.9 +--> Compatible with Arduino-Makefile. (Thanks Raphael!) +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.2.0 // +// Author: Prajwal Bhattaram // +// 24.11.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> When #RUNDIAGNOSTIC is uncommented, the _troubleshoot() function is now optimised for different µCs +--> Added the ability to check if the address has been previously written to before initiating a write + operation. +--> Added a sizeofStr() function to get sizes of String objects, to use with the getAddress() function +--> Fixed a bug with getAddress() +--> Added the ability get the chip's name via getChipName() +--> Diagnostics.ino has been made more and efficient and provides a cleaner Serial output +--> Added getAddressEx.ino to show how getAdress() works. + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.1.1 // +// Author: Prajwal Bhattaram // +// 24.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Fixed bugs that prevented the following functions from working properly + A. powerDown() + B. powerUp() + C. suspendProg() + D. resumeProg() + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.1.0 // +// Author: Prajwal Bhattaram // +// 18.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Arduino Due compatible - refer to wiki for further details +--> Fixed bug with write/readByteArray +--> Added write/readCharArray +--> Added a proper error checking function that gets called when #ifdef RUNDIAGNOSTIC is uncommented in SPIFlash.cpp. + This function returns a verbose error message to the Serial console instead of the terse error codes of the previous version. +--> The following functions have been changed to enable bug fixes and uniformity in coding style. + A. writeBytes() + B. readBytes() + They have been replaced with readByteArray() and writeByteArray(). + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 2.0.0 // +// Author: Prajwal Bhattaram // +// 12.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Sped up all functions atleast 25x +--> Compatible with ATTiny85 +--> All Read/Write/Erase functions can now take either (page number & offset) or (address) as arguments + (Except readPage() & printPage()) +--> getAddress() can now return either a 32-bit address or a page number & offset - Refer to Readme.md +--> Error codes explained: + 0x00 SUCCESS Operation successful. + 0x01 CALLBEGIN Please make sure .begin() has been called in setup(). + 0x02 UNKNOWNCHIP Unknown chip manufacturer. + 0x03 UNKNOWNCAP Unknown chip capacity. + 0x04 CHIPBUSY Chip busy. + 0x05 OUTOFBOUNDS Address out of bounds. Please check if .begin() has been called in setup(). + 0x06 CANTENWRITE Unable to _writeEnable. Check wiring/chip. + 0x07 OUTOFMEM Pagenumber outside maximum. + 0x08 OUTOFPAGE Offset is outside page. +--> The following functions are deprecated to enable compatibility with other AVR chips. + + A. _printPageBytes() + B. printPage() + C. printAllPages() + D. readSerialStr() + + They can be used by uncommenting them in the SPIFlash.cpp file. However, be warned, this particular block of code has only + been tested with the Arduino IDE (1.6.5) and only with 8-bit AVR based Arduino boards and will not be supported any further. + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 1.3.2 // +// Author: Prajwal Bhattaram // +// 09.10.2015 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +--> Added the ability to read and write String objects with a simple high level function readStr() & writeStr() +--> Added the ability to getAddress() +--> Added the ability to fastRead to every read function as the last boolean argument (defaults to FALSE) +--> Changed the example code as given below: + --> Modified TestFlash.ino to use 25% less memory + --> Struct_writer.ino now writes struct to a random location on the Flash Memory chip. + --> Added instructions for real world data storage to Struct_writer.ino + --> Diagnostics.ino now provides a cleaner diagnostic readout diff --git a/arduino_libraries/SPIMemory-2.6.0/extras/Library speed comparisons.xlsx b/arduino_libraries/SPIMemory-2.6.0/extras/Library speed comparisons.xlsx new file mode 100644 index 0000000..ee60855 Binary files /dev/null and b/arduino_libraries/SPIMemory-2.6.0/extras/Library speed comparisons.xlsx differ diff --git a/arduino_libraries/SPIMemory-2.6.0/extras/SPI pinouts.md b/arduino_libraries/SPIMemory-2.6.0/extras/SPI pinouts.md new file mode 100644 index 0000000..0b185f4 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/extras/SPI pinouts.md @@ -0,0 +1,24 @@ +/* +* ESP8266 (Adafruit HUZZAH) SPI pinout is as follows: +* _______________________________________ +* |Pin Name | GPIO # | HSPI Function | +* |---------|------------|----------------| +* | MTDI | GPIO12 | MISO (DIN) | +* | MTCK | GPIO13 | MOSI (DOUT) | +* | MTMS | GPIO14 | CLOCK | +* | MTDO | GPIO15 | CS / SS | +* |_________|____________|________________| +* +* +* ESP32 Thing SPI pinout is as follows: +* _____________________________ +* | GPIO # | HSPI Function | +* |------------|----------------| +* | GPIO19 | MISO (DIN) | +* | GPIO23 | MOSI (DOUT) | +* | GPIO18 | CLOCK | +* | GPIO2 | CS / SS | +* |____________|________________| +* +* +*/ diff --git a/arduino_libraries/SPIMemory-2.6.0/extras/Winbond Flash Instructions - Comparison.xlsx b/arduino_libraries/SPIMemory-2.6.0/extras/Winbond Flash Instructions - Comparison.xlsx new file mode 100644 index 0000000..b8a4b33 Binary files /dev/null and b/arduino_libraries/SPIMemory-2.6.0/extras/Winbond Flash Instructions - Comparison.xlsx differ diff --git a/arduino_libraries/SPIMemory-2.6.0/keywords.txt b/arduino_libraries/SPIMemory-2.6.0/keywords.txt new file mode 100644 index 0000000..74841cb --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/keywords.txt @@ -0,0 +1,58 @@ +####################################### +# Syntax Coloring Map SPI +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SPIFlash KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +setClock KEYWORD2 +error KEYWORD2 +libver KEYWORD2 +getJEDECID KEYWORD2 +getManID KEYWORD2 +getAddress KEYWORD2 +getCapacity KEYWORD2 +getMaxPage KEYWORD2 +sizeofStr KEYWORD2 +readByte KEYWORD2 +readByteArray KEYWORD2 +readChar KEYWORD2 +readCharArray KEYWORD2 +readWord KEYWORD2 +readShort KEYWORD2 +readLong KEYWORD2 +readULong KEYWORD2 +readFloat KEYWORD2 +readStr KEYWORD2 +readAnything KEYWORD2 +writeByte KEYWORD2 +writeByteArray KEYWORD2 +writeChar KEYWORD2 +writeCharArray KEYWORD2 +writeWord KEYWORD2 +writeShort KEYWORD2 +writeLong KEYWORD2 +writeULong KEYWORD2 +writeFloat KEYWORD2 +writeStr KEYWORD2 +writeAnything KEYWORD2 +eraseSector KEYWORD2 +eraseBlock32K KEYWORD2 +eraseBlock64K KEYWORD2 +eraseChip KEYWORD2 +suspendProg KEYWORD2 +resumeProg KEYWORD2 +powerUp KEYWORD2 +powerDown KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/arduino_libraries/SPIMemory-2.6.0/library.properties b/arduino_libraries/SPIMemory-2.6.0/library.properties new file mode 100644 index 0000000..8a2dcb3 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/library.properties @@ -0,0 +1,10 @@ +name=SPIFlash +version=2.6.0 +author=Prajwal Bhattaram +maintainer=Prajwal Bhattaram +sentence=Winbond SPI flash library for Arduino. +paragraph=This library enables read, write, erase and power functions on the following Winbond NOR Flash chips - W25X05CL, W25X10BV, W25X20BV, W25X40BV, W25Q80BV, W25Q16BV, W25Q32BV, W25Q64BV & W25Q128BV. All other Winbond flash chips can also be used with this library from v2.6.0 onwards. Refer to change log for further information about this release. +category=Data Storage +url=https://github.com/Marzogh/SPIFlash +architectures=avr,sam,samd,esp8266,esp32,simblee,rtl8195a +includes=SPIFlash.h diff --git a/arduino_libraries/SPIMemory-2.6.0/src/DMASPI.cpp b/arduino_libraries/SPIMemory-2.6.0/src/DMASPI.cpp new file mode 100644 index 0000000..a92b824 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/src/DMASPI.cpp @@ -0,0 +1,300 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 30/09/2016 + * Modified by Prajwal Bhattaram - 14/04/2017 + * Original code from @manitou48 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ +#if defined (ARDUINO_ARCH_SAM) +#include "SPIFlash.h" + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Private functions used by Arduino Due DMA operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Disable DMA Controller +void SPIFlash::_dmac_disable() { + DMAC->DMAC_EN &= (~DMAC_EN_ENABLE); +} +// Enable DMA Controller. +void SPIFlash::_dmac_enable() { + DMAC->DMAC_EN = DMAC_EN_ENABLE; +} +// Disable DMA Channel +void SPIFlash::_dmac_channel_disable(uint32_t ul_num) { + DMAC->DMAC_CHDR = DMAC_CHDR_DIS0 << ul_num; +} +// Enable DMA Channel +void SPIFlash::_dmac_channel_enable(uint32_t ul_num) { + DMAC->DMAC_CHER = DMAC_CHER_ENA0 << ul_num; +} +// Poll for transfer complete +bool SPIFlash::_dmac_channel_transfer_done(uint32_t ul_num) { + return (DMAC->DMAC_CHSR & (DMAC_CHSR_ENA0 << ul_num)) ? false : true; +} +// start RX DMA +void SPIFlash::_dueSPIDmaRX(uint8_t* dst, uint16_t count) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_SADDR = (uint32_t)&SPI0->SPI_RDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DADDR = (uint32_t)dst; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_PER2MEM_DMA_FC | + DMAC_CTRLB_SRC_INCR_FIXED | DMAC_CTRLB_DST_INCR_INCREMENTING; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CFG = DMAC_CFG_SRC_PER(SPI_RX_IDX) | + DMAC_CFG_SRC_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ASAP_CFG; + _dmac_channel_enable(SPI_DMAC_RX_CH); +} +void SPIFlash::_dueSPIDmaRX(char* dst, uint16_t count) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_SADDR = (uint32_t)&SPI0->SPI_RDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DADDR = (uint32_t)dst; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_PER2MEM_DMA_FC | + DMAC_CTRLB_SRC_INCR_FIXED | DMAC_CTRLB_DST_INCR_INCREMENTING; + DMAC->DMAC_CH_NUM[SPI_DMAC_RX_CH].DMAC_CFG = DMAC_CFG_SRC_PER(SPI_RX_IDX) | + DMAC_CFG_SRC_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ASAP_CFG; + _dmac_channel_enable(SPI_DMAC_RX_CH); +} +// start TX DMA +void SPIFlash::_dueSPIDmaTX(const uint8_t* src, uint16_t count) { + static uint8_t ff = 0XFF; + uint32_t src_incr = DMAC_CTRLB_SRC_INCR_INCREMENTING; + if (!src) { + src = &ff; + src_incr = DMAC_CTRLB_SRC_INCR_FIXED; + } + _dmac_channel_disable(SPI_DMAC_TX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_SADDR = (uint32_t)src; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DADDR = (uint32_t)&SPI0->SPI_TDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_MEM2PER_DMA_FC | + src_incr | DMAC_CTRLB_DST_INCR_FIXED; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CFG = DMAC_CFG_DST_PER(SPI_TX_IDX) | + DMAC_CFG_DST_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ALAP_CFG; + + _dmac_channel_enable(SPI_DMAC_TX_CH); +} + +void SPIFlash::_dueSPIDmaCharTX(const char* src, uint16_t count) { + static char ff = 0XFF; + uint32_t src_incr = DMAC_CTRLB_SRC_INCR_INCREMENTING; + if (!src) { + src = &ff; + src_incr = DMAC_CTRLB_SRC_INCR_FIXED; + } + _dmac_channel_disable(SPI_DMAC_TX_CH); + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_SADDR = (uint32_t)src; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DADDR = (uint32_t)&SPI0->SPI_TDR; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_DSCR = 0; + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLA = count | + DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_DST_WIDTH_BYTE; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CTRLB = DMAC_CTRLB_SRC_DSCR | + DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_FC_MEM2PER_DMA_FC | + src_incr | DMAC_CTRLB_DST_INCR_FIXED; + + DMAC->DMAC_CH_NUM[SPI_DMAC_TX_CH].DMAC_CFG = DMAC_CFG_DST_PER(SPI_TX_IDX) | + DMAC_CFG_DST_H2SEL | DMAC_CFG_SOD | DMAC_CFG_FIFOCFG_ALAP_CFG; + + _dmac_channel_enable(SPI_DMAC_TX_CH); +} + +void SPIFlash::_dueSPIBegin() { + PIO_Configure( + g_APinDescription[PIN_SPI_MOSI].pPort, + g_APinDescription[PIN_SPI_MOSI].ulPinType, + g_APinDescription[PIN_SPI_MOSI].ulPin, + g_APinDescription[PIN_SPI_MOSI].ulPinConfiguration); + PIO_Configure( + g_APinDescription[PIN_SPI_MISO].pPort, + g_APinDescription[PIN_SPI_MISO].ulPinType, + g_APinDescription[PIN_SPI_MISO].ulPin, + g_APinDescription[PIN_SPI_MISO].ulPinConfiguration); + PIO_Configure( + g_APinDescription[PIN_SPI_SCK].pPort, + g_APinDescription[PIN_SPI_SCK].ulPinType, + g_APinDescription[PIN_SPI_SCK].ulPin, + g_APinDescription[PIN_SPI_SCK].ulPinConfiguration); + pmc_enable_periph_clk(ID_SPI0); +#if USE_SAM3X_DMAC + pmc_enable_periph_clk(ID_DMAC); + _dmac_disable(); + DMAC->DMAC_GCFG = DMAC_GCFG_ARB_CFG_FIXED; + _dmac_enable(); +#if USE_SAM3X_BUS_MATRIX_FIX + MATRIX->MATRIX_WPMR = 0x4d415400; + MATRIX->MATRIX_MCFG[1] = 1; + MATRIX->MATRIX_MCFG[2] = 1; + MATRIX->MATRIX_SCFG[0] = 0x01000010; + MATRIX->MATRIX_SCFG[1] = 0x01000010; + MATRIX->MATRIX_SCFG[7] = 0x01000010; +#endif // USE_SAM3X_BUS_MATRIX_FIX +#endif // USE_SAM3X_DMAC +} +// initialize SPI controller +void SPIFlash::_dueSPIInit(uint8_t dueSckDivisor) { +#if ENABLE_SPI_TRANSACTIONS + SPI.beginTransaction(SPISettings()); +#endif // ENABLE_SPI_TRANSACTIONS + uint8_t scbr = dueSckDivisor; + Spi* pSpi = SPI0; + // disable SPI + pSpi->SPI_CR = SPI_CR_SPIDIS; + // reset SPI + pSpi->SPI_CR = SPI_CR_SWRST; + // no mode fault detection, set master mode + pSpi->SPI_MR = SPI_PCS(SPI_CHIP_SEL) | SPI_MR_MODFDIS | SPI_MR_MSTR; + // mode 0, 8-bit, + pSpi->SPI_CSR[SPI_CHIP_SEL] = SPI_CSR_SCBR(scbr) | SPI_CSR_NCPHA; + // enable SPI + pSpi->SPI_CR |= SPI_CR_SPIEN; +} +uint8_t SPIFlash::_dueSPITransfer(uint8_t b) { + Spi* pSpi = SPI0; + + pSpi->SPI_TDR = b; + while ((pSpi->SPI_SR & SPI_SR_RDRF) == 0) {} + b = pSpi->SPI_RDR; + return b; +} +// SPI receive a byte +uint8_t SPIFlash::_dueSPIRecByte() { + return _dueSPITransfer(0XFF); +} +// SPI receive multiple bytes +uint8_t SPIFlash::_dueSPIRecByte(uint8_t* buf, size_t len) { + Spi* pSpi = SPI0; + int rtn = 0; +#if USE_SAM3X_DMAC + // clear overrun error + uint32_t s = pSpi->SPI_SR; + + _dueSPIDmaRX(buf, len); + _dueSPIDmaTX(0, len); + + uint32_t m = millis(); + while (!_dmac_channel_transfer_done(SPI_DMAC_RX_CH)) { + if ((millis() - m) > SAM3X_DMA_TIMEOUT) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + _dmac_channel_disable(SPI_DMAC_TX_CH); + rtn = 2; + break; + } + } + if (pSpi->SPI_SR & SPI_SR_OVRES) rtn |= 1; +#else // USE_SAM3X_DMAC + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = 0XFF; + while ((pSpi->SPI_SR & SPI_SR_RDRF) == 0) {} + buf[i] = pSpi->SPI_RDR; + } +#endif // USE_SAM3X_DMAC + return rtn; +} +// SPI receive a char +int8_t SPIFlash::_dueSPIRecChar() { + return _dueSPITransfer(0XFF); +} +// SPI receive multiple chars +int8_t SPIFlash::_dueSPIRecChar(char* buf, size_t len) { + Spi* pSpi = SPI0; + char rtn = 0; +#if USE_SAM3X_DMAC + // clear overrun error + uint32_t s = pSpi->SPI_SR; + + _dueSPIDmaRX(buf, len); + _dueSPIDmaTX(0, len); + + uint32_t m = millis(); + while (!_dmac_channel_transfer_done(SPI_DMAC_RX_CH)) { + if ((millis() - m) > SAM3X_DMA_TIMEOUT) { + _dmac_channel_disable(SPI_DMAC_RX_CH); + _dmac_channel_disable(SPI_DMAC_TX_CH); + rtn = 2; + break; + } + } + if (pSpi->SPI_SR & SPI_SR_OVRES) rtn |= 1; +#else // USE_SAM3X_DMAC + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = 0XFF; + while ((pSpi->SPI_SR & SPI_SR_RDRF) == 0) {} + buf[i] = pSpi->SPI_RDR; + } +#endif // USE_SAM3X_DMAC + return rtn; +} +// SPI send a byte +void SPIFlash::_dueSPISendByte(uint8_t b) { + _dueSPITransfer(b); +} + +void SPIFlash::_dueSPISendByte(const uint8_t* buf, size_t len) { + Spi* pSpi = SPI0; +#if USE_SAM3X_DMAC + _dueSPIDmaTX(buf, len); + while (!_dmac_channel_transfer_done(SPI_DMAC_TX_CH)) {} +#else // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = buf[i]; + while ((pSpi->SPI_SR & SPI_SR_TDRE) == 0) {} + } +#endif // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + // leave RDR empty + uint8_t b = pSpi->SPI_RDR; +} +// SPI send a char +void SPIFlash::_dueSPISendChar(char b) { + _dueSPITransfer(b); +} +//SPI send multiple chars +void SPIFlash::_dueSPISendChar(const char* buf, size_t len) { + Spi* pSpi = SPI0; +#if USE_SAM3X_DMAC + _dueSPIDmaCharTX(buf, len); + while (!_dmac_channel_transfer_done(SPI_DMAC_TX_CH)) {} +#else // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + for (size_t i = 0; i < len; i++) { + pSpi->SPI_TDR = buf[i]; + while ((pSpi->SPI_SR & SPI_SR_TDRE) == 0) {} + } +#endif // #if USE_SAM3X_DMAC + while ((pSpi->SPI_SR & SPI_SR_TXEMPTY) == 0) {} + // leave RDR empty + char b = pSpi->SPI_RDR; +} + +#endif diff --git a/arduino_libraries/SPIMemory-2.6.0/src/SPIFlash.cpp b/arduino_libraries/SPIMemory-2.6.0/src/SPIFlash.cpp new file mode 100644 index 0000000..ac778d8 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/src/SPIFlash.cpp @@ -0,0 +1,1838 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 19/05/2015 + * Modified by @boseji - 02/03/2017 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + +#include "SPIFlash.h" + +// Constructor +#if defined (ARDUINO_ARCH_AVR) +SPIFlash::SPIFlash(uint8_t cs, bool overflow) { + csPin = cs; +#ifndef __AVR_ATtiny85__ + cs_port = portOutputRegister(digitalPinToPort(csPin)); +#endif + cs_mask = digitalPinToBitMask(csPin); + pageOverflow = overflow; + pinMode(csPin, OUTPUT); +} +// Adding Low level HAL API to initialize the Chip select pinMode on RTL8195A - @boseji 2nd March 2017 +#elif defined (BOARD_RTL8195A) +SPIFlash::SPIFlash(PinName cs, bool overflow) { + gpio_init(&csPin, cs); + gpio_dir(&csPin, PIN_OUTPUT); + gpio_mode(&csPin, PullNone); + gpio_write(&csPin, 1); + pageOverflow = overflow; +} +#else +SPIFlash::SPIFlash(uint8_t cs, bool overflow) { + csPin = cs; + pageOverflow = overflow; + pinMode(csPin, OUTPUT); +} +#endif +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Private functions used by read, write and erase operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Double checks all parameters before calling a read or write. Comes in two variants +//Variant A: Takes address and returns the address if true, else returns false. Throws an error if there is a problem. +bool SPIFlash::_prep(uint8_t opcode, uint32_t address, uint32_t size) { + switch (opcode) { + case PAGEPROG: + if (!_addressCheck(address, size)) { + return false; + } + if(!_notBusy() || !_writeEnable()){ + return false; + } + #ifndef HIGHSPEED + if(!_notPrevWritten(address, size)) { + return false; + } + #endif + return true; + break; + + default: + if (!_addressCheck(address, size)) { + return false; + } + if (!_notBusy()){ + return false; + } + return true; + break; + } +} + +//Variant B: Take the opcode, page number, offset and size of data block as arguments +bool SPIFlash::_prep(uint8_t opcode, uint32_t page_number, uint8_t offset, uint32_t size) { + uint32_t address = _getAddress(page_number, offset); + return _prep(opcode, address, size); +} + +bool SPIFlash::_transferAddress(void) { + _nextByte(_currentAddress >> 16); + _nextByte(_currentAddress >> 8); + _nextByte(_currentAddress); +} + +bool SPIFlash::_startSPIBus(void) { +#ifndef SPI_HAS_TRANSACTION + noInterrupts(); +#endif + +#if defined (ARDUINO_ARCH_SAM) + _dueSPIInit(DUE_SPI_CLK); +#else + #if defined (ARDUINO_ARCH_AVR) + //save current SPI settings + _SPCR = SPCR; + _SPSR = SPSR; + #endif + #ifdef SPI_HAS_TRANSACTION + SPI.beginTransaction(_settings); + #else + SPI.setClockDivider(SPI_CLOCK_DIV_4) + SPI.setDataMode(SPI_MODE0); + SPI.setBitOrder(MSBFIRST); + #endif +#endif + SPIBusState = true; + return true; +} + +//Initiates SPI operation - but data is not transferred yet. Always call _prep() before this function (especially when it involves writing or reading to/from an address) +bool SPIFlash::_beginSPI(uint8_t opcode) { + if (!SPIBusState) { + //Serial.println("Starting SPI Bus"); + _startSPIBus(); + } + CHIP_SELECT + switch (opcode) { + case FASTREAD: + _nextByte(opcode); + _nextByte(DUMMYBYTE); + _transferAddress(); + break; + + case READDATA: + _nextByte(opcode); + _transferAddress(); + break; + + case PAGEPROG: + _nextByte(opcode); + _transferAddress(); + break; + + default: + _nextByte(opcode); + break; + } + return true; +} +//SPI data lines are left open until _endSPI() is called + +//Reads/Writes next byte. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() +uint8_t SPIFlash::_nextByte(uint8_t data) { +#if defined (ARDUINO_ARCH_SAM) + return _dueSPITransfer(data); +#else + return xfer(data); +#endif +} + +//Reads/Writes next int. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() +uint16_t SPIFlash::_nextInt(uint16_t data) { + //return xfer16(data); + return SPI.transfer16(data); +} + +//Reads/Writes next data buffer. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() +void SPIFlash::_nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size) { + uint8_t *_dataAddr = &(*data_buffer); + switch (opcode) { + case READDATA: + #if defined (ARDUINO_ARCH_SAM) + _dueSPIRecByte(&(*data_buffer), size); + #elif defined (ARDUINO_ARCH_AVR) + SPI.transfer(&data_buffer[0], size); + #else + for (uint16_t i = 0; i < size; i++) { + *_dataAddr = xfer(NULLBYTE); + _dataAddr++; + } + #endif + break; + + case PAGEPROG: + #if defined (ARDUINO_ARCH_SAM) + _dueSPISendByte(&(*data_buffer), size); + #elif defined (ARDUINO_ARCH_AVR) + SPI.transfer(&(*data_buffer), size); + #else + for (uint16_t i = 0; i < size; i++) { + xfer(*_dataAddr); + _dataAddr++; + } + #endif + break; + } +} + +//Stops all operations. Should be called after all the required data is read/written from repeated _nextByte() calls +void SPIFlash::_endSPI(void) { + CHIP_DESELECT + #ifdef SPI_HAS_TRANSACTION + SPI.endTransaction(); + #else + interrupts(); + #endif + + #if defined (ARDUINO_ARCH_AVR) + SPCR = _SPCR; + SPSR = _SPSR; + #endif + SPIBusState = false; +} + +// Checks if status register 1 can be accessed - used during powerdown and power up and for debugging +uint8_t SPIFlash::_readStat1(void) { + _beginSPI(READSTAT1); + uint8_t stat1 = _nextByte(); + CHIP_DESELECT + return stat1; +} + +// Checks if status register 2 can be accessed, if yes, reads and returns it +uint8_t SPIFlash::_readStat2(void) { + _beginSPI(READSTAT2); + uint8_t stat2 = _nextByte(); + stat2 = _nextByte(); + CHIP_DESELECT + return stat2; +} + +// Checks the erase/program suspend flag before enabling/disabling a program/erase suspend operation +bool SPIFlash::_noSuspend(void) { + switch (_chip.manufacturerID) { + case WINBOND_MANID: + if(_readStat2() & SUS) { + errorcode = SYSSUSPEND; + return false; + } + return true; + break; + + case MICROCHIP_MANID: + if(_readStat1() & WSE || _readStat1() & WSP) { + errorcode = SYSSUSPEND; + return false; + } + return true; + } + +} + +// Polls the status register 1 until busy flag is cleared or timeout +bool SPIFlash::_notBusy(uint32_t timeout) { + uint32_t startTime = millis(); + + do { + state = _readStat1(); + if((millis()-startTime) > timeout){ + errorcode = CHIPBUSY; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + _endSPI(); + return false; + } + } while(state & BUSY); + return true; +} + +//Enables writing to chip by setting the WRITEENABLE bit +bool SPIFlash::_writeEnable(uint32_t timeout) { + uint32_t startTime = millis(); + if (!(state & WRTEN)) { + do { + _beginSPI(WRITEENABLE); + CHIP_DESELECT + state = _readStat1(); + if((millis()-startTime) > timeout) { + errorcode = CANTENWRITE; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + _endSPI(); + return false; + } + } while (!(state & WRTEN)); + } + return true; +} + +//Disables writing to chip by setting the Write Enable Latch (WEL) bit in the Status Register to 0 +//_writeDisable() is not required under the following conditions because the Write Enable Latch (WEL) flag is cleared to 0 +// i.e. to write disable state: +// Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, Chip Erase, Write Status Register, +// Erase Security Register and Program Security register +bool SPIFlash::_writeDisable(void) { + _beginSPI(WRITEDISABLE); + CHIP_DESELECT + return true; +} + +//Gets address from page number and offset. Takes two arguments: +// 1. page_number --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +uint32_t SPIFlash::_getAddress(uint16_t page_number, uint8_t offset) { + uint32_t address = page_number; + return ((address << 8) + offset); +} + +//Checks the device ID to establish storage parameters +bool SPIFlash::_getManId(uint8_t *b1, uint8_t *b2) { + if(!_notBusy()) + return false; + _beginSPI(MANID); + _nextByte(); + _nextByte(); + _nextByte(); + *b1 = _nextByte(); + *b2 = _nextByte(); + CHIP_DESELECT + return true; +} + +//Checks for presence of chip by requesting JEDEC ID +bool SPIFlash::_getJedecId(void) { + if(!_notBusy()) { + return false; + } + _beginSPI(JEDECID); + _chip.manufacturerID = _nextByte(NULLBYTE); // manufacturer id + _chip.memoryTypeID = _nextByte(NULLBYTE); // memory type + _chip.capacityID = _nextByte(NULLBYTE); // capacity + CHIP_DESELECT + if (!_chip.manufacturerID || !_chip.memoryTypeID || !_chip.capacityID) { + errorcode = NORESPONSE; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + else { + return true; + } +} + +bool SPIFlash::_getSFDP(void) { + if(!_notBusy()) { + return false; + } + _beginSPI(READSFDP); + _currentAddress = 0x00; + _transferAddress(); + _nextByte(DUMMYBYTE); + for (uint8_t i = 0; i < 4; i++) { + _chip.sfdp += (_nextByte() << (8*i)); + } + CHIP_DESELECT + if (_chip.sfdp = 0x50444653) { + //Serial.print("_chip.sfdp: "); + //Serial.println(_chip.sfdp, HEX); + return true; + } + else { + return false; + } +} + +//Identifies the chip +bool SPIFlash::_chipID(void) { + //Get Manfucturer/Device ID so the library can identify the chip + _getSFDP(); + if (!_getJedecId()) { + return false; + } + + // If no capacity is defined in user code + if (!_chip.capacity) { + _chip.supported = _chip.manufacturerID; + if (_chip.supported == WINBOND_MANID || _chip.supported == MICROCHIP_MANID) { + //Identify capacity + for (uint8_t i = 0; i < sizeof(_capID); i++) + { + if (_chip.capacityID == _capID[i]) { + _chip.capacity = (_memSize[i]); + _chip.eraseTime = _eraseTime[i]; + } + } + return true; + } + else { + errorcode = UNKNOWNCAP; //Error code for unidentified capacity + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + } + else { + // If a custom chip size is defined + _chip.eraseTime = _chip.capacity/KB8; + _chip.supported = false;// This chip is not officially supported + errorcode = UNKNOWNCHIP; //Error code for unidentified chip + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + //while(1); //Enable this if usercode is not meant to be run on unsupported chips + } + return true; +} + +//Checks to see if pageOverflow is permitted and assists with determining next address to read/write. +//Sets the global address variable +bool SPIFlash::_addressCheck(uint32_t address, uint32_t size) { + if (errorcode == UNKNOWNCAP || errorcode == NORESPONSE) { + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + if (!_chip.eraseTime) { + errorcode = CALLBEGIN; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + + for (uint32_t i = 0; i < size; i++) { + if (address + i >= _chip.capacity) { + if (!pageOverflow) { + errorcode = OUTOFBOUNDS; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; // At end of memory - (!pageOverflow) + } + else { + _currentAddress = 0x00; + return true; // At end of memory - (pageOverflow) + } + } + } + _currentAddress = address; + return true; // Not at end of memory if (address < _chip.capacity) +} + +bool SPIFlash::_notPrevWritten(uint32_t address, uint32_t size) { + _beginSPI(READDATA); + for (uint16_t i = 0; i < size; i++) { + if (_nextByte() != 0xFF) { + CHIP_DESELECT; + return false; + } + } + CHIP_DESELECT + return true; +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Public functions used for read, write and erase operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Identifies chip and establishes parameters +bool SPIFlash::begin(uint32_t _chipSize) { + if (_chipSize) { + _chip.capacity = _chipSize/8; + } + BEGIN_SPI +#ifdef SPI_HAS_TRANSACTION + //Define the settings to be used by the SPI bus + _settings = SPISettings(SPI_CLK, MSBFIRST, SPI_MODE0); +#endif + if(!_chipID()) { + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } +} + +//Allows the setting of a custom clock speed for the SPI bus to communicate with the chip. +//Only works if the SPI library in use supports SPI Transactions +#ifdef SPI_HAS_TRANSACTION +void SPIFlash::setClock(uint32_t clockSpeed) { + _settings = SPISettings(clockSpeed, MSBFIRST, SPI_MODE0); +} +#endif + +uint8_t SPIFlash::error(bool _verbosity) { + if (!_verbosity) { + return errorcode; + } + else { + _troubleshoot(); + return errorcode; + } +} + +//Returns capacity of chip +uint32_t SPIFlash::getCapacity(void) { + return _chip.capacity; +} + +//Returns maximum number of pages +uint32_t SPIFlash::getMaxPage(void) { + return (_chip.capacity / PAGESIZE); +} + +//Returns the library version as a string +bool SPIFlash::libver(uint8_t *b1, uint8_t *b2, uint8_t *b3) { + *b1 = LIBVER; + *b2 = LIBSUBVER; + *b3 = BUGFIXVER; + return true; +} + +//Checks for and initiates the chip by requesting the Manufacturer ID which is returned as a 16 bit int +uint16_t SPIFlash::getManID(void) { + uint8_t b1, b2; + _getManId(&b1, &b2); + uint32_t id = b1; + id = (id << 8)|(b2 << 0); + return id; +} + +//Returns JEDEC ID which is returned as a 32 bit int +uint32_t SPIFlash::getJEDECID(void) { + uint32_t id = _chip.manufacturerID; + id = (id << 8)|(_chip.memoryTypeID << 0); + id = (id << 8)|(_chip.capacityID << 0); + return id; +} + +//Gets the next available address for use. Has two variants: +// A. Takes the size of the data as an argument and returns a 32-bit address +// B. Takes a three variables, the size of the data and two other variables to return a page number value & an offset into. +// All addresses in the in the sketch must be obtained via this function or not at all. +// Variant A +uint32_t SPIFlash::getAddress(uint16_t size) { + if (!_addressCheck(currentAddress, size)){ + errorcode = OUTOFBOUNDS; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } + else { + uint32_t address = currentAddress; + currentAddress+=size; + return address; + } +} +// Variant B +bool SPIFlash::getAddress(uint16_t size, uint16_t &page_number, uint8_t &offset) { + uint32_t address = getAddress(size); + offset = (address >> 0); + page_number = (address >> 8); + return true; +} + +//Function for returning the size of the string (only to be used for the getAddress() function) +uint16_t SPIFlash::sizeofStr(String &inputStr) { + uint16_t size; + size = (sizeof(char)*(inputStr.length()+1)); + size+=sizeof(inputStr.length()+1); + + return size; +} + +// Reads a byte of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +uint8_t SPIFlash::readByte(uint32_t address, bool fastRead) { + uint8_t data; + + if (!_prep(READDATA, address, sizeof(data))) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + data = _nextByte(); + _endSPI(); + return data; +} +// Variant B +uint8_t SPIFlash::readByte(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readByte(address, fastRead); +} + +// Reads a char of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +int8_t SPIFlash::readChar(uint32_t address, bool fastRead) { + int8_t data; + if (!_prep(READDATA, address, sizeof(data))) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + data = _nextByte(); + _endSPI(); + return data; +} +// Variant B +int8_t SPIFlash::readChar(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readChar(address, fastRead); +} + +// Reads an array of bytes starting from a specific location in a page.// Has two variants: +// A. Takes three arguments +// 1. address --> Any address from 0 to capacity +// 2. data_buffer --> The array of bytes to be read from the flash memory - starting at the address indicated +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes four arguments +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data_buffer --> The array of bytes to be read from the flash memory - starting at the offset on the page indicated +// 4. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +bool SPIFlash::readByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) { + if (!_prep(READDATA, address, bufferSize)) { + return false; + } + if(fastRead) { + _beginSPI(FASTREAD); + } + else { + _beginSPI(READDATA); + } + _nextBuf(READDATA, &(*data_buffer), bufferSize); + _endSPI(); + return true; +} +// Variant B +bool SPIFlash::readByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readByteArray(address, data_buffer, bufferSize, fastRead); +} + +// Reads an array of chars starting from a specific location in a page.// Has two variants: +// A. Takes three arguments +// 1. address --> Any address from 0 to capacity +// 2. data_buffer --> The array of bytes to be read from the flash memory - starting at the address indicated +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes four arguments +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data_buffer --> The array of bytes to be read from the flash memory - starting at the offset on the page indicated +// 4. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +bool SPIFlash::readCharArray(uint32_t address, char *data_buffer, uint16_t bufferSize, bool fastRead) { + if (!_prep(READDATA, address, bufferSize)) { + return false; + } + if(fastRead) { + _beginSPI(FASTREAD); + } + else { + _beginSPI(READDATA); + } + _nextBuf(READDATA, (uint8_t*) &(*data_buffer), bufferSize); + _endSPI(); + return true; +} +// Variant B +bool SPIFlash::readCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t bufferSize, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readCharArray(address, data_buffer, bufferSize, fastRead); +} + +// Reads an unsigned int of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +uint16_t SPIFlash::readWord(uint32_t address, bool fastRead) { + const uint8_t size = sizeof(uint16_t); + union + { + uint8_t b[size]; + uint16_t I; + } data; + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.I; +} +// Variant B +uint16_t SPIFlash::readWord(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readWord(address, fastRead); +} + +// Reads a signed int of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +int16_t SPIFlash::readShort(uint32_t address, bool fastRead) { + const uint8_t size = sizeof(int16_t); + union + { + byte b[size]; + int16_t s; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.s; +} +// Variant B +int16_t SPIFlash::readShort(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readShort(address, fastRead); +} + +// Reads an unsigned long of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +uint32_t SPIFlash::readULong(uint32_t address, bool fastRead) { + const uint8_t size = (sizeof(uint32_t)); + union + { + uint8_t b[size]; + uint32_t l; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.l; +} +// Variant B +uint32_t SPIFlash::readULong(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readULong(address, fastRead); +} + +// Reads a signed long of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +int32_t SPIFlash::readLong(uint32_t address, bool fastRead) { + const uint8_t size = (sizeof(int32_t)); + union + { + byte b[size]; + int32_t l; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.l; +} +// Variant B +int32_t SPIFlash::readLong(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readLong(address, fastRead); +} + +// Reads a signed long of data from a specific location in a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +float SPIFlash::readFloat(uint32_t address, bool fastRead) { + const uint8_t size = (sizeof(float)); + union + { + byte b[size]; + float f; + } data; + + if (!_prep(READDATA, address, size)) { + return false; + } + + switch (fastRead) { + case false: + _beginSPI(READDATA); + break; + + case true: + _beginSPI(FASTREAD); + break; + + default: + break; + } + _nextBuf(READDATA, &data.b[0], size); + _endSPI(); + return data.f; +} +// Variant B +float SPIFlash::readFloat(uint16_t page_number, uint8_t offset, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + + return readFloat(address, fastRead); +} + +// Reads a string from a specific location on a page. +// Has two variants: +// A. Takes three arguments +// 1. address --> Any address from 0 to capacity +// 2. outputString --> String variable to write the output to +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes four arguments +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. outputString --> String variable to write the output to +// 4. fastRead --> defaults to false - executes _beginFastRead() if set to true +// This function first reads a short from the address to figure out the size of the String object stored and +// then reads the String object data +// Variant A +bool SPIFlash::readStr(uint32_t address, String &outStr, bool fastRead) { + uint16_t strLen; + //_delay_us(20); + strLen = readWord(address); + address+=(sizeof(strLen)); + char outputChar[strLen]; + + readCharArray(address, outputChar, strLen, fastRead); + + outStr = String(outputChar); + return true; +} +// Variant B +bool SPIFlash::readStr(uint16_t page_number, uint8_t offset, String &outStr, bool fastRead) { + uint32_t address = _getAddress(page_number, offset); + return readStr(address, outStr, fastRead); +} + +// Writes a byte of data to a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One byte of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One byte of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeByte(uint32_t address, uint8_t data, bool errorCheck) { + if(!_prep(PAGEPROG, address, sizeof(data))) { + return false; + } + + _beginSPI(PAGEPROG); + _nextByte(data); + CHIP_DESELECT + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeByte(address, data, errorCheck); +} + +// Writes a char of data to a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One char of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One char of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeChar(uint32_t address, int8_t data, bool errorCheck) { + if(!_prep(PAGEPROG, address, sizeof(data))) { + return false; + } + + _beginSPI(PAGEPROG); + _nextByte(data); + CHIP_DESELECT + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeChar(address, data, errorCheck); +} + +// Writes an array of bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> An array of bytes to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An array of bytes to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck) { + if (!_prep(PAGEPROG, address, bufferSize)) { + return false; + } + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t length = bufferSize; + uint16_t writeBufSz; + uint16_t data_offset = 0; + + while (length > 0) + { + writeBufSz = (length<=maxBytes) ? length : maxBytes; + + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(data_buffer[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + length -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + if (!_notBusy()) { + return false; + } + _currentAddress = address; + CHIP_SELECT + _nextByte(READDATA); + _transferAddress(); + for (uint16_t j = 0; j < bufferSize; j++) { + if (_nextByte(NULLBYTE) != data_buffer[j]) { + return false; + } + } + _endSPI(); + return true; + } +} +// Variant B +bool SPIFlash::writeByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeByteArray(address, data_buffer, bufferSize, errorCheck); +} + +// Writes an array of bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> An array of chars to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An array of chars to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeCharArray(uint32_t address, char *data_buffer, uint16_t bufferSize, bool errorCheck) { + uint16_t writeBufSz; + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t data_offset = 0; + uint16_t length = bufferSize; + if (!_prep(PAGEPROG, address, bufferSize)) { + return false; + } + + while (length > 0) + { + writeBufSz = (length<=maxBytes) ? length : maxBytes; + + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(data_buffer[data_offset + i]); + Serial.print(data_buffer[data_offset + i]); + Serial.print(", "); + } + Serial.println(); + _currentAddress += writeBufSz; + data_offset += writeBufSz; + length -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + if (!_notBusy()) { + return false; + } + _currentAddress = address; + CHIP_SELECT + _nextByte(READDATA); + _transferAddress(); + for (uint16_t j = 0; j < bufferSize; j++) { + if (_nextByte(NULLBYTE) != data_buffer[j]) { + return false; + } + } + _endSPI(); + return true; + } +} +// Variant B +bool SPIFlash::writeCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t bufferSize, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeCharArray(address, data_buffer, bufferSize, errorCheck); +} + +// Writes an unsigned int as two bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One unsigned int of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One unsigned int of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeWord(uint32_t address, uint16_t data, bool errorCheck) { + const uint8_t size = sizeof(uint16_t); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + uint16_t w; + } var; + var.w = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else + return _writeErrorCheck(address, data); +} +// Variant B +bool SPIFlash::writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeWord(address, data, errorCheck); +} + +// Writes a signed int as two bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One signed int of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One signed int of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeShort(uint32_t address, int16_t data, bool errorCheck) { + const uint8_t size = sizeof(data); + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + int16_t s; + } var; + var.s = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else + return _writeErrorCheck(address, data); +} +// Variant B +bool SPIFlash::writeShort(uint16_t page_number, uint8_t offset, int16_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeShort(address, data, errorCheck); +} + +// Writes an unsigned long as four bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One unsigned long of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One unsigned long of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeULong(uint32_t address, uint32_t data, bool errorCheck) { + const uint8_t size = (sizeof(data)); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + uint32_t l; + } var; + var.l = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck){ + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeULong(uint16_t page_number, uint8_t offset, uint32_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeULong(address, data, errorCheck); +} + +// Writes a signed long as four bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One signed long of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One signed long of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeLong(uint32_t address, int32_t data, bool errorCheck) { +const uint8_t size = sizeof(data); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + + union + { + uint8_t b[size]; + int32_t l; + } var; + var.l = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck){ + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeLong(uint16_t page_number, uint8_t offset, int32_t data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeLong(address, data, errorCheck); +} + +// Writes a float as four bytes starting from a specific location in a page. +// Has two variants: +// A. Takes three arguments - +// 1. address --> Any address - from 0 to capacity +// 2. data --> One float of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One float of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +bool SPIFlash::writeFloat(uint32_t address, float data, bool errorCheck) { + const uint8_t size = (sizeof(data)); + + if(!_prep(PAGEPROG, address, size)) { + return false; + } + union + { + uint8_t b[size]; + float f; + } var; + var.f = data; + + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > size) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + uint16_t _sz = size; + + while (_sz > 0) + { + writeBufSz = (_sz<=maxBytes) ? _sz : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(var.b[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + _sz -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, data); + } +} +// Variant B +bool SPIFlash::writeFloat(uint16_t page_number, uint8_t offset, float data, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + + return writeFloat(address, data, errorCheck); +} + +// Reads a string from a specific location on a page. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to capacity +// 2. inputString --> String variable to write the data from +// 3. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. inputString --> String variable to write the data from +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// This function first writes the size of the string as an unsigned int to the address to figure out the size of the String object stored and +// then writes the String object data. Therefore it takes up two bytes more than the size of the String itself. +// Variant A +bool SPIFlash::writeStr(uint32_t address, String &inputStr, bool errorCheck) { + uint16_t inStrLen = inputStr.length() +1; + if(!_prep(PAGEPROG, address, inStrLen)) { + return false; + } + + const uint16_t size = sizeof(inStrLen); + union + { + uint8_t b[size]; + uint16_t w; + } var; + + var.w = inStrLen; + char inputChar[inStrLen]; + inputStr.toCharArray(inputChar, inStrLen); + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + if (maxBytes > inStrLen) { + _beginSPI(PAGEPROG); + _nextBuf(PAGEPROG, &var.b[0], size); + _nextBuf(PAGEPROG, (uint8_t*)&inputChar, inStrLen); + CHIP_DESELECT + } + else { + uint16_t writeBufSz; + uint16_t data_offset = 0; + bool strLenWritten = false; + + while (inStrLen > 0) + { + writeBufSz = (inStrLen<=maxBytes) ? inStrLen : maxBytes; + if(!_notBusy() || !_writeEnable()){ + return false; + } + + _beginSPI(PAGEPROG); + for (uint16_t i = 0; i < writeBufSz; ++i) { + if(!strLenWritten) { + for (uint8_t j = 0; j < size; j++) { + _nextByte(var.b[j]); + } + strLenWritten = true; + } + _nextByte(inputChar[data_offset + i]); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + inStrLen -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + String tempStr; + readStr(address, tempStr); + return inputStr.equals(tempStr); + } +} +// Variant B +bool SPIFlash::writeStr(uint16_t page_number, uint8_t offset, String &inputStr, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + return writeStr(address, inputStr, errorCheck); +} + + +//Erases one 4k sector. Has two variants: +// A. Takes the address as the argument and erases the sector containing the address. +// B. Takes page to be erased as the argument and erases the sector containing the page. +// The sectors are numbered 0 - 255 containing 16 pages each. +// Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 +// Variant A +bool SPIFlash::eraseSector(uint32_t address) { + if(!_notBusy()||!_writeEnable()) + return false; + + _beginSPI(SECTORERASE); + _nextByte(address >> 16); + _nextByte(address >> 8); + _nextByte(0); + _endSPI(); + + if(!_notBusy(500L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, ``Sector Erase``, Block Erase, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} +// Variant B +bool SPIFlash::eraseSector(uint16_t page_number, uint8_t offset) { + uint32_t address = _getAddress(page_number, offset); + return eraseSector(address); +} + +//Erases one 32k block. Has two variants: +// A. Takes the address as the argument and erases the block containing the address. +// B. Takes page to be erased as the argument and erases the block containing the page. +// The blocks are numbered 0 - 31 containing 128 pages each. +// Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31 +// Variant A +bool SPIFlash::eraseBlock32K(uint32_t address) { + if(!_notBusy()||!_writeEnable()) { + return false; + } + _beginSPI(BLOCK32ERASE); + _nextByte(address >> 16); + _nextByte(address >> 8); + _nextByte(0); + _endSPI(); + + if(!_notBusy(1*S)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} +// Variant B +bool SPIFlash::eraseBlock32K(uint16_t page_number, uint8_t offset) { + uint32_t address = _getAddress(page_number, offset); + return eraseBlock32K(address); +} + +//Erases one 64k block. Has two variants: +// A. Takes the address as the argument and erases the block containing the address. +// B. Takes page to be erased as the argument and erases the block containing the page. +// The blocks are numbered 0 - 15 containing 256 pages each. +// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15 +// Variant A +bool SPIFlash::eraseBlock64K(uint32_t address) { + if(!_notBusy()||!_writeEnable()) { + return false; + } + _beginSPI(BLOCK64ERASE); + _nextByte(address >> 16); + _nextByte(address >> 8); + _nextByte(0); + _endSPI(); + + if(!_notBusy(1200L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} +// Variant B +bool SPIFlash::eraseBlock64K(uint16_t page_number, uint8_t offset) { + uint32_t address = _getAddress(page_number, offset); + return eraseBlock64K(address); +} + +//Erases whole chip. Think twice before using. +bool SPIFlash::eraseChip(void) { + if(!_notBusy()||!_writeEnable()) + return false; + + _beginSPI(CHIPERASE); + _endSPI(); + if(!_notBusy(_chip.eraseTime)) + return false; //Datasheet says erasing chip takes 6s max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, ``Chip Erase``, Write Status Register, + // Erase Security Register and Program Security register + + return true; + +} + +//Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). +//Page Program, Write Status Register, Erase instructions are not allowed. +//Erase suspend is only allowed during Block/Sector erase. +//Program suspend is only allowed during Page/Quad Page Program +bool SPIFlash::suspendProg(void) { + if(_notBusy()) { + return false; + } + + if(!_noSuspend()) { + return true; + } + + else { + _beginSPI(SUSPEND); + _endSPI(); + _delay_us(20); + if(!_notBusy(50) || _noSuspend()) { //Max suspend Enable time according to datasheet + return false; + } + return true; + } +} + +//Resumes previously suspended Block Erase/Sector Erase/Page Program. +bool SPIFlash::resumeProg(void) { + if(!_notBusy() || _noSuspend()) { + return false; + } + + _beginSPI(RESUME); + _endSPI(); + + _delay_us(20); + + if(_notBusy(10) || !_noSuspend()) { + return false; + } + return true; + +} + +//Puts device in low power state. Good for battery powered operations. +//Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4) +//In powerDown() the chip will only respond to powerUp() +bool SPIFlash::powerDown(void) { + if(!_notBusy(20)) + return false; + + _beginSPI(POWERDOWN); + _endSPI(); + + _delay_us(5); + + _beginSPI(WRITEENABLE); + CHIP_DESELECT + if (_readStat1() & WRTEN) { + _endSPI(); + return false; + } + else { + + return true; + } +} + +//Wakes chip from low power state. +bool SPIFlash::powerUp(void) { + _beginSPI(RELEASE); + _endSPI(); + _delay_us(3); //Max release enable time according to the Datasheet + + _beginSPI(WRITEENABLE); + CHIP_DESELECT + if (_readStat1() & WRTEN) { + _endSPI(); + return true; + } + else { + + return false; + } +} diff --git a/arduino_libraries/SPIMemory-2.6.0/src/SPIFlash.h b/arduino_libraries/SPIMemory-2.6.0/src/SPIFlash.h new file mode 100644 index 0000000..d8f9667 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/src/SPIFlash.h @@ -0,0 +1,446 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 19/05/2015 + * Modified by @boseji - 02/03/2017 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + +#ifndef SPIFLASH_H +#define SPIFLASH_H + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Uncomment the code below to run a diagnostic if your flash // +// does not respond // +// // +// Error codes will be generated and returned on functions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//#define RUNDIAGNOSTIC // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Uncomment the code below to increase the speed of the library // +// by disabling _notPrevWritten() // +// // +// Make sure the sectors being written to have been erased beforehand // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//#define HIGHSPEED // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#include +#include "defines.h" + +#if defined (ARDUINO_ARCH_SAM) + #include + #include + #include +#endif + +#ifndef __AVR_ATtiny85__ + #include +#endif + +#if defined (ARDUINO_ARCH_SAM) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_ESP8266) || defined (SIMBLEE) || defined (ARDUINO_ARCH_ESP32) || defined (BOARD_RTL8195A) +// RTL8195A included - @boseji 02.03.17 + #define _delay_us(us) delayMicroseconds(us) +#else + #include +#endif +// Includes specific to RTL8195A to access GPIO HAL - @boseji 02.03.17 +#if defined (BOARD_RTL8195A) +#ifdef __cplusplus +extern "C" { +#endif + +#include "gpio_api.h" +#include "PinNames.h" + +#ifdef __cplusplus +} +#endif + +#endif + +#ifdef ARDUINO_ARCH_AVR + #ifdef __AVR_ATtiny85__ + #define CHIP_SELECT PORTB &= ~cs_mask; + #define CHIP_DESELECT PORTB |= cs_mask; + #define SPIBIT \ + USICR = ((1< 02.03.17 +#elif defined (BOARD_RTL8195A) + #define CHIP_SELECT gpio_write(&csPin, 0); + #define CHIP_DESELECT gpio_write(&csPin, 1); + #define xfer(n) SPI.transfer(n) + #define BEGIN_SPI SPI.begin(); +#else //#elif defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_ARCH_SAMD) + #define CHIP_SELECT digitalWrite(csPin, LOW); + #define CHIP_DESELECT digitalWrite(csPin, HIGH); + #define xfer(n) SPI.transfer(n) + #define BEGIN_SPI SPI.begin(); +#endif + +#define LIBVER 2 +#define LIBSUBVER 6 +#define BUGFIXVER 0 + +#if defined (ARDUINO_ARCH_SAM) + extern char _end; + extern "C" char *sbrk(int i); + //char *ramstart=(char *)0x20070000; + //char *ramend=(char *)0x20088000; +#endif + +class SPIFlash { +public: + //----------------------------------------------Constructor----------------------------------------------- + //New Constructor to Accept the PinNames as a Chip select Parameter - @boseji 02.03.17 + #if !defined (BOARD_RTL8195A) + SPIFlash(uint8_t cs = CS, bool overflow = true); + #else + SPIFlash(PinName cs = CS, bool overflow = true); + #endif + //----------------------------------------Initial / Chip Functions----------------------------------------// + bool begin(uint32_t _chipSize = 0); + void setClock(uint32_t clockSpeed); + bool libver(uint8_t *b1, uint8_t *b2, uint8_t *b3); + uint8_t error(bool verbosity = false); + uint16_t getManID(void); + uint32_t getJEDECID(void); + bool getAddress(uint16_t size, uint16_t &page_number, uint8_t &offset); + uint32_t getAddress(uint16_t size); + //uint16_t getChipName(void); + uint16_t sizeofStr(String &inputStr); + uint32_t getCapacity(void); + uint32_t getMaxPage(void); + //-------------------------------------------Write / Read Bytes-------------------------------------------// + bool writeByte(uint32_t address, uint8_t data, bool errorCheck = true); + bool writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck = true); + uint8_t readByte(uint16_t page_number, uint8_t offset, bool fastRead = false); + uint8_t readByte(uint32_t address, bool fastRead = false); + //----------------------------------------Write / Read Byte Arrays----------------------------------------// + bool writeByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool writeByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool readByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead = false); + bool readByteArray(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead = false); + //-------------------------------------------Write / Read Chars-------------------------------------------// + bool writeChar(uint32_t address, int8_t data, bool errorCheck = true); + bool writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck = true); + int8_t readChar(uint32_t address, bool fastRead = false); + int8_t readChar(uint16_t page_number, uint8_t offset, bool fastRead = false); + //----------------------------------------Write / Read Char Arrays----------------------------------------// + bool writeCharArray(uint32_t address, char *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool writeCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t bufferSize, bool errorCheck = true); + bool readCharArray(uint32_t address, char *data_buffer, uint16_t buffer_size, bool fastRead = false); + bool readCharArray(uint16_t page_number, uint8_t offset, char *data_buffer, uint16_t buffer_size, bool fastRead = false); + //------------------------------------------Write / Read Shorts------------------------------------------// + bool writeShort(uint32_t address, int16_t data, bool errorCheck = true); + bool writeShort(uint16_t page_number, uint8_t offset, int16_t data, bool errorCheck = true); + int16_t readShort(uint32_t address, bool fastRead = false); + int16_t readShort(uint16_t page_number, uint8_t offset, bool fastRead = false); + //-------------------------------------------Write / Read Words-------------------------------------------// + bool writeWord(uint32_t address, uint16_t data, bool errorCheck = true); + bool writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bool errorCheck = true); + uint16_t readWord(uint32_t address, bool fastRead = false); + uint16_t readWord(uint16_t page_number, uint8_t offset, bool fastRead = false); + //-------------------------------------------Write / Read Longs-------------------------------------------// + bool writeLong(uint32_t address, int32_t data, bool errorCheck = true); + bool writeLong(uint16_t page_number, uint8_t offset, int32_t data, bool errorCheck = true); + int32_t readLong(uint32_t address, bool fastRead = false); + int32_t readLong(uint16_t page_number, uint8_t offset, bool fastRead = false); + //--------------------------------------Write / Read Unsigned Longs---------------------------------------// + bool writeULong(uint32_t address, uint32_t data, bool errorCheck = true); + bool writeULong(uint16_t page_number, uint8_t offset, uint32_t data, bool errorCheck = true); + uint32_t readULong(uint32_t address, bool fastRead = false); + uint32_t readULong(uint16_t page_number, uint8_t offset, bool fastRead = false); + //-------------------------------------------Write / Read Floats------------------------------------------// + bool writeFloat(uint32_t address, float data, bool errorCheck = true); + bool writeFloat(uint16_t page_number, uint8_t offset, float data, bool errorCheck = true); + float readFloat(uint32_t address, bool fastRead = false); + float readFloat(uint16_t page_number, uint8_t offset, bool fastRead = false); + //------------------------------------------Write / Read Strings------------------------------------------// + bool writeStr(uint32_t address, String &inputStr, bool errorCheck = true); + bool writeStr(uint16_t page_number, uint8_t offset, String &inputStr, bool errorCheck = true); + bool readStr(uint32_t address, String &outStr, bool fastRead = false); + bool readStr(uint16_t page_number, uint8_t offset, String &outStr, bool fastRead = false); + //------------------------------------------Write / Read Anything-----------------------------------------// + template bool writeAnything(uint32_t address, const T& value, bool errorCheck = true); + template bool writeAnything(uint16_t page_number, uint8_t offset, const T& value, bool errorCheck = true); + template bool readAnything(uint32_t address, T& value, bool fastRead = false); + template bool readAnything(uint16_t page_number, uint8_t offset, T& value, bool fastRead = false); + //--------------------------------------------Erase functions---------------------------------------------// + bool eraseSector(uint32_t address); + bool eraseSector(uint16_t page_number, uint8_t offset); + bool eraseBlock32K(uint32_t address); + bool eraseBlock32K(uint16_t page_number, uint8_t offset); + bool eraseBlock64K(uint32_t address); + bool eraseBlock64K(uint16_t page_number, uint8_t offset); + bool eraseChip(void); + //---------------------------------------------Power functions--------------------------------------------// + bool suspendProg(void); + bool resumeProg(void); + bool powerDown(void); + bool powerUp(void); + //-------------------------------------Public Arduino Due Functions---------------------------------------// +//#if defined (ARDUINO_ARCH_SAM) + //uint32_t freeRAM(void); +//#endif + //-------------------------------------------Public variables---------------------------------------------// + +private: +#if defined (ARDUINO_ARCH_SAM) + //-------------------------------------Private Arduino Due Functions--------------------------------------// + void _dmac_disable(void); + void _dmac_enable(void); + void _dmac_channel_disable(uint32_t ul_num); + void _dmac_channel_enable(uint32_t ul_num); + bool _dmac_channel_transfer_done(uint32_t ul_num); + void _dueSPIDmaRX(uint8_t* dst, uint16_t count); + void _dueSPIDmaRX(char* dst, uint16_t count); + void _dueSPIDmaTX(const uint8_t* src, uint16_t count); + void _dueSPIDmaCharTX(const char* src, uint16_t count); + void _dueSPIBegin(void); + void _dueSPIInit(uint8_t dueSckDivisor); + uint8_t _dueSPITransfer(uint8_t b); + uint8_t _dueSPIRecByte(void); + uint8_t _dueSPIRecByte(uint8_t* buf, size_t len); + int8_t _dueSPIRecChar(void); + int8_t _dueSPIRecChar(char* buf, size_t len); + void _dueSPISendByte(uint8_t b); + void _dueSPISendByte(const uint8_t* buf, size_t len); + void _dueSPISendChar(char b); + void _dueSPISendChar(const char* buf, size_t len); +#endif + //--------------------------------------------Private functions-------------------------------------------// + void _troubleshoot(void); + void _printErrorCode(void); + void _printSupportLink(void); + void _endSPI(void); + bool _prep(uint8_t opcode, uint32_t address, uint32_t size); + bool _prep(uint8_t opcode, uint32_t page_number, uint8_t offset, uint32_t size); + bool _startSPIBus(void); + bool _beginSPI(uint8_t opcode); + bool _noSuspend(void); + bool _notBusy(uint32_t timeout = BUSY_TIMEOUT); + bool _notPrevWritten(uint32_t address, uint32_t size = 1); + bool _writeEnable(uint32_t timeout = 10L); + bool _writeDisable(void); + bool _getJedecId(void); + bool _getManId(uint8_t *b1, uint8_t *b2); + bool _getSFDP(void); + bool _chipID(void); + bool _transferAddress(void); + bool _addressCheck(uint32_t address, uint32_t size = 1); + uint8_t _nextByte(uint8_t data = NULLBYTE); + uint16_t _nextInt(uint16_t = NULLINT); + void _nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size); + uint8_t _readStat1(void); + uint8_t _readStat2(void); + uint32_t _getAddress(uint16_t page_number, uint8_t offset = 0); + template bool _writeErrorCheck(uint32_t address, const T& value); + //-------------------------------------------Private variables------------------------------------------// + #ifdef SPI_HAS_TRANSACTION + SPISettings _settings; + #endif + volatile uint8_t *cs_port; + + #if !defined (BOARD_RTL8195A) + uint8_t csPin; + #else + // Object declaration for the GPIO HAL type for csPin - @boseji 02.03.17 + gpio_t csPin; + #endif + + bool pageOverflow, SPIBusState; + uint8_t cs_mask, errorcode, state, _SPCR, _SPSR; + struct chipID { + uint8_t manufacturerID; + uint8_t memoryTypeID; + uint8_t capacityID; + uint16_t supported; + uint32_t sfdp; + uint32_t capacity; + uint32_t eraseTime; + }; + chipID _chip; + uint32_t currentAddress, _currentAddress = 0; + const uint8_t _capID[11] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x43}; + const uint32_t _memSize[11] = {64L * K, 128L * K, 256L * K, 512L * K, 1L * M, 2L * M, 4L * M, 8L * M, + 16L * M, 32L * M, 8L * M}; + const uint32_t _eraseTime[11] = {1L * S, 2L * S, 2L * S, 4L * S, 6L * S, 10L * S, 15L * S, 100L * S, 200L * S, 400L * S, 50L}; //Erase time in milliseconds +}; + +//--------------------------------------------Templates-------------------------------------------// + +// Writes any type of data to a specific location in the flash memory. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to maxAddress +// 2. T& value --> Variable to write data from +// 4. errorCheck --> Turned on by default. Checks for writing errors +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. const T& value --> Variable with the data to be written +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +// Variant A +template bool SPIFlash::writeAnything(uint32_t address, const T& value, bool errorCheck) { + if (!_prep(PAGEPROG, address, sizeof(value))) { + return false; + } + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t length = sizeof(value); + + //if (maxBytes > length) { + uint32_t writeBufSz; + uint16_t data_offset = 0; + const uint8_t* p = ((const uint8_t*)(const void*)&value); + + if (!SPIBusState) { + _startSPIBus(); + } + while (length > 0) + { + writeBufSz = (length<=maxBytes) ? length : maxBytes; + + if(!_notBusy() || !_writeEnable()){ + return false; + } + + CHIP_SELECT + (void)xfer(PAGEPROG); + _transferAddress(); + + for (uint16_t i = 0; i < writeBufSz; ++i) { + _nextByte(*p++); + } + _currentAddress += writeBufSz; + data_offset += writeBufSz; + length -= writeBufSz; + maxBytes = 256; // Now we can do up to 256 bytes per loop + CHIP_DESELECT + } + + if (!errorCheck) { + _endSPI(); + return true; + } + else { + return _writeErrorCheck(address, value); + } +} +// Variant B +template bool SPIFlash::writeAnything(uint16_t page_number, uint8_t offset, const T& value, bool errorCheck) { + uint32_t address = _getAddress(page_number, offset); + return writeAnything(address, value, errorCheck); +} + +// Reads any type of data from a specific location in the flash memory. +// Has two variants: +// A. Takes two arguments - +// 1. address --> Any address from 0 to maxAddress +// 2. T& value --> Variable to return data into +// 2. fastRead --> defaults to false - executes _beginFastRead() if set to true +// B. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. T& value --> Variable to return data into +// 3. fastRead --> defaults to false - executes _beginFastRead() if set to true +// Variant A +template bool SPIFlash::readAnything(uint32_t address, T& value, bool fastRead) { + if (!_prep(READDATA, address, sizeof(value))) + return false; + + uint8_t* p = (uint8_t*)(void*)&value; + if(!fastRead) + _beginSPI(READDATA); + else + _beginSPI(FASTREAD); + for (uint16_t i = 0; i < sizeof(value); i++) { + *p++ =_nextByte(); + } + _endSPI(); + return true; +} +// Variant B +template bool SPIFlash::readAnything(uint16_t page_number, uint8_t offset, T& value, bool fastRead) +{ + uint32_t address = _getAddress(page_number, offset); + return readAnything(address, value, fastRead); +} + +// Private template to check for errors in writing to flash memory +template bool SPIFlash::_writeErrorCheck(uint32_t address, const T& value) { +if (!_prep(READDATA, address, sizeof(value)) && !_notBusy()) { + return false; +} + + const uint8_t* p = (const uint8_t*)(const void*)&value; + _beginSPI(READDATA); + uint8_t _v; + for(uint16_t i = 0; i < sizeof(value);i++) + { +#if defined (ARDUINO_ARCH_SAM) + if(*p++ != _dueSPIRecByte()) + { + return false; + } +#else + if(*p++ != _nextByte()) + { + errorcode = ERRORCHKFAIL; + #ifdef RUNDIAGNOSTIC + _troubleshoot(); + #endif + return false; + } +#endif + } + _endSPI(); + return true; +} + +#endif // _SPIFLASH_H_ diff --git a/arduino_libraries/SPIMemory-2.6.0/src/defines.h b/arduino_libraries/SPIMemory-2.6.0/src/defines.h new file mode 100644 index 0000000..3dd9da0 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/src/defines.h @@ -0,0 +1,191 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 19/05/2015 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Common Instructions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +#define MANID 0x90 +#define PAGEPROG 0x02 +#define READDATA 0x03 +#define FASTREAD 0x0B +#define WRITEDISABLE 0x04 +#define READSTAT1 0x05 +#define READSTAT2 0x35 +#define WRITESTAT 0x01 +#define WRITEENABLE 0x06 +#define SECTORERASE 0x20 +#define BLOCK32ERASE 0x52 +#define CHIPERASE 0xC7 +#define SUSPEND 0x75 +#define ID 0x90 +#define RESUME 0x7A +#define JEDECID 0x9F +#define RELEASE 0xAB +#define POWERDOWN 0xB9 +#define BLOCK64ERASE 0xD8 +#define READSFDP 0x5A + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// General size definitions // +// B = Bytes; KB = Kilo bits; MB = Mega bits // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#define B1 1L +#define B2 2L +#define B4 4L +#define B8 8L +#define B16 16L +#define B32 32L +#define B64 64L +#define B80 80L +#define B128 128L +#define B256 256L +#define B512 512L +#define KB1 B1 * K +#define KB2 B2 * K +#define KB4 B4 * K +#define KB8 B8 * K +#define KB16 B16 * K +#define KB32 B32 * K +#define KB64 B64 * K +#define KB128 B128 * K +#define KB256 B256 * K +#define KB512 B512 * K +#define MB1 B1 * M +#define MB2 B2 * M +#define MB4 B4 * M +#define MB8 B8 * M +#define MB16 B16 * M +#define MB32 B32 * M +#define MB64 B64 * M +#define MB128 B128 * M +#define MB256 B256 * M +#define MB512 B512 * M +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Chip specific instructions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + + //~~~~~~~~~~~~~~~~~~~~~~~~~ Winbond ~~~~~~~~~~~~~~~~~~~~~~~~~// + #define WINBOND_MANID 0xEF + #define PAGESIZE 0x100 + + //~~~~~~~~~~~~~~~~~~~~~~~~ Microchip ~~~~~~~~~~~~~~~~~~~~~~~~// + #define MICROCHIP_MANID 0xBF +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Definitions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +#define BUSY 0x01 +#if defined (ARDUINO_ARCH_ESP32) +#define SPI_CLK 20000000 +#else +#define SPI_CLK 104000000 //Hex equivalent of 104MHz +#endif +#define WRTEN 0x02 +#define SUS 0x80 +#define WSE 0x04 +#define WSP 0x08 +#define DUMMYBYTE 0xEE +#define NULLBYTE 0x00 +#define NULLINT 0x0000 +#define NO_CONTINUE 0x00 +#define PASS 0x01 +#define FAIL 0x00 +#define NOOVERFLOW false +#define NOERRCHK false +#define VERBOSE true +#if defined (SIMBLEE) +#define BUSY_TIMEOUT 100L +#else +#define BUSY_TIMEOUT 10L +#endif +#define arrayLen(x) (sizeof(x) / sizeof(*x)) +#define lengthOf(x) (sizeof(x))/sizeof(byte) +#define K 1024L +#define M K * K +#define S 1000L + +#if defined (ARDUINO_ARCH_ESP8266) +#define CS 15 +#elif defined (ARDUINO_ARCH_SAMD) +#define CS 10 +#elif defined __AVR_ATtiny85__ +#define CS 5 +/********************************************************************************************* +// Declaration of the Default Chip select pin name for RTL8195A +// Note: This has been shifted due to a bug identified in the HAL layer SPI driver +// @ref http://www.amebaiot.com/en/questions/forum/facing-issues-with-spi-interface-to-w25q32/ +// Note: Please use any pin other than GPIOC_0 which is the D10 marked in the kit +// Original edit by @boseji 02.03.17 +// Modified by Prajwal Bhattaram 14.4.17 +**********************************************************************************************/ +#elif defined (BOARD_RTL8195A) +#define CS PC_4 +#else +#define CS SS +#endif + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Arduino Due DMA definitions // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Use SAM3X DMAC if nonzero +#define USE_SAM3X_DMAC 1 +// Use extra Bus Matrix arbitration fix if nonzero +#define USE_SAM3X_BUS_MATRIX_FIX 0 +// Time in ms for DMA receive timeout +#define SAM3X_DMA_TIMEOUT 100 +// chip select register number +#define SPI_CHIP_SEL 3 +// DMAC receive channel +#define SPI_DMAC_RX_CH 1 +// DMAC transmit channel +#define SPI_DMAC_TX_CH 0 +// DMAC Channel HW Interface Number for SPI TX. +#define SPI_TX_IDX 1 +// DMAC Channel HW Interface Number for SPI RX. +#define SPI_RX_IDX 2 +// Set DUE SPI clock div (any integer from 2 - 255) +#define DUE_SPI_CLK 2 +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// List of Error codes // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + + #define SUCCESS 0x00 + #define CALLBEGIN 0x01 + #define UNKNOWNCHIP 0x02 + #define UNKNOWNCAP 0x03 + #define CHIPBUSY 0x04 + #define OUTOFBOUNDS 0x05 + #define CANTENWRITE 0x06 + #define PREVWRITTEN 0x07 + #define LOWRAM 0x08 + #define SYSSUSPEND 0x09 + #define UNSUPPORTED 0x0A + #define ERRORCHKFAIL 0x0B + #define NORESPONSE 0x0C + #define UNKNOWNERROR 0xFE + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// diff --git a/arduino_libraries/SPIMemory-2.6.0/src/troubleshoot.cpp b/arduino_libraries/SPIMemory-2.6.0/src/troubleshoot.cpp new file mode 100644 index 0000000..6255150 --- /dev/null +++ b/arduino_libraries/SPIMemory-2.6.0/src/troubleshoot.cpp @@ -0,0 +1,184 @@ +/* Arduino SPIFlash Library v.2.6.0 + * Copyright (C) 2017 by Prajwal Bhattaram + * Created by Prajwal Bhattaram - 14/11/2016 + * Modified by @boseji - 02/03/2017 + * Modified by Prajwal Bhattaram - 14/04/2017 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * Winbond NOR flash memory modules. In its current form it enables reading + * and writing individual data variables, structs and arrays from and to various locations; + * reading and writing pages; continuous read functions; sector, block and chip erase; + * suspending and resuming programming/erase and powering down for low power operation. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ + + #include "SPIFlash.h" + + //Subfunctions for troubleshooting function + void SPIFlash::_printErrorCode(void) { + Serial.print("Error code: 0x"); + if (errorcode < 0x10) { + Serial.print("0"); + } + Serial.println(errorcode, HEX); + } + + void SPIFlash::_printSupportLink(void) { + Serial.print("If this does not help resolve/clarify this issue, "); + Serial.println("please raise an issue at http://www.github.com/Marzogh/SPIFlash/issues with the details of what your were doing when this error occurred"); + } + //Troubleshooting function. Called when #ifdef RUNDIAGNOSTIC is uncommented at the top of this file. + void SPIFlash::_troubleshoot(void) { + + switch (errorcode) { + case SUCCESS: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Action completed successfully"); + #endif + break; + + case NORESPONSE: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Check your wiring. Flash chip is non-responsive."); + _printSupportLink(); + #endif + break; + + case CALLBEGIN: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("*constructor_of_choice*.begin() was not called in void setup()"); + _printSupportLink(); + #endif + break; + + case UNKNOWNCHIP: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + Serial.print("Error code: 0x0"); + Serial.println(UNKNOWNCHIP, HEX); + #else + Serial.println("Unable to identify chip. Are you sure this chip is supported?"); + _printSupportLink(); + #endif + Serial.println("Chip details:"); + Serial.print("manufacturer ID: 0x"); Serial.println(_chip.manufacturerID, HEX); + Serial.print("capacity ID: 0x");Serial.println(_chip.memoryTypeID, HEX); + Serial.print("device ID: 0x");Serial.println(_chip.capacityID, HEX); + break; + + case UNKNOWNCAP: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unable to identify capacity. Is this chip officially supported? If not, please define a `CAPACITY` constant and include it in flash.begin(CAPACITY)."); + _printSupportLink(); + #endif + break; + + case CHIPBUSY: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Chip is busy."); + Serial.println("Make sure all pins have been connected properly"); + _printSupportLink(); + #endif + break; + + case OUTOFBOUNDS: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Page overflow has been disabled and the address called exceeds the memory"); + _printSupportLink(); + #endif + break; + + case CANTENWRITE: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unable to Enable Writing to chip."); + Serial.println("Please make sure the HOLD & WRITEPROTECT pins are pulled up to VCC"); + _printSupportLink(); + #endif + break; + + case PREVWRITTEN: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("This sector already contains data."); + Serial.println("Please make sure the sectors being written to are erased."); + _printSupportLink(); + #endif + break; + + case LOWRAM: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("You are running low on SRAM. Please optimise your program for better RAM usage"); + /*#if defined (ARDUINO_ARCH_SAM) + Serial.print("Current Free SRAM: "); + Serial.println(freeRAM()); + #endif*/ + _printSupportLink(); + #endif + break; + + case SYSSUSPEND: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unable to suspend/resume operation."); + _printSupportLink(); + #endif + break; + + case UNSUPPORTED: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("This function is not supported by the current flash IC."); + _printSupportLink(); + #endif + break; + + case ERRORCHKFAIL: +#if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); +#else + Serial.println("Write Function has failed errorcheck."); + _printSupportLink(); +#endif + break; + + default: + #if defined (ARDUINO_ARCH_AVR) || defined (__AVR_ATtiny85__) + _printErrorCode(); + #else + Serial.println("Unknown error"); + _printSupportLink(); + #endif + break; + } + } diff --git a/arduino_libraries/readme.txt b/arduino_libraries/readme.txt new file mode 100644 index 0000000..96ce674 --- /dev/null +++ b/arduino_libraries/readme.txt @@ -0,0 +1 @@ +For information on installing libraries, see: http://www.arduino.cc/en/Guide/Libraries diff --git a/peripheral_tests/Euler_Streaming/Euler_Streaming.ino b/peripheral_tests/Euler_Streaming/Euler_Streaming.ino new file mode 100644 index 0000000..91d407d --- /dev/null +++ b/peripheral_tests/Euler_Streaming/Euler_Streaming.ino @@ -0,0 +1,89 @@ +/* + *************************************************************************** + + Euler_Streaming.pde - part of sample SW for using BNO055 with Arduino + + (C) All rights reserved by ROBERT BOSCH GMBH + + Copyright (C) 2014 Bosch Sensortec GmbH + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + **************************************************************************/ +/* Date: 2014/01/07 + Revision: 1.2 + +*/ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 100) //To stream at 10Hz without using additional timers + { + lastTime = millis(); + + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} diff --git a/peripheral_tests/flashTest/flashTest.ino b/peripheral_tests/flashTest/flashTest.ino new file mode 100644 index 0000000..c92a56e --- /dev/null +++ b/peripheral_tests/flashTest/flashTest.ino @@ -0,0 +1,62 @@ +#include "Wire.h" +#include +#include +#include + +//This is for the SPI Flash chip +#define CHIPSIZE MB64 +SPIFlash flash(1); +uint8_t pageBuffer[256]; +String serialCommand; +char printBuffer[128]; +uint16_t page; +uint8_t offset, dataByte; +uint16_t dataInt; +String inputString, outputString; + +void setup() { + Serial.begin(9600); + + // put your setup code here, to run once: +Serial.println("Looking for the SPI flash chip. Standby..."); + if (flash.begin(CHIPSIZE)){ + flash.eraseChip(); + delay(500); + Serial.println("Great, looks like there's one here!"); + Serial.println("Here's some info about it..."); + Serial.println(); + delay(2500); + uint8_t b1, b2, b3; + uint32_t JEDEC = flash.getJEDECID(); + b1 = (JEDEC >> 16); + b2 = (JEDEC >> 8); + b3 = (JEDEC >> 0); + sprintf(printBuffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3); + Serial.println(printBuffer); + //clearprintBuffer(); + sprintf(printBuffer, "JEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); + Serial.println(); + Serial.println(); + delay(1000); + } + else{ + delay(500); + Serial.println(); + Serial.println("Hmmm, looks like there's no flash chip here. Try checking the following:"); + Serial.println(" - Is the chip soldered on in the correct orientation?"); + Serial.println(" - Is the correct chip select pin defined in the SPIFlash constructor?"); + Serial.println(" - Is the correct CHIPSIZE defined?"); + delay(5000); + Serial.println(); + Serial.println("Proceding with the rest of the startup process"); + delay(1000); + Serial.println(); + } + +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/peripheral_tests/sdTest/sdTest.ino b/peripheral_tests/sdTest/sdTest.ino new file mode 100644 index 0000000..ff6dc3f --- /dev/null +++ b/peripheral_tests/sdTest/sdTest.ino @@ -0,0 +1,51 @@ +#include +#include +#include + +Sd2Card card; +SdVolume volume; +SdFile root; +const int SDchipSelect = 16; + +void setup() { + delay(2000); + + //Now the SD card + Serial.print("Looking for an SD card. Standby..."); + if (!card.init(SPI_HALF_SPEED, SDchipSelect)) { + Serial.println("Looks like there's no card here! Trying checking the following:"); + Serial.println("* is a card inserted?"); + Serial.println("* is your soldering correct?"); + Serial.println("* is the chipselect pin correct?"); + Serial.println(); + Serial.println("We'll continue with the startup without the SD card now :("); + } else { + Serial.println("Found an SD card! Here's some information about it."); + delay(1000); + Serial.println(); + Serial.print("Card type: "); + switch (card.type()) { + case SD_CARD_TYPE_SD1: + Serial.println("SD1"); + break; + case SD_CARD_TYPE_SD2: + Serial.println("SD2"); + break; + case SD_CARD_TYPE_SDHC: + Serial.println("SDHC"); + break; + default: + Serial.println("Unknown"); + } + if (!volume.init(card)) { + Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + while (1); + } + +} +} + +void loop() { + // put your main code here, to run repeatedly: + +}