31 #include "pios_config.h"
33 #if defined(PIOS_INCLUDE_VIDEO)
40 #define VSYNC_REDRAW_CNT 2
42 #ifndef PIOS_VIDEO_HSYNC_OFFSET
43 #define PIOS_VIDEO_HSYNC_OFFSET 0
50 .graphics_bottom = 239,
55 .graphics_bottom = 265,
60 .graphics_column_start = 103,
61 .graphics_line_start = 19,
62 .dma_buffer_length = 45,
69 .graphics_column_start = 149,
70 .graphics_line_start = 28,
71 .dma_buffer_length = 46,
86 #define buffer0_level (buffers.buffer0_level)
87 #define buffer0_mask (buffers.buffer0_mask)
88 #define buffer1_level (buffers.buffer1_level)
89 #define buffer1_mask (buffers.buffer1_mask)
94 uint8_t *disp_buffer_level;
95 uint8_t *disp_buffer_mask;
97 volatile int16_t active_line = 10000;
103 static int8_t x_offset = 0;
104 static int8_t x_offset_new = 0;
105 static int8_t y_offset = 0;
106 static uint16_t arr_value;
108 static uint16_t num_video_lines = 0;
110 static const struct pios_video_type_cfg *pios_video_type_cfg_act = &pios_video_type_cfg_pal;
113 static void swap_buffers();
114 static void prepare_line(int16_t line);
115 static void vid_disable_spis();
122 static uint16_t Vsync_update = 0;
131 num_video_lines = active_line +
136 static uint8_t mode_hysteresis = 0;
146 if ((video_system_act != video_system_tmp) && (mode_hysteresis++ > 10)) {
147 video_system_act = video_system_tmp;
149 pios_video_type_boundary_act = &pios_video_type_boundary_ntsc;
150 pios_video_type_cfg_act = &pios_video_type_cfg_ntsc;
152 pios_video_type_boundary_act = &pios_video_type_boundary_pal;
153 pios_video_type_cfg_act = &pios_video_type_cfg_pal;
165 }
else if (video_system_act == video_system_tmp) {
169 if (x_offset != x_offset_new)
171 x_offset = x_offset_new;
179 if (++Vsync_update >= VSYNC_REDRAW_CNT) {
189 #ifdef PIOS_INCLUDE_WS2811
190 #ifdef SYSTEMMOD_RGBLED_VIDEO_HACK
199 void PIOS_Line_ISR(
void);
205 void PIOS_Line_ISR(
void)
220 if (active_line > 10000) {
225 if (active_line == 0) {
238 void PIOS_VIDEO_DMA_Handler(
void);
242 static
void vid_disable_spis()
245 dev_cfg->
mask.
regs->CR1 &= (uint16_t)~SPI_CR1_SPE;
246 dev_cfg->
level.
regs->CR1 &= (uint16_t)~SPI_CR1_SPE;
257 void PIOS_VIDEO_DMA_Handler(
void)
260 if ((dev_cfg->
mask_dma->LISR & DMA_FLAG_TCIF3) && (dev_cfg->
level_dma->HISR & DMA_FLAG_TCIF4)) {
262 dev_cfg->
mask_dma->LIFCR |= DMA_FLAG_TCIF3;
263 dev_cfg->
level_dma->HIFCR |= DMA_FLAG_TCIF4;
265 dev_cfg->
mask.dma.tx.channel->CR &= ~(uint32_t)DMA_SxCR_EN;
266 dev_cfg->
level.dma.tx.channel->CR &= ~(uint32_t)DMA_SxCR_EN;
269 while ((dev_cfg->
level.
regs->SR & SPI_I2S_FLAG_TXE) == 0);
270 while (dev_cfg->
level.
regs->SR & SPI_I2S_FLAG_BSY);
275 while ((dev_cfg->
mask.
regs->SR & SPI_I2S_FLAG_TXE) == 0);
276 while (dev_cfg->
mask.
regs->SR & SPI_I2S_FLAG_BSY);
278 dev_cfg->
mask.
regs->CR1 |= SPI_CR1_SSI;
282 int16_t line = active_line;
303 static inline void prepare_line(int16_t line)
317 dev_cfg->
mask.dma.tx.channel->M0AR = (uint32_t)&disp_buffer_mask[buf_offset];
318 dev_cfg->
level.dma.tx.channel->M0AR = (uint32_t)&disp_buffer_level[buf_offset];
324 dev_cfg->
mask.
regs->CR1 |= SPI_CR1_SPE;
328 dev_cfg->
mask.dma.tx.channel->CR |= (uint32_t)DMA_SxCR_EN;
329 dev_cfg->
level.dma.tx.channel->CR |= (uint32_t)DMA_SxCR_EN;
334 dev_cfg->
mask.
regs->CR1 &= (uint16_t) ~ SPI_CR1_SSI;
335 dev_cfg->
level.
regs->CR1 &= (uint16_t) ~ SPI_CR1_SSI;
344 static void swap_buffers()
360 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
392 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
393 TIM_TimeBaseStructure.TIM_Period = pios_video_type_cfg_act->
dc * (pios_video_type_cfg_act->
graphics_column_start + x_offset) / 2;
394 TIM_TimeBaseStructure.TIM_Prescaler = 0;
395 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
396 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
403 #ifdef PIOS_VIDEO_HSYNC_FALLING_EDGE
408 tmpccer &= (uint16_t)~(TIM_CCER_CC1NP);
409 tmpccer |= (uint16_t)(TIM_CCER_CC1P);
411 tmpccer &= (uint16_t)~(TIM_CCER_CC2NP);
412 tmpccer |= (uint16_t)(TIM_CCER_CC2P);
419 #ifdef PIOS_VIDEO_INPUT_FILTER
423 tmpccmr1 &= ((uint16_t)~TIM_CCMR1_IC1F);
434 tmpccmr1 &= ((uint16_t)~TIM_CCMR1_IC2F);
479 NVIC_InitTypeDef NVIC_InitStructure;
482 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
487 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
488 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
489 NVIC_Init(&NVIC_InitStructure);
496 DMA_Init(cfg->
mask.dma.tx.channel, (DMA_InitTypeDef *)&(cfg->
mask.dma.tx.
init));
497 DMA_Init(cfg->
level.dma.tx.channel, (DMA_InitTypeDef *)&(cfg->
level.dma.tx.
init));
500 DMA_ITConfig(cfg->
level.dma.tx.channel, DMA_IT_TC, ENABLE);
501 DMA_ITConfig(cfg->
mask.dma.tx.channel, DMA_IT_TC, ENABLE);
506 disp_buffer_level = buffer1_level;
507 disp_buffer_mask = buffer1_mask;
514 NVIC_Init((NVIC_InitTypeDef*)&cfg->
level.dma.irq.
init);
515 NVIC_Init((NVIC_InitTypeDef*)&cfg->
mask.dma.irq.
init);
518 SPI_I2S_DMACmd(cfg->
mask.
regs, SPI_I2S_DMAReq_Tx, ENABLE);
519 SPI_I2S_DMACmd(cfg->
level.
regs, SPI_I2S_DMAReq_Tx, ENABLE);
534 return num_video_lines;
542 return video_system_act;
560 if (x_offset_in > 50)
562 if (x_offset_in < -50)
573 if (y_offset_in > 20)
575 if (y_offset_in < -20)
577 y_offset = y_offset_in;
const struct pios_video_type_boundary * pios_video_type_boundary_act
#define PIOS_VIDEO_HSYNC_OFFSET
const struct pios_exti_cfg * vsync
void PIOS_Video_SetXScale(uint8_t x_scale)
Main PiOS header to include all the compiled in PiOS options.
uint8_t graphics_line_start
OSD gen module, handles OSD draw. Parts from CL-OSD and SUPEROSD projects.
int32_t PIOS_EXTI_Init(const struct pios_exti_cfg *cfg)
uint16_t graphics_height_real
enum pios_video_system PIOS_Video_GetSystem(void)
void(* set_bw_levels)(uint8_t, uint8_t)
#define DMA2_Stream3_IRQHandler
bool PIOS_Semaphore_Give_FromISR(struct pios_semaphore *sema, bool *woken)
#define PIOS_IRQ_PRIO_HIGHEST
struct pios_tim_channel pixel_timer
const struct pios_spi_cfg level
void PIOS_Video_SetYOffset(int8_t)
static struct flyingpicmd_cfg_fa cfg
void PIOS_Video_Set3DConfig(enum pios_video_3d_mode mode, uint8_t right_eye_x_shift)
TIM_OCInitTypeDef tim_oc_init
#define VIDEO_TYPE_PAL_ROWS
uint8_t * draw_buffer_level
struct pios_semaphore * onScreenDisplaySemaphore
const struct pios_spi_cfg mask
void PIOS_Video_SetXOffset(int8_t)
void PIOS_Video_Init(const struct pios_video_cfg *cfg)
struct pios_tim_channel hsync_capture
uint8_t * draw_buffer_mask
uint16_t PIOS_Video_GetLines(void)
void PIOS_Video_SetLevels(uint8_t, uint8_t)
#define DMA1_Stream4_IRQHandler
#define SWAP_BUFFS(tmp, a, b)
void PIOS_WS2811_trigger_update(ws2811_dev_t dev)
Trigger an update of the LED strand.
uint16_t graphics_column_start
#define PIOS_Assert(test)
uint8_t dma_buffer_length