summaryrefslogtreecommitdiff
path: root/software/rda1846dongle/rda1846.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-02-27 15:57:40 +0000
committerChristian Pointner <equinox@mur.at>2013-02-27 15:57:40 +0000
commit64b0e730e97796247e42f1b88352259c1e8f8b71 (patch)
tree8c02fda89c14599e981621c7c0eb4d22c8423f41 /software/rda1846dongle/rda1846.c
parentadded inital version of rda1846dongle (diff)
rda1826dongle: added register write and read subs (not working yet)
git-svn-id: https://svn.spreadspace.org/mur.sat@683 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/rda1846dongle/rda1846.c')
-rw-r--r--software/rda1846dongle/rda1846.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c
new file mode 100644
index 0000000..f12c40f
--- /dev/null
+++ b/software/rda1846dongle/rda1846.c
@@ -0,0 +1,83 @@
+/*
+ * spreadspace avr utils
+ *
+ *
+ * Copyright (C) 2013 Christian Pointner <equinox@spreadspace.org>
+ * Othmar Gsenger <otti@wirdorange.org>
+ *
+ * This file is part of spreadspace avr utils.
+ *
+ * spreadspace avr utils is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * spreadspace avr utils is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "LUFA/Drivers/Peripheral/TWI.h"
+#include <stdio.h>
+
+#include "rda1846.h"
+
+#define RDA1846_CHIP_ADDR 0xE2
+#define RDA1846_ADDR_W (0<<7)
+#define RDA1846_ADDR_R (1<<7)
+
+uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data)
+{
+ if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_WRITE,10) != TWI_ERROR_NoError)
+ return 1;
+
+ if(addr >= 0x7F)
+ goto i2c_error; // no support for this at the moment !!!
+
+ if(!TWI_SendByte(addr | RDA1846_ADDR_W))
+ goto i2c_error;
+ if(!TWI_SendByte((uint8_t)(data>>8)))
+ goto i2c_error;
+ if(!TWI_SendByte((uint8_t)data))
+ goto i2c_error;
+
+ TWI_StopTransmission();
+ return 0;
+
+i2c_error:
+ TWI_StopTransmission();
+ return 1;
+}
+
+uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
+{
+ if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_WRITE,10) != TWI_ERROR_NoError)
+ return 1;
+
+ if(addr >= 0x7F)
+ goto i2c_error; // no support for this at the moment !!!
+
+ if(!TWI_SendByte(addr | RDA1846_ADDR_R))
+ goto i2c_error;
+
+ if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_READ,10) != TWI_ERROR_NoError)
+ goto i2c_error;
+
+ // TODO read data
+
+ TWI_StopTransmission();
+ return 0;
+
+i2c_error:
+ TWI_StopTransmission();
+ return 1;
+}
+
+void rda1846_init(void)
+{
+ TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000));
+}