mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-30 06:34:58 +03:00 
			
		
		
		
	lsm303agr: fix some comments, move helper macros out of defs.h
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
		| @@ -32,6 +32,17 @@ | |||||||
|  |  | ||||||
| #include "lsm303agr.h" | #include "lsm303agr.h" | ||||||
|  |  | ||||||
|  | // some useful macros to save on typing and text wrapping | ||||||
|  | #undef _SHIFT | ||||||
|  | #define _SHIFT(x) (_LSM303AGR_##x##_SHIFT) | ||||||
|  |  | ||||||
|  | #undef _MASK | ||||||
|  | #define _MASK(x) (_LSM303AGR_##x##_MASK) | ||||||
|  |  | ||||||
|  | #undef _SHIFTMASK | ||||||
|  | #define _SHIFTMASK(x) (_MASK(x) << _SHIFT(x)) | ||||||
|  |  | ||||||
|  |  | ||||||
| // init | // init | ||||||
| lsm303agr_context lsm303agr_init(int bus, int acc_addr, int mag_addr) | lsm303agr_context lsm303agr_init(int bus, int acc_addr, int mag_addr) | ||||||
| { | { | ||||||
| @@ -112,7 +123,7 @@ lsm303agr_context lsm303agr_init(int bus, int acc_addr, int mag_addr) | |||||||
|  |  | ||||||
|         if (chipID != LSM303AGR_CHIPID_MAG) |         if (chipID != LSM303AGR_CHIPID_MAG) | ||||||
|         { |         { | ||||||
|             printf("%s: invalid accelerometer chip id: %02x.  Expected %02x\n", |             printf("%s: invalid magnetometer chip id: %02x.  Expected %02x\n", | ||||||
|                    __FUNCTION__, chipID, LSM303AGR_CHIPID_MAG); |                    __FUNCTION__, chipID, LSM303AGR_CHIPID_MAG); | ||||||
|             lsm303agr_close(dev); |             lsm303agr_close(dev); | ||||||
|             return NULL; |             return NULL; | ||||||
| @@ -157,10 +168,10 @@ upm_result_t lsm303agr_devinit(const lsm303agr_context dev, | |||||||
|         // enable temp compensation and continuous mode |         // enable temp compensation and continuous mode | ||||||
|         uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CFG_REG_A_M); |         uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CFG_REG_A_M); | ||||||
|  |  | ||||||
|         reg &= ~_LSM303AGR_SHIFTMASK(CFG_REG_A_M_MD); |         reg &= ~_SHIFTMASK(CFG_REG_A_M_MD); | ||||||
|         reg |= LSM303AGR_CFG_REG_A_M_COMP_TEMP_EN; |         reg |= LSM303AGR_CFG_REG_A_M_COMP_TEMP_EN; | ||||||
|         reg |= (LSM303AGR_CFG_A_M_MD_CONTINUOUS |         reg |= (LSM303AGR_CFG_A_M_MD_CONTINUOUS | ||||||
|                 << _LSM303AGR_SHIFT(CFG_REG_A_M_MD)); |                 << _SHIFT(CFG_REG_A_M_MD)); | ||||||
|  |  | ||||||
|         if (lsm303agr_write_reg(dev, LSM303AGR_REG_CFG_REG_A_M, reg)) |         if (lsm303agr_write_reg(dev, LSM303AGR_REG_CFG_REG_A_M, reg)) | ||||||
|         { |         { | ||||||
| @@ -206,9 +217,9 @@ upm_result_t lsm303agr_devinit(const lsm303agr_context dev, | |||||||
|  |  | ||||||
|         // enable temperature measurement |         // enable temperature measurement | ||||||
|         reg = lsm303agr_read_reg(dev, LSM303AGR_REG_TEMP_CFG_REG_A); |         reg = lsm303agr_read_reg(dev, LSM303AGR_REG_TEMP_CFG_REG_A); | ||||||
|         reg &= ~_LSM303AGR_SHIFTMASK(TEMP_CFG_REG_A_TEMP_EN); |         reg &= ~_SHIFTMASK(TEMP_CFG_REG_A_TEMP_EN); | ||||||
|         reg |= (LSM303AGR_TEMP_EN_ON |         reg |= (LSM303AGR_TEMP_EN_ON | ||||||
|                 << _LSM303AGR_SHIFT(TEMP_CFG_REG_A_TEMP_EN)); |                 << _SHIFT(TEMP_CFG_REG_A_TEMP_EN)); | ||||||
|  |  | ||||||
|         if (lsm303agr_write_reg(dev, LSM303AGR_REG_TEMP_CFG_REG_A, reg)) |         if (lsm303agr_write_reg(dev, LSM303AGR_REG_TEMP_CFG_REG_A, reg)) | ||||||
|         { |         { | ||||||
| @@ -311,8 +322,8 @@ upm_result_t lsm303agr_set_full_scale(const lsm303agr_context dev, | |||||||
|     { |     { | ||||||
|         uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CTRL_REG4_A); |         uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CTRL_REG4_A); | ||||||
|  |  | ||||||
|         reg &= ~_LSM303AGR_SHIFTMASK(CTRL_REG4_A_FS); |         reg &= ~_SHIFTMASK(CTRL_REG4_A_FS); | ||||||
|         reg |= (fs << _LSM303AGR_SHIFT(CTRL_REG4_A_FS)); |         reg |= (fs << _SHIFT(CTRL_REG4_A_FS)); | ||||||
|  |  | ||||||
|         if (lsm303agr_write_reg(dev, LSM303AGR_REG_CTRL_REG4_A, reg)) |         if (lsm303agr_write_reg(dev, LSM303AGR_REG_CTRL_REG4_A, reg)) | ||||||
|             return UPM_ERROR_OPERATION_FAILED; |             return UPM_ERROR_OPERATION_FAILED; | ||||||
| @@ -569,8 +580,8 @@ upm_result_t lsm303agr_set_acc_odr(const lsm303agr_context dev, | |||||||
|         return UPM_ERROR_NO_RESOURCES; |         return UPM_ERROR_NO_RESOURCES; | ||||||
|  |  | ||||||
|     uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CTRL_REG1_A); |     uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CTRL_REG1_A); | ||||||
|     reg &= ~_LSM303AGR_SHIFTMASK(CTRL_REG1_A_ODR); |     reg &= ~_SHIFTMASK(CTRL_REG1_A_ODR); | ||||||
|     reg |= (odr << _LSM303AGR_SHIFT(CTRL_REG1_A_ODR)); |     reg |= (odr << _SHIFT(CTRL_REG1_A_ODR)); | ||||||
|  |  | ||||||
|     if (lsm303agr_write_reg(dev, LSM303AGR_REG_CTRL_REG1_A, reg)) |     if (lsm303agr_write_reg(dev, LSM303AGR_REG_CTRL_REG1_A, reg)) | ||||||
|         return UPM_ERROR_OPERATION_FAILED; |         return UPM_ERROR_OPERATION_FAILED; | ||||||
| @@ -587,8 +598,8 @@ upm_result_t lsm303agr_set_mag_odr(const lsm303agr_context dev, | |||||||
|         return UPM_ERROR_NO_RESOURCES; |         return UPM_ERROR_NO_RESOURCES; | ||||||
|  |  | ||||||
|     uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CFG_REG_A_M); |     uint8_t reg = lsm303agr_read_reg(dev, LSM303AGR_REG_CFG_REG_A_M); | ||||||
|     reg &= ~_LSM303AGR_SHIFTMASK(CFG_REG_A_M_ODR); |     reg &= ~_SHIFTMASK(CFG_REG_A_M_ODR); | ||||||
|     reg |= (odr << _LSM303AGR_SHIFT(CFG_REG_A_M_ODR)); |     reg |= (odr << _SHIFT(CFG_REG_A_M_ODR)); | ||||||
|  |  | ||||||
|     if (lsm303agr_write_reg(dev, LSM303AGR_REG_CFG_REG_A_M, reg)) |     if (lsm303agr_write_reg(dev, LSM303AGR_REG_CFG_REG_A_M, reg)) | ||||||
|         return UPM_ERROR_OPERATION_FAILED; |         return UPM_ERROR_OPERATION_FAILED; | ||||||
|   | |||||||
| @@ -181,7 +181,7 @@ extern "C" { | |||||||
|      * mode set at high resolution. |      * mode set at high resolution. | ||||||
|      * |      * | ||||||
|      * @param dev The device context |      * @param dev The device context | ||||||
|      * @param usage One of the LSM303AGR_POWER_MODE_T values.  This |      * @param mode One of the LSM303AGR_POWER_MODE_T values.  This | ||||||
|      * parameter is passed to a call to lsm303agr_set_power_mode() and |      * parameter is passed to a call to lsm303agr_set_power_mode() and | ||||||
|      * will set the appropriate mode for both the accelerometer and |      * will set the appropriate mode for both the accelerometer and | ||||||
|      * magnetometer.  The default set by the constructor is |      * magnetometer.  The default set by the constructor is | ||||||
| @@ -196,7 +196,7 @@ extern "C" { | |||||||
|      * power, normal, and high resolution. |      * power, normal, and high resolution. | ||||||
|      * |      * | ||||||
|      * @param dev The device context |      * @param dev The device context | ||||||
|      * @param usage One of the LSM303AGR_POWER_MODE_T values.  The |      * @param mode One of the LSM303AGR_POWER_MODE_T values.  The | ||||||
|      * default set at initialization time is |      * default set at initialization time is | ||||||
|      * LSM303AGR_POWER_HIGH_RESOLUTION. |      * LSM303AGR_POWER_HIGH_RESOLUTION. | ||||||
|      * @return UPM result |      * @return UPM result | ||||||
| @@ -208,7 +208,7 @@ extern "C" { | |||||||
|      * Set the accelerometer (acc) output data rate (odr) |      * Set the accelerometer (acc) output data rate (odr) | ||||||
|      * |      * | ||||||
|      * @param dev The device context |      * @param dev The device context | ||||||
|      * @param usage One of the LSM303AGR_A_ODR_T values.  The default |      * @param odr One of the LSM303AGR_A_ODR_T values.  The default | ||||||
|      * set at initialization time is LSM303AGR_A_ODR_100HZ. |      * set at initialization time is LSM303AGR_A_ODR_100HZ. | ||||||
|      * @return UPM result |      * @return UPM result | ||||||
|      */ |      */ | ||||||
| @@ -219,7 +219,7 @@ extern "C" { | |||||||
|      * Set the magnetometer (mag) output data rate (odr) |      * Set the magnetometer (mag) output data rate (odr) | ||||||
|      * |      * | ||||||
|      * @param dev The device context |      * @param dev The device context | ||||||
|      * @param usage One of the LSM303AGR_CFG_A_M_ODR_T values.  The default |      * @param odr One of the LSM303AGR_CFG_A_M_ODR_T values.  The default | ||||||
|      * set at initialization time is LSM303AGR_CFG_A_M_ODR_10HZ. |      * set at initialization time is LSM303AGR_CFG_A_M_ODR_10HZ. | ||||||
|      * @return UPM result |      * @return UPM result | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -194,7 +194,7 @@ namespace upm { | |||||||
|          * Set an operating power mode.  There are 3 modes available: low |          * Set an operating power mode.  There are 3 modes available: low | ||||||
|          * power, normal, and high resolution. |          * power, normal, and high resolution. | ||||||
|          * |          * | ||||||
|          * @param usage One of the LSM303AGR_POWER_MODE_T values.  The |          * @param mode One of the LSM303AGR_POWER_MODE_T values.  The | ||||||
|          * default set at initialization time is |          * default set at initialization time is | ||||||
|          * LSM303AGR_POWER_HIGH_RESOLUTION. |          * LSM303AGR_POWER_HIGH_RESOLUTION. | ||||||
|          * @throws std::runtime_error on failure |          * @throws std::runtime_error on failure | ||||||
| @@ -204,7 +204,7 @@ namespace upm { | |||||||
|         /** |         /** | ||||||
|          * Set the accelerometer output data rate (ODR) |          * Set the accelerometer output data rate (ODR) | ||||||
|          * |          * | ||||||
|          * @param usage One of the LSM303AGR_A_ODR_T values.  The default |          * @param odr One of the LSM303AGR_A_ODR_T values.  The default | ||||||
|          * set at initialization time is LSM303AGR_A_ODR_100HZ. |          * set at initialization time is LSM303AGR_A_ODR_100HZ. | ||||||
|          * @throws std::runtime_error on failure |          * @throws std::runtime_error on failure | ||||||
|          */ |          */ | ||||||
| @@ -213,7 +213,7 @@ namespace upm { | |||||||
|         /** |         /** | ||||||
|          * Set the magnetometer output data rate (ODR) |          * Set the magnetometer output data rate (ODR) | ||||||
|          * |          * | ||||||
|          * @param usage One of the LSM303AGR_CFG_A_M_ODR_T values. |          * @param odr One of the LSM303AGR_CFG_A_M_ODR_T values. | ||||||
|          * The default set at initialization time is |          * The default set at initialization time is | ||||||
|          * LSM303AGR_CFG_A_M_ODR_10HZ. |          * LSM303AGR_CFG_A_M_ODR_10HZ. | ||||||
|          * @throws std::runtime_error on failure |          * @throws std::runtime_error on failure | ||||||
|   | |||||||
| @@ -669,17 +669,6 @@ extern "C" { | |||||||
|         LSM303AGR_POWER_HIGH_RESOLUTION           = 2, |         LSM303AGR_POWER_HIGH_RESOLUTION           = 2, | ||||||
|     } LSM303AGR_POWER_MODE_T; |     } LSM303AGR_POWER_MODE_T; | ||||||
|  |  | ||||||
|     // some useful macros to save on typing and text wrapping |  | ||||||
| #define _LSM303AGR_SHIFT(x) \ |  | ||||||
|     (_LSM303AGR_##x##_SHIFT) |  | ||||||
|  |  | ||||||
| #define _LSM303AGR_MASK(x) \ |  | ||||||
|     (_LSM303AGR_##x##_MASK) |  | ||||||
|  |  | ||||||
| #define _LSM303AGR_SHIFTMASK(x) \ |  | ||||||
|     (_LSM303AGR_MASK(x) << _LSM303AGR_SHIFT(x)) |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jon Trulson
					Jon Trulson