V1.0
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
/*!
|
||||
* \file main.c
|
||||
*
|
||||
* \brief Target main implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
void clock_init(void)
|
||||
{
|
||||
CLOCK_InitCfg_t clock_cfg;
|
||||
|
||||
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
|
||||
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_32M;
|
||||
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
|
||||
|
||||
if(clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
|
||||
} else if(clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
|
||||
}
|
||||
|
||||
xc_clock_init_cfg(&clock_cfg);
|
||||
|
||||
SysTick_Config(xc_clock_hfclk_in_get( ) / 100);
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void app_uart_init(void)
|
||||
{
|
||||
GPIO_InitCfg_t gpio_cfg = {0};
|
||||
|
||||
gpio_cfg.Mux = GPIO_Mux0;
|
||||
gpio_cfg.Pull = GPIO_PULLUP;
|
||||
gpio_cfg.Int = NOT_INT;
|
||||
gpio_cfg.FunSel = UART0_TX;
|
||||
|
||||
gpio_cfg.Pin = GPIO_18;
|
||||
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
gpio_cfg.FunSel = UART0_RX;
|
||||
gpio_cfg.Pin = GPIO_19;
|
||||
gpio_cfg.Dir = GPIO_DIR_INPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
UART_InitCfg_t uart_cfg = {0};
|
||||
|
||||
uart_cfg.Parity = UART_PARITY_DISABLE;
|
||||
uart_cfg.StopBits = UART_STOP_1_BITS;
|
||||
uart_cfg.WordLength = UART_DATA_8_BITS;
|
||||
uart_cfg.BaudRate = UART_BAUDRATE_115200;
|
||||
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
|
||||
|
||||
xc_uart_init(UART0_IDX, &uart_cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief main
|
||||
* @details
|
||||
* @param[in] void
|
||||
* @param[out] void
|
||||
* @retval int - 0
|
||||
* @retval void
|
||||
* @par identifier
|
||||
* reserve
|
||||
* @par other
|
||||
* void
|
||||
* @par change log
|
||||
* Alex created on 2023-05-31
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
// Clock Initialization
|
||||
clock_init();
|
||||
|
||||
app_uart_init( );
|
||||
|
||||
DEBUG("__START__\n");
|
||||
|
||||
/* qdec demo */
|
||||
qdec_demo( );
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* main loop */
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* \file qdec.c
|
||||
*
|
||||
* \brief Target qdec implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
/*------------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
--------------------------------------------------------------------------------------*/
|
||||
#include "qdec.h"
|
||||
#include "xc_drv_qdec.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief
|
||||
*
|
||||
* @param[in]
|
||||
* @param[in]
|
||||
****************************************************************************************
|
||||
*/
|
||||
void qdec_demo(void)
|
||||
{
|
||||
DEBUG("__QDEC_DEMO__\n");
|
||||
|
||||
DEBUG("0_QDEC_CTL[0x%08x]: %08x\n", &QDEC_CTL_REG, qdec_ctl_get());
|
||||
Qdec_InitCfg_t qdec_config;
|
||||
qdec_config.auto_clr_en = DISABLE;
|
||||
qdec_config.single_sample_rst_en = DISABLE;
|
||||
qdec_config.db_filter_en = ENABLE;
|
||||
qdec_config.acc_sample_div = QDEC_DIVIDE_DIV_32768;
|
||||
qdec_config.num_pts_sampled = QDEC_PTS_NUM_80;
|
||||
qdec_config.db_sample_div = QDEC_DB_SAMP_DIV_32;
|
||||
|
||||
xc_qdec_init(&qdec_config);
|
||||
DEBUG("1_QDEC_CTL[0x%08x]: %08x\n", &QDEC_CTL_REG, qdec_ctl_get());
|
||||
DEBUG("SAMP_CTL[0x%08x]: %08x\n", &QDEC_SAMP_CTL_REG, qdec_samp_ctl_get());
|
||||
xc_qdec_enable( );
|
||||
xc_qdec_start( );
|
||||
DEBUG("2_QDEC_CTL[0x%08x]: %08x\n", &QDEC_CTL_REG, qdec_ctl_get());
|
||||
NVIC_EnableIRQ(QDEC_IRQn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user