Ejemplo n.º 1
0
/**
  * @brief  deinitializes the M24LR04E
  * @param  None
  * @retval None
  */
void M24LR04E_deinit () 
{
  if(HAL_I2C_DeInit(&I2CHandle) != HAL_OK) {
		get_app_config()->error_code = I2C_ERROR;
    Error_Handler();    
  }
}
/**
  * @brief I2C3 error treatment function
  * @param None
  * @retval None
  */
static void I2Cbar_Error (void)
{
  /* De-initialise the I2C communication BUS */
  HAL_I2C_DeInit(&I2CbarHandle);

  /* Re-Initialise the I2C communication BUS */
  I2Cbar_Init();
}
Ejemplo n.º 3
0
/**
  * @brief  Manages error callback by re-initializing I2C.
  * @param  Addr: I2C Address
  * @retval None
  */
static void I2Cx_Error(uint8_t Addr)
{
  /* De-initialize the I2C comunication bus */
  HAL_I2C_DeInit(&I2cHandle);
  
  /* Re-Initiaize the I2C comunication bus */
  I2Cx_Init();
}
Ejemplo n.º 4
0
/**
  * @brief  Manages error callback by re-initializing I2C.
  * @param  Addr: I2C Address
  * @retval None
  */
static void I2Cx_Error(uint8_t Addr)
{
  /* De-initialize the IOE comunication BUS */
  HAL_I2C_DeInit(&heval_I2c);
  
  /* Re-Initiaize the IOE comunication BUS */
  I2Cx_Init();  
}
/**
  * @brief  I2Cx error treatment function
  */
static void I2Cx_Error(void)
{
  /* De-initialize the SPI communication BUS */
  HAL_I2C_DeInit(&I2cHandle);
  
  /* Re-Initialize the SPI communication BUS */
  I2Cx_Init();
}
Ejemplo n.º 6
0
/**
  * @brief  Manages error callback by re-initializing I2C.
  * @param  None
  * @retval None
  */
static void I2C1_Error(void)
{
  /* De-initialize the I2C communication BUS */
  HAL_I2C_DeInit(&heval_I2c1);
  
  /* Re-Initiaize the I2C communication BUS */
  I2C1_Init();
}
Ejemplo n.º 7
0
/**
  * @brief I2C1 Bus Deinitialization
  * @retval None
  */
static void I2C1_DeInit(void)
{
  if(HAL_I2C_GetState(&heval_I2c1) != HAL_I2C_STATE_RESET)
  {
    /* DeInit the I2C */
    HAL_I2C_DeInit(&heval_I2c1);
    I2C1_MspDeInit(&heval_I2c1);
  }
}
Ejemplo n.º 8
0
/**
 * @brief  Manages error callback by re-initializing I2C
 * @param  Addr I2C Address
 * @retval None
 */
static void I2C_EXPBD_Error(uint8_t Addr)
{
    /* De-initialize the I2C comunication bus */
    HAL_I2C_DeInit(&I2C_EXPBD_Handle);

    /*FIXME: We need to wait a while in order to have I2C that works fine after deinit */
    HAL_Delay(1);

    /* Re-Initiaize the I2C comunication bus */
    I2C_EXPBD_Init();
}
Ejemplo n.º 9
0
void I2C_Reset(void)
{
  HAL_GPIO_WritePin(I2Cx_WAKEUP_GPIO_PORT, I2Cx_WAKEUP_PIN, GPIO_PIN_RESET);

  HAL_I2C_DeInit(&I2cHandle);

  HAL_I2C_Init(&I2cHandle);

  HAL_Delay(5);
  HAL_GPIO_WritePin(I2Cx_WAKEUP_GPIO_PORT, I2Cx_WAKEUP_PIN, GPIO_PIN_SET);
  HAL_Delay(400);
}
Ejemplo n.º 10
0
void i2c_deinit(I2C_HandleTypeDef *i2c) {
    HAL_I2C_DeInit(i2c);
    if (0) {
#if MICROPY_HW_ENABLE_I2C1
    } else if (i2c->Instance == I2C1) {
        __I2C1_FORCE_RESET();
        __I2C1_RELEASE_RESET();
        __I2C1_CLK_DISABLE();
#endif
    } else if (i2c->Instance == I2C2) {
        __I2C2_FORCE_RESET();
        __I2C2_RELEASE_RESET();
        __I2C2_CLK_DISABLE();
    }
}
Ejemplo n.º 11
0
static int i2c_suspend(struct soc_device *dev, enum suspend_state_t state)
{
	I2C_ID i2cID = (I2C_ID)dev->platform_data;

	hal_i2c_suspending |= (1 << i2cID);

	switch (state) {
	case PM_MODE_SLEEP:
	case PM_MODE_STANDBY:
	case PM_MODE_HIBERNATION:
	case PM_MODE_POWEROFF:
		HAL_I2C_DeInit(i2cID);
		break;
	default:
		break;
	}

	return 0;
}
Ejemplo n.º 12
0
void i2c_deinit(I2C_HandleTypeDef *i2c) {
    HAL_I2C_DeInit(i2c);
    if (0) {
    #if defined(MICROPY_HW_I2C1_SCL)
    } else if (i2c->Instance == I2C1) {
        __I2C1_FORCE_RESET();
        __I2C1_RELEASE_RESET();
        __I2C1_CLK_DISABLE();
        HAL_NVIC_DisableIRQ(I2C1_EV_IRQn);
        HAL_NVIC_DisableIRQ(I2C1_ER_IRQn);
    #endif
    #if defined(MICROPY_HW_I2C2_SCL)
    } else if (i2c->Instance == I2C2) {
        __I2C2_FORCE_RESET();
        __I2C2_RELEASE_RESET();
        __I2C2_CLK_DISABLE();
        HAL_NVIC_DisableIRQ(I2C2_EV_IRQn);
        HAL_NVIC_DisableIRQ(I2C2_ER_IRQn);
    #endif
    #if defined(MICROPY_HW_I2C3_SCL)
    } else if (i2c->Instance == I2C3) {
        __I2C3_FORCE_RESET();
        __I2C3_RELEASE_RESET();
        __I2C3_CLK_DISABLE();
        HAL_NVIC_DisableIRQ(I2C3_EV_IRQn);
        HAL_NVIC_DisableIRQ(I2C3_ER_IRQn);
    #endif
    #if defined(MICROPY_HW_I2C4_SCL)
    } else if (i2c->Instance == I2C4) {
        __HAL_RCC_I2C4_FORCE_RESET();
        __HAL_RCC_I2C4_RELEASE_RESET();
        __HAL_RCC_I2C4_CLK_DISABLE();
        HAL_NVIC_DisableIRQ(I2C4_EV_IRQn);
        HAL_NVIC_DisableIRQ(I2C4_ER_IRQn);
    #endif
    }
}
Ejemplo n.º 13
0
/**
  * @brief  Suspend callback.
  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
{
  U8 i,y;
//  USBD_HID_HandleTypeDef *ptr;
//  ptr = (USBD_HID_HandleTypeDef *)(hUsbDeviceFS.pClassData);
//  GPIO_InitTypeDef GPIO_InitStruct;
  /* Inform USB library that core enters in suspend Mode */
  USBD_LL_Suspend(hpcd->pData);
  /*Enter in STOP mode */
  /* USER CODE BEGIN 2 */
  if (hpcd->Init.low_power_enable)
  {
    //[ slash

//   for (y = COLS; y < COLS+ROWS; y++) {                            // Scan, save, and update the current keyboard state
//     gpio_setDirvalue(matrix[y].port, matrix[y].pin, GPIO_MODE_OUTPUT_PP, GPIO_PIN_SET);
//      for (i = 0; i < 10; i++); 
//    }    
  if (HAL_TIM_Base_Stop_IT(&htim2) != HAL_OK)
  {
    /* Starting Error */
    while(1);
  }       
    HAL_I2CEx_AnalogFilter_Config(&hi2c2, I2C_ANALOGFILTER_DISABLE);
  if  (HAL_I2C_DeInit(&hi2c2)!= HAL_OK) {
    while(1);
  }
    for (i=0;i<3;i++) {
    ((USBD_HID_HandleTypeDef *)&hUsbDeviceFS.pClassData)->state[i] = HID_BUSY;
    }
    HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_RESET);                  // Low to shut down led controller
//    for (i = 0; i < 10; i++);
//    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
//                            |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 
//                            |GPIO_PIN_15;
//    GPIO_InitStruct.Pin = GPIO_PIN_15;
//    GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
//    GPIO_InitStruct.Pull = GPIO_NOPULL;
//    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_2); 
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
//////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);  
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_15);    
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);    
////    HAL_NVIC_SetPriority(EXTI0_1_IRQn, 3, 0);
    HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
////    HAL_NVIC_SetPriority(EXTI2_3_IRQn, 3, 0);
    HAL_NVIC_EnableIRQ(EXTI2_3_IRQn);
//    HAL_NVIC_SetPriority(EXTI4_15_IRQn, 3, 0);
    HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_2); 
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);  
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_15);    
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All); 
////      HAL_NVIC_DisableIRQ(I2C2_IRQn); 
    //]
    for (y = 0; y < COLS; y++) {                             // Scan, save, and update the current keyboard state
     gpio_setDirvalue(matrix[y].port, matrix[y].pin, GPIO_MODE_OUTPUT_PP, GPIO_PIN_RESET);
     for (i = 0; i < 10; i++); 
   }  
    for (y = 0; y < COLS; y++) {                             // Scan, save, and update the current keyboard state
     gpio_setDirvalue(matrix[y].port, matrix[y].pin, GPIO_MODE_OUTPUT_PP, GPIO_PIN_RESET);
     for (i = 0; i < 10; i++); 
   } 
    /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */
//    SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
  }
  /* USER CODE END 2 */
}
Ejemplo n.º 14
0
I2CMaster::~I2CMaster()
{
	HAL_I2C_DeInit(&handle_);
}
Ejemplo n.º 15
0
void I2CMaster::deinit()
{
	HAL_I2C_DeInit(&handle_);
}
Ejemplo n.º 16
0
void i2cInit(I2CDevice device)
{
    /*## Configure the I2C clock source. The clock is derived from the SYSCLK #*/
//    RCC_PeriphCLKInitTypeDef  RCC_PeriphCLKInitStruct;
//    RCC_PeriphCLKInitStruct.PeriphClockSelection = i2cHardwareMap[device].clk;
//    RCC_PeriphCLKInitStruct.I2c1ClockSelection = i2cHardwareMap[device].clk_src;
//    HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);

    switch (device) {
    case I2CDEV_1:
        __HAL_RCC_I2C1_CLK_ENABLE();
        break;
    case I2CDEV_2:
        __HAL_RCC_I2C2_CLK_ENABLE();
        break;
    case I2CDEV_3:
        __HAL_RCC_I2C3_CLK_ENABLE();
        break;
    case I2CDEV_4:
        __HAL_RCC_I2C4_CLK_ENABLE();
        break;
    default:
        break;
    }
    if (device == I2CINVALID)
        return;

    i2cDevice_t *i2c;
    i2c = &(i2cHardwareMap[device]);

    //I2C_InitTypeDef i2cInit;

    IO_t scl = IOGetByTag(i2c->scl);
    IO_t sda = IOGetByTag(i2c->sda);

    IOInit(scl, OWNER_I2C_SCL, RESOURCE_INDEX(device));
    IOInit(sda, OWNER_I2C_SDA, RESOURCE_INDEX(device));

    // Enable RCC
    RCC_ClockCmd(i2c->rcc, ENABLE);


    i2cUnstick(scl, sda);

    // Init pins
#ifdef STM32F7
    IOConfigGPIOAF(scl, IOCFG_I2C, i2c->af);
    IOConfigGPIOAF(sda, IOCFG_I2C, i2c->af);
#else
    IOConfigGPIO(scl, IOCFG_AF_OD);
    IOConfigGPIO(sda, IOCFG_AF_OD);
#endif
    // Init I2C peripheral
    HAL_I2C_DeInit(&i2cHandle[device].Handle);

    i2cHandle[device].Handle.Instance             = i2cHardwareMap[device].dev;
    /// TODO: HAL check if I2C timing is correct
    i2cHandle[device].Handle.Init.Timing          = 0x00B01B59;
    //i2cHandle[device].Handle.Init.Timing          = 0x00D00E28; /* (Rise time = 120ns, Fall time = 25ns) */
    i2cHandle[device].Handle.Init.OwnAddress1     = 0x0;
    i2cHandle[device].Handle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
    i2cHandle[device].Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    i2cHandle[device].Handle.Init.OwnAddress2     = 0x0;
    i2cHandle[device].Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    i2cHandle[device].Handle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLE;


    HAL_I2C_Init(&i2cHandle[device].Handle);
    /* Enable the Analog I2C Filter */
    HAL_I2CEx_ConfigAnalogFilter(&i2cHandle[device].Handle,I2C_ANALOGFILTER_ENABLE);

    HAL_NVIC_SetPriority(i2cHardwareMap[device].er_irq, NVIC_PRIORITY_BASE(NVIC_PRIO_I2C_ER), NVIC_PRIORITY_SUB(NVIC_PRIO_I2C_ER));
    HAL_NVIC_EnableIRQ(i2cHardwareMap[device].er_irq);
    HAL_NVIC_SetPriority(i2cHardwareMap[device].ev_irq, NVIC_PRIORITY_BASE(NVIC_PRIO_I2C_EV), NVIC_PRIORITY_SUB(NVIC_PRIO_I2C_EV));
    HAL_NVIC_EnableIRQ(i2cHardwareMap[device].ev_irq);
}
Ejemplo n.º 17
0
// Disable I2C and free the I2C handle.
void disable_i2c(void)
{
	HAL_I2C_DeInit(&hi2c1);
	//free((void *)hi2c1);
}