void lcd_set_backlight_level(int num) { int _val = num; int _half; int _period; int prescaler = 1; if (_val>=CONFIG_SYS_PWM_FULL) _val = CONFIG_SYS_PWM_FULL-1; if (_val<1) _val =1; if (CONFIG_SYS_PWM_PERIOD < 200) _period = 200; else if (CONFIG_SYS_PWM_PERIOD > 1000000000) _period = 1000000000; else _period = CONFIG_SYS_PWM_PERIOD; _period = (unsigned long long)CONFIG_SYS_EXTAL * _period / 1000000000; while (_period > 0xffff && prescaler < 6) { _period >>= 2; ++prescaler; } _half =_period * _val / (CONFIG_SYS_PWM_FULL); #ifdef SOC_X1000 gpio_set_func(GPIO_PORT_C, GPIO_FUNC_0,1 << (CONFIG_GPIO_LCD_PWM % 32)); #else gpio_set_func(GPIO_PORT_E, GPIO_FUNC_0,1 << (CONFIG_GPIO_LCD_PWM % 32)); #endif struct pwm pwm_backlight = {CONFIG_SYS_PWM_CHN,prescaler,EXTAL,_period,_half}; pwm_init(&pwm_backlight); }
int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func, int pol, int pull, int invert, int debounce) { /* make sure we never pull up and down at the same time */ if (pull == WM8350_GPIO_PULL_NONE) { if (gpio_set_pull_up(wm8350, gpio, 0)) goto err; if (gpio_set_pull_down(wm8350, gpio, 0)) goto err; } else if (pull == WM8350_GPIO_PULL_UP) { if (gpio_set_pull_down(wm8350, gpio, 0)) goto err; if (gpio_set_pull_up(wm8350, gpio, 1)) goto err; } else if (pull == WM8350_GPIO_PULL_DOWN) { if (gpio_set_pull_up(wm8350, gpio, 0)) goto err; if (gpio_set_pull_down(wm8350, gpio, 1)) goto err; } if (gpio_set_invert(wm8350, gpio, invert)) goto err; if (gpio_set_polarity(wm8350, gpio, pol)) goto err; if (gpio_set_debounce(wm8350, gpio, debounce)) goto err; if (gpio_set_dir(wm8350, gpio, dir)) goto err; return gpio_set_func(wm8350, gpio, func); err: return -EIO; }
static void pin_mode(struct rt_device *dev, rt_base_t pin, rt_base_t mode) { if ((pin > PIN_NUM(pin_index)) || (pin_index[pin].magic != PIN_MAGIC)) { dbg_log(DBG_ERROR, "pin:%d value wrongful\n", pin); return; } gpio_set_func(pin_index[pin].pin_port, pin_index[pin].pin, mode); }
/* DMA Timer Initialization */ int8 dtim_init(/*DTIM_Info info, */uint8 u8DTimModule) { /*MCF_SCM_PPMRL &= ~MCF_SCM_PPMRL_CDDTIM0; MCF_SCM_PPMRC |= MCF_SCM_PPMRC_ENABLE_DTIM0;*/ gpio_set_func(PTTC, u8DTimModule, PRIMARY); MCF_DTIM_DTMR(u8DTimModule)|= 0 | MCF_DTIM_DTMR_PS(0) | MCF_DTIM_DTMR_CE_NONE | MCF_DTIM_DTMR_CLK_DTIN | MCF_DTIM_DTMR_FRR; MCF_DTIM_DTRR(u8DTimModule)=~0; MCF_DTIM_DTCN(u8DTimModule)=0; /*MCF_GPIO_PTCPAR|=MCF_GPIO_PTCPAR_DTIN0_DTIN0|MCF_GPIO_PTCPAR_DTIN1_DTIN1; //timer mode reg // MCF_DTIM_DTMR(u8DTimModule) = MCF_DTIM_DTMR_CE(info.u8CapEdge | MCF_DTIM_DTMR_CLK(info.u8ClkSrc); MCF_DTIM_DTMR(u8DTimModule) |= MCF_DTIM_DTMR_CE_NONE | MCF_DTIM_DTMR_CLK_DTIN | MCF_DTIM_DTMR_FRR; MCF_DTIM_DTRR(u8DTimModule) = 0xFFFFFFFF; MCF_DTIM_DTCN(u8DTimModule) = 0x0;*/ /*if(info.u8OutputMode) //toggle output MCF_DTIM_DTMR(u8DTimModule) |= MCF_DTIM_DTMR_OM; else*/ // MCF_DTIM_DTMR(u8DTimModule) &= ~MCF_DTIM_DTMR_OM; // if(info.u8Restart) //restart // MCF_DTIM_DTMR(u8DTimModule) |= MCF_DTIM_DTMR_FRR; // else // MCF_DTIM_DTMR(u8DTimModule) &= ~MCF_DTIM_DTMR_FRR; //Timer extended register // if(info.u8DMAEn) //DMA request enable // MCF_DTIM_DTXMR(u8DTimModule) |= MCF_DTIM_DTXMR_DMAEN; // else // MCF_DTIM_DTXMR(u8DTimModule) &= ~MCF_DTIM_DTXMR_DMAEN; // if(info.u8Halt) //timer stop in halt // MCF_DTIM_DTXMR(u8DTimModule) |= MCF_DTIM_DTXMR_HALTED; // else // MCF_DTIM_DTXMR(u8DTimModule) &= ~MCF_DTIM_DTXMR_HALTED; /*if(info.u8Mode16) MCF_DTIM_DTXMR(u8DTimModule) |= MCF_DTIM_DTXMR_MODE16; else*/ // MCF_DTIM_DTXMR(u8DTimModule) &= ~MCF_DTIM_DTXMR_MODE16; // DTimEnableInts(u8DTimModule, dtim0_isr); return 0; }
int gpio_set_irq_type(enum gpio_port port, enum gpio_pin pin, enum gpio_irq_type irq_type) { enum gpio_function func; RT_ASSERT(IS_GPIO_ALL_PORT(port)); if (irq_type & IRQ_TYPE_PROBE) return 0; switch (irq_type & IRQ_TYPE_SENSE_MASK) { case IRQ_TYPE_LEVEL_HIGH: func = GPIO_INT_HI; break; case IRQ_TYPE_LEVEL_LOW: func = GPIO_INT_LO; break; case IRQ_TYPE_EDGE_RISING: func = GPIO_INT_RE; break; case IRQ_TYPE_EDGE_FALLING: func = GPIO_INT_FE; break; case IRQ_TYPE_EDGE_BOTH: if (gpio_get_value(port, pin)) func = GPIO_INT_FE; else func = GPIO_INT_RE; break; default: return -1; } gpio_set_func(port,pin, func); return 0; }
int rt_hw_spi_init(void) { DEBUG_PRINTF("register spi bus\n"); #ifdef TINA_USING_SPI0 /* register spi bus */ { rt_err_t result; DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); gpio_set_func(GPIO_PORT_C, GPIO_PIN_0, IO_FUN_1); gpio_set_func(GPIO_PORT_C, GPIO_PIN_2, IO_FUN_1); gpio_set_func(GPIO_PORT_C, GPIO_PIN_3, IO_FUN_1); DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); result = tina_spi_bus_register((SPI_T *)SPI0_BASE_ADDR, "spi0"); if (result != RT_EOK) { DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); return result; } } DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); /* attach cs */ { static struct rt_spi_device spi_device; static struct tina_spi_cs spi_cs; rt_err_t result; DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); spi_cs.cs = SPI_TCTRL_SS_SEL_SS0; DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); gpio_set_func(GPIO_PORT_C, GPIO_PIN_1, IO_FUN_1); DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); result = rt_spi_bus_attach_device(&spi_device, "spi00", "spi0", (void *)&spi_cs); if (result != RT_EOK) { DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); return result; } } DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); #endif #ifdef TINA_USING_SPI1 /* register spi bus */ { rt_err_t result; gpio_set_func(GPIO_PORT_A, GPIO_PIN_1, IO_FUN_5); gpio_set_func(GPIO_PORT_A, GPIO_PIN_2, IO_FUN_5); gpio_set_func(GPIO_PORT_A, GPIO_PIN_3, IO_FUN_5); result = tina_spi_bus_register((SPI_T *)SPI1_BASE_ADDR, "spi1"); if (result != RT_EOK) { DEBUG_PRINTF("register spi bus faild: %d\n", result); return result; } } DEBUG_PRINTF("attach cs\n"); /* attach cs */ { static struct rt_spi_device spi_device; static struct tina_spi_cs spi_cs; rt_err_t result; spi_cs.cs = SPI_TCTRL_SS_SEL_SS0; gpio_set_func(GPIO_PORT_A, GPIO_PIN_0, IO_FUN_5); result = rt_spi_bus_attach_device(&spi_device, "spi10", "spi1", (void *)&spi_cs); if (result != RT_EOK) { DEBUG_PRINTF("attach cs faild: %d\n", result); return result; } } #endif return RT_EOK; }
void gpio_direction_output(enum gpio_port port, enum gpio_pin pin,int value) { RT_ASSERT(IS_GPIO_ALL_PORT(port)); gpio_set_func(port, pin, value ? GPIO_OUTPUT1 : GPIO_OUTPUT0); }
void gpio_direction_input(enum gpio_port port, enum gpio_pin pin) { RT_ASSERT(IS_GPIO_ALL_PORT(port)); gpio_set_func(port,pin,GPIO_INPUT); }