OC_04_01

本文介绍Objective-C中如何使用NSValue和NSNumber类将基本数据类型如int、float及CGPoint等封装为对象,以及如何从这些对象中提取原始值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

int main(int argc, const char * argv[]) {
    @autoreleasepool {
       
        /*
         OC中封装,拆包基本数据类型
         Foundation框架下的基础类
         
         NSValue / NSNumber
         功能:将OC 和 C中的基本数据类型转换成实例对象,即将'值类型转'换成'引用类型'
         */
        
        //OC中常用的数据类型
        int a = 5;
        float b = 5.0;
        double c = 5.5;
        char d = 'a';
        bool flag = YES;
        
//        CGPoint point = {3,4};
//        CGSize size = {5,6};
//        CGRect rect = {point,size};
        
        //NSRange包含了两个成员,location 以及 length. location表示起始位置,以0开始,length表示长度
//        NSRange range = {10,3};
        
        CGPoint point = CGPointMake(3, 4);
        CGSize size = CGSizeMake(5, 6);
        CGRect rect = CGRectMake(3, 4, 5, 6);
        NSRange range = NSMakeRange(10, 3);
        NSEdgeInsets edgeInsets = NSEdgeInsetsMake(10, 10, 10, 10);
        
        //NSValue 以及 NSNumber
        //NSValue 为 NSNumber的父类
        //其中NSValue 可以将CGPoint,CGSize,CGRect,NSRange,NSEdgeInsets转换成对象
        NSValue *pointVa = [NSValue valueWithPoint:point];
        NSValue *sizeVa = [NSValue valueWithSize:size];
        NSValue *rectVa = [NSValue valueWithRect:rect];
        NSValue *rangeVa = [NSValue valueWithRange:range];
        NSValue *edgeInsetsVa = [NSValue valueWithEdgeInsets:edgeInsets];
        
        //其中NSNumber 可以将'int','float','double','char','bool'等C中基本数据类型转换成对象
        NSNumber *intNumber = [NSNumber numberWithInt:a];
        NSNumber *floatNumber = [NSNumber numberWithFloat:b];
        NSNumber *doubleNumber = [NSNumber numberWithDouble:c];
        NSNumber *charNumber = [NSNumber numberWithChar:d];
        NSNumber *boolNumber = [NSNumber numberWithBool:flag];
        
        
        //我们将C和OC中的基本数据类型(值类型)转换成对象(引用类型)的过程,叫做封装.相对应的也有一个将对象转变成基本数据类型,此过程叫做拆包.
        
        //拆包
        int a1 = [intNumber intValue];
        float b1 = [floatNumber floatValue];
        double c1 = [doubleNumber doubleValue];
        char d1 = [charNumber charValue];
        bool flag1 = [boolNumber boolValue];
        
        CGPoint point1 = [pointVa pointValue];
        CGSize size1 = [sizeVa sizeValue];
        CGRect rect1 = [rectVa rectValue];
        NSRange range1 = [rangeVa rangeValue];
        NSEdgeInsets edgeInsets1 = [edgeInsetsVa edgeInsetsValue];
        
        
        
        
    }
    return 0;
}
我的代码是这样的void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == TCA9555OC_INT_Pin) //TCA9555的过流信号变化中断 { uint16_t OC_EventBits = 0;//初始化过流事件组的置位位 static uint8_t pause_command[9]={0x01,0x09,0x01,0x00,0x04,0x0D,0x00,0x00,0x1C};//初始化暂停指令 //先读取TCA9555的输入引脚状态 uint16_t TCA9555OC_GPIOINPUT = TCA9555_ReadPortInPutStatus(TCA9555_IIC_HANDLE,TCA9555_OC_Address); //再根据过流信号的状态,将对应的过流事件位置1 if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH1) OC_EventBits |= OverCurrent_Status_CH1; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH2) OC_EventBits |= OverCurrent_Status_CH2; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH3) OC_EventBits |= OverCurrent_Status_CH3; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH4) OC_EventBits |= OverCurrent_Status_CH4; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH5) OC_EventBits |= OverCurrent_Status_CH5; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH6) OC_EventBits |= OverCurrent_Status_CH6; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH7) OC_EventBits |= OverCurrent_Status_CH7; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH8) OC_EventBits |= OverCurrent_Status_CH8; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH9) OC_EventBits |= OverCurrent_Status_CH9; if(TCA9555OC_GPIOINPUT & TCA9555_OC_CH10) OC_EventBits |= OverCurrent_Status_CH10; //全部过流信号取反 OC_EventBits = ~OC_EventBits; //最后把总过流位置1 OC_EventBits |= OverCurrent_Status_All; //将过流事件组的置位位设置到过流事件组中,使用ISR安全操作模式 xEventGroupSetBitsFromISR(OverCurrent_Status_Flags_EventHandle,OC_EventBits, pdFALSE); //全部通道断电 Close_AllChannel_PowerSupply(); //进行暂停 HAL_GPIO_WritePin(PAUSE_LED_32_GPIO_Port,PAUSE_LED_32_Pin,GPIO_PIN_SET);//打开暂停指示灯 Command_SendtoHMI(pause_command,&HMI_UART);//发送暂停指令给HMI osEventFlagsClear(ManageChannel_Test_Flags_EventHandle, Channel_Continue_Flag);//将管理事件组的继续位清0 } }
04-09
; 乒乓球游戏汇编代码 ; 使用MASM语法,针对DOS环境 .MODEL SMALL .STACK 100H .DATA ; 端口地址定义 pa EQU 280H pb EQU 281H pc EQU 282H pn1 EQU 283H p0 EQU 288H p1 EQU 289H p2 EQU 28AH pn2 EQU 28BH ; 数码管编码表 s DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,7BH,71H ; 全局变量 led DB 0 f DW 1 ; 移动方向标志 s1 DW 50 ; 初始速度 m DW 0 ; 甲得分 n DW 0 ; 乙得分 msg DB ‘Please serve!’,0DH,0AH,‘$’ .CODE STARTUP: MOV AX, @DATA MOV DS, AX ; 初始化8255 MOV DX, pn1 MOV AL, 81H ; A/B口输出,C口输入 OUT DX, AL ; 初始化8253定时器 MOV DX, pn2 MOV AL, 36H ; 计数器0,方式3 OUT DX, AL MOV DX, p0 MOV AX, 1193 ; 1MHz时钟,产生50Hz中断 OUT DX, AL MOV AL, AH OUT DX, AL MAIN_LOOP: ; 显示发球提示 MOV AH, 09H MOV DX, OFFSET msg INT 21H CALL START ; 等待发球 GAME_LOOP: MOV DX, pb MOV AL, led OUT DX, AL ; 更新LED状态 ; 数码管动态显示 CALL SCOREM CALL DELAY CALL SCOREN CALL DELAY ; 检测击球 MOV DX, pc IN AL, DX CMP f, 1 JNE CHECK_RIGHT ; 向左移动时检测乙击球(PC1) TEST AL, 02H JZ MOVE_BALL MOV f, 0 ; 改变方向 JMP MOVE_BALL CHECK_RIGHT: ; 向右移动时检测甲击球(PC0) TEST AL, 01H JZ MOVE_BALL MOV f, 1 MOVE_BALL: CALL LEDDIC ; 移动球位置 CALL OUT_CHECK ; 得分检测 CMP led, 0 ; 检查球是否出界 JNE GAME_LOOP JMP MAIN_LOOP ; 开始新回合 MOV AH, 4CH ; 退出程序 INT 21H ; LED移动函数 LEDDIC PROC NEAR CMP f, 1 JE LEFT SHR led, 1 ; 右移 JMP EXIT_LED LEFT: SHL led, 1 ; 左移 EXIT_LED: RET LEDDIC ENDP ; 数码管显示延时 DELAY PROC NEAR PUSH CX MOV CX, 500 DLOOP: LOOP DLOOP POP CX RET DELAY ENDP ; 显示甲得分 SCOREM PROC NEAR MOV DX, pc MOV AL, 20H ; 开启高位数码管 OUT DX, AL MOV BX, m MOV AL, s[BX] MOV DX, pa OUT DX, AL RET SCOREM ENDP ; 显示乙得分 SCOREN PROC NEAR MOV DX, pc MOV AL, 10H ; 开启低位数码管 OUT DX, AL MOV BX, n MOV AL, s[BX] MOV DX, pa OUT DX, AL RET SCOREN ENDP ; 发球检测(带去抖动) START PROC NEAR START_LOOP: MOV DX, pc IN AL, DX TEST AL, 01H ; 检测甲发球 JZ CHECK_PC1 CALL DEBOUNCE TEST AL, 01H JZ CHECK_PC1 MOV led, 80H ; 甲发球位置 MOV f, 0 ; 初始向右移动 JMP START_EXIT CHECK_PC1: TEST AL, 02H ; 检测乙发球 JZ START_LOOP CALL DEBOUNCE TEST AL, 02H JZ START_LOOP MOV led, 01H ; 乙发球位置 MOV f, 1 ; 初始向左移动 START_EXIT: RET START ENDP ; 按键去抖动 DEBOUNCE PROC NEAR PUSH CX MOV CX, 1000 DB_LOOP: LOOP DB_LOOP POP CX RET DEBOUNCE ENDP ; 得分判断 OUT_CHECK PROC NEAR CMP led, 0 JNE OC_EXIT CMP f, 1 JNE PLAYER_A INC n ; 乙得分 JMP SCORE_CHECK PLAYER_A: INC m ; 甲得分 SCORE_CHECK: ; 胜负判断(11分制,领先2分) MOV AX, m CMP AX, 11 JL CHECK_N MOV BX, n SUB AX, BX CMP AX, 2 JGE RESET JMP OC_EXIT CHECK_N: MOV AX, n CMP AX, 11 JL OC_EXIT MOV BX, m SUB AX, BX CMP AX, 2 JL OC_EXIT RESET: MOV m, 0 MOV n, 0 OC_EXIT: RET OUT_CHECK ENDP END优化此代码 使此代码利用8253clock0为1MHz,out0与clock1的串联 实现输出2hz方波 并实现led的移动速度为0.5s ,任意一方领先两分或得到11分时结束游戏 给出修改后全部的代码
04-03
/* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-12-13 zylx first version */ #include <board.h> #include<rtthread.h> #include<rtdevice.h> #ifdef RT_USING_PWM #include "drv_config.h" //#define DRV_DEBUG #define LOG_TAG "drv.pwm" #include <drv_log.h> #define MAX_PERIOD 65535 #define MIN_PERIOD 3 #define MIN_PULSE 2 extern void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); enum { #ifdef BSP_USING_PWM1 PWM1_INDEX, #endif #ifdef BSP_USING_PWM2 PWM2_INDEX, #endif #ifdef BSP_USING_PWM3 PWM3_INDEX, #endif #ifdef BSP_USING_PWM4 PWM4_INDEX, #endif #ifdef BSP_USING_PWM5 PWM5_INDEX, #endif #ifdef BSP_USING_PWM6 PWM6_INDEX, #endif #ifdef BSP_USING_PWM7 PWM7_INDEX, #endif #ifdef BSP_USING_PWM8 PWM8_INDEX, #endif #ifdef BSP_USING_PWM9 PWM9_INDEX, #endif #ifdef BSP_USING_PWM10 PWM10_INDEX, #endif #ifdef BSP_USING_PWM11 PWM11_INDEX, #endif #ifdef BSP_USING_PWM12 PWM12_INDEX, #endif #ifdef BSP_USING_PWM13 PWM13_INDEX, #endif #ifdef BSP_USING_PWM14 PWM14_INDEX, #endif #ifdef BSP_USING_PWM15 PWM15_INDEX, #endif #ifdef BSP_USING_PWM16 PWM16_INDEX, #endif #ifdef BSP_USING_PWM17 PWM17_INDEX, #endif }; struct stm32_pwm { struct rt_device_pwm pwm_device; TIM_HandleTypeDef tim_handle; rt_uint8_t channel; char *name; }; static struct stm32_pwm stm32_pwm_obj[] = { #ifdef BSP_USING_PWM1 PWM1_CONFIG, #endif #ifdef BSP_USING_PWM2 PWM2_CONFIG, #endif #ifdef BSP_USING_PWM3 PWM3_CONFIG, #endif #ifdef BSP_USING_PWM4 PWM4_CONFIG, #endif #ifdef BSP_USING_PWM5 PWM5_CONFIG, #endif #ifdef BSP_USING_PWM6 PWM6_CONFIG, #endif #ifdef BSP_USING_PWM7 PWM7_CONFIG, #endif #ifdef BSP_USING_PWM8 PWM8_CONFIG, #endif #ifdef BSP_USING_PWM9 PWM9_CONFIG, #endif #ifdef BSP_USING_PWM10 PWM10_CONFIG, #endif #ifdef BSP_USING_PWM11 PWM11_CONFIG, #endif #ifdef BSP_USING_PWM12 PWM12_CONFIG, #endif #ifdef BSP_USING_PWM13 PWM13_CONFIG, #endif #ifdef BSP_USING_PWM14 PWM14_CONFIG, #endif #ifdef BSP_USING_PWM15 PWM15_CONFIG, #endif #ifdef BSP_USING_PWM16 PWM16_CONFIG, #endif #ifdef BSP_USING_PWM17 PWM17_CONFIG, #endif }; static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg); static struct rt_pwm_ops drv_ops = { drv_pwm_control }; static rt_err_t drv_pwm_enable(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable) { /* Converts the channel number to the channel number of Hal library */ rt_uint32_t channel = 0x04 * (configuration->channel - 1); if (!enable) { HAL_TIM_PWM_Stop(htim, channel); } else { HAL_TIM_PWM_Start(htim, channel); } return RT_EOK; } static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration) { /* Converts the channel number to the channel number of Hal library */ rt_uint32_t channel = 0x04 * (configuration->channel - 1); rt_uint64_t tim_clock; #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) if (htim->Instance == TIM9 || htim->Instance == TIM10 || htim->Instance == TIM11) #elif defined(SOC_SERIES_STM32L4) if (htim->Instance == TIM15 || htim->Instance == TIM16 || htim->Instance == TIM17) #elif defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) if (0) #endif { #if !defined(SOC_SERIES_STM32F0) && !defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK2Freq() * 2; #endif } else { #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK1Freq(); #else tim_clock = HAL_RCC_GetPCLK1Freq() * 2; #endif } if (__HAL_TIM_GET_CLOCKDIVISION(htim) == TIM_CLOCKDIVISION_DIV2) { tim_clock = tim_clock / 2; } else if (__HAL_TIM_GET_CLOCKDIVISION(htim) == TIM_CLOCKDIVISION_DIV4) { tim_clock = tim_clock / 4; } /* Convert nanosecond to frequency and duty cycle. 1s = 1 * 1000 * 1000 * 1000 ns */ tim_clock /= 1000000UL; configuration->period = (__HAL_TIM_GET_AUTORELOAD(htim) + 1) * (htim->Instance->PSC + 1) * 1000UL / tim_clock; configuration->pulse = (__HAL_TIM_GET_COMPARE(htim, channel) + 1) * (htim->Instance->PSC + 1) * 1000UL / tim_clock; return RT_EOK; } static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration) { rt_uint32_t period, pulse; rt_uint64_t tim_clock, psc; /* Converts the channel number to the channel number of Hal library */ rt_uint32_t channel = 0x04 * (configuration->channel - 1); #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) if (htim->Instance == TIM9 || htim->Instance == TIM10 || htim->Instance == TIM11) #elif defined(SOC_SERIES_STM32L4) if (htim->Instance == TIM15 || htim->Instance == TIM16 || htim->Instance == TIM17) #elif defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) if (0) #endif { #if !defined(SOC_SERIES_STM32F0) && !defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK2Freq() * 2; #endif } else { #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK1Freq(); #else tim_clock = HAL_RCC_GetPCLK1Freq() * 2; #endif } /* Convert nanosecond to frequency and duty cycle. 1s = 1 * 1000 * 1000 * 1000 ns */ tim_clock /= 1000000UL; period = (unsigned long long)configuration->period * tim_clock / 1000ULL ; psc = period / MAX_PERIOD + 1; period = period / psc; __HAL_TIM_SET_PRESCALER(htim, psc - 1); if (period < MIN_PERIOD) { period = MIN_PERIOD; } __HAL_TIM_SET_AUTORELOAD(htim, period - 1); pulse = (unsigned long long)configuration->pulse * tim_clock / psc / 1000ULL; if (pulse < MIN_PULSE) { pulse = MIN_PULSE; } else if (pulse > period) { pulse = period; } __HAL_TIM_SET_COMPARE(htim, channel, pulse - 1); __HAL_TIM_SET_COUNTER(htim, 0); /* Update frequency value */ HAL_TIM_GenerateEvent(htim, TIM_EVENTSOURCE_UPDATE); return RT_EOK; } static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg) { struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)arg; TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)device->parent.user_data; switch (cmd) { case PWM_CMD_ENABLE: return drv_pwm_enable(htim, configuration, RT_TRUE); case PWM_CMD_DISABLE: return drv_pwm_enable(htim, configuration, RT_FALSE); case PWM_CMD_SET: return drv_pwm_set(htim, configuration); case PWM_CMD_GET: return drv_pwm_get(htim, configuration); default: return RT_EINVAL; } } static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device) { rt_err_t result = RT_EOK; TIM_HandleTypeDef *tim = RT_NULL; TIM_OC_InitTypeDef oc_config = {0}; TIM_MasterConfigTypeDef master_config = {0}; TIM_ClockConfigTypeDef clock_config = {0}; RT_ASSERT(device != RT_NULL); tim = (TIM_HandleTypeDef *)&device->tim_handle; /* configure the timer to pwm mode */ tim->Init.Prescaler = 0; tim->Init.CounterMode = TIM_COUNTERMODE_UP; tim->Init.Period = 0; tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; #endif if (HAL_TIM_PWM_Init(tim) != HAL_OK) { LOG_E("%s pwm init failed", device->name); result = -RT_ERROR; goto __exit; } clock_config.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(tim, &clock_config) != HAL_OK) { LOG_E("%s clock init failed", device->name); result = -RT_ERROR; goto __exit; } master_config.MasterOutputTrigger = TIM_TRGO_RESET; master_config.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(tim, &master_config) != HAL_OK) { LOG_E("%s master config failed", device->name); result = -RT_ERROR; goto __exit; } oc_config.OCMode = TIM_OCMODE_PWM1; oc_config.Pulse = 0; oc_config.OCPolarity = TIM_OCPOLARITY_HIGH; oc_config.OCFastMode = TIM_OCFAST_DISABLE; oc_config.OCNIdleState = TIM_OCNIDLESTATE_RESET; oc_config.OCIdleState = TIM_OCIDLESTATE_RESET; /* config pwm channel */ if (device->channel & 0x01) { if (HAL_TIM_PWM_ConfigChannel(tim, &oc_config, TIM_CHANNEL_1) != HAL_OK) { LOG_E("%s channel1 config failed", device->name); result = -RT_ERROR; goto __exit; } } if (device->channel & 0x02) { if (HAL_TIM_PWM_ConfigChannel(tim, &oc_config, TIM_CHANNEL_2) != HAL_OK) { LOG_E("%s channel2 config failed", device->name); result = -RT_ERROR; goto __exit; } } if (device->channel & 0x04) { if (HAL_TIM_PWM_ConfigChannel(tim, &oc_config, TIM_CHANNEL_3) != HAL_OK) { LOG_E("%s channel3 config failed", device->name); result = -RT_ERROR; goto __exit; } } if (device->channel & 0x08) { if (HAL_TIM_PWM_ConfigChannel(tim, &oc_config, TIM_CHANNEL_4) != HAL_OK) { LOG_E("%s channel4 config failed", device->name); result = -RT_ERROR; goto __exit; } } /* pwm pin configuration */ HAL_TIM_MspPostInit(tim); /* enable update request source */ __HAL_TIM_URS_ENABLE(tim); __exit: return result; } static void pwm_get_channel(void) { #ifdef BSP_USING_PWM1_CH1 stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM1_CH2 stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM1_CH3 stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM1_CH4 stm32_pwm_obj[PWM1_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM2_CH1 stm32_pwm_obj[PWM2_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM2_CH2 stm32_pwm_obj[PWM2_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM2_CH3 stm32_pwm_obj[PWM2_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM2_CH4 stm32_pwm_obj[PWM2_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM3_CH1 stm32_pwm_obj[PWM3_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM3_CH2 stm32_pwm_obj[PWM3_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM3_CH3 stm32_pwm_obj[PWM3_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM3_CH4 stm32_pwm_obj[PWM3_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM4_CH1 stm32_pwm_obj[PWM4_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM4_CH2 stm32_pwm_obj[PWM4_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM4_CH3 stm32_pwm_obj[PWM4_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM4_CH4 stm32_pwm_obj[PWM4_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM5_CH1 stm32_pwm_obj[PWM5_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM5_CH2 stm32_pwm_obj[PWM5_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM5_CH3 stm32_pwm_obj[PWM5_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM5_CH4 stm32_pwm_obj[PWM5_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM6_CH1 stm32_pwm_obj[PWM6_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM6_CH2 stm32_pwm_obj[PWM6_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM6_CH3 stm32_pwm_obj[PWM6_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM6_CH4 stm32_pwm_obj[PWM6_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM7_CH1 stm32_pwm_obj[PWM7_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM7_CH2 stm32_pwm_obj[PWM7_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM7_CH3 stm32_pwm_obj[PWM7_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM7_CH4 stm32_pwm_obj[PWM7_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM8_CH1 stm32_pwm_obj[PWM8_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM8_CH2 stm32_pwm_obj[PWM8_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM8_CH3 stm32_pwm_obj[PWM8_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM8_CH4 stm32_pwm_obj[PWM8_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM9_CH1 stm32_pwm_obj[PWM9_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM9_CH2 stm32_pwm_obj[PWM9_INDEX].channel |= 1 << 1; #endif #ifdef BSP_USING_PWM9_CH3 stm32_pwm_obj[PWM9_INDEX].channel |= 1 << 2; #endif #ifdef BSP_USING_PWM9_CH4 stm32_pwm_obj[PWM9_INDEX].channel |= 1 << 3; #endif #ifdef BSP_USING_PWM12_CH1 stm32_pwm_obj[PWM12_INDEX].channel |= 1 << 0; #endif #ifdef BSP_USING_PWM12_CH2 stm32_pwm_obj[PWM12_INDEX].channel |= 1 << 1; #endif } static int stm32_pwm_init(void) { int i = 0; int result = RT_EOK; pwm_get_channel(); for (i = 0; i < sizeof(stm32_pwm_obj) / sizeof(stm32_pwm_obj[0]); i++) { /* pwm init */ if (stm32_hw_pwm_init(&stm32_pwm_obj[i]) != RT_EOK) { LOG_E("%s init failed", stm32_pwm_obj[i].name); result = -RT_ERROR; goto __exit; } else { LOG_D("%s init success", stm32_pwm_obj[i].name); /* register pwm device */ if (rt_device_pwm_register(&stm32_pwm_obj[i].pwm_device, stm32_pwm_obj[i].name, &drv_ops, &stm32_pwm_obj[i].tim_handle) == RT_EOK) { LOG_D("%s register success", stm32_pwm_obj[i].name); } else { LOG_E("%s register failed", stm32_pwm_obj[i].name); result = -RT_ERROR; } } } __exit: return result; } INIT_DEVICE_EXPORT(stm32_pwm_init); #endif /* RT_USING_PWM */ 这段出现很多报错是什么原因
08-19
内容概要:该论文聚焦于T2WI核磁共振图像超分辨率问题,提出了一种利用T1WI模态作为辅助信息的跨模态解决方案。其主要贡献包括:提出基于高频信息约束的网络框架,通过主干特征提取分支和高频结构先验建模分支结合Transformer模块和注意力机制有效重建高频细节;设计渐进式特征匹配融合框架,采用多阶段相似特征匹配算法提高匹配鲁棒性;引入模型量化技术降低推理资源需求。实验结果表明,该方法不仅提高了超分辨率性能,还保持了图像质量。 适合人群:从事医学图像处理、计算机视觉领域的研究人员和工程师,尤其是对核磁共振图像超分辨率感兴趣的学者和技术开发者。 使用场景及目标:①适用于需要提升T2WI核磁共振图像分辨率的应用场景;②目标是通过跨模态信息融合提高图像质量,解决传统单模态方法难以克服的高频细节丢失问题;③为临床诊断提供更高质量的影像资料,帮助医生更准确地识别病灶。 其他说明:论文不仅提供了详细的网络架构设计与实现代码,还深入探讨了跨模态噪声的本质、高频信息约束的实现方式以及渐进式特征匹配的具体过程。此外,作者还对模型进行了量化处理,使得该方法可以在资源受限环境下高效运行。阅读时应重点关注论文中提到的技术创新点及其背后的原理,理解如何通过跨模态信息融合提升图像重建效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值