cube-kl/firmware/include/ov7670.h

83 lines
1.5 KiB
C

#ifndef __ov7670_H__
#define __ov7670_H__ __ov7670_H__
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
void ov7670_init(void);
static inline uint8_t ov7670_vsync(void) {
return (PINC & (1 << PC0)) != 0;
}
static inline void ov7670_wait_vsync(void) {
while(ov7670_vsync()); // Wait until low
while(!ov7670_vsync()); // Wait until high
}
static inline void ov7670_set_rst(void) {
PORTD |= (1 << PD3);
}
static inline void ov7670_unset_rst(void) {
PORTD &= ~(1 << PD3);
}
static inline void ov7670_set_wrst(void) {
PORTC |= (1 << PC3);
}
static inline void ov7670_unset_wrst(void) {
PORTC &= ~(1 << PC3);
}
static inline void ov7670_toggle_wrst(void) {
ov7670_set_wrst();
_delay_us(5);
ov7670_unset_wrst();
}
static inline void ov7670_set_rrst(void) {
PORTC |= (1 << PC2);
}
static inline void ov7670_unset_rrst(void) {
PORTC &= ~(1 << PC2);
}
static inline void ov7670_toggle_rrst(void) {
ov7670_set_rrst();
_delay_us(5);
ov7670_unset_rrst();
}
static inline void ov7670_set_we(void) {
PORTC |= (1 << PC1);
}
static inline void ov7670_unset_we(void) {
PORTC &= ~(1 << PC1);
}
static inline void ov7670_set_rck(void) {
PORTB |= (1 << PB5);
}
static inline void ov7670_unset_rck(void) {
PORTB &= ~(1 << PB5);
}
static inline void ov7670_toggle_rck(void) {
ov7670_set_rck();
_delay_us(5);
ov7670_unset_rck();
}
static inline uint8_t ov7670_read_bits(void) {
return (PINB & 0x0F) | (PIND & 0xF0);
}
#endif