summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-02-27 23:35:54 +0000
committerChristian Pointner <equinox@mur.at>2013-02-27 23:35:54 +0000
commitb6f033950171192fe8069b258757971c85c451c1 (patch)
tree12532cc3705e4e00d2d59beeb1e59a879136a945 /software
parentrda146dongle: raw read and write finished (diff)
rda1846dongle: added support for register writes beyond 0x7F
git-svn-id: https://svn.spreadspace.org/mur.sat@685 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software')
-rw-r--r--software/rda1846dongle/rda1846.c48
-rw-r--r--software/rda1846dongle/rda1846.h2
2 files changed, 41 insertions, 9 deletions
diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c
index 5277d3e..eaa0fbc 100644
--- a/software/rda1846dongle/rda1846.c
+++ b/software/rda1846dongle/rda1846.c
@@ -29,12 +29,10 @@
#define RDA1846_CHIP_ADDR 0xE2
#define RDA1846_ADDR_W (0<<7)
#define RDA1846_ADDR_R (1<<7)
+#define RDA1846_ADDR_LIMIT 0x7F
-uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data)
+static uint8_t rda1846_write_register_raw(const uint8_t addr, const uint16_t data)
{
- if(addr >= 0x7F) // no support for this at the moment !!!
- return 255;
-
if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_WRITE,10) != TWI_ERROR_NoError)
return 1;
@@ -53,11 +51,8 @@ i2c_error:
return 1;
}
-uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
+static uint8_t rda1846_read_register_raw(const uint8_t addr, uint16_t* data)
{
- if(addr >= 0x7F) // no support for this at the moment !!!
- return 255;
-
if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_WRITE,10) != TWI_ERROR_NoError)
return 1;
if(!TWI_SendByte(addr | RDA1846_ADDR_R))
@@ -71,7 +66,7 @@ uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
*data = tmp << 8;
if(!TWI_ReceiveByte(&tmp, 1))
goto i2c_error;
- data |= tmp;
+ *data |= tmp;
TWI_StopTransmission();
return 0;
@@ -81,7 +76,42 @@ i2c_error:
return 1;
}
+
void rda1846_init(void)
{
TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000));
}
+
+uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data)
+{
+ if(addr < RDA1846_ADDR_LIMIT)
+ return rda1846_write_register_raw(addr, data);
+
+ if(addr > RDA1846_ADDR_LIMIT) {
+ uint8_t ret = rda1846_write_register_raw(RDA1846_ADDR_LIMIT, 1);
+ if(ret) return ret;
+
+ ret = rda1846_write_register_raw(addr, data);
+ if(ret) return ret;
+
+ return rda1846_write_register_raw(RDA1846_ADDR_LIMIT, 0);
+ }
+ return 1;
+}
+
+uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data)
+{
+ if(addr < RDA1846_ADDR_LIMIT)
+ return rda1846_read_register_raw(addr, data);
+
+ if(addr > RDA1846_ADDR_LIMIT) {
+ uint8_t ret = rda1846_write_register_raw(RDA1846_ADDR_LIMIT, 1);
+ if(ret) return ret;
+
+ ret = rda1846_read_register_raw(addr, data);
+ if(ret) return ret;
+
+ return rda1846_write_register_raw(RDA1846_ADDR_LIMIT, 0);
+ }
+ return 1;
+}
diff --git a/software/rda1846dongle/rda1846.h b/software/rda1846dongle/rda1846.h
index e320fd3..1d2a2ae 100644
--- a/software/rda1846dongle/rda1846.h
+++ b/software/rda1846dongle/rda1846.h
@@ -34,5 +34,7 @@
#define MURSAT_rda1846_h_INCLUDED
void rda1846_init(void);
+uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data);
+uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data);
#endif