avr/rfm69hcw/rfm.h

92 lines
2.2 KiB
C
Raw Normal View History

2022-06-28 00:05:01 +00:00
/*
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Savanni's AVR library.
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __RFM_H__
#define __RFM_H__
#include <base.h>
#include <spi.h>
#include <stdbool.h>
typedef enum RFM_ERROR_TYPES {
Ok,
radio_not_found,
} rfm_error_e;
2022-06-28 00:05:01 +00:00
typedef struct RFM {
spi_t spi;
gpio_t irq;
gpio_t reset;
} rfm_t;
typedef enum packet_format {
unlimited,
fixed,
variable,
} packet_format_e;
typedef enum MODE {
sleep,
standby,
fs,
tx,
rx,
listen
2022-06-28 00:05:01 +00:00
} mode_e;
/* make mode more of a state machine. define the transitions between those machines. */
typedef struct MODE_FLAGS {
bool listen_on;
mode_e mode;
} op_mode_t;
typedef struct INTERRUPT_FLAGS {
bool mode_ready;
bool rx_ready;
bool tx_ready;
bool timeout;
bool auto_mode;
bool sync_addr_match;
bool fifo_full;
bool fifo_not_empty;
bool fifo_level;
bool fifo_overrun;
bool packet_sent;
bool payload_ready;
bool crc_ok;
} interrupt_flags_t;
void rfm_init(rfm_t *, uint8_t *, size_t, rfm_error_e *);
void rfm_reset(rfm_t *);
2022-06-28 00:05:01 +00:00
void rfm_packet_format(rfm_t *rfm, packet_format_e format, size_t length);
void rfm_sleep(rfm_t *);
void rfm_standby(rfm_t *);
void rfm_receive_mode(rfm_t *);
void rfm_transmit(rfm_t *rfm, uint8_t *data, size_t length);
void rfm_receive(rfm_t *rfm, uint8_t *data, size_t length);
op_mode_t rfm_mode(rfm_t *rfm);
void rfm_set_mode(rfm_t *rfm, op_mode_t mode);
2022-06-28 00:05:01 +00:00
uint8_t rfm_status(rfm_t *rfm);
uint8_t rfm_temperature(rfm_t *rfm);
uint32_t rfm_frequency(rfm_t *rfm);
void rfm_listen(rfm_t *rfm);
interrupt_flags_t rfm_interrupts(rfm_t *rfm);
2022-06-28 00:05:01 +00:00
#endif