From da9c41d89f3bc5cca57243573d9170bce3394616 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 24 May 2019 21:24:51 +0200 Subject: [PATCH] [CC1011] Added missing packetMode method --- src/modules/CC1101.cpp | 28 +++++++++++++++------------- src/modules/CC1101.h | 33 +++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/modules/CC1101.cpp b/src/modules/CC1101.cpp index cd9808f7..3e87c7c0 100644 --- a/src/modules/CC1101.cpp +++ b/src/modules/CC1101.cpp @@ -158,6 +158,13 @@ int16_t CC1101::receiveDirect() { return(ERR_NONE); } +int16_t CC1101::packetMode() { + int16_t state = SPIsetRegValue(CC1101_REG_PKTCTRL1, CC1101_CRC_AUTOFLUSH_OFF | CC1101_APPEND_STATUS_ON | CC1101_ADR_CHK_NONE, 3, 0); + state |= SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_WHITE_DATA_OFF | CC1101_PKT_FORMAT_NORMAL, 6, 4); + state |= SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_CRC_ON | CC1101_LENGTH_CONFIG_VARIABLE, 2, 0); + return(state); +} + void CC1101::setGdo0Action(void (*func)(void), uint8_t dir) { attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, dir); } @@ -359,13 +366,6 @@ int16_t CC1101::setFrequencyDeviation(float freqDev) { return(state); } -int16_t CC1101::setSyncWord(uint8_t syncH, uint8_t syncL) { - // set sync word - int16_t state = SPIsetRegValue(CC1101_REG_SYNC1, syncH); - state |= SPIsetRegValue(CC1101_REG_SYNC0, syncL); - return(state); -} - int16_t CC1101::setOutputPower(int8_t power) { // round to the known frequency settings uint8_t f; @@ -427,6 +427,13 @@ int16_t CC1101::setOutputPower(int8_t power) { return(SPIsetRegValue(CC1101_REG_PATABLE, powerRaw)); } +int16_t CC1101::setSyncWord(uint8_t syncH, uint8_t syncL) { + // set sync word + int16_t state = SPIsetRegValue(CC1101_REG_SYNC1, syncH); + state |= SPIsetRegValue(CC1101_REG_SYNC0, syncL); + return(state); +} + int16_t CC1101::setNodeAddress(uint8_t nodeAddr, uint8_t numBroadcastAddrs) { if(!(numBroadcastAddrs > 0) && (numBroadcastAddrs <= 2)) { return(ERR_INVALID_NUM_BROAD_ADDRS); @@ -475,12 +482,7 @@ int16_t CC1101::config() { } // set packet mode - state = SPIsetRegValue(CC1101_REG_PKTCTRL1, CC1101_CRC_AUTOFLUSH_OFF | CC1101_APPEND_STATUS_ON | CC1101_ADR_CHK_NONE, 3, 0); - state |= SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_WHITE_DATA_OFF | CC1101_PKT_FORMAT_NORMAL, 6, 4); - state |= SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_CRC_ON | CC1101_LENGTH_CONFIG_VARIABLE, 2, 0); - if(state != ERR_NONE) { - return(state); - } + state = packetMode(); return(state); } diff --git a/src/modules/CC1101.h b/src/modules/CC1101.h index c1d991d7..f512fdf8 100644 --- a/src/modules/CC1101.h +++ b/src/modules/CC1101.h @@ -497,7 +497,7 @@ /*! \class CC1101 - \brief Control class for CC1101 module. + \brief Control class for %CC1101 module. */ class CC1101: public PhysicalLayer { public: @@ -525,9 +525,9 @@ class CC1101: public PhysicalLayer { \param rxBw Receiver bandwidth in kHz. Defaults to 325.0 kHz. - \param freqDev Frequency deviation from carrier frequency in kHz Defaults to 48 kHz. + \param freqDev Frequency deviation from carrier frequency in kHz Defaults to 48.0 kHz. - \param power Output power in dBm. Defaults to 0dBm. + \param power Output power in dBm. Defaults to 0 dBm. \returns \ref status_codes */ @@ -567,7 +567,7 @@ class CC1101: public PhysicalLayer { int16_t standby(); /*! - \brief Start direct mode transmission. + \brief Starts direct mode transmission. \param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY. @@ -576,12 +576,17 @@ class CC1101: public PhysicalLayer { int16_t transmitDirect(uint32_t frf = 0); /*! - \brief Start direct mode reception. + \brief Starts direct mode reception. \returns \ref status_codes */ int16_t receiveDirect(); + /*! + \brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions. + */ + int16_t packetMode(); + // interrupt methods /*! @@ -672,6 +677,15 @@ class CC1101: public PhysicalLayer { */ int16_t setFrequencyDeviation(float freqDev); + /*! + \brief Sets output power. Allowed values are -30, -20, -15, -10, 0, 5, 7 or 10 dBm. + + \param power Output power to be set in dBm. + + \returns \ref status_codes + */ + int16_t setOutputPower(int8_t power); + /*! \brief Sets 16-bit sync word as a two byte value. @@ -683,15 +697,6 @@ class CC1101: public PhysicalLayer { */ int16_t setSyncWord(uint8_t syncH, uint8_t syncL); - /*! - \brief Sets output power. Allowed values are -30, -20, -15, -10, 0, 5, 7 or 10 dBm. - - \param power Output power to be set in dBm. - - \returns \ref status_codes - */ - int16_t setOutputPower(int8_t power); - /*! \brief Sets node and broadcast addresses. Calling this method will also enable address filtering.