2022-07-02 21:54:19 +00:00
|
|
|
#include <avr/io.h>
|
2022-07-30 04:33:46 +00:00
|
|
|
#include <dio.h>
|
2022-07-02 21:54:19 +00:00
|
|
|
#include <display.h>
|
|
|
|
#include <rfm.h>
|
|
|
|
#include <spi.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
2022-07-02 23:36:27 +00:00
|
|
|
void status(display_t *display, rfm_t *radio, int clock) {
|
2022-07-02 21:54:19 +00:00
|
|
|
op_mode_t mode = rfm_mode(radio);
|
|
|
|
interrupt_flags_t flags = rfm_interrupts(radio);
|
|
|
|
|
|
|
|
display_clear(display);
|
|
|
|
|
2022-07-02 23:36:27 +00:00
|
|
|
char clock_str[16];
|
|
|
|
sprintf(clock_str, "%4d ", clock);
|
|
|
|
display_write_message(display, clock_str);
|
|
|
|
|
2022-07-02 21:54:19 +00:00
|
|
|
if (mode.listen_on) display_write_message(display, "Listen ");
|
|
|
|
if (mode.mode == sleep) display_write_message(display, "Sleep");
|
|
|
|
if (mode.mode == standby) display_write_message(display, "Standby");
|
|
|
|
if (mode.mode == fs) display_write_message(display, "FS");
|
|
|
|
if (mode.mode == tx) display_write_message(display, "TX");
|
|
|
|
if (mode.mode == rx) display_write_message(display, "RX");
|
|
|
|
|
|
|
|
display_set_location(display, 1, 0);
|
|
|
|
if (flags.mode_ready) display_write_message(display, "R ");
|
|
|
|
if (flags.rx_ready) display_write_message(display, "RX ");
|
|
|
|
if (flags.tx_ready) display_write_message(display, "TX ");
|
|
|
|
if (flags.timeout) display_write_message(display, "TO ");
|
|
|
|
if (flags.auto_mode) display_write_message(display, "AM ");
|
|
|
|
if (flags.sync_addr_match) display_write_message(display, "SM ");
|
|
|
|
if (flags.fifo_full) display_write_message(display, "F ");
|
|
|
|
if (flags.fifo_not_empty) display_write_message(display, "NE ");
|
|
|
|
if (flags.fifo_level) display_write_message(display, "LE ");
|
|
|
|
if (flags.fifo_overrun) display_write_message(display, "OR ");
|
|
|
|
if (flags.packet_sent) display_write_message(display, "PS ");
|
|
|
|
if (flags.payload_ready) display_write_message(display, "PR");
|
|
|
|
if (flags.crc_ok) display_write_message(display, "CRC");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2022-07-02 23:36:27 +00:00
|
|
|
int clock = 0;
|
2022-07-03 01:48:38 +00:00
|
|
|
uint8_t primes[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 0 };
|
2022-07-02 23:36:27 +00:00
|
|
|
|
2022-07-02 21:54:19 +00:00
|
|
|
display_t display = {
|
|
|
|
.reg = {
|
|
|
|
.output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
|
|
|
|
.shift_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 6 },
|
|
|
|
.latch_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
rfm_t radio = (rfm_t){
|
|
|
|
.spi = {
|
|
|
|
.clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 },
|
|
|
|
.data_out = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 },
|
|
|
|
.data_in = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 3 },
|
|
|
|
.chip_select = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 4 },
|
|
|
|
},
|
|
|
|
.irq = { .ddr = &DDRE, .port = &PORTE, .pin = &PINE, .addr = 6 },
|
|
|
|
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
|
|
|
|
};
|
|
|
|
|
2022-07-03 01:55:08 +00:00
|
|
|
_delay_ms(15);
|
|
|
|
display_init(&display);
|
2022-07-02 21:54:19 +00:00
|
|
|
|
|
|
|
rfm_error_e error;
|
|
|
|
|
|
|
|
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
|
|
|
|
|
2022-07-03 01:55:08 +00:00
|
|
|
status(&display, &radio, clock);
|
2022-07-02 21:54:19 +00:00
|
|
|
|
2022-07-03 01:48:38 +00:00
|
|
|
int prime = 0;
|
2022-07-02 21:54:19 +00:00
|
|
|
while (1) {
|
2022-07-07 17:16:36 +00:00
|
|
|
status(&display, &radio, clock);
|
|
|
|
|
|
|
|
op_mode_t mode = rfm_mode(&radio);
|
|
|
|
interrupt_flags_t flags = rfm_interrupts(&radio);
|
|
|
|
if (mode.mode == standby) {
|
2022-07-03 01:48:38 +00:00
|
|
|
rfm_transmit(&radio, &primes[prime], 1);
|
|
|
|
if (primes[prime] == 0) {
|
|
|
|
prime = 0;
|
|
|
|
} else {
|
|
|
|
prime++;
|
|
|
|
}
|
2022-07-07 17:16:36 +00:00
|
|
|
} else if (mode.mode == tx && flags.packet_sent) {
|
2022-07-02 21:54:19 +00:00
|
|
|
rfm_standby(&radio);
|
|
|
|
}
|
2022-07-07 17:16:36 +00:00
|
|
|
|
2022-07-02 23:36:27 +00:00
|
|
|
clock++;
|
|
|
|
_delay_ms(1000);
|
2022-07-02 21:54:19 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|