first commit
This commit is contained in:
		
						commit
						3f016f84d8
					
				
					 47 changed files with 13013 additions and 0 deletions
				
			
		
							
								
								
									
										1870
									
								
								vendor/StdPeriphDriver/inc/CH592SFR.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1870
									
								
								vendor/StdPeriphDriver/inc/CH592SFR.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										273
									
								
								vendor/StdPeriphDriver/inc/CH59x_adc.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										273
									
								
								vendor/StdPeriphDriver/inc/CH59x_adc.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,273 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_adc.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_ADC_H__ | ||||
| #define __CH59x_ADC_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #define ROM_CFG_TMP_25C    0x7F014 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  adc single channel define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     CH_EXTIN_0 = 0,   // ADC 外部模拟通道 0
 | ||||
|     CH_EXTIN_1,       // ADC 外部模拟通道 1
 | ||||
|     CH_EXTIN_2,       // ADC 外部模拟通道 2
 | ||||
|     CH_EXTIN_3,       // ADC 外部模拟通道 3
 | ||||
|     CH_EXTIN_4,       // ADC 外部模拟通道 4
 | ||||
|     CH_EXTIN_5,       // ADC 外部模拟通道 5
 | ||||
|     CH_EXTIN_6,       // ADC 外部模拟通道 6
 | ||||
|     CH_EXTIN_7,       // ADC 外部模拟通道 7
 | ||||
|     CH_EXTIN_8,       // ADC 外部模拟通道 8
 | ||||
|     CH_EXTIN_9,       // ADC 外部模拟通道 9
 | ||||
|     CH_EXTIN_10,      // ADC 外部模拟通道 10
 | ||||
|     CH_EXTIN_11,      // ADC 外部模拟通道 11
 | ||||
|     CH_EXTIN_12,      // ADC 外部模拟通道 12
 | ||||
|     CH_EXTIN_13,      // ADC 外部模拟通道 13
 | ||||
| 
 | ||||
|     CH_INTE_VBAT = 14,  // ADC 内部电池检测通道
 | ||||
|     CH_INTE_VTEMP = 15, // ADC 内部温度传感器检测通道
 | ||||
| 
 | ||||
| } ADC_SingleChannelTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  adc differential channel define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     CH_DIFF_0_2 = 0, // ADC 差分通道 #0-#2
 | ||||
|     CH_DIFF_1_3,     // ADC 差分通道 #1-#3
 | ||||
| 
 | ||||
| } ADC_DiffChannelTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  adc sampling clock | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     SampleFreq_3_2 = 0, // 3.2M 采样频率
 | ||||
|     SampleFreq_8,       // 8M 采样频率
 | ||||
|     SampleFreq_5_33,    // 5.33M 采样频率
 | ||||
|     SampleFreq_4,       // 4M 采样频率
 | ||||
| } ADC_SampClkTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  adc signal PGA | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     ADC_PGA_1_4 = 0,    // -12dB, 1/4倍
 | ||||
|     ADC_PGA_1_2,        // -6dB, 1/2倍
 | ||||
|     ADC_PGA_0,          // 0dB, 1倍,无增益
 | ||||
|     ADC_PGA_2,          // 6dB, 2倍
 | ||||
|     ADC_PGA_2_ = 0x10,  // 6dB, 2倍
 | ||||
|     ADC_PGA_4,          // 12dB, 4倍
 | ||||
|     ADC_PGA_8,          // 18dB, 8倍
 | ||||
|     ADC_PGA_16,         // 24dB, 16倍
 | ||||
| } ADC_SignalPGATypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration DMA mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     ADC_Mode_Single = 0, // 单次模式
 | ||||
|     ADC_Mode_LOOP,       // 循环模式
 | ||||
| } ADC_DMAModeTypeDef; | ||||
| 
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 ADC 采样通道 | ||||
|  * | ||||
|  * @param   d   - refer to ADC_SingleChannelTypeDef | ||||
|  */ | ||||
| #define ADC_ChannelCfg(d)      (R8_ADC_CHANNEL = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 ADC 采样时钟 | ||||
|  * | ||||
|  * @param   d   - refer to ADC_SampClkTypeDef | ||||
|  */ | ||||
| #define ADC_SampClkCfg(d)      (R8_ADC_CFG = R8_ADC_CFG & (~RB_ADC_CLK_DIV) | (d << 6)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 ADC 信号增益 | ||||
|  * | ||||
|  * @param   d   - refer to ADC_SignalPGATypeDef | ||||
|  */ | ||||
| #define ADC_PGACfg(d)          (R8_ADC_CFG = R8_ADC_CFG & (~RB_ADC_PGA_GAIN) | (d << 4)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置内部温度传感器校准值 | ||||
|  * | ||||
|  * @param   d   - 校准值 | ||||
|  */ | ||||
| #define ADC_TempCalibCfg(d)    (R8_TEM_SENSOR = R8_TEM_SENSOR & (~RB_TEM_SEN_CALIB) | d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外部信号单通道采样初始化 | ||||
|  * | ||||
|  * @param   sp  - refer to ADC_SampClkTypeDef | ||||
|  * @param   ga  - refer to ADC_SignalPGATypeDef | ||||
|  */ | ||||
| void ADC_ExtSingleChSampInit(ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外部信号差分通道采样初始化 | ||||
|  * | ||||
|  * @param   sp  - refer to ADC_SampClkTypeDef | ||||
|  * @param   ga  - refer to ADC_SignalPGATypeDef | ||||
|  */ | ||||
| void ADC_ExtDiffChSampInit(ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   触摸按键通道采样初始化 | ||||
|  */ | ||||
| void TouchKey_ChSampInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭TouchKey电源 | ||||
|  */ | ||||
| #define TouchKey_DisableTSPower()    (R8_TKEY_CFG &= ~RB_TKEY_PWR_ON) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   内置温度传感器采样初始化 | ||||
|  */ | ||||
| void ADC_InterTSSampInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭温度传感器电源 | ||||
|  */ | ||||
| #define ADC_DisableTSPower()    (R8_TEM_SENSOR = 0) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   内置电池电压采样初始化 | ||||
|  */ | ||||
| void ADC_InterBATSampInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   ADC执行单次转换 | ||||
|  * | ||||
|  * @return  ADC转换后的数据 | ||||
|  */ | ||||
| uint16_t ADC_ExcutSingleConver(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   采样数据粗调,获取偏差值,必须先配置ADC后调用此函数获取校准值 | ||||
|  * | ||||
|  * @return  偏差 | ||||
|  */ | ||||
| signed short ADC_DataCalib_Rough(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   TouchKey转换后数据 | ||||
|  * | ||||
|  * @param   charg   - Touchkey充电时间,5bits有效, t=charg*Tadc | ||||
|  * @param   disch   - Touchkey放电时间,3bits有效, t=disch*Tadc | ||||
|  * | ||||
|  * @return  当前TouchKey等效数据 | ||||
|  */ | ||||
| uint16_t TouchKey_ExcutSingleConver(uint8_t charg, uint8_t disch); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置连续 ADC的周期 | ||||
|  * | ||||
|  * @param   cycle   - 单位为 16个系统时钟 | ||||
|  */ | ||||
| void ADC_AutoConverCycle(uint8_t cycle); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   配置DMA功能 | ||||
|  * | ||||
|  * @param   s           - 是否打开DMA功能 | ||||
|  * @param   startAddr   - DMA 起始地址 | ||||
|  * @param   endAddr     - DMA 结束地址 | ||||
|  * @param   m           - 配置DMA模式 | ||||
|  */ | ||||
| void ADC_DMACfg(uint8_t s, uint32_t startAddr, uint32_t endAddr, ADC_DMAModeTypeDef m); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   Convert ADC value to temperature(Celsius) | ||||
|  * | ||||
|  * @param   adc_val - adc value | ||||
|  * | ||||
|  * @return  temperature (Celsius) | ||||
|  */ | ||||
| int adc_to_temperature_celsius(uint16_t adc_val); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取ADC转换值 | ||||
|  * | ||||
|  * @return  ADC转换值 | ||||
|  */ | ||||
| #define ADC_ReadConverValue()     (R16_ADC_DATA) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   ADC执行单次转换 | ||||
|  */ | ||||
| #define ADC_StartUp()             (R8_ADC_CONVERT |= RB_ADC_START) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取ADC中断状态 | ||||
|  */ | ||||
| #define ADC_GetITStatus()         (R8_ADC_INT_FLAG & RB_ADC_IF_EOC) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除ADC中断标志 | ||||
|  */ | ||||
| #define ADC_ClearITFlag()         (R8_ADC_CONVERT = R8_ADC_CONVERT) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取ADC DMA完成状态 | ||||
|  */ | ||||
| #define ADC_GetDMAStatus()        (R8_ADC_DMA_IF & RB_ADC_IF_DMA_END) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除ADC DMA完成标志 | ||||
|  */ | ||||
| #define ADC_ClearDMAFlag()        (R8_ADC_DMA_IF |= RB_ADC_IF_DMA_END) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启定时间隔自动连续 ADC | ||||
|  */ | ||||
| #define ADC_StartAutoDMA()        (R8_ADC_CTRL_DMA |= RB_ADC_AUTO_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   停止定时间隔自动连续 ADC | ||||
|  */ | ||||
| #define ADC_StopAutoDMA()         (R8_ADC_CTRL_DMA &= ~RB_ADC_AUTO_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启连续转换 ADC | ||||
|  */ | ||||
| #define ADC_StartContDMA()        (R8_ADC_CTRL_DMA |= RB_ADC_CONT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   停止连续转换 ADC | ||||
|  */ | ||||
| #define ADC_StopContDMA()         (R8_ADC_CTRL_DMA &= ~RB_ADC_CONT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭ADC电源 | ||||
|  */ | ||||
| #define ADC_DisablePower()        (R8_ADC_CFG &= ~RB_ADC_POWER_ON) | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_ADC_H__
 | ||||
							
								
								
									
										291
									
								
								vendor/StdPeriphDriver/inc/CH59x_clk.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										291
									
								
								vendor/StdPeriphDriver/inc/CH59x_clk.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,291 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_clk.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_CLK_H__ | ||||
| #define __CH59x_CLK_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  系统主频定义 | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     CLK_SOURCE_LSI = 0x00, | ||||
|     CLK_SOURCE_LSE, | ||||
| 
 | ||||
|     CLK_SOURCE_HSE_16MHz = 0x22, | ||||
|     CLK_SOURCE_HSE_8MHz = 0x24, | ||||
|     CLK_SOURCE_HSE_6_4MHz = 0x25, | ||||
|     CLK_SOURCE_HSE_4MHz = 0x28, | ||||
| 
 | ||||
|     CLK_SOURCE_PLL_60MHz = 0x48, | ||||
|     CLK_SOURCE_PLL_48MHz = (0x40 | 10), | ||||
|     CLK_SOURCE_PLL_32MHz = (0x40 | 15), | ||||
|     CLK_SOURCE_PLL_24MHz = (0x40 | 20), | ||||
| } SYS_CLKTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  32K时钟选择 | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     Clk32K_LSI = 0, | ||||
|     Clk32K_LSE, | ||||
| 
 | ||||
| } LClk32KTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  32M晶振电流挡位 | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     HSE_RCur_75 = 0, | ||||
|     HSE_RCur_100, | ||||
|     HSE_RCur_125, | ||||
|     HSE_RCur_150 | ||||
| 
 | ||||
| } HSECurrentTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  32M晶振内部电容挡位 | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     HSECap_10p = 0, | ||||
|     HSECap_12p, | ||||
|     HSECap_14p, | ||||
|     HSECap_16p, | ||||
|     HSECap_18p, | ||||
|     HSECap_20p, | ||||
|     HSECap_22p, | ||||
|     HSECap_24p | ||||
| 
 | ||||
| } HSECapTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  32K晶振电流挡位 | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     LSE_RCur_70 = 0, | ||||
|     LSE_RCur_100, | ||||
|     LSE_RCur_140, | ||||
|     LSE_RCur_200 | ||||
| 
 | ||||
| } LSECurrentTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  32K晶振内部电容挡位 | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     LSECap_2p = 0,  // 定义保留,实际上为12p
 | ||||
|     LSECap_12p = 0, | ||||
|     LSECap_13p, | ||||
|     LSECap_14p, | ||||
|     LSECap_15p, | ||||
|     LSECap_16p, | ||||
|     LSECap_17p, | ||||
|     LSECap_18p, | ||||
|     LSECap_19p, | ||||
|     LSECap_20p, | ||||
|     LSECap_21p, | ||||
|     LSECap_22p, | ||||
|     LSECap_23p, | ||||
|     LSECap_24p, | ||||
|     LSECap_25p, | ||||
|     LSECap_26p, | ||||
|     LSECap_27p | ||||
| 
 | ||||
| } LSECapTypeDef; | ||||
| 
 | ||||
| #define RTC_MAX_COUNT             0xA8C00000 | ||||
| 
 | ||||
| #define MAX_DAY                   0x00004000 | ||||
| #define MAX_2_SEC                 0x0000A8C0 | ||||
| //#define	 MAX_SEC		0x545FFFFF
 | ||||
| 
 | ||||
| #define BEGYEAR                   2020 | ||||
| #define IsLeapYear(yr)            (!((yr) % 400) || (((yr) % 100) && !((yr) % 4))) | ||||
| #define YearLength(yr)            (IsLeapYear(yr) ? 366 : 365) | ||||
| #define monthLength(lpyr, mon)    (((mon) == 1) ? (28 + (lpyr)) : (((mon) > 6) ? (((mon) & 1) ? 31 : 30) : (((mon) & 1) ? 30 : 31))) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  rtc timer mode period define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     Period_0_125_S = 0, // 0.125s 周期
 | ||||
|     Period_0_25_S,      // 0.25s 周期
 | ||||
|     Period_0_5_S,       // 0.5s 周期
 | ||||
|     Period_1_S,         // 1s 周期
 | ||||
|     Period_2_S,         // 2s 周期
 | ||||
|     Period_4_S,         // 4s 周期
 | ||||
|     Period_8_S,         // 8s 周期
 | ||||
|     Period_16_S,        // 16s 周期
 | ||||
| } RTC_TMRCycTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  rtc interrupt event define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     RTC_TRIG_EVENT = 0, // RTC 触发事件
 | ||||
|     RTC_TMR_EVENT,      // RTC 周期定时事件
 | ||||
| 
 | ||||
| } RTC_EVENTTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  rtc interrupt event define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     RTC_TRIG_MODE = 0, // RTC 触发模式
 | ||||
|     RTC_TMR_MODE,      // RTC 周期定时模式
 | ||||
| 
 | ||||
| } RTC_MODETypeDef; | ||||
| 
 | ||||
| typedef enum | ||||
| { | ||||
|     /* 校准精度越高,耗时越长 */ | ||||
|     Level_32 = 3, // 用时 1.2ms 1000ppm (32M 主频)  1100ppm (60M 主频)
 | ||||
|     Level_64,     // 用时 2.2ms 800ppm  (32M 主频)  1000ppm (60M 主频)
 | ||||
|     Level_128,    // 用时 4.2ms 600ppm  (32M 主频)  800ppm  (60M 主频)
 | ||||
| 
 | ||||
| } Cali_LevelTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   32K 低频时钟来源 | ||||
|  * | ||||
|  * @param   hc  - 选择32K使用内部还是外部 | ||||
|  */ | ||||
| void LClk32K_Select(LClk32KTypeDef hc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   HSE晶体 偏置电流配置 | ||||
|  * | ||||
|  * @param   c   - 75%,100%,125%,150% | ||||
|  */ | ||||
| void HSECFG_Current(HSECurrentTypeDef c); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   HSE晶体 负载电容配置 | ||||
|  * | ||||
|  * @param   c   - refer to HSECapTypeDef | ||||
|  */ | ||||
| void HSECFG_Capacitance(HSECapTypeDef c); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   LSE晶体 偏置电流配置 | ||||
|  * | ||||
|  * @param   c   - 70%,100%,140%,200% | ||||
|  */ | ||||
| void LSECFG_Current(LSECurrentTypeDef c); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   LSE晶体 负载电容配置 | ||||
|  * | ||||
|  * @param   c   - refer to LSECapTypeDef | ||||
|  */ | ||||
| void LSECFG_Capacitance(LSECapTypeDef c); | ||||
| 
 | ||||
| void Calibration_LSI(Cali_LevelTypeDef cali_Lv); /* 用主频校准内部32K时钟 */ | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   RTC时钟初始化当前时间 | ||||
|  * | ||||
|  * @param   y       - 配置年,MAX_Y = BEGYEAR + 44 | ||||
|  * @param   mon     - 配置月,MAX_MON = 12 | ||||
|  * @param   d       - 配置日,MAX_D = 31 | ||||
|  * @param   h       - 配置小时,MAX_H = 23 | ||||
|  * @param   m       - 配置分钟,MAX_M = 59 | ||||
|  * @param   s       - 配置秒,MAX_S = 59 | ||||
|  */ | ||||
| void RTC_InitTime(uint16_t y, uint16_t mon, uint16_t d, uint16_t h, uint16_t m, uint16_t s); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前时间 | ||||
|  * | ||||
|  * @param   py      - 获取到的年,MAX_Y = BEGYEAR + 44 | ||||
|  * @param   pmon    - 获取到的月,MAX_MON = 12 | ||||
|  * @param   pd      - 获取到的日,MAX_D = 31 | ||||
|  * @param   ph      - 获取到的小时,MAX_H = 23 | ||||
|  * @param   pm      - 获取到的分钟,MAX_M = 59 | ||||
|  * @param   ps      - 获取到的秒,MAX_S = 59 | ||||
|  */ | ||||
| void RTC_GetTime(uint16_t *py, uint16_t *pmon, uint16_t *pd, uint16_t *ph, uint16_t *pm, uint16_t *ps); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   基于LSE/LSI时钟,配置当前RTC 周期数 | ||||
|  * | ||||
|  * @param   cyc     - 配置周期计数初值,MAX_CYC = 0xA8BFFFFF = 2831155199 | ||||
|  */ | ||||
| void RTC_SetCycle32k(uint32_t cyc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   基于LSE/LSI时钟,获取当前RTC 周期数 | ||||
|  * | ||||
|  * @return  当前周期数,MAX_CYC = 0xA8BFFFFF = 2831155199 | ||||
|  */ | ||||
| uint32_t RTC_GetCycle32k(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   RTC定时模式配置(注意定时基准固定为32768Hz) | ||||
|  * | ||||
|  * @param   t   - refer to RTC_TMRCycTypeDef | ||||
|  */ | ||||
| void RTC_TRIGFunCfg(uint32_t cyc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   RTC定时模式配置(注意定时基准固定为32768Hz) | ||||
|  * | ||||
|  * @param   t   - refer to RTC_TMRCycTypeDef | ||||
|  */ | ||||
| void RTC_TMRFunCfg(RTC_TMRCycTypeDef t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   RTC 模式功能关闭 | ||||
|  * | ||||
|  * @param   m   - 需要关闭的当前模式 | ||||
|  */ | ||||
| void RTC_ModeFunDisable(RTC_MODETypeDef m); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取RTC中断标志 | ||||
|  * | ||||
|  * @param   f   - refer to RTC_EVENTTypeDef | ||||
|  * | ||||
|  * @return  中断标志状态 | ||||
|  */ | ||||
| uint8_t RTC_GetITFlag(RTC_EVENTTypeDef f); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除RTC中断标志 | ||||
|  * | ||||
|  * @param   f   - refer to RTC_EVENTTypeDef | ||||
|  */ | ||||
| void RTC_ClearITFlag(RTC_EVENTTypeDef f); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   32K 低频时钟电源配置 | ||||
|  */ | ||||
| void LClk32K_Cfg(LClk32KTypeDef hc, FunctionalState s); | ||||
| 
 | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_CLK_H__
 | ||||
							
								
								
									
										102
									
								
								vendor/StdPeriphDriver/inc/CH59x_common.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								vendor/StdPeriphDriver/inc/CH59x_common.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,102 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_common.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| 
 | ||||
| #ifndef __CH59x_COMM_H__ | ||||
| #define __CH59x_COMM_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| #ifndef  NULL | ||||
| #define  NULL     0 | ||||
| #endif | ||||
| #define  ALL			0xFFFF | ||||
| 
 | ||||
| #ifndef __HIGH_CODE | ||||
| #define __HIGH_CODE   __attribute__((section(".highcode"))) | ||||
| #endif | ||||
| 
 | ||||
| #ifndef __INTERRUPT | ||||
| #ifdef INT_SOFT | ||||
| #define __INTERRUPT   __attribute__((interrupt())) | ||||
| #else | ||||
| #define __INTERRUPT   __attribute__((interrupt("WCH-Interrupt-fast"))) | ||||
| #endif | ||||
| #endif | ||||
| 
 | ||||
| #define Debug_UART0        0 | ||||
| #define Debug_UART1        1 | ||||
| #define Debug_UART2        2 | ||||
| #define Debug_UART3        3 | ||||
| 
 | ||||
| #ifdef DEBUG | ||||
| #include <stdio.h> | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  系统主频时钟(Hz) | ||||
|  */ | ||||
| #ifndef	 FREQ_SYS | ||||
| #define  FREQ_SYS		60000000 | ||||
| #endif | ||||
| 
 | ||||
| #ifndef  SAFEOPERATE | ||||
| #define  SAFEOPERATE    asm volatile("fence.i") | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  32K时钟(Hz) | ||||
|  */ | ||||
| #ifdef CLK_OSC32K | ||||
| #if ( CLK_OSC32K == 1 ) | ||||
| #define CAB_LSIFQ       32000 | ||||
| #else | ||||
| #define CAB_LSIFQ       32768 | ||||
| #endif | ||||
| #else | ||||
| #define CAB_LSIFQ       32000 | ||||
| #endif | ||||
| 
 | ||||
| #include <string.h> | ||||
| #include <stdint.h> | ||||
| #include "CH592SFR.h" | ||||
| #include "core_riscv.h" | ||||
| #include "CH59x_clk.h" | ||||
| #include "CH59x_uart.h" | ||||
| #include "CH59x_gpio.h" | ||||
| #include "CH59x_i2c.h" | ||||
| #include "CH59x_flash.h" | ||||
| #include "CH59x_pwr.h" | ||||
| #include "CH59x_pwm.h" | ||||
| #include "CH59x_adc.h" | ||||
| #include "CH59x_sys.h" | ||||
| #include "CH59x_timer.h" | ||||
| #include "CH59x_spi.h" | ||||
| #include "CH59x_usbdev.h" | ||||
| #include "CH59x_usbhost.h" | ||||
| #include "ISP592.h" | ||||
| 
 | ||||
| 
 | ||||
| #define DelayMs(x)      mDelaymS(x) | ||||
| #define DelayUs(x)      mDelayuS(x) | ||||
| 
 | ||||
| #define ROM_CFG_VERISON    0x7F010 | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif  // __CH59x_COMM_H__
 | ||||
| 
 | ||||
							
								
								
									
										41
									
								
								vendor/StdPeriphDriver/inc/CH59x_flash.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								vendor/StdPeriphDriver/inc/CH59x_flash.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_flash.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_FLASH_H__ | ||||
| #define __CH59x_FLASH_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   读取Flash-ROM | ||||
|  * | ||||
|  * @param   StartAddr   - read address | ||||
|  * @param   Buffer      - read buffer | ||||
|  * @param   len         - read len | ||||
|  */ | ||||
| void FLASH_ROM_READ(uint32_t StartAddr, void *Buffer, uint32_t len); | ||||
| 
 | ||||
| UINT8 UserOptionByteConfig(FunctionalState RESET_EN, FunctionalState BOOT_PIN, FunctionalState UART_NO_KEY_EN, | ||||
|         uint32_t FLASHProt_Size); | ||||
| 
 | ||||
| UINT8 UserOptionByteClose_SWD(void); | ||||
| 
 | ||||
| void UserOptionByte_Active(void); | ||||
| 
 | ||||
| void GET_UNIQUE_ID(uint8_t *Buffer); | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_FLASH_H__
 | ||||
							
								
								
									
										256
									
								
								vendor/StdPeriphDriver/inc/CH59x_gpio.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										256
									
								
								vendor/StdPeriphDriver/inc/CH59x_gpio.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,256 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_gpio.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_GPIO_H__ | ||||
| #define __CH59x_GPIO_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief	GPIO_pins_define | ||||
|  */ | ||||
| #define GPIO_Pin_0      (0x00000001) /*!< Pin 0 selected */ | ||||
| #define GPIO_Pin_1      (0x00000002) /*!< Pin 1 selected */ | ||||
| #define GPIO_Pin_2      (0x00000004) /*!< Pin 2 selected */ | ||||
| #define GPIO_Pin_3      (0x00000008) /*!< Pin 3 selected */ | ||||
| #define GPIO_Pin_4      (0x00000010) /*!< Pin 4 selected */ | ||||
| #define GPIO_Pin_5      (0x00000020) /*!< Pin 5 selected */ | ||||
| #define GPIO_Pin_6      (0x00000040) /*!< Pin 6 selected */ | ||||
| #define GPIO_Pin_7      (0x00000080) /*!< Pin 7 selected */ | ||||
| #define GPIO_Pin_8      (0x00000100) /*!< Pin 8 selected */ | ||||
| #define GPIO_Pin_9      (0x00000200) /*!< Pin 9 selected */ | ||||
| #define GPIO_Pin_10     (0x00000400) /*!< Pin 10 selected */ | ||||
| #define GPIO_Pin_11     (0x00000800) /*!< Pin 11 selected */ | ||||
| #define GPIO_Pin_12     (0x00001000) /*!< Pin 12 selected */ | ||||
| #define GPIO_Pin_13     (0x00002000) /*!< Pin 13 selected */ | ||||
| #define GPIO_Pin_14     (0x00004000) /*!< Pin 14 selected */ | ||||
| #define GPIO_Pin_15     (0x00008000) /*!< Pin 15 selected */ | ||||
| #define GPIO_Pin_16     (0x00010000) /*!< Pin 16 selected */ | ||||
| #define GPIO_Pin_17     (0x00020000) /*!< Pin 17 selected */ | ||||
| #define GPIO_Pin_18     (0x00040000) /*!< Pin 18 selected */ | ||||
| #define GPIO_Pin_19     (0x00080000) /*!< Pin 19 selected */ | ||||
| #define GPIO_Pin_20     (0x00100000) /*!< Pin 20 selected */ | ||||
| #define GPIO_Pin_21     (0x00200000) /*!< Pin 21 selected */ | ||||
| #define GPIO_Pin_22     (0x00400000) /*!< Pin 22 selected */ | ||||
| #define GPIO_Pin_23     (0x00800000) /*!< Pin 23 selected */ | ||||
| #define GPIO_Pin_All    (0xFFFFFFFF) /*!< All pins selected */ | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration GPIO Mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     GPIO_ModeIN_Floating, //浮空输入
 | ||||
|     GPIO_ModeIN_PU,       //上拉输入
 | ||||
|     GPIO_ModeIN_PD,       //下拉输入
 | ||||
|     GPIO_ModeOut_PP_5mA,  //推挽输出最大5mA
 | ||||
|     GPIO_ModeOut_PP_20mA, //推挽输出最大20mA
 | ||||
| 
 | ||||
| } GPIOModeTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration GPIO IT Mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     GPIO_ITMode_LowLevel,  //低电平触发
 | ||||
|     GPIO_ITMode_HighLevel, //高电平触发
 | ||||
|     GPIO_ITMode_FallEdge,  //下降沿触发
 | ||||
|     GPIO_ITMode_RiseEdge,  //上升沿触发
 | ||||
| 
 | ||||
| } GPIOITModeTpDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA端口引脚模式配置 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  * @param   mode    - 输入输出类型 | ||||
|  */ | ||||
| void GPIOA_ModeCfg(uint32_t pin, GPIOModeTypeDef mode); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB端口引脚模式配置 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  * @param   mode    - 输入输出类型 | ||||
|  */ | ||||
| void GPIOB_ModeCfg(uint32_t pin, GPIOModeTypeDef mode); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA端口引脚输出置低 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOA_ResetBits(pin)      (R32_PA_CLR |= pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA端口引脚输出置高 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOA_SetBits(pin)        (R32_PA_OUT |= pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB端口引脚输出置低 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOB_ResetBits(pin)      (R32_PB_CLR |= pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB端口引脚输出置高 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOB_SetBits(pin)        (R32_PB_OUT |= pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA端口引脚输出电平翻转 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOA_InverseBits(pin)    (R32_PA_OUT ^= pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB端口引脚输出电平翻转 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOB_InverseBits(pin)    (R32_PB_OUT ^= pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA端口32位数据返回,低16位有效 | ||||
|  * | ||||
|  * @return  GPIOA端口32位数据 | ||||
|  */ | ||||
| #define GPIOA_ReadPort()          (R32_PA_PIN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB端口32位数据返回,低24位有效 | ||||
|  * | ||||
|  * @return  GPIOB端口32位数据 | ||||
|  */ | ||||
| #define GPIOB_ReadPort()          (R32_PB_PIN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA端口引脚状态,0-引脚低电平,(!0)-引脚高电平 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  * | ||||
|  * @return  GPIOA端口引脚状态 | ||||
|  */ | ||||
| #define GPIOA_ReadPortPin(pin)    (R32_PA_PIN & (pin)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB端口引脚状态,0-引脚低电平,(!0)-引脚高电平 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  * | ||||
|  * @return  GPIOB端口引脚状态 | ||||
|  */ | ||||
| #define GPIOB_ReadPortPin(pin)    (R32_PB_PIN & (pin)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOA引脚中断模式配置 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  * @param   mode    - 触发类型 | ||||
|  */ | ||||
| void GPIOA_ITModeCfg(uint32_t pin, GPIOITModeTpDef mode); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   GPIOB引脚中断模式配置 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  * @param   mode    - 触发类型 | ||||
|  */ | ||||
| void GPIOB_ITModeCfg(uint32_t pin, GPIOITModeTpDef mode); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   读取GPIOA端口中断标志状态 | ||||
|  * | ||||
|  * @return  GPIOA端口中断标志状态 | ||||
|  */ | ||||
| #define GPIOA_ReadITFlagPort()       (R16_PA_INT_IF) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   读取GPIOB端口中断标志状态 | ||||
|  * | ||||
|  * @return  GPIOB端口中断标志状态 | ||||
|  */ | ||||
| #define GPIOB_ReadITFlagPort()       ((R16_PB_INT_IF & (~((GPIO_Pin_22 | GPIO_Pin_23) >> 14))) | ((R16_PB_INT_IF << 14) & (GPIO_Pin_22 | GPIO_Pin_23))) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   读取GPIOA端口引脚中断标志状态 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  * | ||||
|  * @return  GPIOA端口引脚中断标志状态 | ||||
|  */ | ||||
| #define GPIOA_ReadITFlagBit(pin)     (R16_PA_INT_IF & (pin)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   读取GPIOB端口引脚中断标志状态 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  * | ||||
|  * @return  GPIOB端口引脚中断标志状态 | ||||
|  */ | ||||
| #define GPIOB_ReadITFlagBit(pin)     (R16_PB_INT_IF & ((pin) | (((pin) & (GPIO_Pin_22 | GPIO_Pin_23)) >> 14))) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除GPIOA端口引脚中断标志状态 | ||||
|  * | ||||
|  * @param   pin     - PA4-PA15,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOA_ClearITFlagBit(pin)    (R16_PA_INT_IF = pin) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除GPIOB端口引脚中断标志状态 | ||||
|  * | ||||
|  * @param   pin     - PB0,PB4,PB6-PB7,PB10-PB15,PB22-PB23,对应芯片12个GPIO引脚 | ||||
|  */ | ||||
| #define GPIOB_ClearITFlagBit(pin)    (R16_PB_INT_IF = ((pin) | (((pin) & (GPIO_Pin_22 | GPIO_Pin_23)) >> 14))) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外设功能引脚映射 | ||||
|  * | ||||
|  * @param   s       - 是否使能映射 | ||||
|  * @param   perph   - RB_RF_ANT_SW_EN -  RF antenna switch control output on PA4/PA5/PA12/PA13/PA14/PA15 | ||||
|  *                    RB_PIN_MODEM  -  MODEM: PA6/PA7 -> PB12/PB13 | ||||
|  *                    RB_PIN_PWMX   -  PWMX: PA12/PA13 -> PA6/PA7 | ||||
|  *                    RB_PIN_SPI0   -  SPI0:  PA12/PA13/PA14/PA15 -> PB12/PB13/PB14/PB15 | ||||
|  *                    RB_PIN_UART2  -  UART2: PB22/PB23 ->  PA6/PA7 | ||||
|  *                    RB_PIN_UART1  -  UART1: PA8/PA9 ->  PB12/PB13 | ||||
|  *                    RB_PIN_UART0  -  UART0: PB4/PB7 ->  PA15/PA14 | ||||
|  *                    RB_PIN_TMR2   -  TMR2:  PA11 ->  PB11 | ||||
|  *                    RB_PIN_TMR1   -  TMR1:  PA10 ->  PB10 | ||||
|  *                    RB_PIN_TMR0   -  TMR0:  PA9 ->  PB23 | ||||
|  */ | ||||
| void GPIOPinRemap(FunctionalState s, uint16_t perph); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   模拟外设GPIO引脚功能控制 | ||||
|  * | ||||
|  * @param   s       - 是否启用模拟外设功能 | ||||
|  * @param   perph   - RB_PIN_USB_DP_PU  - USB UD+引脚内部上拉电阻 | ||||
|  *                    RB_PIN_USB_IE     - USB 引脚 | ||||
|  */ | ||||
| void GPIOAGPPCfg(FunctionalState s, uint16_t perph); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_GPIO_H__
 | ||||
							
								
								
									
										180
									
								
								vendor/StdPeriphDriver/inc/CH59x_i2c.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										180
									
								
								vendor/StdPeriphDriver/inc/CH59x_i2c.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,180 @@ | |||
| 
 | ||||
| 
 | ||||
| #ifndef __CH59x_I2C_H__ | ||||
| #define __CH59x_I2C_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* I2C_transfer_direction */ | ||||
| #define I2C_Direction_Transmitter    ((uint8_t)0x00) | ||||
| #define I2C_Direction_Receiver       ((uint8_t)0x01) | ||||
| 
 | ||||
| /* I2C ADD0 mask */ | ||||
| #define OADDR1_ADD0_Set              ((uint16_t)0x0001) | ||||
| #define OADDR1_ADD0_Reset            ((uint16_t)0xFFFE) | ||||
| 
 | ||||
| /* I2C_NACK_position */ | ||||
| #define I2C_NACKPosition_Next        ((uint16_t)RB_I2C_POS) | ||||
| #define I2C_NACKPosition_Current     ((uint16_t)~RB_I2C_POS) | ||||
| 
 | ||||
| /* I2C_PEC_position */ | ||||
| #define I2C_PECPosition_Next         ((uint16_t)RB_I2C_POS) | ||||
| #define I2C_PECPosition_Current      ((uint16_t)~RB_I2C_POS) | ||||
| 
 | ||||
| /* I2C_SMBus_alert_pin_level */ | ||||
| #define I2C_SMBusAlert_Low           ((uint16_t)RB_I2C_ALERT) | ||||
| #define I2C_SMBusAlert_High          ((uint16_t)~RB_I2C_ALERT) | ||||
| 
 | ||||
| /* I2C FLAG mask */ | ||||
| #define FLAG_Mask                    ((uint32_t)0x00FFFFFF) | ||||
| 
 | ||||
| /* I2C Interrupt Enable mask */ | ||||
| #define ITEN_Mask                    ((uint32_t)0x07000000) | ||||
| 
 | ||||
| /* I2C_mode */ | ||||
| typedef enum | ||||
| { | ||||
|     I2C_Mode_I2C = 0x0000, | ||||
|     I2C_Mode_SMBusDevice = 0x0002, | ||||
|     I2C_Mode_SMBusHost = 0x000A, | ||||
| } I2C_ModeTypeDef; | ||||
| 
 | ||||
| /* I2C_duty_cycle_in_fast_mode */ | ||||
| typedef enum | ||||
| { | ||||
|     I2C_DutyCycle_16_9 = RB_I2C_DUTY, /* I2C fast mode Tlow/Thigh = 16/9 */ | ||||
|     I2C_DutyCycle_2 = 0x0000,         /* I2C fast mode Tlow/Thigh = 2 */ | ||||
| } I2C_DutyTypeDef; | ||||
| 
 | ||||
| /* I2C_acknowledgement - Enables or disables the acknowledgement.*/ | ||||
| typedef enum | ||||
| { | ||||
|     I2C_Ack_Enable = RB_I2C_ACK, | ||||
|     I2C_Ack_Disable = 0x0000, | ||||
| } I2C_AckTypeDef; | ||||
| 
 | ||||
| /* I2C_acknowledged_address - Specifies if 7-bit or 10-bit address is acknowledged. */ | ||||
| typedef enum | ||||
| { | ||||
|     I2C_AckAddr_7bit = 0x4000, | ||||
|     I2C_AckAddr_10bit = 0xC000, | ||||
| } I2C_AckAddrTypeDef; | ||||
| 
 | ||||
| /* I2C_interrupts_definition */ | ||||
| typedef enum | ||||
| { | ||||
|     I2C_IT_BUF = 0x0400, /* Buffer interrupt mask. */ | ||||
|     I2C_IT_EVT = 0x0200, /* Event interrupt mask. */ | ||||
|     I2C_IT_ERR = 0x0100, /* Error interrupt mask. */ | ||||
| } I2C_ITTypeDef; | ||||
| 
 | ||||
| /* I2C_interrupts_definition */ | ||||
| #define I2C_IT_SMBALERT                                      ((uint32_t)0x01008000) | ||||
| #define I2C_IT_TIMEOUT                                       ((uint32_t)0x01004000) | ||||
| #define I2C_IT_PECERR                                        ((uint32_t)0x01001000) | ||||
| #define I2C_IT_OVR                                           ((uint32_t)0x01000800) | ||||
| #define I2C_IT_AF                                            ((uint32_t)0x01000400) | ||||
| #define I2C_IT_ARLO                                          ((uint32_t)0x01000200) | ||||
| #define I2C_IT_BERR                                          ((uint32_t)0x01000100) | ||||
| #define I2C_IT_TXE                                           ((uint32_t)0x06000080) | ||||
| #define I2C_IT_RXNE                                          ((uint32_t)0x06000040) | ||||
| #define I2C_IT_STOPF                                         ((uint32_t)0x02000010) | ||||
| #define I2C_IT_ADD10                                         ((uint32_t)0x02000008) | ||||
| #define I2C_IT_BTF                                           ((uint32_t)0x02000004) | ||||
| #define I2C_IT_ADDR                                          ((uint32_t)0x02000002) | ||||
| #define I2C_IT_SB                                            ((uint32_t)0x02000001) | ||||
| 
 | ||||
| /* SR2 register flags  */ | ||||
| #define I2C_FLAG_DUALF                                       ((uint32_t)0x00800000) | ||||
| #define I2C_FLAG_SMBHOST                                     ((uint32_t)0x00400000) | ||||
| #define I2C_FLAG_SMBDEFAULT                                  ((uint32_t)0x00200000) | ||||
| #define I2C_FLAG_GENCALL                                     ((uint32_t)0x00100000) | ||||
| #define I2C_FLAG_TRA                                         ((uint32_t)0x00040000) | ||||
| #define I2C_FLAG_BUSY                                        ((uint32_t)0x00020000) | ||||
| #define I2C_FLAG_MSL                                         ((uint32_t)0x00010000) | ||||
| 
 | ||||
| /* SR1 register flags */ | ||||
| #define I2C_FLAG_SMBALERT                                    ((uint32_t)0x10008000) | ||||
| #define I2C_FLAG_TIMEOUT                                     ((uint32_t)0x10004000) | ||||
| #define I2C_FLAG_PECERR                                      ((uint32_t)0x10001000) | ||||
| #define I2C_FLAG_OVR                                         ((uint32_t)0x10000800) | ||||
| #define I2C_FLAG_AF                                          ((uint32_t)0x10000400) | ||||
| #define I2C_FLAG_ARLO                                        ((uint32_t)0x10000200) | ||||
| #define I2C_FLAG_BERR                                        ((uint32_t)0x10000100) | ||||
| #define I2C_FLAG_TXE                                         ((uint32_t)0x10000080) | ||||
| #define I2C_FLAG_RXNE                                        ((uint32_t)0x10000040) | ||||
| #define I2C_FLAG_STOPF                                       ((uint32_t)0x10000010) | ||||
| #define I2C_FLAG_ADD10                                       ((uint32_t)0x10000008) | ||||
| #define I2C_FLAG_BTF                                         ((uint32_t)0x10000004) | ||||
| #define I2C_FLAG_ADDR                                        ((uint32_t)0x10000002) | ||||
| #define I2C_FLAG_SB                                          ((uint32_t)0x10000001) | ||||
| 
 | ||||
| /****************I2C Master Events (Events grouped in order of communication)********************/ | ||||
| 
 | ||||
| #define I2C_EVENT_MASTER_MODE_SELECT                         ((uint32_t)0x00030001) /* BUSY, MSL and SB flag */ | ||||
| #define I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED           ((uint32_t)0x00070082) /* BUSY, MSL, ADDR, TXE and TRA flags */ | ||||
| #define I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED              ((uint32_t)0x00030002) /* BUSY, MSL and ADDR flags */ | ||||
| #define I2C_EVENT_MASTER_MODE_ADDRESS10                      ((uint32_t)0x00030008) /* BUSY, MSL and ADD10 flags */ | ||||
| #define I2C_EVENT_MASTER_BYTE_RECEIVED                       ((uint32_t)0x00030040) /* BUSY, MSL and RXNE flags */ | ||||
| #define I2C_EVENT_MASTER_BYTE_TRANSMITTING                   ((uint32_t)0x00070080) /* TRA, BUSY, MSL, TXE flags */ | ||||
| #define I2C_EVENT_MASTER_BYTE_TRANSMITTED                    ((uint32_t)0x00070084) /* TRA, BUSY, MSL, TXE and BTF flags */ | ||||
| 
 | ||||
| /******************I2C Slave Events (Events grouped in order of communication)******************/ | ||||
| 
 | ||||
| #define I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED             ((uint32_t)0x00020002) /* BUSY and ADDR flags */ | ||||
| #define I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED          ((uint32_t)0x00060082) /* TRA, BUSY, TXE and ADDR flags */ | ||||
| #define I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED       ((uint32_t)0x00820000) /* DUALF and BUSY flags */ | ||||
| #define I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED    ((uint32_t)0x00860080) /* DUALF, TRA, BUSY and TXE flags */ | ||||
| #define I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED           ((uint32_t)0x00120000) /* GENCALL and BUSY flags */ | ||||
| #define I2C_EVENT_SLAVE_BYTE_RECEIVED                        ((uint32_t)0x00020040) /* BUSY and RXNE flags */ | ||||
| #define I2C_EVENT_SLAVE_STOP_DETECTED                        ((uint32_t)0x00000010) /* STOPF flag */ | ||||
| #define I2C_EVENT_SLAVE_BYTE_TRANSMITTED                     ((uint32_t)0x00060084) /* TRA, BUSY, TXE and BTF flags */ | ||||
| #define I2C_EVENT_SLAVE_BYTE_TRANSMITTING                    ((uint32_t)0x00060080) /* TRA, BUSY and TXE flags */ | ||||
| #define I2C_EVENT_SLAVE_ACK_FAILURE                          ((uint32_t)0x00000400) /* AF flag */ | ||||
| 
 | ||||
| void I2C_Init(I2C_ModeTypeDef I2C_Mode, UINT32 I2C_ClockSpeed, I2C_DutyTypeDef I2C_DutyCycle, | ||||
|               I2C_AckTypeDef I2C_Ack, I2C_AckAddrTypeDef I2C_AckAddr, UINT16 I2C_OwnAddress1); | ||||
| void I2C_Cmd(FunctionalState NewState); | ||||
| void I2C_GenerateSTART(FunctionalState NewState); | ||||
| void I2C_GenerateSTOP(FunctionalState NewState); | ||||
| void I2C_AcknowledgeConfig(FunctionalState NewState); | ||||
| void I2C_OwnAddress2Config(uint8_t Address); | ||||
| void I2C_DualAddressCmd(FunctionalState NewState); | ||||
| void I2C_GeneralCallCmd(FunctionalState NewState); | ||||
| void I2C_ITConfig(I2C_ITTypeDef I2C_IT, FunctionalState NewState); | ||||
| void I2C_SendData(uint8_t Data); | ||||
| 
 | ||||
| uint8_t I2C_ReceiveData(void); | ||||
| 
 | ||||
| void I2C_Send7bitAddress(uint8_t Address, uint8_t I2C_Direction); | ||||
| void I2C_SoftwareResetCmd(FunctionalState NewState); | ||||
| void I2C_NACKPositionConfig(uint16_t I2C_NACKPosition); | ||||
| void I2C_SMBusAlertConfig(uint16_t I2C_SMBusAlert); | ||||
| void I2C_TransmitPEC(FunctionalState NewState); | ||||
| void I2C_PECPositionConfig(uint16_t I2C_PECPosition); | ||||
| void I2C_CalculatePEC(FunctionalState NewState); | ||||
| 
 | ||||
| uint8_t I2C_GetPEC(void); | ||||
| 
 | ||||
| void I2C_ARPCmd(FunctionalState NewState); | ||||
| void I2C_StretchClockCmd(FunctionalState NewState); | ||||
| void I2C_FastModeDutyCycleConfig(uint16_t I2C_DutyCycle); | ||||
| 
 | ||||
| /****************************************************************************************
 | ||||
|  *                         I2C State Monitoring Functions | ||||
|  ****************************************************************************************/ | ||||
| uint8_t    I2C_CheckEvent(uint32_t I2C_EVENT); | ||||
| uint32_t   I2C_GetLastEvent(void); | ||||
| FlagStatus I2C_GetFlagStatus(uint32_t I2C_FLAG); | ||||
| 
 | ||||
| void     I2C_ClearFlag(uint32_t I2C_FLAG); | ||||
| ITStatus I2C_GetITStatus(uint32_t I2C_IT); | ||||
| void     I2C_ClearITPendingBit(uint32_t I2C_IT); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_I2C_H__
 | ||||
							
								
								
									
										98
									
								
								vendor/StdPeriphDriver/inc/CH59x_lcd.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								vendor/StdPeriphDriver/inc/CH59x_lcd.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,98 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_lcd.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.0 | ||||
|  * Date               : 2022/12/05 | ||||
|  * Description        :  | ||||
|  ******************************************************************************** | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| 
 | ||||
| #ifndef __CH59x_LCD_H__ | ||||
| #define __CH59x_LCD_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #include "CH592SFR.h" | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Configuration LCD driver power | ||||
|   */ | ||||
| typedef enum | ||||
| { | ||||
| 	LCD_PS_3V3 = 0,					// 3.3V 驱动
 | ||||
| 	LCD_PS_2V5,						// 2.5V 驱动
 | ||||
| }LCDDrvPowerTypeDef;  | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Configuration LCD bias | ||||
|   */ | ||||
| typedef enum | ||||
| { | ||||
| 	LCD_1_2_Bias = 0,				// 2级分压
 | ||||
| 	LCD_1_3_Bias,					// 3级分压
 | ||||
| }LCDBiasTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Configuration LCD duty | ||||
|   */ | ||||
| typedef enum | ||||
| { | ||||
| 	LCD_1_2_Duty = 0,				// COM0-COM1
 | ||||
| 	LCD_1_3_Duty,					// COM0-COM2
 | ||||
| 	LCD_1_4_Duty,					// COM0-COM3
 | ||||
| }LCDDutyTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Configuration LCD scan clk | ||||
|   */ | ||||
| typedef enum | ||||
| { | ||||
| 	LCD_CLK_256 = 0,				// 256Hz
 | ||||
| 	LCD_CLK_512,					// 512Hz
 | ||||
| 	LCD_CLK_1000,					// 1KHz
 | ||||
| 	LCD_CLK_128						// 128Hz
 | ||||
| }LCDSCANCLKTypeDef; | ||||
| 	  | ||||
| /* LCD段式屏驱动初始化配置 */ | ||||
| void LCD_Init(LCDDutyTypeDef duty, LCDBiasTypeDef bias); | ||||
| 
 | ||||
| #define	LCD_PowerDown()			(R32_LCD_CMD &= ~(RB_LCD_ON | RB_LCD_SYS_EN))		/* LCD功能模块关闭 */ | ||||
| #define	LCD_PowerOn()			(R32_LCD_CMD |= (RB_LCD_ON | RB_LCD_SYS_EN))		/* LCD功能模块开启 */ | ||||
| 
 | ||||
| // 输入值参考 LCDDrvPowerTypeDef
 | ||||
| #define LCD_PowerCfg( d )		(R32_LCD_CMD = (R32_LCD_CMD & ~RB_LCD_VLCD_SEL) | (d<<7))			/* 配置LCD的 供电电压选择 */ | ||||
| // 输入值参考 LCDSCANCLKTypeDef
 | ||||
| #define LCD_ScanCLKCfg( d )		(R32_LCD_CMD = (R32_LCD_CMD & ~RB_LCD_SCAN_CLK) | (d<<5))			/* 配置LCD的 扫描时钟选择 */ | ||||
| // 输入值参考 LCDDutyTypeDef
 | ||||
| #define LCD_DutyCfg( d )		(R32_LCD_CMD = (R32_LCD_CMD & ~RB_LCD_DUTY) | (d<<3))				/* 配置LCD的 duty选择 */ | ||||
| // 输入值参考 LCDBiasTypeDef
 | ||||
| #define LCD_BiasCfg( d )		(R32_LCD_CMD = (R32_LCD_CMD & ~RB_LCD_BIAS) | (d<<2))				/* 配置LCD的 bias选择 */ | ||||
| 	  | ||||
| #define LCD_WriteData0( d )		(R32_LCD_RAM0 = (R32_LCD_RAM0 & 0xffffff00) | ((UINT32)d))			/* 填充SEG0驱动数值 */ | ||||
| #define LCD_WriteData1( d )		(R32_LCD_RAM0 = (R32_LCD_RAM0 & 0xffff00ff) | ((UINT32)d<<8))		/* 填充SEG1驱动数值 */ | ||||
| #define LCD_WriteData2( d )		(R32_LCD_RAM0 = (R32_LCD_RAM0 & 0xff00ffff) | ((UINT32)d<<16))		/* 填充SEG2驱动数值 */ | ||||
| #define LCD_WriteData3( d )		(R32_LCD_RAM0 = (R32_LCD_RAM0 & 0x00ffffff) | ((UINT32)d<<24))		/* 填充SEG3驱动数值 */ | ||||
| 	  | ||||
| #define LCD_WriteData4( d )		(R32_LCD_RAM1 = (R32_LCD_RAM1 & 0xffffff00) | ((UINT32)d))			/* 填充SEG4驱动数值 */ | ||||
| #define LCD_WriteData5( d )		(R32_LCD_RAM1 = (R32_LCD_RAM1 & 0xffff00ff) | ((UINT32)d<<8))		/* 填充SEG5驱动数值 */ | ||||
| #define LCD_WriteData6( d )		(R32_LCD_RAM1 = (R32_LCD_RAM1 & 0xff00ffff) | ((UINT32)d<<16))		/* 填充SEG6驱动数值 */ | ||||
| #define LCD_WriteData7( d )		(R32_LCD_RAM1 = (R32_LCD_RAM1 & 0x00ffffff) | ((UINT32)d<<24))		/* 填充SEG7驱动数值 */ | ||||
| 	  | ||||
| #define LCD_WriteData8( d )		(R32_LCD_RAM2 = (R32_LCD_RAM2 & 0xffffff00) | ((UINT32)d))			/* 填充SEG8驱动数值 */ | ||||
| #define LCD_WriteData9( d )		(R32_LCD_RAM2 = (R32_LCD_RAM2 & 0xffff00ff) | ((UINT32)d<<8))		/* 填充SEG9驱动数值 */ | ||||
| #define LCD_WriteData10( d )	(R32_LCD_RAM2 = (R32_LCD_RAM2 & 0xff00ffff) | ((UINT32)d<<16))		/* 填充SEG10驱动数值 */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif  // __CH59x_LCD_H__	
 | ||||
| 
 | ||||
							
								
								
									
										167
									
								
								vendor/StdPeriphDriver/inc/CH59x_pwm.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								vendor/StdPeriphDriver/inc/CH59x_pwm.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,167 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_pwm.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_PWM_H__ | ||||
| #define __CH59x_PWM_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  channel of PWM define | ||||
|  */ | ||||
| #define CH_PWM4     0x01  // PWM4 通道
 | ||||
| #define CH_PWM5     0x02  // PWM5 通道
 | ||||
| #define CH_PWM6     0x04  // PWM6 通道
 | ||||
| #define CH_PWM7     0x08  // PWM7 通道
 | ||||
| #define CH_PWM8     0x10  // PWM8 通道
 | ||||
| #define CH_PWM9     0x20  // PWM9 通道
 | ||||
| #define CH_PWM10    0x40  // PWM10 通道
 | ||||
| #define CH_PWM11    0x80  // PWM11 通道
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  channel of PWM define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     High_Level = 0, // 默认低电平,高电平有效
 | ||||
|     Low_Level,      // 默认高电平,低电平有效
 | ||||
| } PWMX_PolarTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration PWM4_11 Cycle size | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     PWMX_Cycle_256 = 0, // 256 个PWMX周期
 | ||||
|     PWMX_Cycle_255,     // 255 个PWMX周期
 | ||||
|     PWMX_Cycle_128,     // 128 个PWMX周期
 | ||||
|     PWMX_Cycle_127,     // 127 个PWMX周期
 | ||||
|     PWMX_Cycle_64,      // 64 个PWMX周期
 | ||||
|     PWMX_Cycle_63,      // 63 个PWMX周期
 | ||||
| } PWMX_CycleTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM4-PWM11 通道基准时钟配置 | ||||
|  * | ||||
|  * @param   d   - 通道基准时钟 = d*Tsys | ||||
|  */ | ||||
| #define PWMX_CLKCfg(d)    (R8_PWM_CLOCK_DIV = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM4-PWM11周期配置 | ||||
|  * | ||||
|  * @param   cyc - refer to PWMX_CycleTypeDef | ||||
|  */ | ||||
| void PWMX_CycleCfg(PWMX_CycleTypeDef cyc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM4-PWM9 16位周期配置 | ||||
|  * | ||||
|  * @param   cyc - 16位周期 | ||||
|  */ | ||||
| void PWMX_16bit_CycleCfg(uint16_t cyc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM4 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM4_ActDataWidth(d)     (R8_PWM4_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM5 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM5_ActDataWidth(d)     (R8_PWM5_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM6 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM6_ActDataWidth(d)     (R8_PWM6_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM7 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM7_ActDataWidth(d)     (R8_PWM7_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM8 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM8_ActDataWidth(d)     (R8_PWM8_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM9 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM9_ActDataWidth(d)     (R8_PWM9_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM10 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM10_ActDataWidth(d)    (R8_PWM10_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置 PWM11 有效数据脉宽 | ||||
|  * | ||||
|  * @param   d   - 有效数据脉宽 | ||||
|  */ | ||||
| #define PWM11_ActDataWidth(d)    (R8_PWM11_DATA = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM4-PWM11通道输出波形配置 | ||||
|  * | ||||
|  * @param   ch      - select channel of pwm, refer to channel of PWM define | ||||
|  * @param   da      - effective pulse width | ||||
|  * @param   pr      - select wave polar, refer to PWMX_PolarTypeDef | ||||
|  * @param   s       - control pwmx function, ENABLE or DISABLE | ||||
|  */ | ||||
| void PWMX_ACTOUT(uint8_t ch, uint8_t da, PWMX_PolarTypeDef pr, FunctionalState s); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM4-PWM9 通道16位输出波形配置 | ||||
|  * | ||||
|  * @param   ch      - select channel of pwm, refer to channel of PWM define | ||||
|  * @param   da      - effective pulse width | ||||
|  * @param   pr      - select wave polar, refer to PWMX_PolarTypeDef | ||||
|  * @param   s       - control pwmx function, ENABLE or DISABLE | ||||
|  */ | ||||
| void PWMX_16bit_ACTOUT(uint8_t ch, uint16_t da, PWMX_PolarTypeDef pr, FunctionalState s); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM 交替输出模式配置 | ||||
|  * | ||||
|  * @param   ch      - select group of PWM alternate output | ||||
|  *                    RB_PWM4_5_STAG_EN     -  PWM4 和 PWM5 通道交替输出 | ||||
|  *                    RB_PWM6_7_STAG_EN     -  PWM6 和 PWM7 通道交替输出 | ||||
|  *                    RB_PWM8_9_STAG_EN     -  PWM8 和 PWM9 通道交替输出 | ||||
|  *                    RB_PWM10_11_STAG_EN   -  PWM10 和 PWM11 通道交替输出 | ||||
|  * @param   s       - control pwmx function, ENABLE or DISABLE | ||||
|  */ | ||||
| void PWMX_AlterOutCfg(uint8_t ch, FunctionalState s); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_PWM_H__
 | ||||
							
								
								
									
										169
									
								
								vendor/StdPeriphDriver/inc/CH59x_pwr.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								vendor/StdPeriphDriver/inc/CH59x_pwr.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,169 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_pwr.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_PWR_H__ | ||||
| #define __CH59x_PWR_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #define ROM_CFG_ADR_HW       0x7F00C            // config address for hardware config for LDO&OSC and etc
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief	Peripher CLK control bit define | ||||
|  */ | ||||
| #define BIT_SLP_CLK_TMR0     (0x00000001) /*!< TMR0 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_TMR1     (0x00000002) /*!< TMR1 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_TMR2     (0x00000004) /*!< TMR2 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_TMR3     (0x00000008) /*!< TMR3 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_UART0    (0x00000010) /*!< UART0 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_UART1    (0x00000020) /*!< UART1 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_UART2    (0x00000040) /*!< UART2 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_UART3    (0x00000080) /*!< UART3 peripher clk bit */ | ||||
| #define BIT_SLP_CLK_SPI0     (0x00000100) /*!< SPI0 peripher clk bit */ | ||||
| //#define BIT_SLP_CLK_SPI1     (0x00000200)  /*!< SPI1 peripher clk bit */
 | ||||
| #define BIT_SLP_CLK_PWMX     (0x00000400) /*!< PWMX peripher clk bit */ | ||||
| //#define BIT_SLP_CLK_LCD      (0x00000800)  /*!< LCD peripher clk bit */
 | ||||
| #define BIT_SLP_CLK_USB      (0x00001000) /*!< USB peripher clk bit */ | ||||
| //#define BIT_SLP_CLK_ETH      (0x00002000)  /*!< ETH peripher clk bit */
 | ||||
| //#define BIT_SLP_CLK_LED      (0x00004000)  /*!< LED peripher clk bit */
 | ||||
| #define BIT_SLP_CLK_BLE      (0x00008000) /*!< BLE peripher clk bit */ | ||||
| 
 | ||||
| #define BIT_SLP_CLK_RAMX     (0x10000000) /*!< main SRAM RAM16K peripher clk bit */ | ||||
| #define BIT_SLP_CLK_RAM2K    (0x20000000) /*!< RAM2K peripher clk bit */ | ||||
| #define BIT_SLP_CLK_ALL      (0x3000FFFF) /*!< All peripher clk bit */ | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  unit of controllable power supply | ||||
|  */ | ||||
| #define UNIT_SYS_LSE         RB_CLK_XT32K_PON   // 外部32K 时钟振荡
 | ||||
| #define UNIT_SYS_LSI         RB_CLK_INT32K_PON  // 内部32K 时钟振荡
 | ||||
| #define UNIT_SYS_HSE         RB_CLK_XT32M_PON   // 外部32M 时钟振荡
 | ||||
| #define UNIT_SYS_PLL         RB_CLK_PLL_PON     // PLL 时钟振荡
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  wakeup mode define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     Short_Delay = 0, | ||||
|     Long_Delay, | ||||
| 
 | ||||
| } WakeUP_ModeypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  wakeup mode define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     /* 下面等级将使用高精度监控,210uA消耗 */ | ||||
|     HALevel_1V9 = 0, // 1.7-1.9
 | ||||
|     HALevel_2V1,     // 1.9-2.1
 | ||||
|     HALevel_2V3,     // 2.1-2.3
 | ||||
|     HALevel_2V5,     // 2.3-2.5
 | ||||
| 
 | ||||
|     /* 下面等级将使用低功耗监控,1uA消耗 */ | ||||
|     LPLevel_1V8 = 0x80, | ||||
|     LPLevel_1V9, | ||||
|     LPLevel_2V0, | ||||
|     LPLevel_2V1, | ||||
|     LPLevel_2V2, | ||||
|     LPLevel_2V3, | ||||
|     LPLevel_2V4, | ||||
|     LPLevel_2V5, | ||||
| 
 | ||||
| } VolM_LevelypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   启用内部DC/DC电源,用于节约系统功耗 | ||||
|  * | ||||
|  * @param   s   - 是否打开DCDC电源 | ||||
|  */ | ||||
| void PWR_DCDCCfg(FunctionalState s); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   可控单元模块的电源控制 | ||||
|  * | ||||
|  * @param   s       - 是否打开电源 | ||||
|  * @param   unit    - please refer to unit of controllable power supply | ||||
|  */ | ||||
| void PWR_UnitModCfg(FunctionalState s, uint8_t unit); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外设时钟控制位 | ||||
|  * | ||||
|  * @param   s       - 是否打开对应外设时钟 | ||||
|  * @param   perph   - please refer to Peripher CLK control bit define | ||||
|  */ | ||||
| void PWR_PeriphClkCfg(FunctionalState s, uint16_t perph); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   睡眠唤醒源配置 | ||||
|  * | ||||
|  * @param   s       - 是否打开此外设睡眠唤醒功能 | ||||
|  * @param   perph   - 需要设置的唤醒源 | ||||
|  *                    RB_SLP_USB_WAKE   -  USB 为唤醒源 | ||||
|  *                    RB_SLP_RTC_WAKE   -  RTC 为唤醒源 | ||||
|  *                    RB_SLP_GPIO_WAKE  -  GPIO 为唤醒源 | ||||
|  *                    RB_SLP_BAT_WAKE   -  BAT 为唤醒源 | ||||
|  * @param   mode    - refer to WakeUP_ModeypeDef | ||||
|  */ | ||||
| void PWR_PeriphWakeUpCfg(FunctionalState s, uint8_t perph, WakeUP_ModeypeDef mode); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   电源监控 | ||||
|  * | ||||
|  * @param   s       - 是否打开此功能 | ||||
|  * @param   vl      - refer to VolM_LevelypeDef | ||||
|  */ | ||||
| void PowerMonitor(FunctionalState s, VolM_LevelypeDef vl); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   低功耗-Idle模式 | ||||
|  */ | ||||
| void LowPower_Idle(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   低功耗-Halt模式,此低功耗切到HSI/5时钟运行,唤醒后需要用户自己重新选择系统时钟源 | ||||
|  */ | ||||
| void LowPower_Halt(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   低功耗-Sleep模式,此低功耗切到HSI/5时钟运行,唤醒后需要用户自己重新选择系统时钟源 | ||||
|  *          @note 注意调用此函数,DCDC功能强制关闭,唤醒后可以手动再次打开 | ||||
|  * | ||||
|  * @param   rm      - 供电模块选择 | ||||
|  *                    RB_PWR_RAM2K  -   2K retention SRAM 供电 | ||||
|  *                    RB_PWR_RAM16K -   16K main SRAM 供电 | ||||
|  *                    RB_PWR_EXTEND -   USB 和 BLE 单元保留区域供电 | ||||
|  *                    RB_PWR_XROM   -   FlashROM 供电 | ||||
|  *                    NULL          -   以上单元都断电 | ||||
|  */ | ||||
| void LowPower_Sleep(uint16_t rm); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   低功耗-Shutdown模式,此低功耗切到HSI/5时钟运行,唤醒后需要用户自己重新选择系统时钟源 | ||||
|  *          @note 注意调用此函数,DCDC功能强制关闭,唤醒后可以手动再次打开 | ||||
|  * | ||||
|  * @param   rm      - 供电模块选择 | ||||
|  *                    RB_PWR_RAM2K  -   2K retention SRAM 供电 | ||||
|  *                    RB_PWR_RAM16K -   16K main SRAM 供电 | ||||
|  *                    NULL          -   以上单元都断电 | ||||
|  */ | ||||
| void LowPower_Shutdown(uint16_t rm); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_PWR_H__
 | ||||
							
								
								
									
										214
									
								
								vendor/StdPeriphDriver/inc/CH59x_spi.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										214
									
								
								vendor/StdPeriphDriver/inc/CH59x_spi.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,214 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_SPI.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_SPI_H__ | ||||
| #define __CH59x_SPI_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  SPI0 interrupt bit define | ||||
|  */ | ||||
| #define SPI0_IT_FST_BYTE    RB_SPI_IE_FST_BYTE  // 从机模式的首字节命令模式下,接收到首字节中断
 | ||||
| #define SPI0_IT_FIFO_OV     RB_SPI_IE_FIFO_OV   // FIFO 溢出
 | ||||
| #define SPI0_IT_DMA_END     RB_SPI_IE_DMA_END   // DMA 传输结束
 | ||||
| #define SPI0_IT_FIFO_HF     RB_SPI_IE_FIFO_HF   // FIFO 使用过半
 | ||||
| #define SPI0_IT_BYTE_END    RB_SPI_IE_BYTE_END  // 单字节传输完成
 | ||||
| #define SPI0_IT_CNT_END     RB_SPI_IE_CNT_END   // 全部字节传输完成
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration data mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     Mode0_LowBitINFront = 0, // 模式0,低位在前
 | ||||
|     Mode0_HighBitINFront,    // 模式0,高位在前
 | ||||
|     Mode3_LowBitINFront,     // 模式3,低位在前
 | ||||
|     Mode3_HighBitINFront,    // 模式3,高位在前
 | ||||
| } ModeBitOrderTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration SPI0 slave mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     Mode_DataStream = 0, // 数据流模式
 | ||||
|     Mose_FirstCmd,       // 首字节命令模式
 | ||||
| } Slave_ModeTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   主机模式默认初始化:模式0+3线全双工+8MHz | ||||
|  */ | ||||
| void SPI0_MasterDefInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   SPI0 基准时钟配置,= d*Tsys | ||||
|  * | ||||
|  * @param   c       - 时钟分频系数 | ||||
|  */ | ||||
| void SPI0_CLKCfg(uint8_t c); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置数据流模式 | ||||
|  * | ||||
|  * @param   m       - 数据流模式 refer to ModeBitOrderTypeDef | ||||
|  */ | ||||
| void SPI0_DataMode(ModeBitOrderTypeDef m); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   发送单字节 (buffer) | ||||
|  * | ||||
|  * @param   d       - 发送字节 | ||||
|  */ | ||||
| void SPI0_MasterSendByte(uint8_t d); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   接收单字节 (buffer) | ||||
|  * | ||||
|  * @param   none | ||||
|  */ | ||||
| uint8_t SPI0_MasterRecvByte(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   使用FIFO连续发送多字节 | ||||
|  * | ||||
|  * @param   pbuf    - 待发送的数据内容首地址 | ||||
|  * @param   len     - 请求发送的数据长度,最大4095 | ||||
|  */ | ||||
| void SPI0_MasterTrans(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   使用FIFO连续接收多字节 | ||||
|  * | ||||
|  * @param   pbuf    - 待接收的数据首地址 | ||||
|  * @param   len     - 待接收的数据长度,最大4095 | ||||
|  */ | ||||
| void SPI0_MasterRecv(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   DMA方式连续发送数据 | ||||
|  * | ||||
|  * @param   pbuf    - 待发送数据起始地址,需要四字节对其 | ||||
|  * @param   len     - 待发送数据长度 | ||||
|  */ | ||||
| void SPI0_MasterDMATrans(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   DMA方式连续接收数据 | ||||
|  * | ||||
|  * @param   pbuf    - 待接收数据存放起始地址,需要四字节对其 | ||||
|  * @param   len     - 待接收数据长度 | ||||
|  */ | ||||
| void SPI0_MasterDMARecv(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| void SPI1_MasterDefInit(void);             /* 主机模式默认初始化:模式0+3线全双工+8MHz */ | ||||
| void SPI1_CLKCfg(UINT8 c);                 /* SPI1 基准时钟配置,= d*Tsys */ | ||||
| void SPI1_DataMode(ModeBitOrderTypeDef m); /* 设置数据流模式 */ | ||||
| 
 | ||||
| void  SPI1_MasterSendByte(UINT8 d); /* 发送单字节 (buffer) */ | ||||
| UINT8 SPI1_MasterRecvByte(void);    /* 接收单字节 (buffer) */ | ||||
| 
 | ||||
| void SPI1_MasterTrans(UINT8 *pbuf, UINT16 len); /* 使用FIFO连续发送多字节 */ | ||||
| void SPI1_MasterRecv(UINT8 *pbuf, UINT16 len);  /* 使用FIFO连续接收多字节 */ | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设备模式默认初始化,建议设置MISO的GPIO对应为输入模式 | ||||
|  */ | ||||
| void SPI0_SlaveInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   加载首字节数据内容 | ||||
|  * | ||||
|  * @param   d       - 首字节数据内容 | ||||
|  */ | ||||
| #define SetFirstData(d)    (R8_SPI0_SLAVE_PRE = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   从机模式,发送一字节数据 | ||||
|  * | ||||
|  * @param   d       - 待发送数据 | ||||
|  */ | ||||
| void SPI0_SlaveSendByte(uint8_t d); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   从机模式,接收一字节数据 | ||||
|  * | ||||
|  * @return  接收到数据 | ||||
|  */ | ||||
| uint8_t SPI0_SlaveRecvByte(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   从机模式,发送多字节数据 | ||||
|  * | ||||
|  * @param   pbuf    - 待发送的数据内容首地址 | ||||
|  * @param   len     - 请求发送的数据长度,最大4095 | ||||
|  */ | ||||
| void SPI0_SlaveTrans(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   从机模式,接收多字节数据 | ||||
|  * | ||||
|  * @param   pbuf    - 接收收数据存放起始地址 | ||||
|  * @param   len     - 请求接收数据长度 | ||||
|  */ | ||||
| void SPI0_SlaveRecv(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   DMA方式连续发送数据 | ||||
|  * | ||||
|  * @param   pbuf    - 待发送数据起始地址,需要四字节对其 | ||||
|  * @param   len     - 待发送数据长度 | ||||
|  */ | ||||
| void SPI0_SlaveDMATrans(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   DMA方式连续接收数据 | ||||
|  * | ||||
|  * @param   pbuf    - 待接收数据存放起始地址,需要四字节对其 | ||||
|  * @param   len     - 待接收数据长度 | ||||
|  */ | ||||
| void SPI0_SlaveDMARecv(uint8_t *pbuf, uint16_t len); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   配置SPI0中断 | ||||
|  * | ||||
|  * @param   s       - 使能/关闭 | ||||
|  * @param   f       - refer to SPI0 interrupt bit define | ||||
|  */ | ||||
| #define SPI0_ITCfg(s, f)       ((s) ? (R8_SPI0_INTER_EN |= f) : (R8_SPI0_INTER_EN &= ~f)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取中断标志状态,0-未置位,(!0)-触发 | ||||
|  * | ||||
|  * @param   f       - refer to SPI0 interrupt bit define | ||||
|  */ | ||||
| #define SPI0_GetITFlag(f)      (R8_SPI0_INT_FLAG & f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前中断标志 | ||||
|  * | ||||
|  * @param   f       - refer to SPI0 interrupt bit define | ||||
|  */ | ||||
| #define SPI0_ClearITFlag(f)    (R8_SPI0_INT_FLAG = f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭SPI0 | ||||
|  */ | ||||
| #define SPI0_Disable()         (R8_SPI0_CTRL_MOD &= ~(RB_SPI_MOSI_OE | RB_SPI_SCK_OE | RB_SPI_MISO_OE)) | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_SPI_H__
 | ||||
							
								
								
									
										189
									
								
								vendor/StdPeriphDriver/inc/CH59x_sys.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										189
									
								
								vendor/StdPeriphDriver/inc/CH59x_sys.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,189 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_SYS.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_SYS_H__ | ||||
| #define __CH59x_SYS_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  reset state define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     RST_STATUS_SW = 0, // 软件复位
 | ||||
|     RST_STATUS_RPOR,   // 上电复位
 | ||||
|     RST_STATUS_WTR,    // 看门狗超时复位
 | ||||
|     RST_STATUS_MR,     // 外部手动复位
 | ||||
|     RST_STATUS_LRM0,   // 唤醒复位-软复位引起
 | ||||
|     RST_STATUS_GPWSM,  // 下电模式唤醒复位
 | ||||
|     RST_STATUS_LRM1,   //	唤醒复位-看门狗引起
 | ||||
|     RST_STATUS_LRM2,   //	唤醒复位-手动复位引起
 | ||||
| 
 | ||||
| } SYS_ResetStaTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  sys info state define | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     INFO_ROM_READ = 0, // FlashROM 代码和数据区 是否可读
 | ||||
|     INFO_RESET_EN = 2, // RST#外部手动复位输入功能是否开启
 | ||||
|     INFO_BOOT_EN,      // 系统引导程序 BootLoader 是否开启
 | ||||
|     INFO_DEBUG_EN,     // 系统仿真调试接口是否开启
 | ||||
|     INFO_LOADER,       // 当前系统是否处于Bootloader 区
 | ||||
|     STA_SAFEACC_ACT,   // 当前系统是否处于安全访问状态,否则RWA属性区域不可访问
 | ||||
| 
 | ||||
| } SYS_InfoStaTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  获取芯片ID类,一般为固定值 | ||||
|  */ | ||||
| #define SYS_GetChipID()      R8_CHIP_ID | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  获取安全访问ID,一般为固定值 | ||||
|  */ | ||||
| #define SYS_GetAccessID()    R8_SAFE_ACCESS_ID | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   配置系统运行时钟 | ||||
|  * | ||||
|  * @param   sc      - 系统时钟源选择 refer to SYS_CLKTypeDef | ||||
|  */ | ||||
| void SetSysClock(SYS_CLKTypeDef sc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前系统时钟 | ||||
|  * | ||||
|  * @return  Hz | ||||
|  */ | ||||
| uint32_t GetSysClock(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前系统信息状态 | ||||
|  * | ||||
|  * @param   i       - refer to SYS_InfoStaTypeDef | ||||
|  * | ||||
|  * @return  是否开启 | ||||
|  */ | ||||
| uint8_t SYS_GetInfoSta(SYS_InfoStaTypeDef i); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取系统上次复位状态 | ||||
|  * | ||||
|  * @return  refer to SYS_ResetStaTypeDef | ||||
|  */ | ||||
| #define SYS_GetLastResetSta()    (R8_RESET_STATUS & RB_RESET_FLAG) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   执行系统软件复位 | ||||
|  */ | ||||
| void SYS_ResetExecute(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置复位保存寄存器的值,不受手动复位、 软件复位、 看门狗复位或者普通唤醒复位的影响 | ||||
|  * | ||||
|  * @param   i       - refer to SYS_InfoStaTypeDef | ||||
|  */ | ||||
| #define SYS_ResetKeepBuf(d)    (R8_GLOB_RESET_KEEP = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭所有中断,并保留当前中断值 | ||||
|  * | ||||
|  * @param   pirqv   - 当前保留中断值 | ||||
|  */ | ||||
| void SYS_DisableAllIrq(uint32_t *pirqv); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   恢复之前关闭的中断值 | ||||
|  * | ||||
|  * @param   irq_status  - 当前保留中断值 | ||||
|  */ | ||||
| void SYS_RecoverIrq(uint32_t irq_status); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前系统(SYSTICK)计数值 | ||||
|  * | ||||
|  * @return  当前计数值 | ||||
|  */ | ||||
| uint32_t SYS_GetSysTickCnt(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   加载看门狗计数初值,递增型 | ||||
|  * | ||||
|  * @param   c       - 看门狗计数初值 | ||||
|  */ | ||||
| #define WWDG_SetCounter(c)    (R8_WDOG_COUNT = c) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   看门狗定时器溢出中断使能 | ||||
|  * | ||||
|  * @param   s       - 溢出是否中断 | ||||
|  */ | ||||
| void WWDG_ITCfg(FunctionalState s); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   看门狗定时器复位功能 | ||||
|  * | ||||
|  * @param   s       - 溢出是否复位 | ||||
|  */ | ||||
| void WWDG_ResetCfg(FunctionalState s); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前看门狗定时器溢出标志 | ||||
|  * | ||||
|  * @return  看门狗定时器溢出标志 | ||||
|  */ | ||||
| #define WWDG_GetFlowFlag()    (R8_RST_WDOG_CTRL & RB_WDOG_INT_FLAG) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除看门狗中断标志,重新加载计数值也可清除 | ||||
|  */ | ||||
| void WWDG_ClearFlag(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   uS 延时 | ||||
|  * | ||||
|  * @param   t       - 时间参数 | ||||
|  */ | ||||
| void mDelayuS(uint16_t t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   mS 延时 | ||||
|  * | ||||
|  * @param   t       - 时间参数 | ||||
|  */ | ||||
| void mDelaymS(uint16_t t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief Enter safe access mode. | ||||
|  *  | ||||
|  * @NOTE: After enter safe access mode, about 16 system frequency cycles  | ||||
|  * are in safe mode, and one or more secure registers can be rewritten  | ||||
|  * within the valid period. The safe mode will be automatically  | ||||
|  * terminated after the above validity period is exceeded. | ||||
|  *  if sys_safe_access_enable() is called, | ||||
|  *  you must call sys_safe_access_disable() before call sys_safe_access_enable() again. | ||||
|  */ | ||||
| #define sys_safe_access_enable()        do{volatile uint32_t mpie_mie;mpie_mie=__risc_v_disable_irq();SAFEOPERATE;\ | ||||
|                                         R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;SAFEOPERATE; | ||||
| 
 | ||||
| #define sys_safe_access_disable()       R8_SAFE_ACCESS_SIG = 0;__risc_v_enable_irq(mpie_mie);SAFEOPERATE;}while(0) | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_SYS_H__
 | ||||
							
								
								
									
										595
									
								
								vendor/StdPeriphDriver/inc/CH59x_timer.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										595
									
								
								vendor/StdPeriphDriver/inc/CH59x_timer.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,595 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_timer.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_TIMER_H__ | ||||
| #define __CH59x_TIMER_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #define DataBit_25            (1 << 25) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  TMR0 interrupt bit define | ||||
|  */ | ||||
| 
 | ||||
| #define TMR0_3_IT_CYC_END     0x01  // 周期结束标志:捕捉-超时,定时-周期结束,PWM-周期结束
 | ||||
| #define TMR0_3_IT_DATA_ACT    0x02  // 数据有效标志:捕捉-新数据,PWM-有效电平结束
 | ||||
| #define TMR0_3_IT_FIFO_HF     0x04  // FIFO 使用过半:捕捉- FIFO>=4, PWM- FIFO<4
 | ||||
| #define TMR1_2_IT_DMA_END     0x08  // DMA 结束,支持TMR1和TMR2
 | ||||
| #define TMR0_3_IT_FIFO_OV     0x10  // FIFO 溢出:捕捉- FIFO满, PWM- FIFO空
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration PWM effective level repeat times | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     PWM_Times_1 = 0, // PWM 有效输出重复1次数
 | ||||
|     PWM_Times_4,     // PWM 有效输出重复4次数
 | ||||
|     PWM_Times_8,     // PWM 有效输出重复8次数
 | ||||
|     PWM_Times_16,    // PWM 有效输出重复16次数
 | ||||
| } PWM_RepeatTsTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration Cap mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     CAP_NULL = 0,         // 不捕捉 & 不计数
 | ||||
|     Edge_To_Edge,         // 任意边沿之间  &  计数任意边沿
 | ||||
|     FallEdge_To_FallEdge, // 下降沿到下降沿  & 计数下降沿
 | ||||
|     RiseEdge_To_RiseEdge, // 上升沿到上升沿  &  计数上升沿
 | ||||
| } CapModeTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration DMA mode | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     Mode_Single = 0, // 单次模式
 | ||||
|     Mode_LOOP,       // 循环模式
 | ||||
| } DMAModeTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   定时功能初始化 | ||||
|  * | ||||
|  * @param   t       - 定时时间,基于当前系统时钟Tsys, 最长定时周期 67108864 | ||||
|  */ | ||||
| void TMR0_TimerInit(uint32_t t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前定时器值,最大67108864 | ||||
|  * | ||||
|  * @return  当前定时器值 | ||||
|  */ | ||||
| #define TMR0_GetCurrentTimer()    R32_TMR0_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   边沿计数功能初始化 | ||||
|  * | ||||
|  * @param   cap     - 采集计数类型 | ||||
|  */ | ||||
| void TMR0_EXTSingleCounterInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置计数统计溢出大小,最大67108862 | ||||
|  * | ||||
|  * @param   cyc     - 计数统计溢出大小 | ||||
|  */ | ||||
| #define TMR0_CountOverflowCfg(cyc)    (R32_TMR0_CNT_END = (cyc + 2)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前计数值,最大67108862 | ||||
|  * | ||||
|  * @return  当前计数值 | ||||
|  */ | ||||
| #define TMR0_GetCurrentCount()        R32_TMR0_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM0 通道输出波形周期配置, 最大67108864 | ||||
|  * | ||||
|  * @param   cyc     - 输出波形周期 | ||||
|  */ | ||||
| #define TMR0_PWMCycleCfg(cyc)         (R32_TMR0_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM 输出初始化 | ||||
|  * | ||||
|  * @param   pr      - select wave polar, refer to PWMX_PolarTypeDef | ||||
|  * @param   ts      - set pwm repeat times, refer to PWM_RepeatTsTypeDef | ||||
|  */ | ||||
| void TMR0_PWMInit(PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM0 有效数据脉宽, 最大67108864 | ||||
|  * | ||||
|  * @param   d       - 有效数据脉宽 | ||||
|  */ | ||||
| #define TMR0_PWMActDataWidth(d)    (R32_TMR0_FIFO = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   CAP0 捕捉电平超时配置, 最大33554432 | ||||
|  * | ||||
|  * @param   cyc     - 捕捉电平超时 | ||||
|  */ | ||||
| #define TMR0_CAPTimeoutCfg(cyc)    (R32_TMR0_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外部信号捕捉功能初始化 | ||||
|  * | ||||
|  * @param   cap     - select capture mode, refer to CapModeTypeDef | ||||
|  */ | ||||
| void TMR0_CapInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取脉冲数据 | ||||
|  * | ||||
|  * @return  脉冲数据 | ||||
|  */ | ||||
| #define TMR0_CAPGetData()        R32_TMR0_FIFO | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前已捕获数据个数 | ||||
|  * | ||||
|  * @return  当前已捕获数据个数 | ||||
|  */ | ||||
| #define TMR0_CAPDataCounter()    R8_TMR0_FIFO_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR0 PWM输出 | ||||
|  */ | ||||
| #define TMR0_PWMDisable()           (R8_TMR0_CTRL_MOD &= ~RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR0 PWM输出 | ||||
|  */ | ||||
| #define TMR0_PWMEnable()           (R8_TMR0_CTRL_MOD |= RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR0 | ||||
|  */ | ||||
| #define TMR0_Disable()           (R8_TMR0_CTRL_MOD &= ~RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR0 | ||||
|  */ | ||||
| #define TMR0_Enable()            (R8_TMR0_CTRL_MOD |= RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   中断配置 | ||||
|  * | ||||
|  * @param   s       - 使能/关闭 | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR0_ITCfg(s, f)         ((s) ? (R8_TMR0_INTER_EN |= f) : (R8_TMR0_INTER_EN &= ~f)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除中断标志 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR0_ClearITFlag(f)      (R8_TMR0_INT_FLAG = f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询中断标志状态 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR0_GetITFlag(f)        (R8_TMR0_INT_FLAG & f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   定时功能初始化 | ||||
|  * | ||||
|  * @param   t       - 定时时间,基于当前系统时钟Tsys, 最长定时周期 67108864 | ||||
|  */ | ||||
| void TMR1_TimerInit(uint32_t t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前定时器值,最大67108864 | ||||
|  * | ||||
|  * @return  当前定时器值 | ||||
|  */ | ||||
| #define TMR1_GetCurrentTimer()    R32_TMR1_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   边沿计数功能初始化 | ||||
|  * | ||||
|  * @param   cap     - 采集计数类型 | ||||
|  */ | ||||
| void TMR1_EXTSingleCounterInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置计数统计溢出大小,最大67108862 | ||||
|  * | ||||
|  * @param   cyc     - 计数统计溢出大小 | ||||
|  */ | ||||
| #define TMR1_CountOverflowCfg(cyc)    (R32_TMR1_CNT_END = (cyc + 2)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前计数值,最大67108862 | ||||
|  * | ||||
|  * @return  当前计数值 | ||||
|  */ | ||||
| #define TMR1_GetCurrentCount()        R32_TMR1_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM1 通道输出波形周期配置, 最大67108864 | ||||
|  * | ||||
|  * @param   cyc     - 输出波形周期 | ||||
|  */ | ||||
| #define TMR1_PWMCycleCfg(cyc)         (R32_TMR1_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM 输出初始化 | ||||
|  * | ||||
|  * @param   pr      - select wave polar, refer to PWMX_PolarTypeDef | ||||
|  * @param   ts      - set pwm repeat times, refer to PWM_RepeatTsTypeDef | ||||
|  */ | ||||
| void TMR1_PWMInit(PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM1 有效数据脉宽, 最大67108864 | ||||
|  * | ||||
|  * @param   d       - 有效数据脉宽 | ||||
|  */ | ||||
| #define TMR1_PWMActDataWidth(d)    (R32_TMR1_FIFO = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   CAP1 捕捉电平超时配置, 最大33554432 | ||||
|  * | ||||
|  * @param   cyc     - 捕捉电平超时 | ||||
|  */ | ||||
| #define TMR1_CAPTimeoutCfg(cyc)    (R32_TMR1_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外部信号捕捉功能初始化 | ||||
|  * | ||||
|  * @param   cap     - select capture mode, refer to CapModeTypeDef | ||||
|  */ | ||||
| void TMR1_CapInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取脉冲数据 | ||||
|  * | ||||
|  * @return  脉冲数据 | ||||
|  */ | ||||
| #define TMR1_CAPGetData()        R32_TMR1_FIFO | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前已捕获数据个数 | ||||
|  * | ||||
|  * @return  当前已捕获数据个数 | ||||
|  */ | ||||
| #define TMR1_CAPDataCounter()    R8_TMR1_FIFO_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   配置DMA功能 | ||||
|  * | ||||
|  * @param   s           - 是否打开DMA功能 | ||||
|  * @param   startAddr   - DMA 起始地址 | ||||
|  * @param   endAddr     - DMA 结束地址 | ||||
|  * @param   m           - 配置DMA模式 | ||||
|  */ | ||||
| void TMR1_DMACfg(uint8_t s, uint16_t startAddr, uint16_t endAddr, DMAModeTypeDef m); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR1 PWM输出 | ||||
|  */ | ||||
| #define TMR1_PWMDisable()           (R8_TMR1_CTRL_MOD &= ~RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR1 PWM输出 | ||||
|  */ | ||||
| #define TMR1_PWMEnable()           (R8_TMR1_CTRL_MOD |= RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR1 | ||||
|  */ | ||||
| #define TMR1_Disable()         (R8_TMR1_CTRL_MOD &= ~RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR1 | ||||
|  */ | ||||
| #define TMR1_Enable()          (R8_TMR1_CTRL_MOD |= RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   中断配置 | ||||
|  * | ||||
|  * @param   s       - 使能/关闭 | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR1_ITCfg(s, f)       ((s) ? (R8_TMR1_INTER_EN |= f) : (R8_TMR1_INTER_EN &= ~f)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除中断标志 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR1_ClearITFlag(f)    (R8_TMR1_INT_FLAG = f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询中断标志状态 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR1_GetITFlag(f)      (R8_TMR1_INT_FLAG & f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   定时功能初始化 | ||||
|  * | ||||
|  * @param   t       - 定时时间,基于当前系统时钟Tsys, 最长定时周期 67108864 | ||||
|  */ | ||||
| void TMR2_TimerInit(uint32_t t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前定时器值,最大67108864 | ||||
|  * | ||||
|  * @return  当前定时器值 | ||||
|  */ | ||||
| #define TMR2_GetCurrentTimer()    R32_TMR2_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   边沿计数功能初始化 | ||||
|  * | ||||
|  * @param   cap     - 采集计数类型 | ||||
|  */ | ||||
| void TMR2_EXTSingleCounterInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置计数统计溢出大小,最大67108862 | ||||
|  * | ||||
|  * @param   cyc     - 计数统计溢出大小 | ||||
|  */ | ||||
| #define TMR2_CountOverflowCfg(cyc)    (R32_TMR2_CNT_END = (cyc + 2)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前计数值,最大67108862 | ||||
|  * | ||||
|  * @return  当前计数值 | ||||
|  */ | ||||
| #define TMR2_GetCurrentCount()        R32_TMR2_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM2 通道输出波形周期配置, 最大67108864 | ||||
|  * | ||||
|  * @param   cyc     - 输出波形周期 | ||||
|  */ | ||||
| #define TMR2_PWMCycleCfg(cyc)         (R32_TMR2_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM 输出初始化 | ||||
|  * | ||||
|  * @param   pr      - select wave polar, refer to PWMX_PolarTypeDef | ||||
|  * @param   ts      - set pwm repeat times, refer to PWM_RepeatTsTypeDef | ||||
|  */ | ||||
| void TMR2_PWMInit(PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM2 有效数据脉宽, 最大67108864 | ||||
|  * | ||||
|  * @param   d       - 有效数据脉宽 | ||||
|  */ | ||||
| #define TMR2_PWMActDataWidth(d)    (R32_TMR2_FIFO = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   CAP2 捕捉电平超时配置, 最大33554432 | ||||
|  * | ||||
|  * @param   cyc     - 捕捉电平超时 | ||||
|  */ | ||||
| #define TMR2_CAPTimeoutCfg(cyc)    (R32_TMR2_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外部信号捕捉功能初始化 | ||||
|  * | ||||
|  * @param   cap     - select capture mode, refer to CapModeTypeDef | ||||
|  */ | ||||
| void TMR2_CapInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取脉冲数据 | ||||
|  * | ||||
|  * @return  脉冲数据 | ||||
|  */ | ||||
| #define TMR2_CAPGetData()        R32_TMR2_FIFO | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前已捕获数据个数 | ||||
|  * | ||||
|  * @return  当前已捕获数据个数 | ||||
|  */ | ||||
| #define TMR2_CAPDataCounter()    R8_TMR2_FIFO_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   配置DMA功能 | ||||
|  * | ||||
|  * @param   s           - 是否打开DMA功能 | ||||
|  * @param   startAddr   - DMA 起始地址 | ||||
|  * @param   endAddr     - DMA 结束地址 | ||||
|  * @param   m           - 配置DMA模式 | ||||
|  */ | ||||
| void TMR2_DMACfg(uint8_t s, uint32_t startAddr, uint32_t endAddr, DMAModeTypeDef m); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR2 PWM输出 | ||||
|  */ | ||||
| #define TMR2_PWMDisable()           (R8_TMR2_CTRL_MOD &= ~RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR2 PWM输出 | ||||
|  */ | ||||
| #define TMR2_PWMEnable()           (R8_TMR2_CTRL_MOD |= RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR2 | ||||
|  */ | ||||
| #define TMR2_Disable()         (R8_TMR2_CTRL_MOD &= ~RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR2 | ||||
|  */ | ||||
| #define TMR2_Enable()          (R8_TMR2_CTRL_MOD |= RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   中断配置 | ||||
|  * | ||||
|  * @param   s       - 使能/关闭 | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR2_ITCfg(s, f)       ((s) ? (R8_TMR2_INTER_EN |= f) : (R8_TMR2_INTER_EN &= ~f)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除中断标志 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR2_ClearITFlag(f)    (R8_TMR2_INT_FLAG = f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询中断标志状态 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR2_GetITFlag(f)      (R8_TMR2_INT_FLAG & f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   定时功能初始化 | ||||
|  * | ||||
|  * @param   t       - 定时时间,基于当前系统时钟Tsys, 最长定时周期 67108864 | ||||
|  */ | ||||
| void TMR3_TimerInit(uint32_t t); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前定时器值,最大67108864 | ||||
|  * | ||||
|  * @return  当前定时器值 | ||||
|  */ | ||||
| #define TMR3_GetCurrentTimer()    R32_TMR3_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   边沿计数功能初始化 | ||||
|  * | ||||
|  * @param   cap     - 采集计数类型 | ||||
|  */ | ||||
| void TMR3_EXTSingleCounterInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置计数统计溢出大小,最大67108862 | ||||
|  * | ||||
|  * @param   cyc     - 计数统计溢出大小 | ||||
|  */ | ||||
| #define TMR3_CountOverflowCfg(cyc)    (R32_TMR3_CNT_END = (cyc + 2)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前计数值,最大67108862 | ||||
|  * | ||||
|  * @return  当前计数值 | ||||
|  */ | ||||
| #define TMR3_GetCurrentCount()        R32_TMR3_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM3 通道输出波形周期配置, 最大67108864 | ||||
|  * | ||||
|  * @param   cyc     - 输出波形周期 | ||||
|  */ | ||||
| #define TMR3_PWMCycleCfg(cyc)         (R32_TMR3_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM 输出初始化 | ||||
|  * | ||||
|  * @param   pr      - select wave polar, refer to PWMX_PolarTypeDef | ||||
|  * @param   ts      - set pwm repeat times, refer to PWM_RepeatTsTypeDef | ||||
|  */ | ||||
| void TMR3_PWMInit(PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   PWM3 有效数据脉宽, 最大67108864 | ||||
|  * | ||||
|  * @param   d       - 有效数据脉宽 | ||||
|  */ | ||||
| #define TMR3_PWMActDataWidth(d)    (R32_TMR3_FIFO = d) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   CAP3 捕捉电平超时配置, 最大33554432 | ||||
|  * | ||||
|  * @param   cyc     - 捕捉电平超时 | ||||
|  */ | ||||
| #define TMR3_CAPTimeoutCfg(cyc)    (R32_TMR3_CNT_END = cyc) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   外部信号捕捉功能初始化 | ||||
|  * | ||||
|  * @param   cap     - select capture mode, refer to CapModeTypeDef | ||||
|  */ | ||||
| void TMR3_CapInit(CapModeTypeDef cap); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取脉冲数据 | ||||
|  * | ||||
|  * @return  脉冲数据 | ||||
|  */ | ||||
| #define TMR3_CAPGetData()        R32_TMR3_FIFO | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前已捕获数据个数 | ||||
|  * | ||||
|  * @return  当前已捕获数据个数 | ||||
|  */ | ||||
| #define TMR3_CAPDataCounter()    R8_TMR3_FIFO_COUNT | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR3 PWM输出 | ||||
|  */ | ||||
| #define TMR3_PWMDisable()           (R8_TMR3_CTRL_MOD &= ~RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR3 PWM输出 | ||||
|  */ | ||||
| #define TMR3_PWMEnable()           (R8_TMR3_CTRL_MOD |= RB_TMR_OUT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭 TMR3 | ||||
|  */ | ||||
| #define TMR3_Disable()           (R8_TMR3_CTRL_MOD &= ~RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   开启 TMR3 | ||||
|  */ | ||||
| #define TMR3_Enable()            (R8_TMR3_CTRL_MOD |= RB_TMR_COUNT_EN) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   中断配置 | ||||
|  * | ||||
|  * @param   s       - 使能/关闭 | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR3_ITCfg(s, f)         ((s) ? (R8_TMR3_INTER_EN |= f) : (R8_TMR3_INTER_EN &= ~f)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除中断标志 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR3_ClearITFlag(f)      (R8_TMR3_INT_FLAG = f) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询中断标志状态 | ||||
|  * | ||||
|  * @param   f       - refer to TMR interrupt bit define | ||||
|  */ | ||||
| #define TMR3_GetITFlag(f)        (R8_TMR3_INT_FLAG & f) | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_TIMER_H__
 | ||||
							
								
								
									
										412
									
								
								vendor/StdPeriphDriver/inc/CH59x_uart.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										412
									
								
								vendor/StdPeriphDriver/inc/CH59x_uart.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,412 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_uart.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_UART_H__ | ||||
| #define __CH59x_UART_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief	LINE error and status define | ||||
|  */ | ||||
| #define STA_ERR_BREAK     RB_LSR_BREAK_ERR    // 数据间隔错误
 | ||||
| #define STA_ERR_FRAME     RB_LSR_FRAME_ERR    // 数据帧错误
 | ||||
| #define STA_ERR_PAR       RB_LSR_PAR_ERR      // 奇偶校验位出错
 | ||||
| #define STA_ERR_FIFOOV    RB_LSR_OVER_ERR     // 接收数据溢出
 | ||||
| 
 | ||||
| #define STA_TXFIFO_EMP    RB_LSR_TX_FIFO_EMP  // 当前发送FIFO空,可以继续填充发送数据
 | ||||
| #define STA_TXALL_EMP     RB_LSR_TX_ALL_EMP   // 当前所有发送数据都发送完成
 | ||||
| #define STA_RECV_DATA     RB_LSR_DATA_RDY     // 当前有接收到数据
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Configuration UART TrigByte num | ||||
|  */ | ||||
| typedef enum | ||||
| { | ||||
|     UART_1BYTE_TRIG = 0, // 1字节触发
 | ||||
|     UART_2BYTE_TRIG,     // 2字节触发
 | ||||
|     UART_4BYTE_TRIG,     // 4字节触发
 | ||||
|     UART_7BYTE_TRIG,     // 7字节触发
 | ||||
| 
 | ||||
| } UARTByteTRIGTypeDef; | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口默认初始化配置 | ||||
|  */ | ||||
| void UART0_DefInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口波特率配置 | ||||
|  * | ||||
|  * @param   baudrate    - 波特率 | ||||
|  */ | ||||
| void UART0_BaudRateCfg(uint32_t baudrate); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口字节触发中断配置 | ||||
|  * | ||||
|  * @param   b       - 触发字节数 refer to UARTByteTRIGTypeDef | ||||
|  */ | ||||
| void UART0_ByteTrigCfg(UARTByteTRIGTypeDef b); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口中断配置 | ||||
|  * | ||||
|  * @param   s       - 中断控制状态,是否使能相应中断 | ||||
|  * @param   i       - 中断类型 | ||||
|  *                    RB_IER_MODEM_CHG  - 调制解调器输入状态变化中断使能位(仅 UART0 支持) | ||||
|  *                    RB_IER_LINE_STAT  - 接收线路状态中断 | ||||
|  *                    RB_IER_THR_EMPTY  - 发送保持寄存器空中断 | ||||
|  *                    RB_IER_RECV_RDY   - 接收数据中断 | ||||
|  */ | ||||
| void UART0_INTCfg(FunctionalState s, uint8_t i); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口软件复位 | ||||
|  */ | ||||
| void UART0_Reset(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前接收FIFO | ||||
|  */ | ||||
| #define UART0_CLR_RXFIFO()    (R8_UART0_FCR |= RB_FCR_RX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前发送FIFO | ||||
|  */ | ||||
| #define UART0_CLR_TXFIFO()    (R8_UART0_FCR |= RB_FCR_TX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前中断标志 | ||||
|  * | ||||
|  * @return  当前中断标志 | ||||
|  */ | ||||
| #define UART0_GetITFlag()     (R8_UART0_IIR & RB_IIR_INT_MASK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前通讯状态 | ||||
|  * | ||||
|  * @return  refer to LINE error and status define | ||||
|  */ | ||||
| #define UART0_GetLinSTA()     (R8_UART0_LSR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口单字节发送 | ||||
|  * | ||||
|  * @param   b       待发送的字节 | ||||
|  */ | ||||
| #define UART0_SendByte(b)     (R8_UART0_THR = b) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口多字节发送 | ||||
|  * | ||||
|  * @param   buf     - 待发送的数据内容首地址 | ||||
|  * @param   l       - 待发送的数据长度 | ||||
|  */ | ||||
| void UART0_SendString(uint8_t *buf, uint16_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取单字节 | ||||
|  * | ||||
|  * @return  读取到的单字节 | ||||
|  */ | ||||
| #define UART0_RecvByte()    (R8_UART0_RBR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取多字节 | ||||
|  * | ||||
|  * @param   buf     - 读取数据存放缓存区首地址 | ||||
|  * | ||||
|  * @return  读取数据长度 | ||||
|  */ | ||||
| uint16_t UART0_RecvString(uint8_t *buf); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口默认初始化配置 | ||||
|  */ | ||||
| void UART1_DefInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口波特率配置 | ||||
|  * | ||||
|  * @param   baudrate    - 波特率 | ||||
|  */ | ||||
| void UART1_BaudRateCfg(uint32_t baudrate); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口字节触发中断配置 | ||||
|  * | ||||
|  * @param   b       - 触发字节数 refer to UARTByteTRIGTypeDef | ||||
|  */ | ||||
| void UART1_ByteTrigCfg(UARTByteTRIGTypeDef b); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口中断配置 | ||||
|  * | ||||
|  * @param   s       - 中断控制状态,是否使能相应中断 | ||||
|  * @param   i       - 中断类型 | ||||
|  *                    RB_IER_MODEM_CHG  - 调制解调器输入状态变化中断使能位(仅 UART0 支持) | ||||
|  *                    RB_IER_LINE_STAT  - 接收线路状态中断 | ||||
|  *                    RB_IER_THR_EMPTY  - 发送保持寄存器空中断 | ||||
|  *                    RB_IER_RECV_RDY   - 接收数据中断 | ||||
|  */ | ||||
| void UART1_INTCfg(FunctionalState s, uint8_t i); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口软件复位 | ||||
|  */ | ||||
| void UART1_Reset(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前接收FIFO | ||||
|  */ | ||||
| #define UART1_CLR_RXFIFO()    (R8_UART1_FCR |= RB_FCR_RX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前发送FIFO | ||||
|  */ | ||||
| #define UART1_CLR_TXFIFO()    (R8_UART1_FCR |= RB_FCR_TX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前中断标志 | ||||
|  * | ||||
|  * @return  当前中断标志 | ||||
|  */ | ||||
| #define UART1_GetITFlag()     (R8_UART1_IIR & RB_IIR_INT_MASK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前通讯状态 | ||||
|  * | ||||
|  * @return  refer to LINE error and status define | ||||
|  */ | ||||
| #define UART1_GetLinSTA()     (R8_UART1_LSR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口单字节发送 | ||||
|  * | ||||
|  * @param   b       待发送的字节 | ||||
|  */ | ||||
| #define UART1_SendByte(b)     (R8_UART1_THR = b) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口多字节发送 | ||||
|  * | ||||
|  * @param   buf     - 待发送的数据内容首地址 | ||||
|  * @param   l       - 待发送的数据长度 | ||||
|  */ | ||||
| void UART1_SendString(uint8_t *buf, uint16_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取单字节 | ||||
|  * | ||||
|  * @return  读取到的单字节 | ||||
|  */ | ||||
| #define UART1_RecvByte()    (R8_UART1_RBR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取多字节 | ||||
|  * | ||||
|  * @param   buf     - 读取数据存放缓存区首地址 | ||||
|  * | ||||
|  * @return  读取数据长度 | ||||
|  */ | ||||
| uint16_t UART1_RecvString(uint8_t *buf); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口默认初始化配置 | ||||
|  */ | ||||
| void UART2_DefInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口波特率配置 | ||||
|  * | ||||
|  * @param   baudrate    - 波特率 | ||||
|  */ | ||||
| void UART2_BaudRateCfg(uint32_t baudrate); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口字节触发中断配置 | ||||
|  * | ||||
|  * @param   b       - 触发字节数 refer to UARTByteTRIGTypeDef | ||||
|  */ | ||||
| void UART2_ByteTrigCfg(UARTByteTRIGTypeDef b); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口中断配置 | ||||
|  * | ||||
|  * @param   s       - 中断控制状态,是否使能相应中断 | ||||
|  * @param   i       - 中断类型 | ||||
|  *                    RB_IER_MODEM_CHG  - 调制解调器输入状态变化中断使能位(仅 UART0 支持) | ||||
|  *                    RB_IER_LINE_STAT  - 接收线路状态中断 | ||||
|  *                    RB_IER_THR_EMPTY  - 发送保持寄存器空中断 | ||||
|  *                    RB_IER_RECV_RDY   - 接收数据中断 | ||||
|  */ | ||||
| void UART2_INTCfg(FunctionalState s, uint8_t i); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口软件复位 | ||||
|  */ | ||||
| void UART2_Reset(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前接收FIFO | ||||
|  */ | ||||
| #define UART2_CLR_RXFIFO()    (R8_UART2_FCR |= RB_FCR_RX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前发送FIFO | ||||
|  */ | ||||
| #define UART2_CLR_TXFIFO()    (R8_UART2_FCR |= RB_FCR_TX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前中断标志 | ||||
|  * | ||||
|  * @return  当前中断标志 | ||||
|  */ | ||||
| #define UART2_GetITFlag()     (R8_UART2_IIR & RB_IIR_INT_MASK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前通讯状态 | ||||
|  * | ||||
|  * @return  refer to LINE error and status define | ||||
|  */ | ||||
| #define UART2_GetLinSTA()     (R8_UART2_LSR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口单字节发送 | ||||
|  * | ||||
|  * @param   b       待发送的字节 | ||||
|  */ | ||||
| #define UART2_SendByte(b)     (R8_UART2_THR = b) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口多字节发送 | ||||
|  * | ||||
|  * @param   buf     - 待发送的数据内容首地址 | ||||
|  * @param   l       - 待发送的数据长度 | ||||
|  */ | ||||
| void UART2_SendString(uint8_t *buf, uint16_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取单字节 | ||||
|  * | ||||
|  * @return  读取到的单字节 | ||||
|  */ | ||||
| #define UART2_RecvByte()    (R8_UART2_RBR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取多字节 | ||||
|  * | ||||
|  * @param   buf     - 读取数据存放缓存区首地址 | ||||
|  * | ||||
|  * @return  读取数据长度 | ||||
|  */ | ||||
| uint16_t UART2_RecvString(uint8_t *buf); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口默认初始化配置 | ||||
|  */ | ||||
| void UART3_DefInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口波特率配置 | ||||
|  * | ||||
|  * @param   baudrate    - 波特率 | ||||
|  */ | ||||
| void UART3_BaudRateCfg(uint32_t baudrate); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口字节触发中断配置 | ||||
|  * | ||||
|  * @param   b       - 触发字节数 refer to UARTByteTRIGTypeDef | ||||
|  */ | ||||
| void UART3_ByteTrigCfg(UARTByteTRIGTypeDef b); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口中断配置 | ||||
|  * | ||||
|  * @param   s       - 中断控制状态,是否使能相应中断 | ||||
|  * @param   i       - 中断类型 | ||||
|  *                    RB_IER_MODEM_CHG  - 调制解调器输入状态变化中断使能位(仅 UART0 支持) | ||||
|  *                    RB_IER_LINE_STAT  - 接收线路状态中断 | ||||
|  *                    RB_IER_THR_EMPTY  - 发送保持寄存器空中断 | ||||
|  *                    RB_IER_RECV_RDY   - 接收数据中断 | ||||
|  */ | ||||
| void UART3_INTCfg(FunctionalState s, uint8_t i); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口软件复位 | ||||
|  */ | ||||
| void UART3_Reset(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前接收FIFO | ||||
|  */ | ||||
| #define UART3_CLR_RXFIFO()    (R8_UART3_FCR |= RB_FCR_RX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除当前发送FIFO | ||||
|  */ | ||||
| #define UART3_CLR_TXFIFO()    (R8_UART3_FCR |= RB_FCR_TX_FIFO_CLR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前中断标志 | ||||
|  * | ||||
|  * @return  当前中断标志 | ||||
|  */ | ||||
| #define UART3_GetITFlag()     (R8_UART3_IIR & RB_IIR_INT_MASK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取当前通讯状态 | ||||
|  * | ||||
|  * @return  refer to LINE error and status define | ||||
|  */ | ||||
| #define UART3_GetLinSTA()     (R8_UART3_LSR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口单字节发送 | ||||
|  * | ||||
|  * @param   b       待发送的字节 | ||||
|  */ | ||||
| #define UART3_SendByte(b)     (R8_UART3_THR = b) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口多字节发送 | ||||
|  * | ||||
|  * @param   buf     - 待发送的数据内容首地址 | ||||
|  * @param   l       - 待发送的数据长度 | ||||
|  */ | ||||
| void UART3_SendString(uint8_t *buf, uint16_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取单字节 | ||||
|  * | ||||
|  * @return  读取到的单字节 | ||||
|  */ | ||||
| #define UART3_RecvByte()    (R8_UART3_RBR) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   串口读取多字节 | ||||
|  * | ||||
|  * @param   buf     - 读取数据存放缓存区首地址 | ||||
|  * | ||||
|  * @return  读取数据长度 | ||||
|  */ | ||||
| uint16_t UART3_RecvString(uint8_t *buf); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_UART_H__
 | ||||
							
								
								
									
										152
									
								
								vendor/StdPeriphDriver/inc/CH59x_usbdev.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								vendor/StdPeriphDriver/inc/CH59x_usbdev.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,152 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_usbdev.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_USBDEV_H__ | ||||
| #define __CH59x_USBDEV_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* HID类请求 */ | ||||
| #define DEF_USB_GET_IDLE           0x02                                         /* get idle for key or mouse */ | ||||
| #define DEF_USB_GET_PROTOCOL       0x03                                         /* get protocol for bios type */ | ||||
| #define DEF_USB_SET_REPORT         0x09                                         /* set report for key */ | ||||
| #define DEF_USB_SET_IDLE           0x0A                                         /* set idle for key or mouse */ | ||||
| #define DEF_USB_SET_PROTOCOL       0x0B                                         /* set protocol for bios type */ | ||||
| 
 | ||||
| /* 以下缓存区是USB模块收发使用的数据缓冲区,总共9个通道(9块缓存),用户可根据实际使用的通道数定义相应缓存区 */ | ||||
| extern uint8_t *pEP0_RAM_Addr; //ep0(64)+ep4_out(64)+ep4_in(64)
 | ||||
| extern uint8_t *pEP1_RAM_Addr; //ep1_out(64)+ep1_in(64)
 | ||||
| extern uint8_t *pEP2_RAM_Addr; //ep2_out(64)+ep2_in(64)
 | ||||
| extern uint8_t *pEP3_RAM_Addr; //ep3_out(64)+ep3_in(64)
 | ||||
| 
 | ||||
| #define pSetupReqPak          ((PUSB_SETUP_REQ)pEP0_RAM_Addr) | ||||
| #define pEP0_DataBuf          (pEP0_RAM_Addr) | ||||
| #define pEP1_OUT_DataBuf      (pEP1_RAM_Addr) | ||||
| #define pEP1_IN_DataBuf       (pEP1_RAM_Addr + 64) | ||||
| #define pEP2_OUT_DataBuf      (pEP2_RAM_Addr) | ||||
| #define pEP2_IN_DataBuf       (pEP2_RAM_Addr + 64) | ||||
| #define pEP3_OUT_DataBuf      (pEP3_RAM_Addr) | ||||
| #define pEP3_IN_DataBuf       (pEP3_RAM_Addr + 64) | ||||
| #define pEP4_OUT_DataBuf      (pEP0_RAM_Addr + 64) | ||||
| #define pEP4_IN_DataBuf       (pEP0_RAM_Addr + 128) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   USB设备功能初始化,4个端点,8个通道。 | ||||
|  */ | ||||
| void USB_DeviceInit(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   USB设备应答传输处理 | ||||
|  */ | ||||
| void USB_DevTransProcess(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点1下传数据处理 | ||||
|  * | ||||
|  * @param   l   - 待处理数据长度(<64B) | ||||
|  */ | ||||
| void DevEP1_OUT_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点2下传数据处理 | ||||
|  * | ||||
|  * @param   l   - 待处理数据长度(<64B) | ||||
|  */ | ||||
| void DevEP2_OUT_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点3下传数据处理 | ||||
|  * | ||||
|  * @param   l   - 待处理数据长度(<64B) | ||||
|  */ | ||||
| void DevEP3_OUT_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点4下传数据处理 | ||||
|  * | ||||
|  * @param   l   - 待处理数据长度(<64B) | ||||
|  */ | ||||
| void DevEP4_OUT_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点1数据上传 | ||||
|  * | ||||
|  * @param   l   - 上传数据长度(<64B) | ||||
|  */ | ||||
| void DevEP1_IN_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点2数据上传 | ||||
|  * | ||||
|  * @param   l   - 上传数据长度(<64B) | ||||
|  */ | ||||
| void DevEP2_IN_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点3数据上传 | ||||
|  * | ||||
|  * @param   l   - 上传数据长度(<64B) | ||||
|  */ | ||||
| void DevEP3_IN_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   端点4数据上传 | ||||
|  * | ||||
|  * @param   l   - 上传数据长度(<64B) | ||||
|  */ | ||||
| void DevEP4_IN_Deal(uint8_t l); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询端点1是否上传完成 | ||||
|  * | ||||
|  * @return  0-未完成  (!0)-已完成 | ||||
|  */ | ||||
| #define EP1_GetINSta()    (R8_UEP1_CTRL & UEP_T_RES_NAK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询端点2是否上传完成 | ||||
|  * | ||||
|  * @return  0-未完成  (!0)-已完成 | ||||
|  */ | ||||
| #define EP2_GetINSta()    (R8_UEP2_CTRL & UEP_T_RES_NAK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询端点3是否上传完成 | ||||
|  * | ||||
|  * @return  0-未完成  (!0)-已完成 | ||||
|  */ | ||||
| #define EP3_GetINSta()    (R8_UEP3_CTRL & UEP_T_RES_NAK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询端点4是否上传完成 | ||||
|  * | ||||
|  * @return  0-未完成  (!0)-已完成 | ||||
|  */ | ||||
| #define EP4_GetINSta()    (R8_UEP4_CTRL & UEP_T_RES_NAK) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭USB上拉电阻 | ||||
|  */ | ||||
| #define USB_DisablePin()  (R16_PIN_ANALOG_IE &= ~(RB_PIN_USB_IE | RB_PIN_USB_DP_PU)) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭USB | ||||
|  */ | ||||
| #define USB_Disable()     (R32_USB_CONTROL = 0) | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_USBDEV_H__
 | ||||
							
								
								
									
										314
									
								
								vendor/StdPeriphDriver/inc/CH59x_usbhost.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										314
									
								
								vendor/StdPeriphDriver/inc/CH59x_usbhost.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,314 @@ | |||
| /********************************** (C) COPYRIGHT *******************************
 | ||||
|  * File Name          : CH59x_usbhost.h | ||||
|  * Author             : WCH | ||||
|  * Version            : V1.2 | ||||
|  * Date               : 2021/11/17 | ||||
|  * Description | ||||
|  ********************************************************************************* | ||||
|  * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||||
|  * Attention: This software (modified or not) and binary are used for  | ||||
|  * microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||||
|  *******************************************************************************/ | ||||
| 
 | ||||
| #ifndef __CH59x_USBHOST_H__ | ||||
| #define __CH59x_USBHOST_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #if DISK_LIB_ENABLE | ||||
|   #if DISK_WITHOUT_USB_HUB | ||||
|   /* 不使用U盘文件系统库或者U盘挂载USBhub下面,需要关闭下面定义 */ | ||||
|     #define FOR_ROOT_UDISK_ONLY | ||||
|   #endif | ||||
|   /* 使用U盘文件系统库,需要开启下面定义, 不使用请关闭 */ | ||||
|   #define DISK_BASE_BUF_LEN    512  /* 默认的磁盘数据缓冲区大小为512字节,建议选择为2048甚至4096以支持某些大扇区的U盘,为0则禁止在.H文件中定义缓冲区并由应用程序在pDISK_BASE_BUF中指定 */ | ||||
| #endif | ||||
| 
 | ||||
| // 各子程序返回状态码
 | ||||
| #define ERR_SUCCESS            0x00  // 操作成功
 | ||||
| #define ERR_USB_CONNECT        0x15  /* 检测到USB设备连接事件,已经连接 */ | ||||
| #define ERR_USB_DISCON         0x16  /* 检测到USB设备断开事件,已经断开 */ | ||||
| #define ERR_USB_BUF_OVER       0x17  /* USB传输的数据有误或者数据太多缓冲区溢出 */ | ||||
| #define ERR_USB_DISK_ERR       0x1F  /* USB存储器操作失败,在初始化时可能是USB存储器不支持,在读写操作中可能是磁盘损坏或者已经断开 */ | ||||
| #define ERR_USB_TRANSFER       0x20  /* NAK/STALL等更多错误码在0x20~0x2F */ | ||||
| #define ERR_USB_UNSUPPORT      0xFB  /* 不支持的USB设备*/ | ||||
| #define ERR_USB_UNKNOWN        0xFE  /* 设备操作出错*/ | ||||
| #define ERR_AOA_PROTOCOL       0x41  /* 协议版本出错 */ | ||||
| 
 | ||||
| /*USB设备相关信息表,最多支持1个设备*/ | ||||
| #define ROOT_DEV_DISCONNECT    0 | ||||
| #define ROOT_DEV_CONNECTED     1 | ||||
| #define ROOT_DEV_FAILED        2 | ||||
| #define ROOT_DEV_SUCCESS       3 | ||||
| #define DEV_TYPE_KEYBOARD      (USB_DEV_CLASS_HID | 0x20) | ||||
| #define DEV_TYPE_MOUSE         (USB_DEV_CLASS_HID | 0x30) | ||||
| #define DEF_AOA_DEVICE         0xF0 | ||||
| #define DEV_TYPE_UNKNOW        0xFF | ||||
| 
 | ||||
| /*
 | ||||
| 约定: USB设备地址分配规则(参考USB_DEVICE_ADDR) | ||||
| 地址值  设备位置 | ||||
| 0x02    内置Root-HUB下的USB设备或外部HUB | ||||
| 0x1x    内置Root-HUB下的外部HUB的端口x下的USB设备,x为1~n | ||||
| */ | ||||
| #define HUB_MAX_PORTS          4 | ||||
| #define WAIT_USB_TOUT_200US    800   // 等待USB中断超时时间
 | ||||
| 
 | ||||
| typedef struct | ||||
| { | ||||
|     uint8_t  DeviceStatus;  // 设备状态,0-无设备,1-有设备但尚未初始化,2-有设备但初始化枚举失败,3-有设备且初始化枚举成功
 | ||||
|     uint8_t  DeviceAddress; // 设备被分配的USB地址
 | ||||
|     uint8_t  DeviceSpeed;   // 0为低速,非0为全速
 | ||||
|     uint8_t  DeviceType;    // 设备类型
 | ||||
|     uint16_t DeviceVID; | ||||
|     uint16_t DevicePID; | ||||
|     uint8_t  GpVar[4];     // 通用变量,存放端点
 | ||||
|     uint8_t  GpHUBPortNum; // 通用变量,如果是HUB,表示HUB端口数
 | ||||
| } _RootHubDev; | ||||
| 
 | ||||
| typedef struct | ||||
| { | ||||
|     UINT8  DeviceStatus;  // 设备状态,0-无设备,1-有设备但尚未初始化,2-有设备但初始化枚举失败,3-有设备且初始化枚举成功
 | ||||
|     UINT8  DeviceAddress; // 设备被分配的USB地址
 | ||||
|     UINT8  DeviceSpeed;   // 0为低速,非0为全速
 | ||||
|     UINT8  DeviceType;    // 设备类型
 | ||||
|     UINT16 DeviceVID; | ||||
|     UINT16 DevicePID; | ||||
|     UINT8  GpVar[4]; // 通用变量
 | ||||
| } _DevOnHubPort;     // 假定:不超过1个外部HUB,每个外部HUB不超过HUB_MAX_PORTS个端口(多了不管)
 | ||||
| 
 | ||||
| extern _RootHubDev   ThisUsbDev; | ||||
| extern _DevOnHubPort DevOnHubPort[HUB_MAX_PORTS]; // 假定:不超过1个外部HUB,每个外部HUB不超过HUB_MAX_PORTS个端口(多了不管)
 | ||||
| extern uint8_t       UsbDevEndp0Size;             // USB设备的端点0的最大包尺寸 */
 | ||||
| extern uint8_t       FoundNewDev; | ||||
| 
 | ||||
| extern uint8_t *pHOST_RX_RAM_Addr; | ||||
| extern uint8_t *pHOST_TX_RAM_Addr; | ||||
| 
 | ||||
| extern _RootHubDev   ThisUsb2Dev; | ||||
| extern _DevOnHubPort DevOnU2HubPort[HUB_MAX_PORTS]; // 假定:不超过1个外部HUB,每个外部HUB不超过HUB_MAX_PORTS个端口(多了不管)
 | ||||
| extern uint8_t       Usb2DevEndp0Size;              // USB设备的端点0的最大包尺寸 */
 | ||||
| extern uint8_t       FoundNewU2Dev; | ||||
| 
 | ||||
| extern uint8_t *pU2HOST_RX_RAM_Addr; | ||||
| extern uint8_t *pU2HOST_TX_RAM_Addr; | ||||
| 
 | ||||
| #define pSetupReq      ((PUSB_SETUP_REQ)pHOST_TX_RAM_Addr) | ||||
| #define pU2SetupReq    ((PUSB_SETUP_REQ)pU2HOST_TX_RAM_Addr) | ||||
| extern uint8_t Com_Buffer[]; | ||||
| extern uint8_t U2Com_Buffer[]; | ||||
| 
 | ||||
| /* 以下为USB主机请求包 */ | ||||
| extern const uint8_t SetupGetDevDescr[];     // 获取设备描述符*/
 | ||||
| extern const uint8_t SetupGetCfgDescr[];     // 获取配置描述符*/
 | ||||
| extern const uint8_t SetupSetUsbAddr[];      // 设置USB地址*/
 | ||||
| extern const uint8_t SetupSetUsbConfig[];    // 设置USB配置*/
 | ||||
| extern const uint8_t SetupSetUsbInterface[]; // 设置USB接口配置*/
 | ||||
| extern const uint8_t SetupClrEndpStall[];    // 清除端点STALL*/
 | ||||
| 
 | ||||
| extern const uint8_t SetupGetU2DevDescr[];    // 获取设备描述符*/
 | ||||
| extern const uint8_t SetupGetU2CfgDescr[];    // 获取配置描述符*/
 | ||||
| extern const uint8_t SetupSetUsb2Addr[];      // 设置USB地址*/
 | ||||
| extern const uint8_t SetupSetUsb2Config[];    // 设置USB配置*/
 | ||||
| extern const uint8_t SetupSetUsb2Interface[]; // 设置USB接口配置*/
 | ||||
| extern const uint8_t SetupClrU2EndpStall[];   // 清除端点STALL*/
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   关闭ROOT-HUB端口,实际上硬件已经自动关闭,此处只是清除一些结构状态 | ||||
|  */ | ||||
| void DisableRootHubPort(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   分析ROOT-HUB状态,处理ROOT-HUB端口的设备插拔事件 | ||||
|  *          如果设备拔出,函数中调用DisableRootHubPort()函数,将端口关闭,插入事件,置相应端口的状态位 | ||||
|  * | ||||
|  * @return  返回ERR_SUCCESS为没有情况,返回ERR_USB_CONNECT为检测到新连接,返回ERR_USB_DISCON为检测到断开 | ||||
|  */ | ||||
| uint8_t AnalyzeRootHub(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置USB主机当前操作的USB设备地址 | ||||
|  * | ||||
|  * @param   addr    - USB设备地址 | ||||
|  */ | ||||
| void SetHostUsbAddr(uint8_t addr); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置当前USB速度 | ||||
|  * | ||||
|  * @param   FullSpeed   - USB速度 | ||||
|  */ | ||||
| void SetUsbSpeed(uint8_t FullSpeed); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   检测到设备后,复位总线,为枚举设备准备,设置为默认为全速 | ||||
|  */ | ||||
| void ResetRootHubPort(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   使能ROOT-HUB端口,相应的bUH_PORT_EN置1开启端口,设备断开可能导致返回失败 | ||||
|  * | ||||
|  * @return  返回ERR_SUCCESS为检测到新连接,返回ERR_USB_DISCON为无连接 | ||||
|  */ | ||||
| uint8_t EnableRootHubPort(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   等待USB中断 | ||||
|  * | ||||
|  * @return  返回ERR_SUCCESS 数据接收或者发送成功,返回ERR_USB_UNKNOWN 数据接收或者发送失败 | ||||
|  */ | ||||
| uint8_t WaitUSB_Interrupt(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   传输事务,输入目的端点地址/PID令牌,同步标志,以20uS为单位的NAK重试总时间(0则不重试,0xFFFF无限重试),返回0成功,超时/出错重试 | ||||
|  *          本子程序着重于易理解,而在实际应用中,为了提供运行速度,应该对本子程序代码进行优化 | ||||
|  * | ||||
|  * @param   endp_pid    - 令牌和地址, 高4位是token_pid令牌, 低4位是端点地址 | ||||
|  * @param   tog         - 同步标志 | ||||
|  * @param   timeout     - 超时时间 | ||||
|  * | ||||
|  * @return  ERR_USB_UNKNOWN 超时,可能硬件异常 | ||||
|  *          ERR_USB_DISCON  设备断开 | ||||
|  *          ERR_USB_CONNECT 设备连接 | ||||
|  *          ERR_SUCCESS     传输完成 | ||||
|  */ | ||||
| uint8_t USBHostTransact(uint8_t endp_pid, uint8_t tog, uint32_t timeout); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   执行控制传输,8字节请求码在pSetupReq中,DataBuf为可选的收发缓冲区 | ||||
|  * | ||||
|  * @param   DataBuf     - 如果需要接收和发送数据,那么DataBuf需指向有效缓冲区用于存放后续数据 | ||||
|  * @param   RetLen      - 实际成功收发的总长度保存在RetLen指向的字节变量中 | ||||
|  * | ||||
|  * @return  ERR_USB_BUF_OVER    IN状态阶段出错 | ||||
|  *          ERR_SUCCESS         数据交换成功 | ||||
|  */ | ||||
| uint8_t HostCtrlTransfer(uint8_t *DataBuf, uint8_t *RetLen); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   复制控制传输的请求包 | ||||
|  * | ||||
|  * @param   pReqPkt     - 控制请求包地址 | ||||
|  */ | ||||
| void CopySetupReqPkg(const uint8_t *pReqPkt); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取设备描述符,返回在 pHOST_TX_RAM_Addr 中 | ||||
|  * | ||||
|  * @return  ERR_USB_BUF_OVER    描述符长度错误 | ||||
|  *          ERR_SUCCESS         成功 | ||||
|  */ | ||||
| uint8_t CtrlGetDeviceDescr(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取配置描述符,返回在 pHOST_TX_RAM_Addr 中 | ||||
|  * | ||||
|  * @return  ERR_USB_BUF_OVER    描述符长度错误 | ||||
|  *          ERR_SUCCESS         成功 | ||||
|  */ | ||||
| uint8_t CtrlGetConfigDescr(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置USB设备地址 | ||||
|  * | ||||
|  * @param   addr    - 设备地址 | ||||
|  * | ||||
|  * @return  ERR_SUCCESS     成功 | ||||
|  */ | ||||
| uint8_t CtrlSetUsbAddress(uint8_t addr); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置USB设备配置 | ||||
|  * | ||||
|  * @param   cfg     - 配置值 | ||||
|  * | ||||
|  * @return  ERR_SUCCESS     成功 | ||||
|  */ | ||||
| uint8_t CtrlSetUsbConfig(uint8_t cfg); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除端点STALL | ||||
|  * | ||||
|  * @param   endp    - 端点地址 | ||||
|  * | ||||
|  * @return  ERR_SUCCESS     成功 | ||||
|  */ | ||||
| uint8_t CtrlClearEndpStall(uint8_t endp); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置USB设备接口 | ||||
|  * | ||||
|  * @param   cfg     - 配置值 | ||||
|  * | ||||
|  * @return  ERR_SUCCESS     成功 | ||||
|  */ | ||||
| uint8_t CtrlSetUsbIntercace(uint8_t cfg); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   USB主机功能初始化 | ||||
|  */ | ||||
| void USB_HostInit(void); | ||||
| uint8_t EnumAllHubPort(void);// 枚举所有ROOT-HUB端口下外部HUB后的二级USB设备
 | ||||
| void SelectHubPort(uint8_t HubPortIndex); // HubPortIndex=0选择操作指定的ROOT-HUB端口,否则选择操作指定的ROOT-HUB端口的外部HUB的指定端口
 | ||||
| uint16_t SearchTypeDevice(uint8_t type); // 在ROOT-HUB以及外部HUB各端口上搜索指定类型的设备所在的端口号,输出端口号为0xFFFF则未搜索到.
 | ||||
| uint8_t SETorOFFNumLock(uint8_t *buf); // NumLock的点灯判断
 | ||||
| 
 | ||||
| /*************************************************************/ | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   初始化指定ROOT-HUB端口的USB设备 | ||||
|  * | ||||
|  * @return  错误码 | ||||
|  */ | ||||
| uint8_t InitRootDevice(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取HID设备报表描述符,返回在TxBuffer中 | ||||
|  * | ||||
|  * @return  错误码 | ||||
|  */ | ||||
| uint8_t CtrlGetHIDDeviceReport(uint8_t infc); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   获取HUB描述符,返回在Com_Buffer中 | ||||
|  * | ||||
|  * @return  错误码 | ||||
|  */ | ||||
| uint8_t CtrlGetHubDescr(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   查询HUB端口状态,返回在Com_Buffer中 | ||||
|  * | ||||
|  * @param   HubPortIndex    - 端口号 | ||||
|  * | ||||
|  * @return  错误码 | ||||
|  */ | ||||
| uint8_t HubGetPortStatus(uint8_t HubPortIndex); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   设置HUB端口特性 | ||||
|  * | ||||
|  * @param   HubPortIndex    - 端口号 | ||||
|  * @param   FeatureSelt     - 端口特性 | ||||
|  * | ||||
|  * @return  错误码 | ||||
|  */ | ||||
| uint8_t HubSetPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   清除HUB端口特性 | ||||
|  * | ||||
|  * @param   HubPortIndex    - 端口号 | ||||
|  * @param   FeatureSelt     - 端口特性 | ||||
|  * | ||||
|  * @return  错误码 | ||||
|  */ | ||||
| uint8_t HubClearPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif // __CH59x_USBHOST_H__
 | ||||
							
								
								
									
										193
									
								
								vendor/StdPeriphDriver/inc/ISP592.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										193
									
								
								vendor/StdPeriphDriver/inc/ISP592.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,193 @@ | |||
| /* CH592 Flash-ROM & Data-Flash  */ | ||||
| /* Website:  http://wch.cn       */ | ||||
| /* Email:    tech@wch.cn         */ | ||||
| /* Author:   W.ch 2020.06        */ | ||||
| /* V1.0 FlashROM library for USER/BOOT */ | ||||
| /* for the target in USER code area on the chip divided into USER code area and BOOT area */ | ||||
| /* 用于具有用户代码区和引导区的芯片、操作目标为用户代码区的情况,
 | ||||
|    可以在用户代码中被调用(IAP,擦写自身),也可以在引导代码中被调用(更新用户代码) */ | ||||
| 
 | ||||
| /* Flash-ROM feature:
 | ||||
|      for store program code, support block erasing, dword and page writing, dword verifying, unit for Length is byte, | ||||
|      minimal quantity for write or verify is one dword (4-bytes), | ||||
|      256 bytes/page for writing, FLASH_ROM_WRITE support one dword or more dword writing, but multiple of 256 is the best, | ||||
|      4KB (4096 bytes) bytes/block for erasing, so multiple of 4096 is the best */ | ||||
| 
 | ||||
| /* Data-Flash(EEPROM) feature:
 | ||||
|      for store data, support block erasing, byte and page writing, byte reading, | ||||
|      minimal quantity for write or read is one byte, | ||||
|      256 bytes/page for writing, EEPROM_WRITE support one byte or more byte writing, but multiple of 256 is the best, | ||||
|      0.25KB/4KB (256/4096 bytes) bytes/block for erasing, so multiple of 256 or 4096 is the best */ | ||||
| 
 | ||||
| 
 | ||||
| #ifndef EEPROM_PAGE_SIZE | ||||
| #define EEPROM_PAGE_SIZE    256                       // Flash-ROM & Data-Flash page size for writing
 | ||||
| #define EEPROM_BLOCK_SIZE   4096                      // Flash-ROM & Data-Flash block size for erasing
 | ||||
| #define EEPROM_MIN_ER_SIZE  EEPROM_PAGE_SIZE          // Data-Flash minimal size for erasing
 | ||||
| //#define EEPROM_MIN_ER_SIZE  EEPROM_BLOCK_SIZE         // Flash-ROM  minimal size for erasing
 | ||||
| #define EEPROM_MIN_WR_SIZE  1                         // Data-Flash minimal size for writing
 | ||||
| #define EEPROM_MAX_SIZE     0x8000                    // Data-Flash maximum size, 32KB
 | ||||
| #endif | ||||
| #ifndef FLASH_MIN_WR_SIZE | ||||
| #define FLASH_MIN_WR_SIZE   4                         // Flash-ROM minimal size for writing
 | ||||
| #endif | ||||
| #ifndef FLASH_ROM_MAX_SIZE | ||||
| #define FLASH_ROM_MAX_SIZE  0x070000                  // Flash-ROM maximum program size, 448KB
 | ||||
| #endif | ||||
| 
 | ||||
| #ifndef CMD_FLASH_ROM_SW_RESET | ||||
| // CMD_* for caller from FlashROM or RAM, auto execute CMD_FLASH_ROM_SW_RESET before command
 | ||||
| 
 | ||||
| #define CMD_FLASH_ROM_START_IO	0x00		// start FlashROM I/O, without parameter
 | ||||
| #define CMD_FLASH_ROM_SW_RESET	0x04		// software reset FlashROM, without parameter
 | ||||
| #define CMD_GET_ROM_INFO		0x06		// get information from FlashROM, parameter @Address,Buffer
 | ||||
| #define CMD_GET_UNIQUE_ID		0x07		// get 64 bit unique ID, parameter @Buffer
 | ||||
| #define CMD_FLASH_ROM_PWR_DOWN	0x0D		// power-down FlashROM, without parameter
 | ||||
| #define CMD_FLASH_ROM_PWR_UP	0x0C		// power-up FlashROM, without parameter
 | ||||
| #define CMD_FLASH_ROM_LOCK		0x08		// lock(protect)/unlock FlashROM data block, return 0 if success, parameter @StartAddr
 | ||||
| // StartAddr: 0=unlock all, 1=lock boot code, 3=lock all code and data
 | ||||
| 
 | ||||
| #define CMD_EEPROM_ERASE		0x09		// erase Data-Flash block, return 0 if success, parameter @StartAddr,Length
 | ||||
| #define CMD_EEPROM_WRITE		0x0A		// write Data-Flash data block, return 0 if success, parameter @StartAddr,Buffer,Length
 | ||||
| #define CMD_EEPROM_READ			0x0B		// read Data-Flash data block, parameter @StartAddr,Buffer,Length
 | ||||
| #define CMD_FLASH_ROM_ERASE		0x01		// erase FlashROM block, return 0 if success, parameter @StartAddr,Length
 | ||||
| #define CMD_FLASH_ROM_WRITE		0x02		// write FlashROM data block, minimal block is dword, return 0 if success, parameter @StartAddr,Buffer,Length
 | ||||
| #define CMD_FLASH_ROM_VERIFY	0x03		// read FlashROM data block, minimal block is dword, return 0 if success, parameter @StartAddr,Buffer,Length
 | ||||
| #endif | ||||
| 
 | ||||
| #define ROM_CFG_VERISON     0x7F010 | ||||
| #define DEF_CHIP_ID_CH592A  9               // QFN28
 | ||||
| #define ROM_CFG_MAC_ADDR	0x7F018			// address for MAC address information
 | ||||
| #define ROM_CFG_BOOT_INFO	0x7DFF8			// address for BOOT information
 | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   execute Flash/EEPROM command, caller from FlashROM or RAM | ||||
|  * | ||||
|  * @param   cmd         - CMD_* for caller from FlashROM or RAM. | ||||
|  * @param   StartAddr   - Address of the data to be process. | ||||
|  * @param   Buffer      - Pointer to the buffer where data should be process, Must in RAM and be aligned to 4 bytes. | ||||
|  * @param   Length      - Size of data to be process, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| extern uint32_t FLASH_EEPROM_CMD( uint8_t cmd, uint32_t StartAddr, void *Buffer, uint32_t Length ); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   start FlashROM I/O | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_START_IO( )                       FLASH_EEPROM_CMD( CMD_FLASH_ROM_START_IO, 0, NULL, 0 ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   software reset FlashROM | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_SW_RESET( )                       FLASH_EEPROM_CMD( CMD_FLASH_ROM_SW_RESET, 0, NULL, 0 ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   get 6 bytes MAC address | ||||
|  * | ||||
|  * @param   Buffer      - Pointer to the buffer where data should be stored, Must in RAM and be aligned to 4 bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define GetMACAddress(Buffer)                       FLASH_EEPROM_CMD( CMD_GET_ROM_INFO, ROM_CFG_MAC_ADDR, Buffer, 0 ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   get 8 bytes BOOT information | ||||
|  * | ||||
|  * @param   Buffer      - Pointer to the buffer where data should be stored, Must in RAM and be aligned to 4 bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define GET_BOOT_INFO(Buffer)                       FLASH_EEPROM_CMD( CMD_GET_ROM_INFO, ROM_CFG_BOOT_INFO, Buffer, 0 ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   power-down FlashROM | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_PWR_DOWN( )                       FLASH_EEPROM_CMD( CMD_FLASH_ROM_PWR_DOWN, 0, NULL, 0 ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   power-up FlashROM | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_PWR_UP( )                         FLASH_EEPROM_CMD( CMD_FLASH_ROM_PWR_UP, 0, NULL, 0 ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   read Data-Flash data block | ||||
|  * | ||||
|  * @param   StartAddr   - Address of the data to be read. | ||||
|  * @param   Buffer      - Pointer to the buffer where data should be stored, Must in RAM and be aligned to 4 bytes. | ||||
|  * @param   Length      - Size of data to be read, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define EEPROM_READ(StartAddr,Buffer,Length)        FLASH_EEPROM_CMD( CMD_EEPROM_READ, StartAddr, Buffer, Length ) | ||||
| 
 | ||||
| /**
 | ||||
|  * | ||||
|  * @param   StartAddr   - Address of the data to be erased. | ||||
|  * @param   Length      - Size of data to be erased, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| __attribute__((always_inline)) RV_STATIC_INLINE uint32_t EEPROM_ERASE(uint32_t StartAddr, uint32_t Length) | ||||
| { | ||||
|     if(((*(uint32_t*)ROM_CFG_VERISON)&0xFF) == DEF_CHIP_ID_CH592A) | ||||
|     { | ||||
|         if(Length%EEPROM_BLOCK_SIZE) | ||||
|         { | ||||
|             while(1); | ||||
|         } | ||||
|     } | ||||
|     return FLASH_EEPROM_CMD( CMD_EEPROM_ERASE, StartAddr, NULL, Length ); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   write Data-Flash data block | ||||
|  * | ||||
|  * @param   StartAddr   - Address of the data to be written. | ||||
|  * @param   Buffer      - Pointer to the source buffer, Must in RAM and be aligned to 4 bytes. | ||||
|  * @param   Length      - Size of data to be written, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define EEPROM_WRITE(StartAddr,Buffer,Length)       FLASH_EEPROM_CMD( CMD_EEPROM_WRITE, StartAddr, Buffer, Length ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   erase FlashROM block | ||||
|  * | ||||
|  * @param   StartAddr   - Address of the data to be erased. | ||||
|  * @param   Length      - Size of data to be erased, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_ERASE(StartAddr,Length)           FLASH_EEPROM_CMD( CMD_FLASH_ROM_ERASE, StartAddr, NULL, Length ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   write FlashROM data block, minimal block is dword. | ||||
|  * | ||||
|  * @param   StartAddr   - Address of the data to be written. | ||||
|  * @param   Buffer      - Pointer to the source buffer, Must in RAM and be aligned to 4 bytes. | ||||
|  * @param   Length      - Size of data to be written, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_WRITE(StartAddr,Buffer,Length)    FLASH_EEPROM_CMD( CMD_FLASH_ROM_WRITE, StartAddr, Buffer, Length ) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief   verify FlashROM data block, minimal block is dword. | ||||
|  * | ||||
|  * @param   StartAddr   - Address of the data to verify. | ||||
|  * @param   Buffer      - Pointer to the source buffer, Must in RAM and be aligned to 4 bytes. | ||||
|  * @param   Length      - Size of data to verify, in bytes. | ||||
|  * | ||||
|  * @return  0-SUCCESS  (!0)-FAILURE | ||||
|  */ | ||||
| #define FLASH_ROM_VERIFY(StartAddr,Buffer,Length)   FLASH_EEPROM_CMD( CMD_FLASH_ROM_VERIFY, StartAddr, Buffer, Length ) | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue