stmhal/accel: Raise an exception if the accel couldn't be initialised.

On PYBLITEv1.0 there is no accelerometer and in this case the Accel()
constructor should not silently succeed.
pull/2038/head
Damien George 2016-04-29 15:43:15 +01:00
rodzic b3bc2ee1b9
commit 12c61ddddd
1 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -89,15 +89,17 @@ STATIC void accel_start(void) {
HAL_StatusTypeDef status;
//printf("IsDeviceReady\n");
for (int i = 0; i < 10; i++) {
status = HAL_I2C_IsDeviceReady(&I2CHandle1, MMA_ADDR, 10, 200);
//printf(" got %d\n", status);
if (status == HAL_OK) {
break;
}
}
if (status != HAL_OK) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "accelerometer not found"));
}
// set MMA to active mode
uint8_t data[1] = {1}; // active mode
status = HAL_I2C_Mem_Write(&I2CHandle1, MMA_ADDR, MMA_REG_MODE, I2C_MEMADD_SIZE_8BIT, data, 1, 200);