From 777a56d1319a901cd0c6e529e110fe6de21f6908 Mon Sep 17 00:00:00 2001 From: Morgan Redfield Date: Tue, 20 Aug 2019 14:34:20 -0700 Subject: [PATCH] fix I2C comments --- examples/CTCSS/CTCSS.ino | 4 +- examples/HandyTalkie/HandyTalkie.ino | 4 +- .../HandyTalkie_nRF52840.ino | 2 +- src/HamShield.cpp | 214 +++++++++--------- src/HamShield.h | 2 +- src/HamShield_comms.cpp | 6 + 6 files changed, 119 insertions(+), 113 deletions(-) diff --git a/examples/CTCSS/CTCSS.ino b/examples/CTCSS/CTCSS.ino index 859a1d1..efbe162 100644 --- a/examples/CTCSS/CTCSS.ino +++ b/examples/CTCSS/CTCSS.ino @@ -68,10 +68,10 @@ void setup() { // verify connection Serial.println("Testing device connections..."); - Serial.println(radio.testConnection() ? "RDA radio connection successful" : "RDA radio connection failed"); + Serial.println(radio.testConnection() ? "radio connection successful" : "radio connection failed"); // initialize device - Serial.println("Initializing I2C devices..."); + Serial.println("Initializing radio device..."); radio.initialize(); // initializes automatically for UHF 12.5kHz channel Serial.println("setting default Radio configuration"); diff --git a/examples/HandyTalkie/HandyTalkie.ino b/examples/HandyTalkie/HandyTalkie.ino index 4a2aa62..96b53f6 100644 --- a/examples/HandyTalkie/HandyTalkie.ino +++ b/examples/HandyTalkie/HandyTalkie.ino @@ -65,10 +65,10 @@ void setup() { // verify connection Serial.println("Testing device connections..."); - Serial.println(radio.testConnection() ? "RDA radio connection successful" : "RDA radio connection failed"); + Serial.println(radio.testConnection() ? "radio connection successful" : "radio connection failed"); // initialize device - Serial.println("Initializing I2C devices..."); + Serial.println("Initializing radio device..."); radio.initialize(); // initializes automatically for UHF 12.5kHz channel Serial.println("setting default Radio configuration"); diff --git a/examples/HandyTalkie_nRF52840/HandyTalkie_nRF52840.ino b/examples/HandyTalkie_nRF52840/HandyTalkie_nRF52840.ino index da2d065..e87006e 100644 --- a/examples/HandyTalkie_nRF52840/HandyTalkie_nRF52840.ino +++ b/examples/HandyTalkie_nRF52840/HandyTalkie_nRF52840.ino @@ -117,7 +117,7 @@ void setup() { } // initialize device - Serial.println("Initializing I2C devices..."); + Serial.println("Initializing radio device..."); radio.initialize(); // initializes automatically for UHF 12.5kHz channel Serial.println("setting default Radio configuration"); diff --git a/src/HamShield.cpp b/src/HamShield.cpp index dabdb49..724fa8c 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -234,8 +234,8 @@ void HamShield::initialize(bool narrowBand) { setDTMFTxTime(60); setDTMFDetectTime(24); - HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf); - old_dtmf_reg = radio_i2c_buf[0]; + HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_dat_buf); + old_dtmf_reg = radio_dat_buf[0]; } @@ -388,13 +388,13 @@ void HamShield::setupWideBand() { // end AGC table } -/** Verify the I2C connection. +/** Verify the data connection. * Make sure the device is connected and responds as expected. * @return True if connection is valid, false otherwise */ bool HamShield::testConnection() { - HSreadWord(devAddr, 0x00, radio_i2c_buf); - return radio_i2c_buf[0] == 0x1846; + HSreadWord(devAddr, 0x00, radio_dat_buf); + return radio_dat_buf[0] == 0x1846; } @@ -414,8 +414,8 @@ bool HamShield::testConnection() { */ uint16_t HamShield::readCtlReg() { - HSreadWord(devAddr, A1846S_CTL_REG, radio_i2c_buf); - return radio_i2c_buf[0]; + HSreadWord(devAddr, A1846S_CTL_REG, radio_dat_buf); + return radio_dat_buf[0]; } void HamShield::softReset() { @@ -503,8 +503,8 @@ void HamShield::setClkMode(bool LFClk){ HSwriteWord(devAddr, A1846S_CLK_MODE_REG, tx_data); } bool HamShield::getClkMode(){ - HSreadBitW(devAddr, A1846S_CLK_MODE_REG, A1846S_CLK_MODE_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] != 0); + HSreadBitW(devAddr, A1846S_CLK_MODE_REG, A1846S_CLK_MODE_BIT, radio_dat_buf); + return (radio_dat_buf[0] != 0); } // TODO: create a 25kHz setup option as well as 12.5kHz (as is implemented now) @@ -517,8 +517,8 @@ void HamShield::setChanMode(uint16_t mode){ HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, mode); } uint16_t HamShield::getChanMode(){ - HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, radio_i2c_buf); - return radio_i2c_buf[0]; + HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, radio_dat_buf); + return radio_dat_buf[0]; } */ @@ -551,8 +551,8 @@ void HamShield::setTX(bool on_noff){ HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff); } bool HamShield::getTX(){ - HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] != 0); + HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_dat_buf); + return (radio_dat_buf[0] != 0); } void HamShield::setRX(bool on_noff){ @@ -573,8 +573,8 @@ void HamShield::setRX(bool on_noff){ HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff); } bool HamShield::getRX(){ - HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] != 0); + HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, radio_dat_buf); + return (radio_dat_buf[0] != 0); } void HamShield::setModeTransmit(){ @@ -634,8 +634,8 @@ void HamShield::setTxSourceNone(){ setTxSource(0); } uint16_t HamShield::getTxSource(){ - HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, radio_i2c_buf); - return radio_i2c_buf[0]; + HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, radio_dat_buf); + return radio_dat_buf[0]; } /* @@ -652,8 +652,8 @@ void HamShield::setPABiasVoltage(uint16_t voltage){ HSwriteBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, voltage); } uint16_t HamShield::getPABiasVoltage(){ - HSreadBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, radio_i2c_buf); - return radio_i2c_buf[0]; + HSreadBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, radio_dat_buf); + return radio_dat_buf[0]; } */ // Subaudio settings @@ -672,8 +672,8 @@ void HamShield::setCtcssCdcssMode(uint16_t mode){ HSwriteBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_LEN, mode); } uint16_t HamShield::getCtcssCdcssMode(){ - HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_BIT, radio_i2c_buf); - return radio_i2c_buf[0]; + HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_BIT, radio_dat_buf); + return radio_dat_buf[0]; } void HamShield::setDetPhaseShift() { @@ -711,16 +711,16 @@ void HamShield::setCdcssSel(bool long_nshort){ HSwriteBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, long_nshort); } bool HamShield::getCdcssSel(){ - HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] == 1); + HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, radio_dat_buf); + return (radio_dat_buf[0] == 1); } void HamShield::setCdcssInvert(bool invert) { HSwriteBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, invert); } bool HamShield::getCdcssInvert() { - HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] == 1); + HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, radio_dat_buf); + return (radio_dat_buf[0] == 1); } // Cdcss neg_det_en @@ -763,8 +763,8 @@ float HamShield::getCtcssFreqHz() { //y = mx + b float m = 1.678; float b = -3.3; - HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_i2c_buf); - float f = (float) radio_i2c_buf[0]; + HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_dat_buf); + float f = (float) radio_dat_buf[0]; return (f/m-b)/100; } @@ -810,8 +810,8 @@ void HamShield::setCtcssDetThreshIn(uint8_t thresh) { HSwriteBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, thresh); } uint8_t HamShield::getCtcssDetThreshIn() { - HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, radio_i2c_buf); - return (uint8_t) radio_i2c_buf[0]; + HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, radio_dat_buf); + return (uint8_t) radio_dat_buf[0]; } // unmatch threshold @@ -819,13 +819,13 @@ void HamShield::setCtcssDetThreshOut(uint8_t thresh) { HSwriteBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, thresh); } uint8_t HamShield::getCtcssDetThreshOut() { - HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, radio_i2c_buf); - return (uint8_t) radio_i2c_buf[0]; + HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, radio_dat_buf); + return (uint8_t) radio_dat_buf[0]; } bool HamShield::getCtcssToneDetected() { - HSreadBitW(devAddr, A1846S_FLAG_REG, A1846S_CTCSS1_FLAG_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] != 0); + HSreadBitW(devAddr, A1846S_FLAG_REG, A1846S_CTCSS1_FLAG_BIT, radio_dat_buf); + return (radio_dat_buf[0] != 0); } // cdcss codes @@ -856,10 +856,10 @@ void HamShield::setCdcssCode(uint16_t code) { } uint16_t HamShield::getCdcssCode() { uint32_t oct_code; - HSreadWord(devAddr, A1846S_CDCSS_CODE_HI_REG, radio_i2c_buf); - oct_code = ((uint32_t)radio_i2c_buf[0] << 16); - HSreadWord(devAddr, A1846S_CDCSS_CODE_LO_REG, radio_i2c_buf); - oct_code += radio_i2c_buf[0]; + HSreadWord(devAddr, A1846S_CDCSS_CODE_HI_REG, radio_dat_buf); + oct_code = ((uint32_t)radio_dat_buf[0] << 16); + HSreadWord(devAddr, A1846S_CDCSS_CODE_LO_REG, radio_dat_buf); + oct_code += radio_dat_buf[0]; oct_code = oct_code >> 12; uint16_t code = (oct_code & 0x3); @@ -879,8 +879,8 @@ void HamShield::setSQOff(){ HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 0); } bool HamShield::getSQState(){ - HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, radio_i2c_buf); - return (radio_i2c_buf[0] != 0); + HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, radio_dat_buf); + return (radio_dat_buf[0] != 0); } // SQ threshold @@ -890,9 +890,9 @@ void HamShield::setSQHiThresh(int16_t sq_hi_threshold){ HSwriteBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, sq); } int16_t HamShield::getSQHiThresh(){ - HSreadBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, radio_i2c_buf); + HSreadBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, radio_dat_buf); - return radio_i2c_buf[0] - 137; + return radio_dat_buf[0] - 137; } void HamShield::setSQLoThresh(int16_t sq_lo_threshold){ // Sq detect low th, rssi_cmp will be 0 when rssi