[feat][timer][qdec] add timer clock config,add timer and qdec perpherial config

This commit is contained in:
jzlv 2021-07-26 10:08:12 +08:00
parent 3f8f00e4df
commit eccaa8adc4
6 changed files with 217 additions and 51 deletions

View File

@ -48,6 +48,14 @@
#define BSP_SPI_CLOCK_SOURCE ROOT_CLOCK_SOURCE_BCLK
#define BSP_SPI_CLOCK_DIV 0
#endif
#if defined(BSP_USING_TIMER0)
#define BSP_TIMER0_CLOCK_SOURCE ROOT_CLOCK_SOURCE_FCLK
#define BSP_TIMER0_CLOCK_DIV 0
#endif
#if defined(BSP_USING_TIMER1)
#define BSP_TIMER1_CLOCK_SOURCE ROOT_CLOCK_SOURCE_FCLK
#define BSP_TIMER1_CLOCK_DIV 0
#endif
#if defined(BSP_USING_PWM_CH0) || defined(BSP_USING_PWM_CH1) || defined(BSP_USING_PWM_CH2) || defined(BSP_USING_PWM_CH3) || defined(BSP_USING_PWM_CH4) || defined(BSP_USING_PWM_CH5)
#define BSP_PWM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
#define BSP_PWM_CLOCK_DIV 0

View File

@ -33,10 +33,13 @@
#define BSP_USING_I2S0
#define BSP_USING_USB
#define BSP_USING_PWM_CH2
#define BSP_USING_TIMER_CH0
#define BSP_USING_TIMER_CH1
#define BSP_USING_TIMER0
#define BSP_USING_TIMER1
#define BSP_USING_CAM
#define BSP_USING_KEYSCAN
#define BSP_USING_QDEC0
#define BSP_USING_QDEC1
#define BSP_USING_QDEC2
/* ----------------------*/
/* PERIPHERAL With DMA LIST */
@ -332,26 +335,32 @@
#endif
#endif
#if defined(BSP_USING_TIMER_CH0)
#ifndef TIMER_CH0_CONFIG
#define TIMER_CH0_CONFIG \
#if defined(BSP_USING_TIMER0)
#ifndef TIMER0_CONFIG
#define TIMER0_CONFIG \
{ \
.id = 0, \
.ch = 0, \
.cnt_mode = TIMER_CNT_PRELOAD, \
.pl_trig_src = TIMER_PL_TRIG_COMP0, \
.trigger = TIMER_PRELOAD_TRIGGER_COMP2, \
.reload = 0, \
.timeout1 = 1000000, \
.timeout2 = 2000000, \
.timeout3 = 3000000, \
}
#endif
#endif
#if defined(BSP_USING_TIMER_CH1)
#ifndef TIMER_CH1_CONFIG
#define TIMER_CH1_CONFIG \
#if defined(BSP_USING_TIMER1)
#ifndef TIMER1_CONFIG
#define TIMER1_CONFIG \
{ \
.id = 0, \
.ch = 1, \
.id = 1, \
.cnt_mode = TIMER_CNT_PRELOAD, \
.pl_trig_src = TIMER_PL_TRIG_COMP2, \
.trigger = TIMER_PRELOAD_TRIGGER_COMP0, \
.reload = 0, \
.timeout1 = 1000000, \
.timeout2 = 2000000, \
.timeout3 = 3000000, \
}
#endif
#endif
@ -367,4 +376,58 @@
#endif
#endif
#if defined(BSP_USING_QDEC0)
#ifndef QDEC0_CONFIG
#define QDEC0_CONFIG \
{ \
.id = 0, \
.acc_mode = QDEC_ACC_CONTINUE_ACCUMULATE, \
.sample_period = QDEC_SAMPLE_PERIOD_256US, \
.report_mode = QDEC_REPORT_TIME_MOD, \
.report_period = 2000, \
.led_en = ENABLE, \
.led_swap = DISABLE, \
.led_period = 7, \
.deglitch_en = DISABLE, \
.deglitch_strength = 0x0, \
}
#endif
#endif
#if defined(BSP_USING_QDEC1)
#ifndef QDEC1_CONFIG
#define QDEC1_CONFIG \
{ \
.id = 1, \
.acc_mode = QDEC_ACC_CONTINUE_ACCUMULATE, \
.sample_period = QDEC_SAMPLE_PERIOD_256US, \
.report_mode = QDEC_REPORT_TIME_MOD, \
.report_period = 2000, \
.led_en = ENABLE, \
.led_swap = DISABLE, \
.led_period = 7, \
.deglitch_en = DISABLE, \
.deglitch_strength = 0x0, \
}
#endif
#endif
#if defined(BSP_USING_QDEC2)
#ifndef QDEC2_CONFIG
#define QDEC2_CONFIG \
{ \
.id = 2, \
.acc_mode = QDEC_ACC_CONTINUE_ACCUMULATE, \
.sample_period = QDEC_SAMPLE_PERIOD_256US, \
.report_mode = QDEC_REPORT_TIME_MOD, \
.report_period = 2000, \
.led_en = ENABLE, \
.led_swap = DISABLE, \
.led_period = 7, \
.deglitch_en = DISABLE, \
.deglitch_strength = 0x0, \
}
#endif
#endif
#endif

View File

@ -43,6 +43,14 @@
#define BSP_SPI_CLOCK_SOURCE ROOT_CLOCK_SOURCE_BCLK
#define BSP_SPI_CLOCK_DIV 0
#endif
#if defined(BSP_USING_TIMER0)
#define BSP_TIMER0_CLOCK_SOURCE ROOT_CLOCK_SOURCE_FCLK
#define BSP_TIMER0_CLOCK_DIV 0
#endif
#if defined(BSP_USING_TIMER1)
#define BSP_TIMER1_CLOCK_SOURCE ROOT_CLOCK_SOURCE_FCLK
#define BSP_TIMER1_CLOCK_DIV 0
#endif
#if defined(BSP_USING_PWM_CH0) || defined(BSP_USING_PWM_CH1) || defined(BSP_USING_PWM_CH2) || defined(BSP_USING_PWM_CH3) || defined(BSP_USING_PWM_CH4) || defined(BSP_USING_PWM_CH5)
#define BSP_PWM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_32K_CLK
#define BSP_PWM_CLOCK_DIV 32

View File

@ -37,9 +37,12 @@
#define BSP_USING_PWM_CH1
#define BSP_USING_PWM_CH2
#define BSP_USING_PWM_CH3
#define BSP_USING_TIMER_CH0
#define BSP_USING_TIMER_CH1
#define BSP_USING_TIMER0
#define BSP_USING_TIMER1
#define BSP_USING_KEYSCAN
#define BSP_USING_QDEC0
#define BSP_USING_QDEC1
#define BSP_USING_QDEC2
/* ----------------------*/
/* PERIPHERAL With DMA LIST */
@ -335,26 +338,32 @@
#endif
#endif
#if defined(BSP_USING_TIMER_CH0)
#ifndef TIMER_CH0_CONFIG
#define TIMER_CH0_CONFIG \
#if defined(BSP_USING_TIMER0)
#ifndef TIMER0_CONFIG
#define TIMER0_CONFIG \
{ \
.id = 0, \
.ch = 0, \
.cnt_mode = TIMER_CNT_PRELOAD, \
.pl_trig_src = TIMER_PL_TRIG_COMP0, \
.trigger = TIMER_PRELOAD_TRIGGER_COMP2, \
.reload = 0, \
.timeout1 = 1000000, \
.timeout2 = 2000000, \
.timeout3 = 3000000, \
}
#endif
#endif
#if defined(BSP_USING_TIMER_CH1)
#ifndef TIMER_CH1_CONFIG
#define TIMER_CH1_CONFIG \
#if defined(BSP_USING_TIMER1)
#ifndef TIMER1_CONFIG
#define TIMER1_CONFIG \
{ \
.id = 0, \
.ch = 1, \
.id = 1, \
.cnt_mode = TIMER_CNT_PRELOAD, \
.pl_trig_src = TIMER_PL_TRIG_COMP2, \
.trigger = TIMER_PRELOAD_TRIGGER_COMP0, \
.reload = 0, \
.timeout1 = 1000000, \
.timeout2 = 2000000, \
.timeout3 = 3000000, \
}
#endif
#endif
@ -370,4 +379,58 @@
#endif
#endif
#if defined(BSP_USING_QDEC0)
#ifndef QDEC0_CONFIG
#define QDEC0_CONFIG \
{ \
.id = 0, \
.acc_mode = QDEC_ACC_CONTINUE_ACCUMULATE, \
.sample_period = QDEC_SAMPLE_PERIOD_256US, \
.report_mode = QDEC_REPORT_TIME_MOD, \
.report_period = 2000, \
.led_en = ENABLE, \
.led_swap = DISABLE, \
.led_period = 7, \
.deglitch_en = DISABLE, \
.deglitch_strength = 0x0, \
}
#endif
#endif
#if defined(BSP_USING_QDEC1)
#ifndef QDEC1_CONFIG
#define QDEC1_CONFIG \
{ \
.id = 1, \
.acc_mode = QDEC_ACC_CONTINUE_ACCUMULATE, \
.sample_period = QDEC_SAMPLE_PERIOD_256US, \
.report_mode = QDEC_REPORT_TIME_MOD, \
.report_period = 2000, \
.led_en = ENABLE, \
.led_swap = DISABLE, \
.led_period = 7, \
.deglitch_en = DISABLE, \
.deglitch_strength = 0x0, \
}
#endif
#endif
#if defined(BSP_USING_QDEC2)
#ifndef QDEC2_CONFIG
#define QDEC2_CONFIG \
{ \
.id = 2, \
.acc_mode = QDEC_ACC_CONTINUE_ACCUMULATE, \
.sample_period = QDEC_SAMPLE_PERIOD_256US, \
.report_mode = QDEC_REPORT_TIME_MOD, \
.report_period = 2000, \
.led_en = ENABLE, \
.led_swap = DISABLE, \
.led_period = 7, \
.deglitch_en = DISABLE, \
.deglitch_strength = 0x0, \
}
#endif
#endif
#endif

View File

@ -33,19 +33,19 @@
// <i> config gpio1 function
#define CONFIG_GPIO1_FUNC GPIO_FUN_UNUSED
// <q> GPIO2 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_TX//GPIO_FUN_UART1_TX//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC]
// <q> GPIO2 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_TX//GPIO_FUN_UART1_TX//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC_LED]
// <i> config gpio2 function
#define CONFIG_GPIO2_FUNC GPIO_FUN_UNUSED
// <q> GPIO3 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_RX//GPIO_FUN_UART1_RX//GPIO_FUN_QDEC]
// <i> config gpio3 function
#define CONFIG_GPIO3_FUNC GPIO_FUN_UNUSED
#define CONFIG_GPIO3_FUNC GPIO_FUN_QDEC
// <q> GPIO4 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC]
// <i> config gpio4 function
#define CONFIG_GPIO4_FUNC GPIO_FUN_UNUSED
#define CONFIG_GPIO4_FUNC GPIO_FUN_QDEC
// <q> GPIO5 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_CTS//GPIO_FUN_UART1_CTS//GPIO_FUN_QDEC]
// <q> GPIO5 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_CTS//GPIO_FUN_UART1_CTS//GPIO_FUN_QDEC_LED]
// <i> config gpio5 function
#define CONFIG_GPIO5_FUNC GPIO_FUN_UNUSED
@ -57,7 +57,7 @@
// <i> config gpio7 function
#define CONFIG_GPIO7_FUNC GPIO_FUN_USB
// <q> GPIO8 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_USB//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC]
// <q> GPIO8 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_USB//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC_LED]
// <i> config gpio8 function
#define CONFIG_GPIO8_FUNC GPIO_FUN_USB
@ -69,7 +69,7 @@
// <i> config gpio10 function
#define CONFIG_GPIO10_FUNC GPIO_FUN_UNUSED
// <q> GPIO11 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC]
// <q> GPIO11 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC_LED]
// <i> config gpio11 function
#define CONFIG_GPIO11_FUNC GPIO_FUN_UNUSED
@ -81,7 +81,7 @@
// <i> config gpio13 function
#define CONFIG_GPIO13_FUNC GPIO_FUN_UNUSED
// <q> GPIO14 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC]
// <q> GPIO14 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC_LED]
// <i> config gpio14 function
#define CONFIG_GPIO14_FUNC GPIO_FUN_UART0_TX
@ -93,7 +93,7 @@
// <i> config gpio16 function
#define CONFIG_GPIO16_FUNC GPIO_FUN_UNUSED
// <q> GPIO17 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC]
// <q> GPIO17 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC_LED]
// <i> config gpio17 function
#define CONFIG_GPIO17_FUNC GPIO_FUN_UNUSED
@ -105,7 +105,7 @@
// <i> config gpio19 function
#define CONFIG_GPIO19_FUNC GPIO_FUN_UART1_RX
// <q> GPIO20 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC]
// <q> GPIO20 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_ADC//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC_LED]
// <i> config gpio20 function
#define CONFIG_GPIO20_FUNC GPIO_FUN_UNUSED
@ -117,7 +117,7 @@
// <i> config gpio22 function
#define CONFIG_GPIO22_FUNC GPIO_FUN_PWM
// <q> GPIO23 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_ANALOG//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC]
// <q> GPIO23 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_ANALOG//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC_LED]
// <i> config gpio23 function
#define CONFIG_GPIO23_FUNC GPIO_FUN_UNUSED
@ -129,7 +129,7 @@
// <i> config gpio25 function
#define CONFIG_GPIO25_FUNC GPIO_FUN_UNUSED
// <q> GPIO26 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC]
// <q> GPIO26 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_ETHER_MAC//GPIO_FUN_QDEC_LED]
// <i> config gpio26 function
#define CONFIG_GPIO26_FUNC GPIO_FUN_UNUSED
@ -141,7 +141,7 @@
// <i> config gpio28 function
#define CONFIG_GPIO28_FUNC GPIO_FUN_UNUSED
// <q> GPIO29 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC]
// <q> GPIO29 <2> [GPIO_FUN_UNUSED//GPIO_FUN_I2S//GPIO_FUN_SPI//GPIO_FUN_I2C//GPIO_FUN_PWM//GPIO_FUN_CAM//GPIO_FUN_UART0_RTS//GPIO_FUN_UART1_RTS//GPIO_FUN_QDEC_LED]
// <i> config gpio29 function
#define CONFIG_GPIO29_FUNC GPIO_FUN_UNUSED

View File

@ -181,6 +181,16 @@ static void board_pin_mux_init(void)
} else if (af_pin_table[i].func == GPIO_FUN_PWM) {
/*if pwm func*/
gpio_cfg.pullType = GPIO_PULL_DOWN;
} else if (af_pin_table[i].func == GPIO_FUN_QDEC) {
/* if qdec a/b */
gpio_cfg.pullType = GPIO_PULL_NONE;
gpio_cfg.gpioMode = GPIO_MODE_INPUT;
gpio_cfg.gpioFun = GPIO_FUN_QDEC;
} else if (af_pin_table[i].func == GPIO_FUN_QDEC_LED) {
/* if qdec led */
gpio_cfg.pullType = GPIO_PULL_NONE;
gpio_cfg.gpioMode = GPIO_MODE_OUTPUT;
gpio_cfg.gpioFun = GPIO_FUN_QDEC;
} else if ((af_pin_table[i].func == GPIO_FUN_USB) || (af_pin_table[i].func == GPIO_FUN_DAC) || (af_pin_table[i].func == GPIO_FUN_ADC)) {
/*if analog func , for usb、adc、dac*/
gpio_cfg.gpioFun = GPIO_FUN_ANALOG;
@ -225,15 +235,15 @@ static void board_pin_mux_init(void)
gpio_cfg.pullType = GPIO_PULL_NONE;
} else if (af_pin_table[i].func == GPIO_FUN_GPIO_OUTPUT_UP) {
gpio_cfg.gpioFun = GPIO_FUN_GPIO;
gpio_cfg.gpioMode = GPIO_MODE_INPUT;
gpio_cfg.gpioMode = GPIO_MODE_OUTPUT;
gpio_cfg.pullType = GPIO_PULL_UP;
} else if (af_pin_table[i].func == GPIO_FUN_GPIO_OUTPUT_DOWN) {
gpio_cfg.gpioFun = GPIO_FUN_GPIO;
gpio_cfg.gpioMode = GPIO_MODE_INPUT;
gpio_cfg.gpioMode = GPIO_MODE_OUTPUT;
gpio_cfg.pullType = GPIO_PULL_DOWN;
} else if (af_pin_table[i].func == GPIO_FUN_GPIO_OUTPUT_NONE) {
gpio_cfg.gpioFun = GPIO_FUN_GPIO;
gpio_cfg.gpioMode = GPIO_MODE_INPUT;
gpio_cfg.gpioMode = GPIO_MODE_OUTPUT;
gpio_cfg.pullType = GPIO_PULL_NONE;
}
GLB_GPIO_Init(&gpio_cfg);
@ -275,3 +285,17 @@ void board_init(void)
board_clock_init();
board_pin_mux_init();
}
int bflb_get_board_config(uint8_t func, uint8_t *pinlist)
{
uint16_t i = 0;
int len = 0;
for (i = 0; i < sizeof(af_pin_table) / sizeof(struct pin_mux_cfg); i++) {
if (af_pin_table[i].func == func) {
pinlist[len] = af_pin_table[i].pin;
len++;
}
}
return len;
}