summaryrefslogtreecommitdiff
path: root/software/rda1846dongle
diff options
context:
space:
mode:
Diffstat (limited to 'software/rda1846dongle')
-rw-r--r--software/rda1846dongle/Makefile4
-rw-r--r--software/rda1846dongle/rda1846.c83
-rw-r--r--software/rda1846dongle/rda1846.h38
-rw-r--r--software/rda1846dongle/rda1846dongle.c5
4 files changed, 128 insertions, 2 deletions
diff --git a/software/rda1846dongle/Makefile b/software/rda1846dongle/Makefile
index b1a7913..f9715c2 100644
--- a/software/rda1846dongle/Makefile
+++ b/software/rda1846dongle/Makefile
@@ -22,7 +22,7 @@
NAME := rda1846dongle
BOARD_TYPE := rda1846dongle
-OBJ := $(NAME).o
+OBJ := $(NAME).o rda1846.o
LIBS := util led lufa-descriptor-usbserial usbio
EXTERNAL_LIBS := lufa
@@ -40,6 +40,6 @@ LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT
LUFA_OPTS += -D USB_MANUFACTURER="L\"mur.sat\""
LUFA_OPTS += -D USB_PRODUCT="L\"$(NAME)\""
-LUFA_COMPONENTS := USB USBCLASS
+LUFA_COMPONENTS := USB USBCLASS TWI
include ../avr.include.mk
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));
+}
diff --git a/software/rda1846dongle/rda1846.h b/software/rda1846dongle/rda1846.h
new file mode 100644
index 0000000..e320fd3
--- /dev/null
+++ b/software/rda1846dongle/rda1846.h
@@ -0,0 +1,38 @@
+/*
+ *
+ * mur.sat
+ *
+ * Somewhen in the year 2012, mur.at will have a nano satellite launched
+ * into a low earth orbit (310 km above the surface of our planet). The
+ * satellite itself is a TubeSat personal satellite kit, developed and
+ * launched by interorbital systems. mur.sat is a joint venture of mur.at,
+ * ESC im Labor and realraum.
+ *
+ * Please visit the project hompage at sat.mur.at for further information.
+ *
+ *
+ * Copyright (C) 2013 Christian Pointner <equinox@mur.at>
+ *
+ * This file is part of mur.sat.
+ *
+ * mur.sat 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.
+ *
+ * mur.sat 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 mur.sat. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MURSAT_rda1846_h_INCLUDED
+#define MURSAT_rda1846_h_INCLUDED
+
+void rda1846_init(void);
+
+#endif
diff --git a/software/rda1846dongle/rda1846dongle.c b/software/rda1846dongle/rda1846dongle.c
index 421ee86..618b7ea 100644
--- a/software/rda1846dongle/rda1846dongle.c
+++ b/software/rda1846dongle/rda1846dongle.c
@@ -39,6 +39,8 @@
#include "util.h"
#include "usbio.h"
+#include "rda1846.h"
+
void handle_cmd(uint8_t cmd)
{
switch(cmd) {
@@ -59,6 +61,9 @@ int main(void)
cpu_init();
led_init();
usbio_init();
+
+ rda1846_init();
+
sei();
for(;;) {