2022-10-19 22:44:15 +08:00

222 lines
6.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************************************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>: SWM320_port.c
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SWM320<32><30>Ƭ<EFBFBD><C6AC><EFBFBD>Ķ˿<C4B6><CBBF><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><E2BAAF>
* <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* <20><EFBFBD><E6B1BE><EFBFBD><EFBFBD>: V1.1.0 2017<31><37>10<31><30>25<32><35>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
*
*
*******************************************************************************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
* -ECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2012 Synwit Technology
*******************************************************************************************************************************************/
#include "SWM320.h"
#include "SWM320_port.h"
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PORT_Init()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09>˿<EFBFBD><CBBF><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ѡ<EFBFBD>񣬿<EFBFBD><F1A3ACBF>õĹ<C3B5><C4B9>ܼ<EFBFBD>"SWM320_port.h"<22>ļ<EFBFBD>
* <20><> <20><>: uint32_t PORTx ָ<><D6B8>PORT<52>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PORTA<54><41>PORTB<54><42>PORTC<54><43>PORTM<54><4D>PORTN<54><4E>PORTP
* uint32_t n ָ<><D6B8>PORT<52><54><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* uint32_t func ָ<><D6B8><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ȡֵ<C8A1><D6B5>"SWM320_port.h"<22>ļ<EFBFBD>
* uint32_t digit_in_en <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD>nΪż<CEAA><C5BC>ʱ<EFBFBD><CAB1>funcȡֵֻ<D6B5><D6BB><EFBFBD><EFBFBD>FUNMUX0<58><30>ͷ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>FUNMUX0_UART0_RXD
* <09><><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD><6E><CEAA><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>funcȡֵֻ<D6B5><D6BB><EFBFBD><EFBFBD>FUNMUX1<58><31>ͷ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>FUNMUX1_UART0_TXD
******************************************************************************************************************************************/
void PORT_Init(uint32_t PORTx, uint32_t n, uint32_t func, uint32_t digit_in_en)
{
switch((uint32_t)PORTx)
{
case ((uint32_t)PORTA):
if(func > 99)
{
if(n < PIN6)
{
PORT->PORTA_MUX0 &= ~(0x1F << (n*5));
PORT->PORTA_MUX0 |= (func-100) << (n*5);
}
else if(n < PIN12)
{
PORT->PORTA_MUX1 &= ~(0x1F << ((n-6)*5));
PORT->PORTA_MUX1 |= (func-100) << ((n-6)*5);
}
}
PORT->PORTA_SEL &= ~(0x03 << (n*2));
PORT->PORTA_SEL |= (func > 99 ? 1 : func) << (n*2);
PORT->PORTA_INEN &= ~(0x01 << n);
PORT->PORTA_INEN |= (digit_in_en << n);
break;
case ((uint32_t)PORTB):
if(func > 99)
{
if(n < PIN6)
{
PORT->PORTB_MUX0 &= ~(0x1F << (n*5));
PORT->PORTB_MUX0 |= (func-100) << (n*5);
}
else if(n < PIN12)
{
PORT->PORTB_MUX1 &= ~(0x1F << ((n-6)*5));
PORT->PORTB_MUX1 |= (func-100) << ((n-6)*5);
}
}
PORT->PORTB_SEL &= ~(0x03 << (n*2));
PORT->PORTB_SEL |= (func > 99 ? 1 : func) << (n*2);
PORT->PORTB_INEN &= ~(0x01 << n);
PORT->PORTB_INEN |= (digit_in_en << n);
break;
case ((uint32_t)PORTC):
if(func > 99)
{
if(n < PIN6)
{
PORT->PORTC_MUX0 &= ~(0x1F << (n*5));
PORT->PORTC_MUX0 |= (func-100) << (n*5);
}
else if(n < PIN12)
{
PORT->PORTC_MUX1 &= ~(0x1F << ((n-6)*5));
PORT->PORTC_MUX1 |= (func-100) << ((n-6)*5);
}
}
PORT->PORTC_SEL &= ~(0x03 << (n*2));
PORT->PORTC_SEL |= (func > 99 ? 1 : func) << (n*2);
PORT->PORTC_INEN &= ~(0x01 << n);
PORT->PORTC_INEN |= (digit_in_en << n);
break;
case ((uint32_t)PORTM):
if(func > 99)
{
if(n < PIN6)
{
PORT->PORTM_MUX0 &= ~(0x1F << (n*5));
PORT->PORTM_MUX0 |= (func-100) << (n*5);
}
else if(n < PIN12)
{
PORT->PORTM_MUX1 &= ~(0x1F << ((n-6)*5));
PORT->PORTM_MUX1 |= (func-100) << ((n-6)*5);
}
else if(n < PIN18)
{
PORT->PORTM_MUX2 &= ~(0x1F << ((n-12)*5));
PORT->PORTM_MUX2 |= (func-100) << ((n-12)*5);
}
else if(n < PIN24)
{
PORT->PORTM_MUX3 &= ~(0x1F << ((n-18)*5));
PORT->PORTM_MUX3 |= (func-100) << ((n-18)*5);
}
}
if(n < 16)
{
PORT->PORTM_SEL0 &= ~(0x03 << (n*2));
PORT->PORTM_SEL0 |= (func > 99 ? 1 : func) << (n*2);
}
else
{
PORT->PORTM_SEL1 &= ~(0x03 << ((n-16)*2));
PORT->PORTM_SEL1 |= (func > 99 ? 1 : func) << ((n-16)*2);
}
PORT->PORTM_INEN &= ~(0x01 << n);
PORT->PORTM_INEN |= (digit_in_en << n);
break;
case ((uint32_t)PORTN):
if(func > 99)
{
if(n < PIN6)
{
PORT->PORTN_MUX0 &= ~(0x1F << (n*5));
PORT->PORTN_MUX0 |= (func-100) << (n*5);
}
else if(n < PIN12)
{
PORT->PORTN_MUX1 &= ~(0x1F << ((n-6)*5));
PORT->PORTN_MUX1 |= (func-100) << ((n-6)*5);
}
else if(n < PIN18)
{
PORT->PORTN_MUX2 &= ~(0x1F << ((n-12)*5));
PORT->PORTN_MUX2 |= (func-100) << ((n-12)*5);
}
}
if(n < 16)
{
PORT->PORTN_SEL0 &= ~(0x03 << (n*2));
PORT->PORTN_SEL0 |= (func > 99 ? 1 : func) << (n*2);
}
else
{
PORT->PORTN_SEL1 &= ~(0x03 << ((n-16)*2));
PORT->PORTN_SEL1 |= (func > 99 ? 1 : func) << ((n-16)*2);
}
PORT->PORTN_INEN &= ~(0x01 << n);
PORT->PORTN_INEN |= (digit_in_en << n);
break;
case ((uint32_t)PORTP):
if(func > 99)
{
if(n < PIN6)
{
PORT->PORTP_MUX0 &= ~(0x1F << (n*5));
PORT->PORTP_MUX0 |= (func-100) << (n*5);
}
else if(n < PIN12)
{
PORT->PORTP_MUX1 &= ~(0x1F << ((n-6)*5));
PORT->PORTP_MUX1 |= (func-100) << ((n-6)*5);
}
else if(n < PIN18)
{
PORT->PORTP_MUX2 &= ~(0x1F << ((n-12)*5));
PORT->PORTP_MUX2 |= (func-100) << ((n-12)*5);
}
else if(n < PIN24)
{
PORT->PORTP_MUX3 &= ~(0x1F << ((n-18)*5));
PORT->PORTP_MUX3 |= (func-100) << ((n-18)*5);
}
}
if(n < 16)
{
PORT->PORTP_SEL0 &= ~(0x03 << (n*2));
PORT->PORTP_SEL0 |= (func > 99 ? 1 : func) << (n*2);
}
else
{
PORT->PORTP_SEL1 &= ~(0x03 << ((n-16)*2));
PORT->PORTP_SEL1 |= (func > 99 ? 1 : func) << ((n-16)*2);
}
PORT->PORTP_INEN &= ~(0x01 << n);
PORT->PORTP_INEN |= (digit_in_en << n);
break;
}
}