/ * @brief * Initialize the accelerometer * * @details * * @note * * @return * Error code ******************************************************************************/
| 741 | * Error code |
| 742 | ******************************************************************************/ |
| 743 | rt_err_t efm_accel_init(void) |
| 744 | { |
| 745 | rt_err_t ret; |
| 746 | |
| 747 | ret = RT_EOK; |
| 748 | do |
| 749 | { |
| 750 | /* Find ADC device */ |
| 751 | accel = rt_device_find(ACCEL_USING_DEVICE_NAME); |
| 752 | if (accel == RT_NULL) |
| 753 | { |
| 754 | accel_debug("Accel err: Can't find device: %s!\n", ACCEL_USING_DEVICE_NAME); |
| 755 | ret = -RT_ERROR; |
| 756 | break; |
| 757 | } |
| 758 | accel_debug("Accel: Find device %s\n", ACCEL_USING_DEVICE_NAME); |
| 759 | |
| 760 | /* --------- ADC interface --------- */ |
| 761 | #if (EFM32_USING_ACCEL == EFM32_INTERFACE_ADC) |
| 762 | ADC_InitScan_TypeDef scanInit = ADC_INITSCAN_DEFAULT; |
| 763 | |
| 764 | #if defined(EFM32_GXXX_DK) |
| 765 | /* Enable accelerometer */ |
| 766 | DVK_enablePeripheral(DVK_ACCEL); |
| 767 | /* Select g-range */ |
| 768 | #if (ACCEL_G_SELECT == 0) |
| 769 | DVK_disablePeripheral(DVK_ACCEL_GSEL); |
| 770 | #elif (ACCEL_G_SELECT == 1) |
| 771 | DVK_enablePeripheral(DVK_ACCEL_GSEL); |
| 772 | #else |
| 773 | #error "Wrong value for ACCEL_G_SELECT" |
| 774 | #endif |
| 775 | #endif |
| 776 | /* Init ADC for scan mode */ |
| 777 | scanInit.reference = adcRefVDD; |
| 778 | scanInit.input = ACCEL_X_ADC_CH | ACCEL_Y_ADC_CH | ACCEL_Z_ADC_CH; |
| 779 | |
| 780 | control.scan.init = &scanInit; |
| 781 | if ((ret = accel->control(accel, RT_DEVICE_CTRL_ADC_MODE, \ |
| 782 | (void *)&control)) != RT_EOK) |
| 783 | { |
| 784 | break; |
| 785 | } |
| 786 | |
| 787 | /* --------- IIC interface --------- */ |
| 788 | #elif (EFM32_USING_ACCEL == EFM32_INTERFACE_IIC) |
| 789 | rt_uint8_t cmd[2]; |
| 790 | |
| 791 | /* Initialize */ |
| 792 | if ((ret = accel->control(accel, RT_DEVICE_CTRL_IIC_SETTING, \ |
| 793 | (void *)&control)) != RT_EOK) |
| 794 | { |
| 795 | break; |
| 796 | } |
| 797 | |
| 798 | if (efm_accel_config( |
| 799 | ACCEL_MODE_MEASUREMENT | ACCEL_RANGE_2G, |
| 800 | EFM32_NO_DATA, |
no test coverage detected