示例#1
0
static void ENC_IOInit(unsigned char channel_number)
{
  GPIO_Port     ENCPort=GPIO_PF;
  unsigned char ENCMask=0;
  
  switch (channel_number)
  {
#ifdef __TMPM_370__
  case 0:
    ENCPort = GPIO_PD;
    ENCMask = GPIO_BIT_0 | GPIO_BIT_1 | GPIO_BIT_2;
    break;
#endif    
  case 1:
    ENCPort = GPIO_PF;
    ENCMask = GPIO_BIT_2 | GPIO_BIT_3 | GPIO_BIT_4;
    break;
  default:
    assert_param(0);
    break;
  }
  
  GPIO_Init             (ENCPort, ENCMask, &portConfigENC);
  GPIO_SetInputEnableReg(ENCPort, ENCMask, ENABLE);

  GPIO_EnableFuncReg    (ENCPort, GPIO_FUNC_REG_1, ENCMask);
  GPIO_DisableFuncReg   (ENCPort, GPIO_FUNC_REG_2, ENCMask);
}
示例#2
0
文件: pinmap.c 项目: sg-/mbed-os
void pin_function(PinName pin, int function)
{
    uint32_t port = 0;
    uint8_t bit = 0;
    uint8_t i = 0;
    uint8_t func = 0;
    uint8_t dir = 0;

    // Assert that pin is valid
    MBED_ASSERT(pin != NC);

    // Calculate pin function and pin direction
    func = PIN_FUNC(function);
    dir  = PIN_DIR(function);
    // Calculate port and pin position
    port = PIN_PORT(pin);
    bit  = PIN_POS(pin);
    // Set function if function is in range
    if (func <= PIN_FUNC_MAX) {
        // Disable other functions
        for (i = 0; i < PIN_FUNC_MAX; i++) {
            if (i != (func - 1)) {
                GPIO_DisableFuncReg((GPIO_Port)port, i, (1 << bit));
            }
        }
        // Set pin function
        if (func) {
            GPIO_EnableFuncReg((GPIO_Port)port, (uint8_t)(func - 1), (1 << bit));
        }
    }

    // Set direction if direction is in range
    switch (dir) {
        case PIN_INPUT:
            GPIO_SetInputEnableReg((GPIO_Port)port, (1 << bit), ENABLE);
            GPIO_SetOutputEnableReg((GPIO_Port)port, (1 << bit), DISABLE);
            break;
        case PIN_OUTPUT:
            GPIO_SetOutputEnableReg((GPIO_Port)port, (1 << bit), ENABLE);
            GPIO_SetInputEnableReg((GPIO_Port)port, (1 << bit), DISABLE);
            break;
        case PIN_INOUT:
            GPIO_SetOutputEnableReg((GPIO_Port)port, (1 << bit), ENABLE);
            GPIO_SetInputEnableReg((GPIO_Port)port, (1 << bit), ENABLE);
            break;
        default:
            break;
    }
}
示例#3
0
/**
  * @brief  IGBT port initialization
  * @param  IGBTx: IGBT channel.
  *         InitTypeDef: initialization structure.
  * @retval None.
  */
void IGBT_IO_Configuration(TSB_MT_TypeDef * IGBTx, IGBT_InitTypeDef * InitTypeDef)
{
    if (IGBTx == IGBT0) {
        /* Check whether the trigger is used to start */
        if ((InitTypeDef->StartMode != IGBT_CMD_START) ||
            (InitTypeDef->StartMode != IGBT_CMD_START_NO_START_INT)) {
            GPIO_SetInputEnableReg(GPIO_PG, GPIO_BIT_0, ENABLE);        /* Enable PG0 input */
            GPIO_EnableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_0);   /* Set PG0 as MT0IN */
        } else {
            GPIO_SetInputEnableReg(GPIO_PG, GPIO_BIT_0, DISABLE);
            GPIO_DisableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_0);
        }
        /* Enable ouput0 or not */
        if (InitTypeDef->Output0Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PG, GPIO_BIT_3, ENABLE);       /* Enable PG3 output */
            GPIO_EnableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_3);   /* Set PG3 as MTOUT00 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PG, GPIO_BIT_3, DISABLE);
            GPIO_DisableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_3);
        }
        /* Enable ouput1 or not */
        if (InitTypeDef->Output1Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PG, GPIO_BIT_2, ENABLE);       /* Enable PG2 output */
            GPIO_EnableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_2);   /* Set PG2 as MTOUT10 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PG, GPIO_BIT_2, DISABLE);
            GPIO_DisableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_2);
        }

        GPIO_SetInputEnableReg(GPIO_PG, GPIO_BIT_1, ENABLE);    /* Enable PG1 input */
        GPIO_EnableFuncReg(GPIO_PG, GPIO_FUNC_REG_3, GPIO_BIT_1);       /* Set PG1 as GEMG0 */
    }


    if (IGBTx == IGBT1) {
        /* Check whether the trigger is used to start */
        if ((InitTypeDef->StartMode != IGBT_CMD_START) ||
            (InitTypeDef->StartMode != IGBT_CMD_START_NO_START_INT)) {
            GPIO_SetInputEnableReg(GPIO_PL, GPIO_BIT_0, ENABLE);        /* Enable PL0 input */
            GPIO_EnableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_0);   /* Set PL0 as MT1IN */
        } else {
            GPIO_SetInputEnableReg(GPIO_PL, GPIO_BIT_0, DISABLE);
            GPIO_DisableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_0);
        }
        /* Enable ouput0 or not */
        if (InitTypeDef->Output0Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PL, GPIO_BIT_3, ENABLE);       /* Enable PL3 output */
            GPIO_EnableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_3);   /* Set PL3 as MTOUT01 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PL, GPIO_BIT_3, DISABLE);
            GPIO_DisableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_3);
        }
        /* Enable ouput1 or not */
        if (InitTypeDef->Output1Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PL, GPIO_BIT_2, ENABLE);       /* Enable PL2 output */
            GPIO_EnableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_2);   /* Set PL2 as MTOUT11 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PL, GPIO_BIT_2, DISABLE);
            GPIO_DisableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_2);
        }

        GPIO_SetInputEnableReg(GPIO_PL, GPIO_BIT_1, ENABLE);    /* Enable PL1 input */
        GPIO_EnableFuncReg(GPIO_PL, GPIO_FUNC_REG_3, GPIO_BIT_1);       /* Set PL1 as GEMG1 */
    }

    if (IGBTx == IGBT2) {
        /* Check whether the trigger is used to start */
        if ((InitTypeDef->StartMode != IGBT_CMD_START) ||
            (InitTypeDef->StartMode != IGBT_CMD_START_NO_START_INT)) {
            GPIO_SetInputEnableReg(GPIO_PH, GPIO_BIT_0, ENABLE);        /* Enable PH0 input */
            GPIO_EnableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_0);   /* Set PH0 as MT2IN */
        } else {
            GPIO_SetInputEnableReg(GPIO_PH, GPIO_BIT_0, DISABLE);
            GPIO_DisableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_0);
        }
        /* Enable ouput0 or not */
        if (InitTypeDef->Output0Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PH, GPIO_BIT_3, ENABLE);       /* Enable PH3 output */
            GPIO_EnableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_3);   /* Set PH3 as MTOUT02 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PH, GPIO_BIT_3, DISABLE);
            GPIO_DisableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_3);
        }
        /* Enable ouput1 or not */
        if (InitTypeDef->Output1Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PH, GPIO_BIT_2, ENABLE);       /* Enable PH2 output */
            GPIO_EnableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_2);   /* Set PH2 as MTOUT12 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PH, GPIO_BIT_2, DISABLE);
            GPIO_DisableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_2);
        }

        GPIO_SetInputEnableReg(GPIO_PH, GPIO_BIT_1, ENABLE);    /* Enable PH1 input */
        GPIO_EnableFuncReg(GPIO_PH, GPIO_FUNC_REG_3, GPIO_BIT_1);       /* Set PH1 as GEMG2 */
    }

    if (IGBTx == IGBT3) {
        /* Check whether the trigger is used to start */
        if ((InitTypeDef->StartMode != IGBT_CMD_START) ||
            (InitTypeDef->StartMode != IGBT_CMD_START_NO_START_INT)) {
            GPIO_SetInputEnableReg(GPIO_PB, GPIO_BIT_5, ENABLE);        /* Enable PB5 input */
            GPIO_EnableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_5);   /* Set PB5 as MT3IN */
        } else {
            GPIO_SetInputEnableReg(GPIO_PB, GPIO_BIT_5, DISABLE);
            GPIO_DisableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_5);
        }
        /* Enable ouput0 or not */
        if (InitTypeDef->Output0Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PB, GPIO_BIT_2, ENABLE);       /* Enable PB2 output */
            GPIO_EnableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_2);   /* Set PB2 as MTOUT03 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PB, GPIO_BIT_2, DISABLE);
            GPIO_DisableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_2);
        }
        /* Enable ouput1 or not */
        if (InitTypeDef->Output1Init != IGBT_OUTPUT_DISABLE) {
            GPIO_SetOutputEnableReg(GPIO_PB, GPIO_BIT_3, ENABLE);       /* Enable PB3 output */
            GPIO_EnableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_3);   /* Set PB3 as MTOUT13 */
        } else {
            GPIO_SetOutputEnableReg(GPIO_PB, GPIO_BIT_3, DISABLE);
            GPIO_DisableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_3);
        }

        GPIO_SetInputEnableReg(GPIO_PB, GPIO_BIT_4, ENABLE);    /* Enable PB4 input */
        GPIO_EnableFuncReg(GPIO_PB, GPIO_FUNC_REG_3, GPIO_BIT_4);       /* Set PB4 as GEMG3 */
    }
}