int pwm_devinit(void) { static bool initialized = false; struct pwm_lowerhalf_s *pwm; int ret; /* Have we already initialized? */ if (!initialized) { /* Call kl_pwminitialize() to get an instance of the PWM interface */ pwm = kl_pwminitialize(0); if (!pwm) { adbg("Failed to get the KL26 PWM lower half\n"); return -ENODEV; } /* Register the PWM driver at "/dev/pwm0" */ ret = pwm_register("/dev/pwm0", pwm); if (ret < 0) { adbg("pwm_register failed: %d\n", ret); return ret; } /* Now we are initialized */ initialized = true; } return OK; }
int adc_devinit(void) { static bool initialized = false; struct adc_dev_s *adc; int ret; /* Check if we have already initialized */ if (!initialized) { /* Call lpc17_adcinitialize() to get an instance of the ADC interface */ adc = lpc17_adcinitialize(); if (adc == NULL) { adbg("ERROR: Failed to get ADC interface\n"); return -ENODEV; } /* Register the ADC driver at "/dev/adc0" */ ret = adc_register("/dev/adc0", adc); if (ret < 0) { adbg("adc_register failed: %d\n", ret); return ret; } /* Now we are initialized */ initialized = true; } return OK; }
int dac_devinit(void) { static bool initialized = false; struct dac_dev_s *dac; int ret; if (!initialized) { /* Call lpc17_dacinitialize() to get an instance of the dac interface */ dac = lpc17_dacinitialize(); if (dac == NULL) { adbg("ERROR: Failed to get dac interface\n"); return -ENODEV; } ret = dac_register("/dev/dac0", dac); if (ret < 0) { adbg("dac_register failed: %d\n", ret); return ret; } initialized = true; } return OK; }
int board_gsensoradc_setup(void) { #ifdef CONFIG_STM32_ADC1 static bool initialized = false; struct adc_dev_s *adc; int ret; int i; /* Check if we have already initialized */ if (!initialized){ /* Configure the pins as analog inputs for the selected channels */ for (i = 0; i < ADC1_NCHANNELS; i++) { stm32_configgpio(g_pinlist[i]); //stm32_configgpio(g_detect[i]); } /* Call stm32_adcinitialize() to get an instance of the ADC interface */ adc = stm32_adcinitialize(1, g_chanlist, ADC1_NCHANNELS); if (adc == NULL) { adbg("ERROR: Failed to get ADC interface\n"); return -ENODEV; } /* Register the ADC driver at "/dev/adc0" */ ret = adc_register("/dev/gsensor", adc); if (ret < 0) { adbg("adc_register failed: %d\n", ret); return ret; } /* Now we are initialized */ initialized = true; } return OK; #else return -ENOSYS; #endif }
/* * Caution: * For TSB, PWM1 is pinshared with GPIO9, and their use is therefore exclusive. * Applications intending to control PWM1 must ensure that the PINSHARE register is * configured appropriately. */ int pwm_devinit(void) { static int pwm0_initialized = 0; static int pwm1_initialized = 0; struct pwm_lowerhalf_s *pwm; int ret; /* Have we already initialized PWM0? */ if (!pwm0_initialized) { /* Call tsb_pwminitialize() to get an instance of the PWM0 interface */ pwm = tsb_pwminitialize(0); if (!pwm) { adbg("Failed to get the TSB PWM0 lower half\n"); return -ENODEV; } /* Register the PWM0 driver at "/dev/pwm0" */ ret = pwm_register("/dev/pwm0", pwm); if (ret < 0) { adbg("pwm_register for /dev/pwm0 failed: %d\n", ret); return ret; } /* Now PWM0 is initialized */ pwm0_initialized = 1; } /* Have we already initialized PWM1? */ if (!pwm1_initialized) { /* Call tsb_pwminitialize() to get an instance of the PWM1 interface */ pwm = tsb_pwminitialize(1); if (!pwm) { adbg("Failed to get the TSB PWM1 lower half\n"); return -ENODEV; } /* Register the PWM1 driver at "/dev/pwm1" */ ret = pwm_register("/dev/pwm1", pwm); if (ret < 0) { adbg("pwm_register for /dev/pwm1 failed: %d\n", ret); return ret; } /* Now PWM0 is initialized */ pwm1_initialized = 1; } return 0; }
int board_pwm_setup(void) { static bool initialized = false; struct pwm_lowerhalf_s *pwm; int ret; /* Have we already initialized? */ if (!initialized) { /* Call sam_pwminitialize() to get an instance of the PWM interface */ pwm = sam_pwminitialize(CONFIG_SAMA5D3XPLAINED_CHANNEL); if (!pwm) { dbg("Failed to get the SAMA5 PWM lower half\n"); return -ENODEV; } /* Register the PWM driver at "/dev/pwm0" */ ret = pwm_register("/dev/pwm0", pwm); if (ret < 0) { adbg("pwm_register failed: %d\n", ret); return ret; } /* Now we are initialized */ initialized = true; } return OK; }
int board_pwm_setup(void) { static bool initialized = false; struct pwm_lowerhalf_s *pwm; int ret; /* Have we already initialized? */ if (!initialized) { /* Call stm32_pwminitialize() to get an instance of the PWM interface */ pwm = stm32_pwminitialize(STM32F4DISCOVERY_PWMTIMER); if (!pwm) { dbg("Failed to get the STM32 PWM lower half\n"); return -ENODEV; } /* Register the PWM driver at "/dev/pwm0" */ ret = pwm_register("/dev/pwm0", pwm); if (ret < 0) { adbg("pwm_register failed: %d\n", ret); return ret; } /* Now we are initialized */ initialized = true; } return OK; }
static void tiva_adc_interrupt(struct tiva_adc_sse_s *sse) { int ret; int irq = tiva_adc_getirq(sse->adc, sse->num); DEBUGASSERT(sse->ena == true); /* disable further interrupts. Interrupts will be re-enabled * after the worker thread executes. */ up_disable_irq(irq); /* Clear interrupt status */ tiva_adc_sse_clear_int(sse->adc, sse->num); /* Transfer processing to the worker thread. Since interrupts are * disabled while the work is pending, no special action should be * required to protected the work queue. */ DEBUGASSERT(sse->work.worker == NULL); ret = work_queue(HPWORK, &sse->work, tiva_adc_read, sse, 0); if (ret != 0) { adbg("ERROR: Failed to queue work: %d ADC.SSE: %d.%d\n", ret, sse->adc, sse->num); } }
int adc_devinit(void) { static bool initialized = false; struct adc_dev_s *adc[ADC3_NCHANNELS]; int ret; int i; /* Check if we have already initialized */ if (!initialized) { char name[11]; for (i = 0; i < ADC3_NCHANNELS; i++) { stm32_configgpio(g_pinlist[i]); } for (i = 0; i < 1; i++) { /* Configure the pins as analog inputs for the selected channels */ //stm32_configgpio(g_pinlist[i]); /* Call stm32_adcinitialize() to get an instance of the ADC interface */ //multiple channels only supported with dma! adc[i] = stm32_adcinitialize(3, (g_chanlist), 4); if (adc == NULL) { adbg("ERROR: Failed to get ADC interface\n"); return -ENODEV; } /* Register the ADC driver at "/dev/adc0" */ sprintf(name, "/dev/adc%d", i); ret = adc_register(name, adc[i]); if (ret < 0) { adbg("adc_register failed for adc %s: %d\n", name, ret); return ret; } } /* Now we are initialized */ initialized = true; } return OK; }
void tiva_adc_irq_detach(uint8_t adc, uint8_t sse) { uint32_t ret = 0; int irq = sse2irq[SSE_IDX(adc, sse)]; /* Disable ADC interrupts at the level of the AIC */ up_disable_irq(irq); /* Then detach the ADC interrupt handler. */ ret = irq_detach(irq); if (ret < 0) { adbg("ERROR: Failed to detach IRQ %d: %d\n", irq, ret); return; } }
void tiva_adc_irq_attach(uint8_t adc, uint8_t sse, xcpt_t isr) { uint32_t ret = 0; int irq = sse2irq[SSE_IDX(adc, sse)]; #ifdef CONFIG_DEBUG_ANALOG avdbg("assigning ISR=0x%p to ADC%d SSE%d IRQ=0x%02x...\n", isr, adc, sse, irq); #endif ret = irq_attach(irq, isr); if (ret < 0) { adbg("ERROR: Failed to attach IRQ %d: %d\n", irq, ret); return; } up_enable_irq(irq); }
int tiva_adc_initialize(const char *devpath, struct tiva_adc_cfg_s *cfg, uint32_t clock, uint8_t sample_rate) { struct tiva_adc_s *adc; int ret = 0; avdbg("initializing...\n"); /* Initialize the private ADC device data structure */ adc = tiva_adc_struct_init(cfg); if (adc == NULL) { adbg("Invalid ADC device number: expected=%d actual=%d\n", 0, cfg->adc); return -ENODEV; } /* Turn on peripheral */ if (tiva_adc_enable(adc->devno, true) < 0) { adbg("ERROR: failure to power ADC peripheral (devno=%d)\n", cfg->adc); return ret; } /* Perform actual initialization */ tiva_adc_one_time_init(clock, sample_rate); tiva_adc_configure(cfg); tiva_adc_irqinitialize(cfg); /* Now we are initialized */ adc->ena = true; #ifdef CONFIG_DEBUG_ANALOG tiva_adc_runtimeobj_vals(); #endif /* Ensure our lower half is valid */ if (adc->dev == NULL) { adbg("ERROR: Failed to get interface %s\n", devpath); return -ENODEV; } avdbg("adc_dev_s=0x%08x\n", adc->dev); /* Register the ADC driver */ avdbg("Register the ADC driver at %s\n", devpath); ret = adc_register(devpath, adc->dev); if (ret < 0) { adbg("ERROR: Failed to register %s to character driver: %d\n", devpath, ret); return ret; } return OK; }