You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.5 KiB
91 lines
2.5 KiB
#include "rx5808.h"
|
|
#include <SPI.h>
|
|
#include "SoftSPI.h"
|
|
#include "channels.h"
|
|
|
|
#define SPI_ADDRESS_SYNTH_B 0x01
|
|
#define SPI_ADDRESS_POWER 0x0A
|
|
#define SPI_ADDRESS_STATE 0x0F
|
|
#define PIN_SPI_RX_A 18
|
|
#define PIN_SPI_RX_B 16
|
|
|
|
static inline void sendRegister(uint8_t address, uint32_t data);
|
|
|
|
// Create new SPI port for RX5808_SPI1
|
|
// D5: (CH1) MOSI
|
|
// D12: MISO (using an unused pin)
|
|
// D18: (CH2) CS
|
|
// D19: (CH3) SCK
|
|
SoftSPI RX5808_SPI1(5, 34, 19);
|
|
|
|
// D4: (CH1) MOSI
|
|
// D13: MISO (using an unused pin)
|
|
// D16: (CH2) CS
|
|
// D17: (CH3) SCK
|
|
SoftSPI RX5808_SPI2(4, 35, 17);
|
|
|
|
// TODO: COntinue to set address to power down the SPI
|
|
namespace RX5808 {
|
|
|
|
void begin() {
|
|
RX5808_SPI1.begin();
|
|
RX5808_SPI2.begin();
|
|
}
|
|
|
|
void setSynthRegisterB(uint16_t value) {
|
|
sendRegister(SPI_ADDRESS_SYNTH_B, value);
|
|
}
|
|
|
|
void setPowerDownRegister(uint32_t value) {
|
|
sendRegister(SPI_ADDRESS_POWER, value);
|
|
}
|
|
|
|
void setStateRegister(uint32_t value) {
|
|
sendRegister(SPI_ADDRESS_STATE, value);
|
|
}
|
|
|
|
void rxStandby(uint8_t receiver_id) {
|
|
sendRegister(SPI_ADDRESS_STATE, 0b00000000000000000010);
|
|
// sendCommand(0b00000000000000000010);
|
|
}
|
|
|
|
void rxPowerOn(uint8_t receiver_id) {
|
|
sendRegister(SPI_ADDRESS_STATE, 0b00000000000000000001);
|
|
// sendCommand(0b00000000000000000001);
|
|
}
|
|
|
|
void rxReset(uint8_t receiver_id) {
|
|
sendRegister(SPI_ADDRESS_STATE, 0b00000000000000000000);
|
|
// sendCommand(0b00000000000000000000);
|
|
}
|
|
|
|
void setChannel(uint8_t channel) {
|
|
setSynthRegisterB(Channels::getSynthRegisterB(channel));
|
|
}
|
|
|
|
void setChannelByFreq(uint16_t freq) {
|
|
setSynthRegisterB(Channels::getSynthRegisterBFreq(freq));
|
|
}
|
|
}
|
|
|
|
|
|
static inline void sendRegister(uint8_t addressBits, uint32_t dataBits) {
|
|
uint32_t data = addressBits | (1 << 4) | (dataBits << 5);
|
|
|
|
RX5808_SPI1.setDataMode(SPI_MODE0);
|
|
RX5808_SPI1.setBitOrder(LSBFIRST);
|
|
RX5808_SPI1.setClockDivider(SPI_CLOCK_DIV8);
|
|
digitalWrite(PIN_SPI_RX_A, LOW);
|
|
RX5808_SPI1.transfer32(data, 25);
|
|
digitalWrite(PIN_SPI_RX_A, HIGH);
|
|
|
|
RX5808_SPI2.setDataMode(SPI_MODE0);
|
|
RX5808_SPI2.setBitOrder(LSBFIRST);
|
|
RX5808_SPI2.setClockDivider(SPI_CLOCK_DIV8);
|
|
digitalWrite(PIN_SPI_RX_B, LOW);
|
|
RX5808_SPI2.transfer32(data, 25);
|
|
digitalWrite(PIN_SPI_RX_B, HIGH);
|
|
|
|
// RX5808_SPI1.endTransaction();
|
|
// RX5808_SPI2.endTransaction();
|
|
}
|