移植到stm32f1,实现手动线赋码控制器功能
This commit is contained in:
		
							
								
								
									
										218
									
								
								source/interface/if_gpioout.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										218
									
								
								source/interface/if_gpioout.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,218 @@ | ||||
| #include "board.h" | ||||
| #include "stm32f10x.h" | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| /* | ||||
| --------------------------------------------------- | ||||
| |                输出通道对应关系                 | | ||||
| |-------------------------------------------------| | ||||
| |PA4 |PA5 |PA6 |PA7 |PC4 |PC5 |PB0 |PB1 |PB12|PB13| | ||||
| |-------------------------------------------------| | ||||
| |OUT0|OUT1|OUT2|OUT3|OUT4|OUT5|OUT6|OUT7|OUT8|OUT9| | ||||
| --------------------------------------------------- | ||||
|  | ||||
| */ | ||||
|  | ||||
|  | ||||
|  | ||||
| #define GPIO_Initer() {.GPIO_Speed=GPIO_Speed_50MHz,\ | ||||
|   .GPIO_Mode=GPIO_Mode_Out_PP,\ | ||||
| } | ||||
|  | ||||
|  | ||||
| typedef struct{ | ||||
|   const char *name; | ||||
|   void (*gpio_clock_fun)(uint32_t,FunctionalState); | ||||
|   uint32_t gpio_rcc; | ||||
|   GPIO_TypeDef *gpio_base; | ||||
|   uint16_t gpio_pin; | ||||
|   volatile uint32_t *bitmap_pin; | ||||
| }gpioout_dtb; | ||||
|  | ||||
|  | ||||
| static const gpioout_dtb g_dtb[]={ | ||||
|   { | ||||
|     .name="gpioout0", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOA, | ||||
|     .gpio_base=GPIOA, | ||||
|     .gpio_pin=4, | ||||
|     .bitmap_pin=&PINOUT(A,4), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout1", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOA, | ||||
|     .gpio_base=GPIOA, | ||||
|     .gpio_pin=5, | ||||
|     .bitmap_pin=&PINOUT(A,5), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout2", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOA, | ||||
|     .gpio_base=GPIOA, | ||||
|     .gpio_pin=6, | ||||
|     .bitmap_pin=&PINOUT(A,6), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout3", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOA, | ||||
|     .gpio_base=GPIOA, | ||||
|     .gpio_pin=7, | ||||
|     .bitmap_pin=&PINOUT(A,7), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout4", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOC, | ||||
|     .gpio_base=GPIOC, | ||||
|     .gpio_pin=4, | ||||
|     .bitmap_pin=&PINOUT(C,4), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout5", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOC, | ||||
|     .gpio_base=GPIOC, | ||||
|     .gpio_pin=5, | ||||
|     .bitmap_pin=&PINOUT(C,5), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout6", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOB, | ||||
|     .gpio_base=GPIOB, | ||||
|     .gpio_pin=0, | ||||
|     .bitmap_pin=&PINOUT(B,0), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout7", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOB, | ||||
|     .gpio_base=GPIOB, | ||||
|     .gpio_pin=1, | ||||
|     .bitmap_pin=&PINOUT(B,1), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout8", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOB, | ||||
|     .gpio_base=GPIOB, | ||||
|     .gpio_pin=12, | ||||
|     .bitmap_pin=&PINOUT(B,12), | ||||
|   }, | ||||
|   { | ||||
|     .name="gpioout9", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOB, | ||||
|     .gpio_base=GPIOB, | ||||
|     .gpio_pin=13, | ||||
|     .bitmap_pin=&PINOUT(B,13), | ||||
|   }, | ||||
|   { | ||||
|     .name="led", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOC, | ||||
|     .gpio_base=GPIOC, | ||||
|     .gpio_pin=6, | ||||
|     .bitmap_pin=&PINOUT(C,6), | ||||
|   }, | ||||
|   { | ||||
|     .name="mod1_use", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOC, | ||||
|     .gpio_base=GPIOC, | ||||
|     .gpio_pin=7, | ||||
|     .bitmap_pin=&PINOUT(C,7), | ||||
|   }, | ||||
|   { | ||||
|     .name="bus_sel", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOC, | ||||
|     .gpio_base=GPIOC, | ||||
|     .gpio_pin=8, | ||||
|     .bitmap_pin=&PINOUT(C,8), | ||||
|   }, | ||||
|   { | ||||
|     .name="mod_sel", | ||||
|     .gpio_clock_fun=RCC_APB2PeriphClockCmd, | ||||
|     .gpio_rcc=RCC_APB2Periph_GPIOC, | ||||
|     .gpio_base=GPIOC, | ||||
|     .gpio_pin=9, | ||||
|     .bitmap_pin=&PINOUT(C,9), | ||||
|   }, | ||||
| }; | ||||
|  | ||||
|  | ||||
|  | ||||
| typedef struct{ | ||||
|   const gpioout_dtb *dtb; | ||||
| }self_data; | ||||
|  | ||||
|  | ||||
| static self_data g_self[LENGTH(g_dtb)]; | ||||
|  | ||||
|  | ||||
| def_find_fun(gpioout_dtb,g_dtb) | ||||
|  | ||||
|  | ||||
|  | ||||
| static int init(gpioout_def *g) | ||||
| { | ||||
|   param_check(g); | ||||
|   if(g->private_data) return 0; | ||||
|   GPIO_InitTypeDef init=GPIO_Initer(); | ||||
|   int index; | ||||
|   const gpioout_dtb *dtb=find(g->name,&index); | ||||
|   self_data *self=&g_self[index]; | ||||
|   self->dtb=dtb; | ||||
|   g->private_data=self; | ||||
|  | ||||
|   dtb->gpio_clock_fun(dtb->gpio_rcc,ENABLE); | ||||
| 	init.GPIO_Pin = 1<<dtb->gpio_pin;	  | ||||
| 	GPIO_Init(dtb->gpio_base, &init);	 | ||||
|   *dtb->bitmap_pin=1; | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| static int deinit(gpioout_def *g) | ||||
| { | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| static int set(gpioout_def *g,int state) | ||||
| { | ||||
|   param_check(g); | ||||
|   param_check(g->private_data); | ||||
|   self_data *self=g->private_data; | ||||
|   // 电路上0为导通,逻辑上1为真,在此反向 | ||||
|   *self->dtb->bitmap_pin=state?0:1; | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| gpioout_init_export(gpioout0,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout1,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout2,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout3,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout4,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout5,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout6,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout7,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout8,init,deinit,set,0) | ||||
| gpioout_init_export(gpioout9,init,deinit,set,0) | ||||
| gpioout_init_export(led,init,deinit,set,0) | ||||
| gpioout_init_export(mod1_use,init,deinit,set,0) | ||||
| gpioout_init_export(bus_sel,init,deinit,set,0) | ||||
| gpioout_init_export(mod_sel,init,deinit,set,0) | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 ranchuan
					ranchuan