34#include "pprzlink/messages.h"
53 cyrf->has_irq =
false;
62 cyrf->spi_t.input_length = 0;
63 cyrf->spi_t.output_length = 0;
64 cyrf->spi_t.input_buf =
cyrf->input_buf;
65 cyrf->spi_t.output_buf =
cyrf->output_buf;
66 cyrf->spi_t.slave_idx = slave_idx;
100 switch (
cyrf->status) {
112 switch (
cyrf->buffer_idx) {
121 for (i = 0; i < 6; i++) {
122 cyrf->mfg_id[i] =
cyrf->input_buf[i + 1];
143 if (
cyrf->buffer_idx ==
cyrf->buffer_length) {
168 switch (
cyrf->buffer_idx) {
200 switch (
cyrf->buffer_idx) {
205 cyrf->rx_irq_status =
cyrf->input_buf[1];
209 cyrf->tx_irq_status =
cyrf->input_buf[1];
213 cyrf->rx_status =
cyrf->input_buf[1];
217 cyrf->rx_count =
cyrf->input_buf[1];
222 for (i = 0; i < 16; i++) {
223 cyrf->rx_packet[i] =
cyrf->input_buf[i + 1];
226 cyrf->has_irq =
true;
242 switch (
cyrf->buffer_idx) {
288 cyrf->spi_t.output_length = length + 1;
289 cyrf->spi_t.input_length = 0;
293 for (i = 0; i < length; i++) {
294 cyrf->output_buf[i + 1] = data[i];
319 cyrf->spi_t.output_length = 1;
320 cyrf->spi_t.input_length = length + 1;
321 cyrf->output_buf[0] = addr;
353 cyrf->buffer_length = length;
354 cyrf->buffer_idx = 0;
357 for (i = 0; i < length; i++) {
358 cyrf->buffer[i * 2] = data[i][0];
359 cyrf->buffer[i * 2 + 1] = data[i][1];
386 cyrf->buffer[0] = crc_seed & 0xFF;
387 cyrf->buffer[1] = (crc_seed >> 8) & 0xFF;
390 for (i = 0; i < 8; i++) {
395 for (i = 0; i < 16; i++) {
403 cyrf->buffer_idx = 0;
423 cyrf->buffer_idx = 0;
445 cyrf->buffer[0] = length;
446 for (i = 0; i < length; i++) {
447 cyrf->buffer[i + 1] = data[i];
451 cyrf->buffer_idx = 0;
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
void cyrf6936_event(struct Cyrf6936 *cyrf)
The on event call for the CYRF6936 chip.
void cyrf6936_init(struct Cyrf6936 *cyrf, struct spi_periph *spi_p, const uint8_t slave_idx, const uint32_t rst_port, const uint16_t rst_pin)
Initializing the cyrf chip.
bool cyrf6936_multi_write(struct Cyrf6936 *cyrf, const uint8_t data[][2], const uint8_t length)
Write to multiple registers one byte.
bool cyrf6936_write_chan_sop_data_crc(struct Cyrf6936 *cyrf, const uint8_t chan, const uint8_t sop_code[], const uint8_t data_code[], const uint16_t crc_seed)
Set the channel, SOP code, DATA code and the CRC seed.
bool cyrf6936_write(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data)
Write to one register.
static bool cyrf6936_write_register(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data)
Write a byte to a register.
bool cyrf6936_read_rx_irq_status_packet(struct Cyrf6936 *cyrf)
Read the RX IRQ status register, the rx status register and the rx packet.
bool cyrf6936_send(struct Cyrf6936 *cyrf, const uint8_t data[], const uint8_t length)
Send a packet with a certain length.
static bool cyrf6936_read_register(struct Cyrf6936 *cyrf, const uint8_t addr)
Read a byte from a register.
static bool cyrf6936_write_block(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data[], const uint8_t length)
Write multiple bytes to a register.
static bool cyrf6936_read_block(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t length)
Read multiple bytes from a register.
Driver for the cyrf6936 2.4GHz radio chip.
@ CYRF6936_DATA_CODE
The chip is writing a data code.
@ CYRF6936_IDLE
The chip is idle and can be used.
@ CYRF6936_GET_MFG_ID
The chip is busy with getting the manufacturer ID.
@ CYRF6936_MULTIWRITE
The chip is writing multiple registers.
@ CYRF6936_RX_IRQ_STATUS_PACKET
The chip is getting the receive irq status, receive status and the receive packet.
@ CYRF6936_UNINIT
The chip isn't initialized.
@ CYRF6936_SEND
The chip is busy sending a packet.
@ CYRF6936_CHAN_SOP_DATA_CRC
The chip is setting the channel, SOP code, DATA code and the CRC seed.
#define CYRF_DIR
Bit for enabling writing.
Common code for AP and FBW telemetry.
Some architecture independent helper functions for GPIOs.
enum SPIStatus status
internal state of the peripheral
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
@ SPICpolIdleLow
CPOL = 0.
@ SPISelectUnselect
slave is selected before transaction and unselected after
SPI peripheral structure.
Generic interface for radio control modules.
Architecture independent SPI (Serial Peripheral Interface) API.
Architecture independent timing functions.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.