done
This commit is contained in:
parent
2f13f30b3d
commit
24770a1266
@ -59,7 +59,7 @@ static const TIM_OCInitTypeDef t4_output_compare_cfg = {
|
||||
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||
.TIM_OCPolarity = TIM_OCPolarity_High,
|
||||
.TIM_OutputState = TIM_OutputState_Enable,
|
||||
.TIM_Pulse = 0 // Initiale Pulsweite in Millisekunden
|
||||
.TIM_Pulse = 0,
|
||||
};
|
||||
|
||||
static const GPIO_InitTypeDef port_cfg = {
|
||||
@ -85,6 +85,15 @@ static const struct pwm pwm_ch4 = {
|
||||
.fp = &stm32f4_pwm_fp,
|
||||
};
|
||||
|
||||
#ifdef TEST_APP
|
||||
static const struct driver pwm_4 = {
|
||||
#else
|
||||
const struct driver pwm_4 = {
|
||||
#endif
|
||||
DRIVER_TYPE_PWM,
|
||||
&pwm_ch4,
|
||||
};
|
||||
|
||||
// UART 1
|
||||
static char console_linear_buffer[80];
|
||||
static struct ringbuffer console_buffer = {
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "adc.h"
|
||||
#include "gpio.h"
|
||||
#include "i2c.h"
|
||||
#include "pwm.h"
|
||||
#include "rtc.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
@ -30,6 +31,9 @@ int open(const struct driver *driver)
|
||||
case DRIVER_TYPE_I2C:
|
||||
ret = i2c_open((struct i2c *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = pwm_open((const struct pwm *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
ret = rtc_open((const struct rtc *)(driver->device_driver));
|
||||
break;
|
||||
@ -58,6 +62,9 @@ int close(const struct driver *driver)
|
||||
case DRIVER_TYPE_I2C:
|
||||
ret = i2c_close((struct i2c *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = pwm_close((const struct pwm *)(driver->device_driver));
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
ret = rtc_close((const struct rtc *)(driver->device_driver));
|
||||
break;
|
||||
@ -88,6 +95,9 @@ int read(const struct driver *driver, char *buffer, int len)
|
||||
break;
|
||||
case DRIVER_TYPE_I2C:
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = -1;
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
break;
|
||||
case DRIVER_TYPE_SPI:
|
||||
@ -118,6 +128,9 @@ int write(const struct driver *driver, const char *buffer, int len)
|
||||
break;
|
||||
case DRIVER_TYPE_I2C:
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
ret = -1;
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
break;
|
||||
case DRIVER_TYPE_SPI:
|
||||
@ -128,3 +141,31 @@ int write(const struct driver *driver, const char *buffer, int len)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ioctl(const struct driver *driver, unsigned int cmd, const void *data)
|
||||
{
|
||||
int ret = -1;
|
||||
if(NULL == driver)
|
||||
return ret;
|
||||
switch(driver->driver_type) {
|
||||
case DRIVER_TYPE_ADC:
|
||||
break;
|
||||
case DRIVER_TYPE_GPIO:
|
||||
break;
|
||||
case DRIVER_TYPE_I2C:
|
||||
break;
|
||||
case DRIVER_TYPE_PWM:
|
||||
if(cmd == IOCTL_PWM_SET_DUTY_CYCLE) {
|
||||
unsigned int *duty = (unsigned int *)data;
|
||||
pwm_set_duty_cycle((const struct pwm *)(driver->device_driver), *duty);
|
||||
}
|
||||
break;
|
||||
case DRIVER_TYPE_RTC:
|
||||
break;
|
||||
case DRIVER_TYPE_SPI:
|
||||
break;
|
||||
case DRIVER_TYPE_UART:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -8,10 +8,13 @@
|
||||
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||
|
||||
#define IOCTL_PWM_SET_DUTY_CYCLE 0
|
||||
|
||||
enum driver_type {
|
||||
DRIVER_TYPE_ADC,
|
||||
DRIVER_TYPE_GPIO,
|
||||
DRIVER_TYPE_I2C,
|
||||
DRIVER_TYPE_PWM,
|
||||
DRIVER_TYPE_RTC,
|
||||
DRIVER_TYPE_SPI,
|
||||
DRIVER_TYPE_UART
|
||||
@ -26,5 +29,6 @@ int open(const struct driver *driver);
|
||||
int close(const struct driver *driver);
|
||||
int read(const struct driver *driver, char *buffer, int len);
|
||||
int write(const struct driver *driver, const char *buffer, int len);
|
||||
int ioctl(const struct driver *driver, unsigned int cmd, const void *data);
|
||||
|
||||
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
||||
|
@ -23,15 +23,16 @@ struct thread_context th_ctx;
|
||||
static void th_func(void *arg)
|
||||
{
|
||||
unsigned int duty = 0;
|
||||
pwm_open(&pwm_ch4);
|
||||
open(&pwm_4);
|
||||
while(1) {
|
||||
while(duty < 100) {
|
||||
ioctl(&pwm_4, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
||||
pwm_set_duty_cycle(&pwm_ch4, duty);
|
||||
sleep_ms(10);
|
||||
duty++;
|
||||
}
|
||||
while(duty > 0) {
|
||||
pwm_set_duty_cycle(&pwm_ch4, duty);
|
||||
ioctl(&pwm_4, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
||||
sleep_ms(10);
|
||||
duty--;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user