updating files for HS09

This commit is contained in:
morgan 2016-03-24 20:31:17 -07:00
parent 9111ba5301
commit 3a209d8db4
7 changed files with 370 additions and 1908 deletions

View File

@ -150,129 +150,130 @@ void HamShield::initialize() {
// set up GPIO voltage (want 3.3V) // set up GPIO voltage (want 3.3V)
tx_data = 0x03AC; // default is 0x32C tx_data = 0x03AC; // default is 0x32C
I2Cdev::writeWord(devAddr, 0x09, tx_data); HSwriteWord(devAddr, 0x09, tx_data);
tx_data = 0x47E0; //0x43A0; // 0x7C20; // tx_data = 0x47E0; //0x43A0; // 0x7C20; //
I2Cdev::writeWord(devAddr, 0x0A, tx_data); // pga gain [10:6] HSwriteWord(devAddr, 0x0A, tx_data); // pga gain [10:6]
tx_data = 0xA100; tx_data = 0xA100;
I2Cdev::writeWord(devAddr, 0x13, tx_data); HSwriteWord(devAddr, 0x13, tx_data);
tx_data = 0x5001; tx_data = 0x5001;
I2Cdev::writeWord(devAddr, 0x1F, tx_data); // GPIO7->VOX, GPIO0->CTC/DCS HSwriteWord(devAddr, 0x1F, tx_data); // GPIO7->VOX, GPIO0->CTC/DCS
tx_data = 0x0031; tx_data = 0x0031;
I2Cdev::writeWord(devAddr, 0x31, tx_data); HSwriteWord(devAddr, 0x31, tx_data);
tx_data = 0x0AF2; // tx_data = 0x0AF2; //
I2Cdev::writeWord(devAddr, 0x33, tx_data); // agc number HSwriteWord(devAddr, 0x33, tx_data); // agc number
// AGC table // AGC table
tx_data = 0x0001; tx_data = 0x0001;
I2Cdev::writeWord(devAddr, 0x7F, tx_data); HSwriteWord(devAddr, 0x7F, tx_data);
tx_data = 0x000C; tx_data = 0x000C;
I2Cdev::writeWord(devAddr, 0x05, tx_data); HSwriteWord(devAddr, 0x05, tx_data);
tx_data = 0x020C; tx_data = 0x020C;
I2Cdev::writeWord(devAddr, 0x06, tx_data); HSwriteWord(devAddr, 0x06, tx_data);
tx_data = 0x030C; tx_data = 0x030C;
I2Cdev::writeWord(devAddr, 0x07, tx_data); HSwriteWord(devAddr, 0x07, tx_data);
tx_data = 0x0324; tx_data = 0x0324;
I2Cdev::writeWord(devAddr, 0x08, tx_data); HSwriteWord(devAddr, 0x08, tx_data);
tx_data = 0x1344; tx_data = 0x1344;
I2Cdev::writeWord(devAddr, 0x09, tx_data); HSwriteWord(devAddr, 0x09, tx_data);
tx_data = 0x3F44; tx_data = 0x3F44;
I2Cdev::writeWord(devAddr, 0x0A, tx_data); HSwriteWord(devAddr, 0x0A, tx_data);
tx_data = 0x3F44; tx_data = 0x3F44;
I2Cdev::writeWord(devAddr, 0x0B, tx_data); HSwriteWord(devAddr, 0x0B, tx_data);
tx_data = 0x3F44; tx_data = 0x3F44;
I2Cdev::writeWord(devAddr, 0x0C, tx_data); HSwriteWord(devAddr, 0x0C, tx_data);
tx_data = 0x3F44; tx_data = 0x3F44;
I2Cdev::writeWord(devAddr, 0x0D, tx_data); HSwriteWord(devAddr, 0x0D, tx_data);
tx_data = 0x3F44; tx_data = 0x3F44;
I2Cdev::writeWord(devAddr, 0x0E, tx_data); HSwriteWord(devAddr, 0x0E, tx_data);
tx_data = 0x3F44; tx_data = 0x3F44;
I2Cdev::writeWord(devAddr, 0x0F, tx_data); HSwriteWord(devAddr, 0x0F, tx_data);
tx_data = 0xE0ED; tx_data = 0xE0ED;
I2Cdev::writeWord(devAddr, 0x12, tx_data); HSwriteWord(devAddr, 0x12, tx_data);
tx_data = 0xF2FE; tx_data = 0xF2FE;
I2Cdev::writeWord(devAddr, 0x13, tx_data); HSwriteWord(devAddr, 0x13, tx_data);
tx_data = 0x0A16; tx_data = 0x0A16;
I2Cdev::writeWord(devAddr, 0x14, tx_data); HSwriteWord(devAddr, 0x14, tx_data);
tx_data = 0x2424; tx_data = 0x2424;
I2Cdev::writeWord(devAddr, 0x15, tx_data); HSwriteWord(devAddr, 0x15, tx_data);
tx_data = 0x2424; tx_data = 0x2424;
I2Cdev::writeWord(devAddr, 0x16, tx_data); HSwriteWord(devAddr, 0x16, tx_data);
tx_data = 0x2424; tx_data = 0x2424;
I2Cdev::writeWord(devAddr, 0x17, tx_data); HSwriteWord(devAddr, 0x17, tx_data);
tx_data = 0x0000; tx_data = 0x0000;
I2Cdev::writeWord(devAddr, 0x7F, tx_data); HSwriteWord(devAddr, 0x7F, tx_data);
// end AGC table // end AGC table
tx_data = 0x067F; //0x0601; //0x470F; tx_data = 0x067F; //0x0601; //0x470F;
I2Cdev::writeWord(devAddr, 0x41, tx_data); // voice gain tx [6:0] HSwriteWord(devAddr, 0x41, tx_data); // voice gain tx [6:0]
tx_data = 0x02FF; // using 0x04FF to avoid tx voice delay tx_data = 0x02FF; // using 0x04FF to avoid tx voice delay
I2Cdev::writeWord(devAddr, 0x44, tx_data); // tx gain [11:8] HSwriteWord(devAddr, 0x44, tx_data); // tx gain [11:8]
tx_data = 0x7F2F; tx_data = 0x7F2F;
I2Cdev::writeWord(devAddr, 0x47, tx_data); HSwriteWord(devAddr, 0x47, tx_data);
tx_data = 0x2C62; tx_data = 0x2C62;
I2Cdev::writeWord(devAddr, 0x4F, tx_data); HSwriteWord(devAddr, 0x4F, tx_data);
tx_data = 0x0094; tx_data = 0x0094;
I2Cdev::writeWord(devAddr, 0x53, tx_data); // compressor update time (bits 6:0, 5.12ms per unit) HSwriteWord(devAddr, 0x53, tx_data); // compressor update time (bits 6:0, 5.12ms per unit)
tx_data = 0x2A18; tx_data = 0x2A18;
I2Cdev::writeWord(devAddr, 0x54, tx_data); HSwriteWord(devAddr, 0x54, tx_data);
tx_data = 0x0081; tx_data = 0x0081;
I2Cdev::writeWord(devAddr, 0x55, tx_data); HSwriteWord(devAddr, 0x55, tx_data);
tx_data = 0x0B22; tx_data = 0x0B22;
I2Cdev::writeWord(devAddr, 0x56, tx_data); // sq detect time HSwriteWord(devAddr, 0x56, tx_data); // sq detect time
tx_data = 0x1C00; tx_data = 0x1C00;
I2Cdev::writeWord(devAddr, 0x57, tx_data); HSwriteWord(devAddr, 0x57, tx_data);
tx_data = 0x800D; tx_data = 0x800D;
I2Cdev::writeWord(devAddr, 0x58, tx_data); HSwriteWord(devAddr, 0x58, tx_data);
tx_data = 0x0EDD; tx_data = 0x0EDD;
I2Cdev::writeWord(devAddr, 0x5A, tx_data); // sq and noise detect times HSwriteWord(devAddr, 0x5A, tx_data); // sq and noise detect times
tx_data = 0x3FFF; tx_data = 0x3FFF;
I2Cdev::writeWord(devAddr, 0x63, tx_data); // pre-emphasis bypass HSwriteWord(devAddr, 0x63, tx_data); // pre-emphasis bypass
// calibration // calibration
tx_data = 0x00A4; tx_data = 0x00A4;
I2Cdev::writeWord(devAddr, 0x30, tx_data); HSwriteWord(devAddr, 0x30, tx_data);
delay(100); delay(100);
tx_data = 0x00A6; tx_data = 0x00A6;
I2Cdev::writeWord(devAddr, 0x30, tx_data); HSwriteWord(devAddr, 0x30, tx_data);
delay(100); delay(100);
tx_data = 0x0006; tx_data = 0x0006;
I2Cdev::writeWord(devAddr, 0x30, tx_data); HSwriteWord(devAddr, 0x30, tx_data);
delay(100); delay(100);
// setup for 12.5kHz channel width // setup for 12.5kHz channel width
tx_data = 0x3D37; tx_data = 0x3D37;
I2Cdev::writeWord(devAddr, 0x11, tx_data); HSwriteWord(devAddr, 0x11, tx_data);
tx_data = 0x0100; tx_data = 0x0100;
I2Cdev::writeWord(devAddr, 0x12, tx_data); HSwriteWord(devAddr, 0x12, tx_data);
tx_data = 0x1100; tx_data = 0x1100;
I2Cdev::writeWord(devAddr, 0x15, tx_data); HSwriteWord(devAddr, 0x15, tx_data);
tx_data = 0x4495; tx_data = 0x4495;
I2Cdev::writeWord(devAddr, 0x32, tx_data); // agc target power [11:6] HSwriteWord(devAddr, 0x32, tx_data); // agc target power [11:6]
tx_data = 0x2B8E; tx_data = 0x2B8E;
I2Cdev::writeWord(devAddr, 0x34, tx_data); HSwriteWord(devAddr, 0x34, tx_data);
tx_data = 0x40C3; tx_data = 0x40C3;
I2Cdev::writeWord(devAddr, 0x3A, tx_data); // modu_det_sel sq setting HSwriteWord(devAddr, 0x3A, tx_data); // modu_det_sel sq setting
tx_data = 0x0407; tx_data = 0x0407;
I2Cdev::writeWord(devAddr, 0x3C, tx_data); // pk_det_th sq setting [8:7] HSwriteWord(devAddr, 0x3C, tx_data); // pk_det_th sq setting [8:7]
tx_data = 0x28D0; tx_data = 0x28D0;
I2Cdev::writeWord(devAddr, 0x3F, tx_data); // rssi3_th sq setting HSwriteWord(devAddr, 0x3F, tx_data); // rssi3_th sq setting
tx_data = 0x203E; tx_data = 0x203E;
I2Cdev::writeWord(devAddr, 0x48, tx_data); HSwriteWord(devAddr, 0x48, tx_data);
tx_data = 0x1BB7; tx_data = 0x1BB7;
I2Cdev::writeWord(devAddr, 0x60, tx_data); HSwriteWord(devAddr, 0x60, tx_data);
tx_data = 0x0A10; // use 0x1425 if there's an LNA tx_data = 0x0A10; // use 0x1425 if there's an LNA
I2Cdev::writeWord(devAddr, 0x62, tx_data); HSwriteWord(devAddr, 0x62, tx_data);
tx_data = 0x2494; tx_data = 0x2494;
I2Cdev::writeWord(devAddr, 0x65, tx_data); HSwriteWord(devAddr, 0x65, tx_data);
tx_data = 0xEB2E; tx_data = 0xEB2E;
I2Cdev::writeWord(devAddr, 0x66, tx_data); HSwriteWord(devAddr, 0x66, tx_data);
delay(100); delay(100);
/*
// setup default values // setup default values
frequency(446000); frequency(446000);
//setVolume1(0xF); //setVolume1(0xF);
@ -282,6 +283,7 @@ void HamShield::initialize() {
setRfPower(0); setRfPower(0);
setSQLoThresh(80); setSQLoThresh(80);
setSQOn(); setSQOn();
*/
} }
/** Verify the I2C connection. /** Verify the I2C connection.
@ -289,7 +291,7 @@ void HamShield::initialize() {
* @return True if connection is valid, false otherwise * @return True if connection is valid, false otherwise
*/ */
bool HamShield::testConnection() { bool HamShield::testConnection() {
I2Cdev::readWord(devAddr, 0x00, radio_i2c_buf); HSreadWord(devAddr, 0x00, radio_i2c_buf);
return radio_i2c_buf[0] == 0x1846; return radio_i2c_buf[0] == 0x1846;
} }
@ -316,16 +318,16 @@ bool HamShield::testConnection() {
*/ */
uint16_t HamShield::readCtlReg() { uint16_t HamShield::readCtlReg() {
I2Cdev::readWord(devAddr, A1846S_CTL_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_CTL_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::softReset() { void HamShield::softReset() {
uint16_t tx_data = 0x1; uint16_t tx_data = 0x1;
I2Cdev::writeWord(devAddr, A1846S_CTL_REG, tx_data); HSwriteWord(devAddr, A1846S_CTL_REG, tx_data);
delay(100); // Note: see A1846S setup info for timing guidelines delay(100); // Note: see A1846S setup info for timing guidelines
tx_data = 0x4; tx_data = 0x4;
I2Cdev::writeWord(devAddr, A1846S_CTL_REG, tx_data); HSwriteWord(devAddr, A1846S_CTL_REG, tx_data);
} }
@ -334,7 +336,7 @@ void HamShield::setFrequency(uint32_t freq_khz) {
uint32_t freq_raw = freq_khz << 4; // shift by 4 to multiply by 16 (was shift by 3 in old 1846 chip) uint32_t freq_raw = freq_khz << 4; // shift by 4 to multiply by 16 (was shift by 3 in old 1846 chip)
// turn off tx/rx // turn off tx/rx
I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0); HSwriteBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0);
// if we're using a 12MHz crystal and the frequency is // if we're using a 12MHz crystal and the frequency is
// 136.5M,409.5M and 455M, then we have to do special stuff // 136.5M,409.5M and 455M, then we have to do special stuff
@ -343,19 +345,19 @@ void HamShield::setFrequency(uint32_t freq_khz) {
radio_frequency == 455000) { radio_frequency == 455000) {
// set up AU1846 for funky freq // set up AU1846 for funky freq
I2Cdev::writeWord(devAddr, 0x05, 0x86D3); HSwriteWord(devAddr, 0x05, 0x86D3);
} else { } else {
// set up AU1846 for normal freq // set up AU1846 for normal freq
I2Cdev::writeWord(devAddr, 0x05, 0x8763); HSwriteWord(devAddr, 0x05, 0x8763);
} }
// send top 16 bits to A1846S_FREQ_HI_REG // send top 16 bits to A1846S_FREQ_HI_REG
uint16_t freq_half = (uint16_t) (0x3FFF & (freq_raw >> 16)); uint16_t freq_half = (uint16_t) (0x3FFF & (freq_raw >> 16));
I2Cdev::writeWord(devAddr, A1846S_FREQ_HI_REG, freq_half); HSwriteWord(devAddr, A1846S_FREQ_HI_REG, freq_half);
// send bottom 16 bits to A1846S_FREQ_LO_REG // send bottom 16 bits to A1846S_FREQ_LO_REG
freq_half = (uint16_t) (freq_raw & 0xFFFF); freq_half = (uint16_t) (freq_raw & 0xFFFF);
I2Cdev::writeWord(devAddr, A1846S_FREQ_LO_REG, freq_half); HSwriteWord(devAddr, A1846S_FREQ_LO_REG, freq_half);
if (rx_active) { if (rx_active) {
setRX(true); setRX(true);
@ -385,7 +387,7 @@ void HamShield::setTxBand70cm() {
uint16_t mode_len = 4; uint16_t mode_len = 4;
uint16_t bit = 11; uint16_t bit = 11;
I2Cdev::writeBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, 0xF); HSwriteBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, 0xF);
} }
// clk mode // clk mode
@ -398,10 +400,10 @@ void HamShield::setClkMode(bool LFClk){
tx_data = 0x0FD0; tx_data = 0x0FD0;
} }
I2Cdev::writeWord(devAddr, A1846S_CLK_MODE_REG, tx_data); HSwriteWord(devAddr, A1846S_CLK_MODE_REG, tx_data);
} }
bool HamShield::getClkMode(){ bool HamShield::getClkMode(){
I2Cdev::readBitW(devAddr, A1846S_CLK_MODE_REG, A1846S_CLK_MODE_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_CLK_MODE_REG, A1846S_CLK_MODE_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
@ -412,10 +414,10 @@ bool HamShield::getClkMode(){
// 00 - 12.5kHz channel // 00 - 12.5kHz channel
// 10,01 - reserved // 10,01 - reserved
void HamShield::setChanMode(uint16_t mode){ void HamShield::setChanMode(uint16_t mode){
I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, mode); HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, mode);
} }
uint16_t HamShield::getChanMode(){ uint16_t HamShield::getChanMode(){
I2Cdev::readBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
*/ */
@ -428,6 +430,7 @@ void HamShield::setTX(bool on_noff){
rx_active = false; rx_active = false;
setRX(false); setRX(false);
if((radio_frequency >= 134000) && (radio_frequency <= 174000)) { if((radio_frequency >= 134000) && (radio_frequency <= 174000)) {
setTxBand2m(); setTxBand2m();
} }
@ -437,14 +440,18 @@ void HamShield::setTX(bool on_noff){
if((radio_frequency >= 400000) && (radio_frequency <= 520000)) { if((radio_frequency >= 400000) && (radio_frequency <= 520000)) {
setTxBand70cm(); setTxBand70cm();
} }
// FOR HS03
//setGpioLow(5); // V2
//setGpioHi(4); // V1
delay(50); // delay required by AU1846 delay(50); // delay required by AU1846
} }
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff);
} }
bool HamShield::getTX(){ bool HamShield::getTX(){
I2Cdev::readBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
@ -454,16 +461,19 @@ void HamShield::setRX(bool on_noff){
tx_active = false; tx_active = false;
rx_active = true; rx_active = true;
setTX(false); setTX(false);
// FOR HS03
//setGpioLow(4); // V1
//setGpioHi(5); // V2
setGpioLow(4); // V1 setGpioLow(4); // V1
setGpioLow(5); // V2 setGpioLow(5); // V2
delay(50); // delay required by AU1846 delay(50); // delay required by AU1846
} }
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff);
} }
bool HamShield::getRX(){ bool HamShield::getRX(){
I2Cdev::readBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
@ -483,7 +493,7 @@ void HamShield::setModeReceive(){
} }
void HamShield::setModeOff(){ void HamShield::setModeOff(){
// turn off tx/rx // turn off tx/rx
I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0); HSwriteBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0);
// turn off amplifiers // turn off amplifiers
setGpioLow(4); // V1 setGpioLow(4); // V1
@ -502,7 +512,7 @@ void HamShield::setModeOff(){
// 011 - sine source from tone1 and tone2 // 011 - sine source from tone1 and tone2
// 100 - mic // 100 - mic
void HamShield::setTxSource(uint16_t tx_source){ void HamShield::setTxSource(uint16_t tx_source){
I2Cdev::writeBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, tx_source); HSwriteBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, tx_source);
} }
void HamShield::setTxSourceMic(){ void HamShield::setTxSourceMic(){
setTxSource(4); setTxSource(4);
@ -520,7 +530,7 @@ void HamShield::setTxSourceNone(){
setTxSource(0); setTxSource(0);
} }
uint16_t HamShield::getTxSource(){ uint16_t HamShield::getTxSource(){
I2Cdev::readBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
@ -535,10 +545,10 @@ uint16_t HamShield::getTxSource(){
// 100000: 2.45V // 100000: 2.45V
// 1111111:3.13V // 1111111:3.13V
void HamShield::setPABiasVoltage(uint16_t voltage){ void HamShield::setPABiasVoltage(uint16_t voltage){
I2Cdev::writeBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, voltage); HSwriteBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, voltage);
} }
uint16_t HamShield::getPABiasVoltage(){ uint16_t HamShield::getPABiasVoltage(){
I2Cdev::readBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
*/ */
@ -567,10 +577,10 @@ uint16_t HamShield::getPABiasVoltage(){
// 110=outer cdcss en // 110=outer cdcss en
// others =disable // others =disable
void HamShield::setCtcssCdcssMode(uint16_t mode){ void HamShield::setCtcssCdcssMode(uint16_t mode){
I2Cdev::writeBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_C_MODE_BIT, A1846S_C_MODE_LENGTH, mode); HSwriteBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_C_MODE_BIT, A1846S_C_MODE_LENGTH, mode);
} }
uint16_t HamShield::getCtcssCdcssMode(){ uint16_t HamShield::getCtcssCdcssMode(){
I2Cdev::readBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_C_MODE_BIT, A1846S_C_MODE_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_C_MODE_BIT, A1846S_C_MODE_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setInnerCtcssMode(){ void HamShield::setInnerCtcssMode(){
@ -593,10 +603,10 @@ void HamShield::disableCtcssCdcss(){
// 1 = ctcss_cmp/cdcss_cmp out via gpio // 1 = ctcss_cmp/cdcss_cmp out via gpio
// 0 = ctcss/cdcss sdo out vio gpio // 0 = ctcss/cdcss sdo out vio gpio
void HamShield::setCtcssSel(bool cmp_nsdo){ void HamShield::setCtcssSel(bool cmp_nsdo){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CTCSS_SEL_BIT, cmp_nsdo); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CTCSS_SEL_BIT, cmp_nsdo);
} }
bool HamShield::getCtcssSel(){ bool HamShield::getCtcssSel(){
I2Cdev::readBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CTCSS_SEL_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CTCSS_SEL_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
@ -604,46 +614,46 @@ bool HamShield::getCtcssSel(){
// 1 = long (24 bit) code // 1 = long (24 bit) code
// 0 = short(23 bit) code // 0 = short(23 bit) code
void HamShield::setCdcssSel(bool long_nshort){ void HamShield::setCdcssSel(bool long_nshort){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CDCSS_SEL_BIT, long_nshort); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CDCSS_SEL_BIT, long_nshort);
} }
bool HamShield::getCdcssSel(){ bool HamShield::getCdcssSel(){
I2Cdev::readBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CDCSS_SEL_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CDCSS_SEL_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// Cdcss neg_det_en // Cdcss neg_det_en
void HamShield::enableCdcssNegDet(){ void HamShield::enableCdcssNegDet(){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_NEG_DET_EN_BIT, 1); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_NEG_DET_EN_BIT, 1);
} }
void HamShield::disableCdcssNegDet(){ void HamShield::disableCdcssNegDet(){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_NEG_DET_EN_BIT, 0); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_NEG_DET_EN_BIT, 0);
} }
bool HamShield::getCdcssNegDetEnabled(){ bool HamShield::getCdcssNegDetEnabled(){
I2Cdev::readBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_NEG_DET_EN_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_NEG_DET_EN_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// Cdcss pos_det_en // Cdcss pos_det_en
void HamShield::enableCdcssPosDet(){ void HamShield::enableCdcssPosDet(){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_POS_DET_EN_BIT, 1); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_POS_DET_EN_BIT, 1);
} }
void HamShield::disableCdcssPosDet(){ void HamShield::disableCdcssPosDet(){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_POS_DET_EN_BIT, 0); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_POS_DET_EN_BIT, 0);
} }
bool HamShield::getCdcssPosDetEnabled(){ bool HamShield::getCdcssPosDetEnabled(){
I2Cdev::readBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_POS_DET_EN_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_POS_DET_EN_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// css_det_en // css_det_en
void HamShield::enableCssDet(){ void HamShield::enableCssDet(){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CSS_DET_EN_BIT, 1); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CSS_DET_EN_BIT, 1);
} }
void HamShield::disableCssDet(){ void HamShield::disableCssDet(){
I2Cdev::writeBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CSS_DET_EN_BIT, 0); HSwriteBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CSS_DET_EN_BIT, 0);
} }
bool HamShield::getCssDetEnabled(){ bool HamShield::getCssDetEnabled(){
I2Cdev::readBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CSS_DET_EN_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_SUBAUDIO_REG, A1846S_CSS_DET_EN_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
@ -655,10 +665,10 @@ void HamShield::setCtcss(float freq) {
} }
void HamShield::setCtcssFreq(uint16_t freq){ void HamShield::setCtcssFreq(uint16_t freq){
I2Cdev::writeWord(devAddr, A1846S_CTCSS_FREQ_REG, freq); HSwriteWord(devAddr, A1846S_CTCSS_FREQ_REG, freq);
} }
uint16_t HamShield::getCtcssFreq(){ uint16_t HamShield::getCtcssFreq(){
I2Cdev::readWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
@ -689,15 +699,15 @@ void HamShield::setCdcssCode(uint16_t code) {
// set registers // set registers
uint16_t temp_code = (uint16_t) cdcss_code; uint16_t temp_code = (uint16_t) cdcss_code;
I2Cdev::writeWord(devAddr, A1846S_CDCSS_CODE_HI_REG, temp_code); HSwriteWord(devAddr, A1846S_CDCSS_CODE_HI_REG, temp_code);
temp_code = (uint16_t) (cdcss_code >> 16); temp_code = (uint16_t) (cdcss_code >> 16);
I2Cdev::writeWord(devAddr, A1846S_CDCSS_CODE_LO_REG, temp_code); HSwriteWord(devAddr, A1846S_CDCSS_CODE_LO_REG, temp_code);
} }
uint16_t HamShield::getCdcssCode() { uint16_t HamShield::getCdcssCode() {
uint32_t oct_code; uint32_t oct_code;
I2Cdev::readWord(devAddr, A1846S_CDCSS_CODE_HI_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_CDCSS_CODE_HI_REG, radio_i2c_buf);
oct_code = (radio_i2c_buf[0] << 16); oct_code = (radio_i2c_buf[0] << 16);
I2Cdev::readWord(devAddr, A1846S_CDCSS_CODE_LO_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_CDCSS_CODE_LO_REG, radio_i2c_buf);
oct_code += radio_i2c_buf[0]; oct_code += radio_i2c_buf[0];
oct_code = oct_code >> 12; oct_code = oct_code >> 12;
@ -712,89 +722,89 @@ uint16_t HamShield::getCdcssCode() {
// SQ // SQ
void HamShield::setSQOn(){ void HamShield::setSQOn(){
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 1); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 1);
} }
void HamShield::setSQOff(){ void HamShield::setSQOff(){
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 0); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 0);
} }
bool HamShield::getSQState(){ bool HamShield::getSQState(){
I2Cdev::readBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// SQ threshold // SQ threshold
void HamShield::setSQHiThresh(uint16_t sq_hi_threshold){ void HamShield::setSQHiThresh(uint16_t sq_hi_threshold){
// Sq detect high th, rssi_cmp will be 1 when rssi>th_h_sq, unit 1/8dB // Sq detect high th, rssi_cmp will be 1 when rssi>th_h_sq, unit 1/8dB
I2Cdev::writeWord(devAddr, A1846S_SQ_OPEN_THRESH_REG, sq_hi_threshold); HSwriteWord(devAddr, A1846S_SQ_OPEN_THRESH_REG, sq_hi_threshold);
} }
uint16_t HamShield::getSQHiThresh(){ uint16_t HamShield::getSQHiThresh(){
I2Cdev::readWord(devAddr, A1846S_SQ_OPEN_THRESH_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_SQ_OPEN_THRESH_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setSQLoThresh(uint16_t sq_lo_threshold){ void HamShield::setSQLoThresh(uint16_t sq_lo_threshold){
// Sq detect low th, rssi_cmp will be 0 when rssi<th_l_sq && time delay meet, unit 1/8 dB // Sq detect low th, rssi_cmp will be 0 when rssi<th_l_sq && time delay meet, unit 1/8 dB
I2Cdev::writeWord(devAddr, A1846S_SQ_SHUT_THRESH_REG, sq_lo_threshold); HSwriteWord(devAddr, A1846S_SQ_SHUT_THRESH_REG, sq_lo_threshold);
} }
uint16_t HamShield::getSQLoThresh(){ uint16_t HamShield::getSQLoThresh(){
I2Cdev::readWord(devAddr, A1846S_SQ_SHUT_THRESH_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_SQ_SHUT_THRESH_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
// SQ out select // SQ out select
void HamShield::setSQOutSel(){ void HamShield::setSQOutSel(){
I2Cdev::writeBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, 1); HSwriteBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, 1);
} }
void HamShield::clearSQOutSel(){ void HamShield::clearSQOutSel(){
I2Cdev::writeBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, 0); HSwriteBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, 0);
} }
bool HamShield::getSQOutSel(){ bool HamShield::getSQOutSel(){
I2Cdev::readBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// VOX // VOX
void HamShield::setVoxOn(){ void HamShield::setVoxOn(){
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, 1); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, 1);
} }
void HamShield::setVoxOff(){ void HamShield::setVoxOff(){
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, 0); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, 0);
} }
bool HamShield::getVoxOn(){ bool HamShield::getVoxOn(){
I2Cdev::readBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// Vox Threshold // Vox Threshold
void HamShield::setVoxOpenThresh(uint16_t vox_open_thresh){ void HamShield::setVoxOpenThresh(uint16_t vox_open_thresh){
// When vssi > th_h_vox, then vox will be 1(unit mV ) // When vssi > th_h_vox, then vox will be 1(unit mV )
I2Cdev::writeWord(devAddr, A1846S_TH_H_VOX_REG, vox_open_thresh); HSwriteWord(devAddr, A1846S_TH_H_VOX_REG, vox_open_thresh);
} }
uint16_t HamShield::getVoxOpenThresh(){ uint16_t HamShield::getVoxOpenThresh(){
I2Cdev::readWord(devAddr, A1846S_TH_H_VOX_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_TH_H_VOX_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setVoxShutThresh(uint16_t vox_shut_thresh){ void HamShield::setVoxShutThresh(uint16_t vox_shut_thresh){
// When vssi < th_l_vox && time delay meet, then vox will be 0 (unit mV ) // When vssi < th_l_vox && time delay meet, then vox will be 0 (unit mV )
I2Cdev::writeWord(devAddr, A1846S_TH_L_VOX_REG, vox_shut_thresh); HSwriteWord(devAddr, A1846S_TH_L_VOX_REG, vox_shut_thresh);
} }
uint16_t HamShield::getVoxShutThresh(){ uint16_t HamShield::getVoxShutThresh(){
I2Cdev::readWord(devAddr, A1846S_TH_L_VOX_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_TH_L_VOX_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
// Tail Noise // Tail Noise
void HamShield::enableTailNoiseElim(){ void HamShield::enableTailNoiseElim(){
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, 1); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, 1);
} }
void HamShield::disableTailNoiseElim(){ void HamShield::disableTailNoiseElim(){
I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, 1); HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, 1);
} }
bool HamShield::getTailNoiseElimEnabled(){ bool HamShield::getTailNoiseElimEnabled(){
I2Cdev::readBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, radio_i2c_buf); HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
@ -805,100 +815,100 @@ bool HamShield::getTailNoiseElimEnabled(){
// 10 = 240 degree shift // 10 = 240 degree shift
// 11 = reserved // 11 = reserved
void HamShield::setShiftSelect(uint16_t shift_sel){ void HamShield::setShiftSelect(uint16_t shift_sel){
I2Cdev::writeBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LENGTH, shift_sel); HSwriteBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LENGTH, shift_sel);
} }
uint16_t HamShield::getShiftSelect(){ uint16_t HamShield::getShiftSelect(){
I2Cdev::readBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_SUBAUDIO_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
// DTMF // DTMF
void HamShield::setDTMFC0(uint16_t freq) { void HamShield::setDTMFC0(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C0_BIT, A1846S_DTMF_C0_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C0_BIT, A1846S_DTMF_C0_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC0() { uint16_t HamShield::getDTMFC0() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C0_BIT, A1846S_DTMF_C0_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C0_BIT, A1846S_DTMF_C0_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC1(uint16_t freq) { void HamShield::setDTMFC1(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C1_BIT, A1846S_DTMF_C1_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C1_BIT, A1846S_DTMF_C1_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC1() { uint16_t HamShield::getDTMFC1() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C1_BIT, A1846S_DTMF_C1_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C01_REG, A1846S_DTMF_C1_BIT, A1846S_DTMF_C1_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC2(uint16_t freq) { void HamShield::setDTMFC2(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C2_BIT, A1846S_DTMF_C2_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C2_BIT, A1846S_DTMF_C2_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC2() { uint16_t HamShield::getDTMFC2() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C2_BIT, A1846S_DTMF_C2_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C2_BIT, A1846S_DTMF_C2_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC3(uint16_t freq) { void HamShield::setDTMFC3(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C3_BIT, A1846S_DTMF_C3_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C3_BIT, A1846S_DTMF_C3_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC3() { uint16_t HamShield::getDTMFC3() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C3_BIT, A1846S_DTMF_C3_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C23_REG, A1846S_DTMF_C3_BIT, A1846S_DTMF_C3_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC4(uint16_t freq) { void HamShield::setDTMFC4(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C4_BIT, A1846S_DTMF_C4_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C4_BIT, A1846S_DTMF_C4_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC4() { uint16_t HamShield::getDTMFC4() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C4_BIT, A1846S_DTMF_C4_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C4_BIT, A1846S_DTMF_C4_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC5(uint16_t freq) { void HamShield::setDTMFC5(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C5_BIT, A1846S_DTMF_C5_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C5_BIT, A1846S_DTMF_C5_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC5() { uint16_t HamShield::getDTMFC5() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C5_BIT, A1846S_DTMF_C5_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C45_REG, A1846S_DTMF_C5_BIT, A1846S_DTMF_C5_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC6(uint16_t freq) { void HamShield::setDTMFC6(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C6_BIT, A1846S_DTMF_C6_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C6_BIT, A1846S_DTMF_C6_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC6() { uint16_t HamShield::getDTMFC6() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C6_BIT, A1846S_DTMF_C6_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C6_BIT, A1846S_DTMF_C6_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setDTMFC7(uint16_t freq) { void HamShield::setDTMFC7(uint16_t freq) {
I2Cdev::writeBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C7_BIT, A1846S_DTMF_C7_LENGTH, freq); HSwriteBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C7_BIT, A1846S_DTMF_C7_LENGTH, freq);
} }
uint16_t HamShield::getDTMFC7() { uint16_t HamShield::getDTMFC7() {
I2Cdev::readBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C7_BIT, A1846S_DTMF_C7_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_C67_REG, A1846S_DTMF_C7_BIT, A1846S_DTMF_C7_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
// TX FM deviation // TX FM deviation
void HamShield::setFMVoiceCssDeviation(uint16_t deviation){ void HamShield::setFMVoiceCssDeviation(uint16_t deviation){
I2Cdev::writeBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, deviation); HSwriteBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, deviation);
} }
uint16_t HamShield::getFMVoiceCssDeviation(){ uint16_t HamShield::getFMVoiceCssDeviation(){
I2Cdev::readBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setFMCssDeviation(uint16_t deviation){ void HamShield::setFMCssDeviation(uint16_t deviation){
I2Cdev::writeBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, deviation); HSwriteBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, deviation);
} }
uint16_t HamShield::getFMCssDeviation(){ uint16_t HamShield::getFMCssDeviation(){
I2Cdev::readBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
// RX voice range // RX voice range
void HamShield::setVolume1(uint16_t volume){ void HamShield::setVolume1(uint16_t volume){
I2Cdev::writeBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, volume); HSwriteBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, volume);
} }
uint16_t HamShield::getVolume1(){ uint16_t HamShield::getVolume1(){
I2Cdev::readBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setVolume2(uint16_t volume){ void HamShield::setVolume2(uint16_t volume){
I2Cdev::writeBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, volume); HSwriteBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, volume);
} }
uint16_t HamShield::getVolume2(){ uint16_t HamShield::getVolume2(){
I2Cdev::readBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
@ -907,7 +917,7 @@ void HamShield::setGpioMode(uint16_t gpio, uint16_t mode){
uint16_t mode_len = 2; uint16_t mode_len = 2;
uint16_t bit = gpio*2 + 1; uint16_t bit = gpio*2 + 1;
I2Cdev::writeBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, mode); HSwriteBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, mode);
} }
void HamShield::setGpioHiZ(uint16_t gpio){ void HamShield::setGpioHiZ(uint16_t gpio){
setGpioMode(gpio, 0); setGpioMode(gpio, 0);
@ -925,33 +935,33 @@ uint16_t HamShield::getGpioMode(uint16_t gpio){
uint16_t mode_len = 2; uint16_t mode_len = 2;
uint16_t bit = gpio*2 + 1; uint16_t bit = gpio*2 + 1;
I2Cdev::readBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
uint16_t HamShield::getGpios(){ uint16_t HamShield::getGpios(){
I2Cdev::readWord(devAddr, A1846S_GPIO_MODE_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_GPIO_MODE_REG, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
// Int // Int
void HamShield::enableInterrupt(uint16_t interrupt){ void HamShield::enableInterrupt(uint16_t interrupt){
I2Cdev::writeBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 1); HSwriteBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 1);
} }
void HamShield::disableInterrupt(uint16_t interrupt){ void HamShield::disableInterrupt(uint16_t interrupt){
I2Cdev::writeBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 0); HSwriteBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 0);
} }
bool HamShield::getInterruptEnabled(uint16_t interrupt){ bool HamShield::getInterruptEnabled(uint16_t interrupt){
I2Cdev::readBitW(devAddr, A1846S_INT_MODE_REG, interrupt, radio_i2c_buf); HSreadBitW(devAddr, A1846S_INT_MODE_REG, interrupt, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// ST mode // ST mode
void HamShield::setStMode(uint16_t mode){ void HamShield::setStMode(uint16_t mode){
I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, mode); HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, mode);
} }
uint16_t HamShield::getStMode(){ uint16_t HamShield::getStMode(){
I2Cdev::readBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
void HamShield::setStFullAuto(){ void HamShield::setStFullAuto(){
@ -966,31 +976,31 @@ setStMode(0);
// Pre-emphasis, De-emphasis filter // Pre-emphasis, De-emphasis filter
void HamShield::bypassPreDeEmph(){ void HamShield::bypassPreDeEmph(){
I2Cdev::writeBitW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 1); HSwriteBitW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 1);
} }
void HamShield::usePreDeEmph(){ void HamShield::usePreDeEmph(){
I2Cdev::writeBitW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 0); HSwriteBitW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 0);
} }
bool HamShield::getPreDeEmphEnabled(){ bool HamShield::getPreDeEmphEnabled(){
I2Cdev::readBitW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, radio_i2c_buf); HSreadBitW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, radio_i2c_buf);
return (radio_i2c_buf[0] != 0); return (radio_i2c_buf[0] != 0);
} }
// Read Only Status Registers // Read Only Status Registers
int16_t HamShield::readRSSI(){ int16_t HamShield::readRSSI(){
I2Cdev::readBitsW(devAddr, A1846S_RSSI_REG, A1846S_RSSI_BIT, A1846S_RSSI_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_RSSI_REG, A1846S_RSSI_BIT, A1846S_RSSI_LENGTH, radio_i2c_buf);
int16_t rssi = (radio_i2c_buf[0] & 0x3FF) - 137; int16_t rssi = (radio_i2c_buf[0] & 0x3FF) - 137;
return rssi; return rssi;
} }
uint16_t HamShield::readVSSI(){ uint16_t HamShield::readVSSI(){
I2Cdev::readWord(devAddr, A1846S_VSSI_REG, radio_i2c_buf); HSreadWord(devAddr, A1846S_VSSI_REG, radio_i2c_buf);
return radio_i2c_buf[0] & 0x7FF; // only need lowest 10 bits return radio_i2c_buf[0] & 0x7FF; // only need lowest 10 bits
} }
uint16_t HamShield::readDTMFIndex(){ uint16_t HamShield::readDTMFIndex(){
// TODO: may want to split this into two (index1 and index2) // TODO: may want to split this into two (index1 and index2)
I2Cdev::readBitsW(devAddr, A1846S_DTMF_RX_REG, A1846S_DTMF_INDEX_BIT, A1846S_DTMF_INDEX_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_RX_REG, A1846S_DTMF_INDEX_BIT, A1846S_DTMF_INDEX_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
uint16_t HamShield::readDTMFCode(){ uint16_t HamShield::readDTMFCode(){
@ -998,7 +1008,7 @@ uint16_t HamShield::readDTMFCode(){
// 4:f1+f4, 5:f1+f5, 6:f1+f6, B:f1+f7, // 4:f1+f4, 5:f1+f5, 6:f1+f6, B:f1+f7,
// 7:f2+f4, 8:f2+f5, 9:f2+f6, C:f2+f7, // 7:f2+f4, 8:f2+f5, 9:f2+f6, C:f2+f7,
// E(*):f3+f4, 0:f3+f5, F(#):f3+f6, D:f3+f7 // E(*):f3+f4, 0:f3+f5, F(#):f3+f6, D:f3+f7
I2Cdev::readBitsW(devAddr, A1846S_DTMF_RX_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LENGTH, radio_i2c_buf); HSreadBitsW(devAddr, A1846S_DTMF_RX_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LENGTH, radio_i2c_buf);
return radio_i2c_buf[0]; return radio_i2c_buf[0];
} }
@ -1010,9 +1020,9 @@ void HamShield::setRfPower(uint8_t pwr) {
} }
// turn off tx/rx // turn off tx/rx
I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0); HSwriteBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0);
I2Cdev::writeBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PADRV_BIT, A1846S_PADRV_LENGTH, pwr); HSwriteBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PADRV_BIT, A1846S_PADRV_LENGTH, pwr);
if (rx_active) { if (rx_active) {
setRX(true); setRX(true);

View File

@ -9,7 +9,8 @@
#define _HAMSHIELD_H_ #define _HAMSHIELD_H_
//#include "I2Cdev_rda.h" //#include "I2Cdev_rda.h"
#include "I2Cdev.h" //#include "I2Cdev.h"
#include "HamShield_comms.h"
#include "SimpleFIFO.h" #include "SimpleFIFO.h"
#include "AFSK.h" #include "AFSK.h"
#include "DDS.h" #include "DDS.h"

168
HamShield_comms.cpp Normal file
View File

@ -0,0 +1,168 @@
/*
* Based loosely on I2Cdev by Jeff Rowberg, except for all kludgy bit-banging
*/
#include "HamShield_comms.h"
int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data)
{
uint16_t b;
uint8_t count = HSreadWord(devAddr, regAddr, &b);
*data = b & (1 << bitNum);
return count;
}
int8_t HSreadBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data)
{
uint8_t count;
uint16_t w;
if ((count = HSreadWord(devAddr, regAddr, &w)) != 0) {
uint16_t mask = ((1 << length) - 1) << (bitStart - length + 1);
w &= mask;
w >>= (bitStart - length + 1);
*data = w;
}
return count;
}
int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data)
{
//return I2Cdev::readWord(devAddr, regAddr, data);
uint8_t temp;
uint16_t temp_dat;
// bitbang for great justice!
*data = 0;
cli();
DDRC |= ((1<<5) | (1<<4)); // set direction to output
sei();
regAddr = regAddr | (1 << 7);
cli();
PORTC &= ~(1<<1); //digitalWrite(nSEN, 0);
sei();
for (int i = 0; i < 8; i++) {
temp = ((regAddr & (0x80 >> i)) != 0);
cli();
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
sei();
//digitalWrite(DAT, regAddr & (0x80 >> i));
temp = (PORTC & ~(1<<4)) + (temp << 4);
cli();
PORTC = temp;
sei();
delayMicroseconds(9);
cli();
PORTC |= (1<<5); //digitalWrite(CLK, 1);
sei();
delayMicroseconds(9);
}
// change direction of DAT
cli();
DDRC &= ~(1<<4); //pinMode(DAT, INPUT);
sei();
for (int i = 15; i >= 0; i--) {
cli();
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
sei();
delayMicroseconds(9);
cli();
PORTC |= (1<<5); //digitalWrite(CLK, 1);
sei();
cli();
temp_dat = ((PINC & (1<<4)) != 0);
sei();
temp_dat = temp_dat << i;
*data |= temp_dat; // digitalRead(DAT);
delayMicroseconds(9);
}
cli();
PORTC |= (1<<1);//digitalWrite(nSEN, 1);
DDRC &= ~((1<<5) | (1<<4)); // set direction all input (for ADC)
sei();
return 1;
}
bool HSwriteBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data)
{
uint16_t w;
HSreadWord(devAddr, regAddr, &w);
w = (data != 0) ? (w | (1 << bitNum)) : (w & ~(1 << bitNum));
return HSwriteWord(devAddr, regAddr, w);
}
bool HSwriteBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data)
{
uint16_t w;
if (HSreadWord(devAddr, regAddr, &w) != 0) {
uint16_t mask = ((1 << length) - 1) << (bitStart - length + 1);
data <<= (bitStart - length + 1); // shift data into correct position
data &= mask; // zero all non-important bits in data
w &= ~(mask); // zero all important bits in existing word
w |= data; // combine data with existing word
return HSwriteWord(devAddr, regAddr, w);
} else {
return false;
}
}
bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data)
{
//return I2Cdev::writeWord(devAddr, regAddr, data);
uint8_t temp_reg;
uint16_t temp_dat;
//digitalWrite(13, HIGH);
// bitbang for great justice!
cli();
DDRC |= ((1<<5) | (1<<4)); // set direction all output
//PORTC |= (1<<5) & (1<<4);
sei();
regAddr = regAddr & ~(1 << 7);
cli();
PORTC &= ~(1<<1); //digitalWrite(nSEN, 0);
sei();
for (int i = 0; i < 8; i++) {
temp_reg = ((regAddr & (0x80 >> i)) != 0);
cli();
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
sei();
//digitalWrite(DAT, regAddr & (0x80 >> i));
temp_reg = (PORTC & ~(1<<4)) + (temp_reg << 4);
cli();
PORTC = temp_reg;
sei();
delayMicroseconds(8);
cli();
PORTC |= (1<<5); //digitalWrite(CLK, 1);
sei();
delayMicroseconds(10);
}
for (int i = 0; i < 16; i++) {
temp_dat = ((data & (0x8000 >> i)) != 0);
cli();
PORTC &= ~(1<<5); //digitalWrite(CLK, 0);
sei();
//digitalWrite(DAT, data & (0x80000 >> i));
temp_reg = (PORTC & ~(1<<4)) + (temp_dat << 4);
cli();
PORTC = temp_reg;
sei();
delayMicroseconds(7);
cli();
PORTC |= (1<<5); //digitalWrite(CLK, 1);
sei();
delayMicroseconds(10);
}
cli();
PORTC |= (1<<1); //digitalWrite(nSEN, 1);
DDRC &= ~((1<<5) | (1<<4)); // set direction to input for ADC
sei();
return true;
}

22
HamShield_comms.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _HAMSHIELD_COMMS_H_
#define _HAMSHIELD_COMMS_H_
#include "Arduino.h"
//#include "I2Cdev.h"
#define nSEN A1
#define CLK A5
#define DAT A4
int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data);
int8_t HSreadBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data);
int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data);
bool HSwriteBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
bool HSwriteBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
#endif /* _HAMSHIELD_COMMS_H_ */

1457
I2Cdev.cpp

File diff suppressed because it is too large Load Diff

281
I2Cdev.h
View File

@ -1,281 +0,0 @@
// I2Cdev library collection - Main I2C device class header file
// Abstracts bit and byte I2C R/W functions into a convenient class
// 2013-06-05 by Jeff Rowberg <jeff@rowberg.net>
//
// Changelog:
// 2015-10-30 - simondlevy : support i2c_t3 for Teensy3.1
// 2013-05-06 - add Francesco Ferrara's Fastwire v0.24 implementation with small modifications
// 2013-05-05 - fix issue with writing bit values to words (Sasquatch/Farzanegan)
// 2012-06-09 - fix major issue with reading > 32 bytes at a time with Arduino Wire
// - add compiler warnings when using outdated or IDE or limited I2Cdev implementation
// 2011-11-01 - fix write*Bits mask calculation (thanks sasquatch @ Arduino forums)
// 2011-10-03 - added automatic Arduino version detection for ease of use
// 2011-10-02 - added Gene Knight's NBWire TwoWire class implementation with small modifications
// 2011-08-31 - added support for Arduino 1.0 Wire library (methods are different from 0.x)
// 2011-08-03 - added optional timeout parameter to read* methods to easily change from default
// 2011-08-02 - added support for 16-bit registers
// - fixed incorrect Doxygen comments on some methods
// - added timeout value for read operations (thanks mem @ Arduino forums)
// 2011-07-30 - changed read/write function structures to return success or byte counts
// - made all methods static for multi-device memory savings
// 2011-07-28 - initial release
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2013 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
#ifndef _I2CDEV_H_
#define _I2CDEV_H_
// -----------------------------------------------------------------------------
// I2C interface implementation setting
// -----------------------------------------------------------------------------
#ifndef I2CDEV_IMPLEMENTATION
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE
//#define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_FASTWIRE
#endif // I2CDEV_IMPLEMENTATION
// comment this out if you are using a non-optimal IDE/implementation setting
// but want the compiler to shut up about it
#define I2CDEV_IMPLEMENTATION_WARNINGS
// -----------------------------------------------------------------------------
// I2C interface implementation options
// -----------------------------------------------------------------------------
#define I2CDEV_ARDUINO_WIRE 1 // Wire object from Arduino
#define I2CDEV_BUILTIN_NBWIRE 2 // Tweaked Wire object from Gene Knight's NBWire project
// ^^^ NBWire implementation is still buggy w/some interrupts!
#define I2CDEV_BUILTIN_FASTWIRE 3 // FastWire object from Francesco Ferrara's project
#define I2CDEV_I2CMASTER_LIBRARY 4 // I2C object from DSSCircuits I2C-Master Library at https://github.com/DSSCircuits/I2C-Master-Library
// -----------------------------------------------------------------------------
// Arduino-style "Serial.print" debug constant (uncomment to enable)
// -----------------------------------------------------------------------------
//#define I2CDEV_SERIAL_DEBUG
#ifdef ARDUINO
#if ARDUINO < 100
#include "WProgram.h"
#else
#include "Arduino.h"
#endif
#if defined(CORE_TEENSY) && defined(__MK20DX256__)
#include <i2c_t3.h>
#define BUFFER_LENGTH 32
#elif I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include <Wire.h>
#endif
#if I2CDEV_IMPLEMENTATION == I2CDEV_I2CMASTER_LIBRARY
#include <I2C.h>
#endif
#endif
#ifdef SPARK
#include <spark_wiring_i2c.h>
#define ARDUINO 101
#endif
// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
#define I2CDEV_DEFAULT_READ_TIMEOUT 1000
class I2Cdev {
public:
I2Cdev();
static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);
static uint16_t readTimeout;
};
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
//////////////////////
// FastWire 0.24
// This is a library to help faster programs to read I2C devices.
// Copyright(C) 2012
// Francesco Ferrara
//////////////////////
/* Master */
#define TW_START 0x08
#define TW_REP_START 0x10
/* Master Transmitter */
#define TW_MT_SLA_ACK 0x18
#define TW_MT_SLA_NACK 0x20
#define TW_MT_DATA_ACK 0x28
#define TW_MT_DATA_NACK 0x30
#define TW_MT_ARB_LOST 0x38
/* Master Receiver */
#define TW_MR_ARB_LOST 0x38
#define TW_MR_SLA_ACK 0x40
#define TW_MR_SLA_NACK 0x48
#define TW_MR_DATA_ACK 0x50
#define TW_MR_DATA_NACK 0x58
#define TW_OK 0
#define TW_ERROR 1
class Fastwire {
private:
static boolean waitInt();
public:
static void setup(int khz, boolean pullup);
static byte beginTransmission(byte device);
static byte write(byte value);
static byte writeBuf(byte device, byte address, byte *data, byte num);
static byte readBuf(byte device, byte address, byte *data, byte num);
static void reset();
static byte stop();
};
#endif
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
// NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com>
// Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
// Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html
#define NBWIRE_BUFFER_LENGTH 32
class TwoWire {
private:
static uint8_t rxBuffer[];
static uint8_t rxBufferIndex;
static uint8_t rxBufferLength;
static uint8_t txAddress;
static uint8_t txBuffer[];
static uint8_t txBufferIndex;
static uint8_t txBufferLength;
// static uint8_t transmitting;
static void (*user_onRequest)(void);
static void (*user_onReceive)(int);
static void onRequestService(void);
static void onReceiveService(uint8_t*, int);
public:
TwoWire();
void begin();
void begin(uint8_t);
void begin(int);
void beginTransmission(uint8_t);
//void beginTransmission(int);
uint8_t endTransmission(uint16_t timeout=0);
void nbendTransmission(void (*function)(int)) ;
uint8_t requestFrom(uint8_t, int, uint16_t timeout=0);
//uint8_t requestFrom(int, int);
void nbrequestFrom(uint8_t, int, void (*function)(int));
void send(uint8_t);
void send(uint8_t*, uint8_t);
//void send(int);
void send(char*);
uint8_t available(void);
uint8_t receive(void);
void onReceive(void (*)(int));
void onRequest(void (*)(void));
};
#define TWI_READY 0
#define TWI_MRX 1
#define TWI_MTX 2
#define TWI_SRX 3
#define TWI_STX 4
#define TW_WRITE 0
#define TW_READ 1
#define TW_MT_SLA_NACK 0x20
#define TW_MT_DATA_NACK 0x30
#define CPU_FREQ 16000000L
#define TWI_FREQ 100000L
#define TWI_BUFFER_LENGTH 32
/* TWI Status is in TWSR, in the top 5 bits: TWS7 - TWS3 */
#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))
#define TW_STATUS (TWSR & TW_STATUS_MASK)
#define TW_START 0x08
#define TW_REP_START 0x10
#define TW_MT_SLA_ACK 0x18
#define TW_MT_SLA_NACK 0x20
#define TW_MT_DATA_ACK 0x28
#define TW_MT_DATA_NACK 0x30
#define TW_MT_ARB_LOST 0x38
#define TW_MR_ARB_LOST 0x38
#define TW_MR_SLA_ACK 0x40
#define TW_MR_SLA_NACK 0x48
#define TW_MR_DATA_ACK 0x50
#define TW_MR_DATA_NACK 0x58
#define TW_ST_SLA_ACK 0xA8
#define TW_ST_ARB_LOST_SLA_ACK 0xB0
#define TW_ST_DATA_ACK 0xB8
#define TW_ST_DATA_NACK 0xC0
#define TW_ST_LAST_DATA 0xC8
#define TW_SR_SLA_ACK 0x60
#define TW_SR_ARB_LOST_SLA_ACK 0x68
#define TW_SR_GCALL_ACK 0x70
#define TW_SR_ARB_LOST_GCALL_ACK 0x78
#define TW_SR_DATA_ACK 0x80
#define TW_SR_DATA_NACK 0x88
#define TW_SR_GCALL_DATA_ACK 0x90
#define TW_SR_GCALL_DATA_NACK 0x98
#define TW_SR_STOP 0xA0
#define TW_NO_INFO 0xF8
#define TW_BUS_ERROR 0x00
//#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
//#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))
#ifndef sbi // set bit
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif // sbi
#ifndef cbi // clear bit
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif // cbi
extern TwoWire Wire;
#endif // I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
#endif /* _I2CDEV_H_ */

View File

@ -1,7 +1,7 @@
/* Fox Hunt */ /* Fox Hunt */
#include <HAMShield.h> #include <HamShield.h>
#include <Wire.h> //#include <Wire.h>
#define PWM_PIN 3 #define PWM_PIN 3
#define RESET_PIN A3 #define RESET_PIN A3
@ -13,7 +13,7 @@
#define INTERVAL 10 #define INTERVAL 10
#define RANDOMCHANCE 3 #define RANDOMCHANCE 3
HAMShield radio; HamShield radio;
void setup() { void setup() {
// NOTE: if not using PWM out, it should be held low to avoid tx noise // NOTE: if not using PWM out, it should be held low to avoid tx noise
@ -27,15 +27,15 @@ void setup() {
pinMode(RESET_PIN, OUTPUT); pinMode(RESET_PIN, OUTPUT);
digitalWrite(RESET_PIN, HIGH); digitalWrite(RESET_PIN, HIGH);
Wire.begin(); //Wire.begin();
radio.initialize(); radio.initialize();
radio.setFrequency(145510); radio.frequency(145510);
radio.setModeReceive(); radio.setModeReceive();
} }
void loop() { void loop() {
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly up to 3 minutes later waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly up to 3 minutes later
if(radio.waitForChannel(30000,2000)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers
radio.setModeTransmit(); // turn on transmit mode radio.setModeTransmit(); // turn on transmit mode
tone(1000,11,TRANSMITLENGTH * 60 * 1000); // play a long solid tone tone(1000,11,TRANSMITLENGTH * 60 * 1000); // play a long solid tone
radio.morseOut("1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter radio.morseOut("1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter
@ -49,4 +49,3 @@ void waitMinute(int period) {
delay(period * 60 * 1000); delay(period * 60 * 1000);
} }