#ifndef _MIRF_H_
#define _MIRF_H_

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>

#define CE  PB0
#define CSN PB2

#define PORT_SPI  PORTB
#define DDR_SPI   DDRB
#define SPI_MISO  PB4
#define SPI_MOSI  PB3
#define SPI_SCK   PB5
#define SPI_SS    PB2

#define mirf_CH				10 //transmission channel
#define mirf_PAYLOAD		0 //payload lenght
#define mirf_CONFIG			((1<<EN_CRC)|(0<<CRCO)) //default configuration


#define mirf_CSN_hi PORTB |=  (1<<CSN);
#define mirf_CSN_lo PORTB &= ~(1<<CSN);
#define mirf_CE_hi PORTB |=  (1<<CE);
#define mirf_CE_lo PORTB &= ~(1<<CE);

#define mirf_setTX mirf_write_register(CONFIG, mirf_CONFIG|((1<<PWR_UP)|(0<<PRIM_RX)))
#define mirf_setRX mirf_write_register(CONFIG, mirf_CONFIG|((1<<PWR_UP)|(1<<PRIM_RX)))

extern void spi_init();
extern uint8_t spi_writeread (uint8_t data);

extern void mirf_init();
extern uint8_t mirf_config();
extern uint8_t mirf_get_status();
extern void mirf_set_rxaddr(uint8_t channel, uint8_t *addr);
extern void mirf_set_txaddr(uint8_t *addr);
extern uint8_t mirf_read_ready();
extern void mirf_read(uint8_t *data);
extern void mirf_read_buf(uint8_t *data, uint8_t lenght);
extern uint8_t mirf_write(char *data, uint8_t data_lenght);

extern	uint8_t nrf24_retransmissionCount();

extern void mirf_write_register(uint8_t reg, uint8_t value);
extern void mirf_write_registers(uint8_t reg, uint8_t *value, uint8_t len);
extern uint8_t mirf_read_register(uint8_t reg);
extern void mirf_read_registers(uint8_t reg, uint8_t *value, uint8_t len);
extern uint8_t radio_read_rx_payload_width();
extern void mirf_power_up(void);
extern void mirf_power_down(void);
extern void nrf_print_status(void);
extern void nrf_print_config(void);
extern void nrf_print_setup(void);
extern void nrf_print_future(void);
extern void print_sprintf(const char* name,uint8_t reg);
extern void mirf_send_cmd(uint8_t reg);

extern void nrf_print_fifostatus(void);
extern void nrf_print_cd(void);
extern void nrf_print_chanel(void);
extern void nrf_print_payload(void);
extern void nrf_print_observe_tx(void);

extern void nrf_print_tx_addr(void);
extern void nrf_print_rx_addr_p0(void);
extern void nrf_print_rx_addr_p1(void);
extern void nrf_clear_tx_buffer(void);

#endif /* _MIRF_H_ */
