//遥控引脚初始化
//PTA4,PTA5,PTA14,PTA15
//使能中断,中断服务函数在 PredatorCamera.c 中
void RemoteControlInit(void)
{
  PORT_PCR_REG(PORTA_BASE_PTR, 4) = (0 
                                     | PORT_PCR_MUX(1) 
                                     | 0x0003           //输入下拉      
                                     |PORT_PCR_IRQC(0) //下降沿中断
                                     );
  //设置端口方向为输入
  GPIO_PDDR_REG(PTA_BASE_PTR) &= ~(1 << 4);  
  PORT_PCR_REG(PORTA_BASE_PTR, 5) = (0 
                                     | PORT_PCR_MUX(1)
                                     | 0x0003//输入下拉      
                                     |PORT_PCR_IRQC(0) //下降沿中断
                                     );
  //设置端口方向为输入
  GPIO_PDDR_REG(PTA_BASE_PTR) &= ~(1 << 5); 
  PORT_PCR_REG(PORTA_BASE_PTR, 14) = (0 
                                     | PORT_PCR_MUX(1)
                                     | 0x03            //输入下拉      
                                     |PORT_PCR_IRQC(0) //下降沿中断
                                     );
  //设置端口方向为输入
  GPIO_PDDR_REG(PTA_BASE_PTR) &= ~(1 << 14); 
  PORT_PCR_REG(PORTA_BASE_PTR, 15) = (0 
                                     | PORT_PCR_MUX(1)
                                     | 0x03             //输入下拉      
                                     |PORT_PCR_IRQC(0) //下降沿中断
                                     );
  //设置端口方向为输入
  GPIO_PDDR_REG(PTA_BASE_PTR) &= ~(1 << 15); 
}
Esempio n. 2
0
/*************************************************************************
*                             野火嵌入式开发工作室
*
*  函数名称:gpio_init
*  功能说明:初始化gpio
*  参数说明:PORTx       端口号(PORTA,PORTB,PORTC,PORTD,PORTE)
*            n           端口引脚
*            IO          引脚方向,0=输入,1=输出
*            data        输出初始状态,0=低电平,1=高电平 (对输入无效)
*  函数返回:无
*  修改时间:2012-1-15   已测试
*  备    注:PDDR引脚方向寄存器   PCR引脚控制寄存器每个引脚都有这样的独立的一个寄存器
*************************************************************************/
void gpio_init (PORTx portx, u8 n, GPIO_CFG cfg, u8 data)
{
    ASSERT( (n < 32u)  && (data < 2u) );           //使用断言检查输入、电平 是否为1bit

    //选择功能脚 PORTx_PCRx ,每个端口都有个寄存器 PORTx_PCRx
    PORT_PCR_REG(PORTX[portx], n) = (0 | PORT_PCR_MUX(1) | cfg);
    //                                    选择为GPIO功能   cfg为是否上下拉使能
    //端口方向控制输入还是输出
    if( ( (cfg & 0x01) == GPI) || (cfg == GPI_UP) ||     (cfg == GPI_UP_PF)      )
        //   最低位为0则输入   ||   输入上拉模式  ||   输入上拉,带无源滤波器
    {
        GPIO_PDDR_REG(GPIOx[portx]) &= ~(1 << n);  //设置端口方向为输入
    }
    else
    {
        GPIO_PDDR_REG(GPIOx[portx]) |= (1 << n);    //设置端口方向为输出
        if(data == 1)//output
        {
            GPIO_SET(portx, n, 1);                  //对端口输出控制,输出为1
        }
        else
        {
            GPIO_SET(portx, n, 0);                  //对端口输出控制,输出为0
        }
    }
}
Esempio n. 3
0
/*!
 *  @brief      初始化gpio
 *  @param      PTxn    端口
 *  @param      cfg     引脚方向,0=输入,1=输出
 *  @param      data    输出初始状态,0=低电平,1=高电平 (对输入无效)
 *  @since      v5.0
 *  Sample usage:       gpio_init (PTA8, GPI,0);    //初始化 PTA8 管脚为输入
 */
void gpio_init (PTXn_e ptxn, GPIO_CFG cfg, uint8 data)
{
    //复用管脚为GPIO功能
    port_init( ptxn, ALT1);

    //端口方向控制输入还是输出
    if(  cfg == GPI )
    {
        //设置端口方向为输入
        GPIO_PDDR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn));       // GPIO PDDR 管脚号 清0,即对应管脚配置为端口方向输入
    }
    else
    {
        //设置端口方向为输出
        GPIO_PDDR_REG(GPIOX_BASE(ptxn)) |= (1 << PTn(ptxn));        // GPIO PDDR 管脚号 置1,即对应管脚配置为端口方向输出

        //端口输出数据
        if(data == 0)
        {
            GPIO_PDOR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn));   // GPIO PDOR 管脚号 清0,即对应管脚配置为端口输出低电平
        }
        else
        {
            GPIO_PDOR_REG(GPIOX_BASE(ptxn))  |= (1 << PTn(ptxn));   // GPIO PDOR 管脚号 置1,即对应管脚配置为端口输出高电平
        }
    }
}
//按键引脚初始化
//PTB8
//PTB18
void KeyInit(void)
{
  //指定该引脚功能为GPIO功能(即令引脚控制寄存器的MUX=0b001)
  PORT_PCR_REG(PORTB_BASE_PTR, 8)=  0 ;
  PORT_PCR_REG(PORTB_BASE_PTR, 8)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTB_BASE_PTR) &= ~(1 << 8);  //设置端口方向为输入
  //指定该引脚功能为GPIO功能(即令引脚控制寄存器的MUX=0b001)
  PORT_PCR_REG(PORTB_BASE_PTR, 18)=  0 ;
  PORT_PCR_REG(PORTB_BASE_PTR, 18)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTB_BASE_PTR) &= ~(1 << 18);  //设置端口方向为输入
}
Esempio n. 5
0
/*************************************************************************
*                             蓝宙电子工作室
*
*  函数名称:gpio_init
*  功能说明:初始化gpio
*  参数说明:port:端口号(gpio.h中宏定义,分别为PORTA~PORTE=0~4)
*            dir:引脚方向(0=输入,1=输出)
*            state:引脚初始状态(0=低电平,1=高电平)
*  函数返回:无
*  修改时间:2014-9-18   已测试
*  备    注:
*************************************************************************/
void gpio_init(PTxn ptxn, uint8_t dir, uint8_t state)
{	
  //根据带入参数pin,指定该引脚功能为GPIO功能(即令引脚控制寄存器的MUX=0b001)
  PORT_PCR_REG(PORTX_BASE(ptxn), PTn(ptxn))= PORT_PCR_MUX(1);
  
  //根据带入参数dir,决定引脚为输出还是输入
  if (1 == dir)   //希望为输出
  {
    GPIO_PDDR_REG(GPIOX_BASE(ptxn)) |= (1 << PTn(ptxn));    //设置端口方向为输出
    gpio_set(ptxn , state);   //调用gpio_set函数,设定引脚初始状态
  }
  else         //希望为输入
    GPIO_PDDR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn));  //设置端口方向为输入
}
Esempio n. 6
0
/*!
 *  @brief      设置引脚数据方向
 *  @param      PTxn    端口
 *  @param      cfg     引脚方向,0=输入,1=输出
 *  @since      v5.0
 *  Sample usage:       gpio_ddr (PTA8, GPI);    //设置 PTA8 管脚为输入
 */
void    gpio_ddr   (PTXn_e ptxn, GPIO_CFG cfg)
{
    //端口方向控制输入还是输出
    if(  cfg == GPI )
    {
        //设置端口方向为输入
        GPIO_PDDR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn));           // GPIO PDDR 管脚号 清0,即对应管脚配置为端口方向输入
    }
    else
    {
        //设置端口方向为输出
        GPIO_PDDR_REG(GPIOX_BASE(ptxn)) |= (1 << PTn(ptxn));            // GPIO PDDR 管脚号 置1,即对应管脚配置为端口方向输出
    }
}
//拨码开关初始化
//PTC1-4输入上拉 ,不允许中断
void SwitchInit(void)
{
  //PTC0输入上拉 ,不允许中断
  PORT_PCR_REG(PORTC_BASE_PTR,0) = (0 | PORT_PCR_MUX(1) | 0x03|PORT_PCR_IRQC(0) );
  GPIO_PDDR_REG(PTC_BASE_PTR) &= ~(1 << 0);  //设置端口方向为输入
  //PTC1输入上拉 ,不允许中断
  PORT_PCR_REG(PORTC_BASE_PTR,1) = (0 | PORT_PCR_MUX(1) | 0x03|PORT_PCR_IRQC(0) );
  GPIO_PDDR_REG(PTC_BASE_PTR) &= ~(1 << 1);  //设置端口方向为输入
  //PTC2输入上拉 ,不允许中断
  PORT_PCR_REG(PORTC_BASE_PTR,2) = (0 | PORT_PCR_MUX(1) | 0x03|PORT_PCR_IRQC(0) );
  GPIO_PDDR_REG(PTC_BASE_PTR) &= ~(1 << 2);  //设置端口方向为输入
  //PTC3输入上拉 ,不允许中断
  PORT_PCR_REG(PORTC_BASE_PTR,3) = (0 | PORT_PCR_MUX(1) | 0x03|PORT_PCR_IRQC(0) );
  GPIO_PDDR_REG(PTC_BASE_PTR) &= ~(1 << 3);  //设置端口方向为输入
}
Esempio n. 8
0
/*!
 *  @brief      读取引脚输入状态
 *  @param      PTxn    端口
 *  @return     管脚的状态,1为高电平,0为低电平
 *  @since      v5.0
 *  @warning    务必保证数据方向为输入(DEBUG模式下,有断言进行检测)
 *  Sample usage:       uint8 pta8_data = gpio_get (PTA8);    // 获取 PT8A 管脚 输入电平
 */
uint8 gpio_get(PTXn_e ptxn)
{
    ASSERT( BIT_GET( GPIO_PDDR_REG(GPIOX_BASE(ptxn)) , PTn(ptxn)) == GPI ); // 断言,检测 输出方向是否为输入
                                                                            // 获取 GPIO PDDR 管脚号 ,比较是否为输入

    return ((GPIO_PDIR_REG(GPIOX_BASE(ptxn)) >> PTn(ptxn )) & 0x01);        // 获取 GPIO PDIR ptxn 状态,即读取管脚输入电平
}
Esempio n. 9
0
/*************************************************************************
*                             蓝宙电子科技有限公司
*
*  函数名称:gpio_Interrupt_init
*  功能说明:初始化gpio
*  参数说明:PTxn      端口号(PORTA,PORTD)
*            IO          引脚方向,0=输入,1=输出,输入输出状态定义____________(修改:这个函数中只有定义为输入模式有效,否则不改变相关状态)
*            mode        中断模式
*  函数返回:无
*  修改时间:2012-9-15   已测试
*  备    注:
*************************************************************************/
void gpio_Interrupt_init(PTxn ptxn, GPIO_CFG cfg, GPIO_INP mode)
{
  ASSERT( (PTn(ptxn) < 32u)  );           //使用断言检查输入、电平 是否为1bit
  
  //选择功能脚 PORTx_PCRx ,每个端口都有个寄存器 PORTx_PCRx 
  
  PORT_PCR_REG(PORTX_BASE(ptxn), PTn(ptxn)) = (0 | PORT_PCR_MUX(1) | cfg | PORT_PCR_IRQC(mode) );
  //选择功能脚 PORTx_PCRx ,每个端口都有中断模型
  
//  PORT_DFER_REG(PORTX_BASE(ptxn)) = PORT_DFER_DFE( 1<<PTn(ptxn));
  
  //端口方向控制输入还是输出
  if( ( (cfg & 0x01) == GPI) || (cfg == GPI_UP) ||     (cfg == GPI_UP_PF) 
     || (cfg == GPI_DOWN) ||     (cfg == GPI_DOWN_PF)     )
    //   最低位为0则输入   ||   输入上拉模式  ||   输入上拉,带无源滤波器
  {
    GPIO_PDDR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn));  //设置端口方向为输入
  }
  
  if(PTX(ptxn)==0)
    enable_irq(PortA_irq_no);
  else if(PTX(ptxn)==3)
    enable_irq(PortD_irq_no);
  
}
Esempio n. 10
0
/*!
 *  @brief      反转引脚状态
 *  @param      PTxn    端口
 *  @since      v5.0
 *  @warning    务必保证数据方向为输出(DEBUG模式下,有断言进行检测)
 *  Sample usage:       gpio_turn (PTA8);    // PTA8 管脚 输出 反转
 */
void gpio_turn (PTXn_e ptxn)
{
    ASSERT( BIT_GET( GPIO_PDDR_REG(GPIOX_BASE(ptxn)) , PTn(ptxn)) == GPO ); // 断言,检测 输出方向是否为输出
                                                                            // 获取 GPIO PDDR 管脚号 ,比较是否为输出

    GPIO_PTOR_REG( GPIOX_BASE(ptxn))  =  1 << (PTn(ptxn ));                 // GPIO PTOR ptxn 置1,其他清0 ,即对应管脚配置为端口输出反转,其他位不变
                                                                            // 此处不能用 BIT_SET 这个宏来置1 ,因为必须保证其他位 不变,其他位直接清0即可
}
//Beep引脚初始化
//PTB2初始输出高电平
//
void BeepInit(void)
{
  //指定该引脚功能为GPIO功能(即令引脚控制寄存器的MUX=0b001)
  PORT_PCR_REG(PORTB_BASE_PTR, 2)=  0 ;
  PORT_PCR_REG(PORTB_BASE_PTR, 2)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTB_BASE_PTR) |= (1 << 2); //设置端口方向为输出
  GPIO_PDOR_REG(PTB_BASE_PTR) |=  (1 << 2); //设置输出为高电平    
}
Esempio n. 12
0
_mqx_int _bsp_usb_io_init
(
    void
)
{
#if PE_LDD_VERSION
        /* USB clock is configured using CPU component */

        /* Check if peripheral is not used by Processor Expert USB_LDD component */
        if (PE_PeripheralUsed((uint32_t)USB0_BASE_PTR) == TRUE) {
            /* IO Device used by PE Component*/
            return IO_ERROR;
        }
    /**
     * Workaround for Processor Expert as USB clock divider settings has been removed
     * from __pe_initialize_hardware() and Cpu_SetClockConfiguration() functions
     * Needs to be replaced by dynamic calculation of dividers.
     * SIM_CLKDIV2: USBDIV=1,USBFRAC=0
     */
    SIM_CLKDIV2 = (uint32_t)((SIM_CLKDIV2 & (uint32_t)~0x0DUL) | (uint32_t)0x02UL); /* Update USB clock prescalers */
#endif
#if BSPCFG_USB_USE_IRC48M

    /*
    * Configure SIM_CLKDIV2: USBDIV = 0, USBFRAC = 0
    */
    SIM_CLKDIV2 = (uint32_t)0x0UL; /* Update USB clock prescalers */

    /* Configure USB to be clocked from IRC 48MHz */
    SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL(3);

    /* Enable USB-OTG IP clocking */
    SIM_SCGC4_REG(SIM_BASE_PTR) |= SIM_SCGC4_USBOTG_MASK;
    /* Enable IRC 48MHz for USB module */
    USB0_CLK_RECOVER_IRC_EN = 0x03;
#else
    /* Configure USB to be clocked from PLL */
    SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL(1);

    /* Enable USB-OTG IP clocking */
    SIM_SCGC4_REG(SIM_BASE_PTR) |= SIM_SCGC4_USBOTG_MASK;

        /* USB D+ and USB D- are standalone not multiplexed one-purpose pins */
        /* VREFIN for device is standalone not multiplexed one-purpose pin */
#endif

#if BSP_USB_TWR_SER2
        /* TWR-SER2 board has 2 connectors: on channel A, there is Micro-USB connector,
        ** which is not routed to TWRK64 board. On channel B, there is standard
        ** A-type host connector routed to the USB0 peripheral on TWRK64. To enable
        ** power to this connector, GPIO PB8 must be set as GPIO output
        */
        PORT_PCR_REG(PORTB_BASE_PTR, 8) = PORT_PCR_MUX(0x01);
        GPIO_PDDR_REG(PTB_BASE_PTR) |= 1 << 8; // PB8 as output
        GPIO_PDOR_REG(PTB_BASE_PTR) |= 1 << 8; // PB8 in high level
#endif
    return MQX_OK;
}
Esempio n. 13
0
File: gpio.c Progetto: pepe1791/KL25
void gpio_set_pin_mode(GPIO_MemMapPtr gpioMapPtr, uint8_t pin, uint8_t mode)
{
	PORT_MemMapPtr portMapPtr;

	if(gpioMapPtr == PTA)
	{
		portMapPtr = PORTA;
	}else if(gpioMapPtr == PTB)
	{
		portMapPtr = PORTB;
	}else if(gpioMapPtr == PTC)
	{
		portMapPtr = PORTC;
	}else if(gpioMapPtr == PTD)
	{
		portMapPtr = PORTD;
	}else if(gpioMapPtr == PTE)
	{
		portMapPtr = PORTE;
	}

	PORT_PCR_REG(portMapPtr, pin) |= PORT_PCR_MUX(0x01);
	
	switch(mode)
	{
		case INPUT:  			
			GPIO_PDDR_REG(gpioMapPtr) &= (~(1<<pin));
		break;

		case INPUT_PULLUP: 		
			GPIO_PDDR_REG(gpioMapPtr) &= (~(1<<pin));
			PORT_PCR_REG(portMapPtr, pin) |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK);
		break;
		
		case INPUT_PULLDWN: 	
			GPIO_PDDR_REG(gpioMapPtr) &= (~(1<<pin));
			PORT_PCR_REG(portMapPtr, pin) |= (PORT_PCR_PE_MASK);
			PORT_PCR_REG(portMapPtr, pin) &= (~PORT_PCR_PS_MASK);
		break;
		
		case OUTPUT: 			
			GPIO_PDDR_REG(gpioMapPtr) |= ((1<<pin));
		break;
		
		case OUTPUT_HIGH: 		
			GPIO_PDDR_REG(gpioMapPtr) |= ((1<<pin));\
			PORT_PCR_REG(portMapPtr, pin) |= PORT_PCR_DSE_MASK;
		break;
		
		case INPUT_PULLUP_INT: 		
			GPIO_PDDR_REG(gpioMapPtr) &= (~(1<<pin));
			PORT_PCR_REG(portMapPtr, pin) |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK | PORT_PCR_IRQC(0xA));
		break;
		
		default: break;
	}
}
Esempio n. 14
0
/*!
 *  @brief      设置引脚状态
 *  @param      PTxn    端口
 *  @param      data    输出初始状态,0=低电平,1=高电平 (对输入无效)
 *  @since      v5.0
 *  @warning    务必保证数据方向为输出(DEBUG模式下,有断言进行检测)
 *  Sample usage:       gpio_set (PTA8, 1);    // PTA8 管脚 输出 1
 */
void gpio_set (PTXn_e ptxn, uint8 data)
{
    ASSERT( BIT_GET( GPIO_PDDR_REG(GPIOX_BASE(ptxn)) , PTn(ptxn)) == GPO ); // 断言,检测 输出方向是否为输出
                                                                            // 获取 GPIO PDDR 管脚号 ,比较是否为输出

    //端口输出数据
    if(data == 0)
    {
        GPIO_PDOR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn));   // GPIO PDOR 管脚号 清0,即对应管脚配置为端口输出低电平
    }
    else
    {
        GPIO_PDOR_REG(GPIOX_BASE(ptxn))  |= (1 << PTn(ptxn));   // GPIO PDOR 管脚号 置1,即对应管脚配置为端口输出高电平
    }
}
Esempio n. 15
0
void Gpio::setOutPort (uint32_t value, mode m)
{
	union
	{
		uint32_t full;
		uint16_t half[2];
	}val;
	val.full = value;
	PORT_GPCLR_REG(portAdrSet[prt]) = (val.half[0]<<16 & ~(0x07 << 8));
	PORT_GPCLR_REG(portAdrSet[prt]) = (val.half[1]<<16 & ~(0x07 << 8));
	PORT_GPCLR_REG(portAdrSet[prt]) = (val.half[0]<<16| m << 8);
	PORT_GPCHR_REG(portAdrSet[prt]) = (val.half[1]<<16| m << 8);
	if (m == 1)
	{
		GPIO_PDDR_REG(portAdr[prt]) |= value;
	}
}
Esempio n. 16
0
_mqx_int _bsp_usb_io_init
(
    void
)
{
#if PE_LDD_VERSION
    /* USB clock is configured using CPU component */

    /* Check if peripheral is not used by Processor Expert USB_LDD component */
    if (PE_PeripheralUsed((uint32_t)USB0_BASE_PTR) == TRUE) {
        /* IO Device used by PE Component*/
        return IO_ERROR;
    }

    /**
     * Workaround for Processor Expert as USB clock divider settings has been removed
     * from __pe_initialize_hardware() and Cpu_SetClockConfiguration() functions
     * Needs to be replaced by dynamic calculation of dividers.
     * SIM_CLKDIV2: USBDIV=1,USBFRAC=0
     */
    SIM_CLKDIV2 = (uint32_t)((SIM_CLKDIV2 & (uint32_t)~0x0DUL) | (uint32_t)0x02UL); /* Update USB clock prescalers */
#endif

    /* Configure USB to be clocked from PLL */
    SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK;

    /* Enable USB-OTG IP clocking */
    SIM_SCGC4_REG(SIM_BASE_PTR) |= SIM_SCGC4_USBOTG_MASK;

    /* USB D+ and USB D- are standalone not multiplexed one-purpose pins */
    /* VREFIN for device is standalone not multiplexed one-purpose pin */

    /** If we need the USB working as a host we have to provide
     ** power to the USB connector. To do this PTC9 has to be set
     ** as a GPIO output in high level.
     ** If USB should work as a device, the J26 jumper should be removed.
     */
    PORT_PCR_REG(PORTC_BASE_PTR, 9) = PORT_PCR_MUX(0x01) | PORT_PCR_PE_MASK;
    GPIO_PDDR_REG(PTC_BASE_PTR) |= 0x00000200; // PTC9 as output
    GPIO_PDOR_REG(PTC_BASE_PTR) |= 0x00000200; // PTC9 in high level

    return MQX_OK;
}
Esempio n. 17
0
_mqx_int _bsp_usb_host_io_init
(
    struct usb_host_if_struct *dev_if
)
{
    if (dev_if->HOST_INIT_PARAM == &_khci0_host_init_param)
    {
        _bsp_usb_io_init();
        /* Set pin to enable power supply to on board usb conector */
        PORT_PCR_REG(PORTC_BASE_PTR, 9) = PORT_PCR_MUX(0x01) | PORT_PCR_PE_MASK;
        GPIO_PDDR_REG(PTC_BASE_PTR) |= 0x00000200; // PC9 as output
        GPIO_PDOR_REG(PTC_BASE_PTR) |= 0x00000200; // PC9 in high level
    }
    else
    {
        return IO_ERROR; //unknown controller
    }

    return MQX_OK;
}
Esempio n. 18
0
_mqx_int _bsp_usb_io_init
(
    void
)
{
#if PE_LDD_VERSION
    /* USB clock is configured using CPU component */

    /* Check if peripheral is not used by Processor Expert USB_LDD component */
     if (PE_PeripheralUsed((uint_32)USB0_BASE_PTR) == TRUE) {
         /* IO Device used by PE Component*/
         return IO_ERROR;
     }
#endif
    /* Configure USB to be clocked from PLL */
    SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK;
     
    /* Enable USB-OTG IP clocking */
    SIM_SCGC4_REG(SIM_BASE_PTR) |= SIM_SCGC4_USBOTG_MASK;

    /* USB D+ and USB D- are standalone not multiplexed one-purpose pins */
    /* VREFIN for device is standalone not multiplexed one-purpose pin */

#if BSP_USB_TWR_SER2
    /* TWR-SER2 board has 2 connectors: on channel A, there is Micro-USB connector,
    ** which is not routed to TWRK60 board. On channel B, there is standard
    ** A-type host connector routed to the USB0 peripheral on TWRK60. To enable
    ** power to this connector, GPIO PB8 must be set as GPIO output
    */
    PORT_PCR_REG(PORTB_BASE_PTR, 8) = PORT_PCR_MUX(0x01) | PORT_PCR_PE_MASK;
    GPIO_PDDR_REG(PTB_BASE_PTR) |= 0x00000100; // PB8 as output
    GPIO_PDOR_REG(PTB_BASE_PTR) |= 0x00000100; // PB8 in high level
#endif

    return MQX_OK;
}
Esempio n. 19
0
void Gpio::setOutPin (uint8_t pin, mode m, dir d)
{
	PORT_PCR_REG(portAdrSet[prt],pin) |= m << 8;
	GPIO_PDDR_REG(portAdr[prt]) &= ~(1 << pin);
	GPIO_PDDR_REG(portAdr[prt]) |= (d << pin);
}
Esempio n. 20
0
static _mqx_int _bsp_usb_io_init
(
    _mqx_uint i
)
{
    if (i == 0) {
#if PE_LDD_VERSION
    /* USB clock is configured using CPU component */

    /* Check if peripheral is not used by Processor Expert USB_LDD component */
     if (PE_PeripheralUsed((uint_32)USB0_BASE_PTR) == TRUE) {
         /* IO Device used by PE Component*/
         return IO_ERROR;
     }
#endif
    /* Configure USB to be clocked from PLL0 */
    SIM_SOPT2_REG(SIM_BASE_PTR) &= ~(SIM_SOPT2_USBFSRC_MASK);
    SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBFSRC(1);
    /* Configure USB to be clocked from clock divider */
    SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBF_CLKSEL_MASK;
    /* Configure USB divider to be 120MHz * 2 / 5 = 48 MHz */
    SIM_CLKDIV2_REG(SIM_BASE_PTR) &= ~(SIM_CLKDIV2_USBFSDIV_MASK | SIM_CLKDIV2_USBFSFRAC_MASK);
    SIM_CLKDIV2_REG(SIM_BASE_PTR) |= SIM_CLKDIV2_USBFSDIV(4) | SIM_CLKDIV2_USBFSFRAC_MASK;

    /* Enable USB-OTG IP clocking */
    SIM_SCGC4_REG(SIM_BASE_PTR) |= SIM_SCGC4_USBFS_MASK;

    /* USB D+ and USB D- are standalone not multiplexed one-purpose pins */
    /* VREFIN for device is standalone not multiplexed one-purpose pin */

#if BSP_USB_TWR_SER2
    /* TWR-SER2 board has 2 connectors: on channel A, there is Micro-USB connector,
    ** which is not routed to TWRK60 board. On channel B, there is standard
    ** A-type host connector routed to the USB0 peripheral on TWRK60. To enable
    ** power to this connector, GPIO PB8 must be set as GPIO output
    */
    PORT_PCR_REG(PORTB_BASE_PTR, 8) = PORT_PCR_MUX(0x01);
    GPIO_PDDR_REG(PTB_BASE_PTR) |= 0x00000100; // PB8 as output
    GPIO_PDOR_REG(PTB_BASE_PTR) |= 0x00000100; // PB8 in high level
#endif
    }
    else if (i == 1) {
        //Disable MPU so the module can access RAM
        MPU_CESR &= ~MPU_CESR_VLD_MASK;

        //Enable clock to the module
        SIM_SCGC6 |= SIM_SCGC6_USBHS_MASK;

//        SIM_MCR &= (uint32_t)~0x40000000UL;  /* Disconnect internal generated ULPI clock from pin */

//        SIM_CLKDIV2 |= SIM_CLKDIV2_USBHSFRAC_MASK | SIM_CLKDIV2_USBHSDIV_MASK; // Divide reference clock to obtain 60MHz 
//        SIM_SOPT2 |= SIM_SOPT2_USBHSRC(1);     // MCGPLLCLK for the USB 60MHz CLKC source 
        //Select external clock for USBH controller
        SIM_SOPT2 |= SIM_SOPT2_USBH_CLKSEL_MASK;

        PORTA_PCR7 = PORT_PCR_MUX(2);   //ULPI DIR
        PORTA_PCR8 = PORT_PCR_MUX(2);   //ULPI NXT
        PORTA_PCR10 = PORT_PCR_MUX(2);  //ULPI DATA0
        PORTA_PCR11 = PORT_PCR_MUX(2);  //ULPI DATA1
        PORTA_PCR24 = PORT_PCR_MUX(2);  //ULPI DATA2
        PORTA_PCR25 = PORT_PCR_MUX(2);  //ULPI DATA3
        PORTA_PCR26 = PORT_PCR_MUX(2);  //ULPI DATA4
        PORTA_PCR27 = PORT_PCR_MUX(2);  //ULPI DATA5
        PORTA_PCR28 = PORT_PCR_MUX(2);  //ULPI DATA6
        PORTA_PCR29 = PORT_PCR_MUX(2);  //ULPI DATA7
        PORTA_PCR6 = PORT_PCR_MUX(2);   //ULPI CLK
        PORTA_PCR9 = PORT_PCR_MUX(2);   //ULPI STP
    }
    else {
        return IO_ERROR; //unknow controller
    }

    return MQX_OK;
}
Esempio n. 21
0
/*************************************************************************
*                           蓝宙电子工作室
*
*  函数名称:OLED_Init
*  功能说明:初始化函数
*  参数说明:无
*  函数返回:无
*  修改时间:2014-9-13
*  备    注:
*************************************************************************/
void OLED_Init(void)
{
  PORT_PCR_REG(PORTE_BASE_PTR, 1)=  0 ;
  PORT_PCR_REG(PORTE_BASE_PTR, 1)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTE_BASE_PTR) |= (1 << 1);
  GPIO_PDOR_REG(PTE_BASE_PTR) |=  (1<<(1));
  PORT_PCR_REG(PORTE_BASE_PTR, 2)=  0 ;
  PORT_PCR_REG(PORTE_BASE_PTR, 2)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTE_BASE_PTR) |= (1 << 2);
  GPIO_PDOR_REG(PTE_BASE_PTR) |=  (1<<(2));
  PORT_PCR_REG(PORTE_BASE_PTR, 3)=  0 ;
  PORT_PCR_REG(PORTE_BASE_PTR, 3)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTE_BASE_PTR) |= (1 << 3);
  GPIO_PDOR_REG(PTE_BASE_PTR) |=  (1<<(3));
  PORT_PCR_REG(PORTE_BASE_PTR, 4)=  0 ;
  PORT_PCR_REG(PORTE_BASE_PTR, 4)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTE_BASE_PTR) |= (1 << 4);
  GPIO_PDOR_REG(PTE_BASE_PTR) |=  (1<<(4));
  PORT_PCR_REG(PORTE_BASE_PTR, 5)=  0 ;
  PORT_PCR_REG(PORTE_BASE_PTR, 5)= PORT_PCR_MUX(1);
  GPIO_PDDR_REG(PTE_BASE_PTR) |= (1 << 5);
  GPIO_PDOR_REG(PTE_BASE_PTR) |=  (1<<(5));
 /* gpio_init (PTE1, GPO,HIGH);
  gpio_init (PTE2, GPO,HIGH);
  gpio_init (PTE3, GPO,HIGH);
  gpio_init (PTE4, GPO,HIGH);
  gpio_init (PTE5, GPO,LOW);*/
  
  OLED_SCL=1;
  OLED_CS = 0 ; ///使能信号端,拉低时正常使用
  OLED_RST=0;
  OLED_DLY_ms(100);
  OLED_RST=1;
  
  OLED_WrCmd(0xae);//--turn off oled panel
  OLED_WrCmd(0x00);//---set low column address
  OLED_WrCmd(0x10);//---set high column address
  OLED_WrCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  OLED_WrCmd(0x81);//--set contrast control register
  OLED_WrCmd(0xcf); // Set SEG Output Current Brightness
  OLED_WrCmd(0xa1);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  OLED_WrCmd(0xc8);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  OLED_WrCmd(0xa6);//--set normal display
  OLED_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
  OLED_WrCmd(0x3f);//--1/64 duty
  OLED_WrCmd(0xd3);//-set display offset	Shift Mapping RAM Counter (0x00~0x3F)
  OLED_WrCmd(0x00);//-not offset
  OLED_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
  OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
  OLED_WrCmd(0xd9);//--set pre-charge period
  OLED_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  OLED_WrCmd(0xda);//--set com pins hardware configuration
  OLED_WrCmd(0x12);
  OLED_WrCmd(0xdb);//--set vcomh
  OLED_WrCmd(0x40);//Set VCOM Deselect Level
  OLED_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
  OLED_WrCmd(0x02);//
  OLED_WrCmd(0x8d);//--set Charge Pump enable/disable
  OLED_WrCmd(0x14);//--set(0x10) disable
  OLED_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
  OLED_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
  OLED_WrCmd(0xaf);//--turn on oled panel
  OLED_Fill(0x00);  //初始清屏
  //OLED_Set_Pos(0,0);
  //OLED_Fill(0x00);//黑屏 
  //OLED_DLY_ms(100); 
}